package com.palmnest.webapp.controller.wechat;

import com.alibaba.fastjson.JSONObject;
import com.palmnest.application.core.util.StringUtil;
import com.palmnest.service.estateserve.PushBillManager;
import com.palmnest.webapp.controller.BaseFormController;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping(value = "/wechat/billPush*")
public class BillPushWechatController extends BaseFormController {


	@Autowired
	private PushBillManager pushBillManager;

	@RequestMapping(value = "/getWechatPushBillList")
	public void getWechatPushBillList(HttpServletRequest request, HttpServletResponse response) throws Exception {

		JSONObject json   = new JSONObject();
		String     openId = request.getParameter("openId");

		if (StringUtils.isNotBlank(openId)) {

			Map<String, Object> map = new HashMap<String, Object>();

			List<Map<String, Object>> pushList = pushBillManager.getWechatPushBillList(openId);

			map.put("pushList", pushList);
			map.put("title1", this.getElementGroupManager().getElementsByGroupName("title").get(0).getItemname());
			map.put("remark1", this.getElementGroupManager().getElementsByGroupName("remark").get(0).getItemname());
			map.put("title2", this.getElementGroupManager().getElementsByGroupName("title").get(1).getItemname());
			map.put("remark2", this.getElementGroupManager().getElementsByGroupName("remark").get(1).getItemname());

			json.put("result", "success");
			json.put("message", "");
			json.put("data", map);
			StringUtil.charSet(json, request, response);
		} else {
			json.put("result", "fail");
			json.put("message", "账号不正确");
			json.put("data", "");
			StringUtil.charSet(json, request, response);
		}
	}
}
