package cn.pluss.platform.controller.wxCityInfo;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.WxCityInfo;
import cn.pluss.platform.util.StringUtil;
import cn.pluss.platform.wxCityInfo.WxCityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
@RequestMapping("wxCityInfo")
public class WxCityInfoController extends BaseNoModelController {

    private Integer PAGE_SIZE = 12;

    @Autowired
    private WxCityInfoService wxCityInfoService;

    /**
     * 引导页
     *
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index() {

        return "wxCityInfo/wxCityInfoList";
    }

    /**
     * 分页查询
     */
    @RequestMapping(value = "/queryWxCityInfoByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryWxCityInfoByPage(Integer currPage, Integer id) {

        if (currPage == null) {
            currPage = 1;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pageSize", PAGE_SIZE);
        map.put("offset", (currPage - 1) * PAGE_SIZE);
        map.put("id", id);
        List<WxCityInfo> wxCityInfoList = wxCityInfoService.queryWxCityInfoPage(map);
        Integer count = wxCityInfoService.queryWxCityInfoPageCount(map);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("wxCityInfoList", wxCityInfoList);
        result.put("count", count);
        result.put("pageCount", StringUtil.getPageCount(count, PAGE_SIZE));
        result.put("currPage", currPage);
        return result;
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryWxCityInfoDetails", method = RequestMethod.GET)
    public String queryWxCityInfoDetails(HttpServletRequest request, Integer id, Integer pageIndex) {

        if (id != null && id != 0) {
            WxCityInfo wxCityInfo = new WxCityInfo();
            wxCityInfo.setId(id);
            wxCityInfo = wxCityInfoService.queryWxCityInfo(wxCityInfo);
            request.setAttribute("wxCityInfo", wxCityInfo);
            request.setAttribute("pageIndex", pageIndex);
        }
        return "wxCityInfo/wxCityInfoDetails";
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryWxCityInfoBaseInfo", method = RequestMethod.GET)
    public String queryWxCityInfoBaseInfo(HttpServletRequest request, Integer id, Integer pageIndex) {

        if (id != null && id != 0) {
            WxCityInfo wxCityInfo = new WxCityInfo();
            wxCityInfo.setId(id);
            wxCityInfo = wxCityInfoService.queryWxCityInfo(wxCityInfo);
            request.setAttribute("wxCityInfo", wxCityInfo);
            request.setAttribute("pageIndex", pageIndex);
        }
        return "wxCityInfo/wxCityInfoBaseInfo";
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryWxCityInfoExtendsInfo", method = RequestMethod.GET)
    public String queryWxCityInfoExtendsInfo() {

        return "wxCityInfo/wxCityInfoExtendsInfo";
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryWxCityInfoFunctionsInfo", method = RequestMethod.GET)
    public String queryWxCityInfoFunctionsInfo() {

        return "wxCityInfo/wxCityInfoFunctionsInfo";
    }

    /**
     * 保存对象
     *
     * @throws IOException
     */
    @RequestMapping(value = "/saveWxCityInfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> saveWxCityInfo(WxCityInfo wxCityInfo) {

        if (wxCityInfo.getId() != null && wxCityInfo.getId() != 0) {
            wxCityInfoService.updateWxCityInfo(wxCityInfo);
        } else {
            wxCityInfoService.saveWxCityInfo(wxCityInfo);
        }
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("resultCode", "1");
        result.put("resultMessage", "保存成功!");
        return result;
    }

    /**
     * 修改对象
     *
     * @throws IOException
     */
    @RequestMapping(value = "/updateWxCityInfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateWxCityInfo(Integer id) {

        WxCityInfo wxCityInfo = new WxCityInfo();
        wxCityInfo.setId(id);
        wxCityInfoService.updateWxCityInfo(wxCityInfo);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("resultCode", "1");
        result.put("resultMessage", "保存成功!");
        return result;
    }

    /**
     * 删除对象
     *
     * @throws IOException
     */
    @RequestMapping(value = "/deleteWxCityInfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> deleteWxCityInfo(Integer id) {
        WxCityInfo wxCityInfo = new WxCityInfo();
        wxCityInfo.setId(id);
        wxCityInfoService.deleteWxCityInfo(wxCityInfo);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("resultCode", "1");
        result.put("resultMessage", "保存成功!");
        return result;
    }

}


