package com.iamberry.wechat.handles.admin; import com.iamberry.wechat.core.entity.PageBean; import com.iamberry.wechat.core.entity.ResultMsg; import com.iamberry.wechat.core.entity.agentInfo.AgentConfig; import com.iamberry.wechat.core.entity.agentInfo.AgentTooth; import com.iamberry.wechat.core.entity.product.ProductColor; import com.iamberry.wechat.face.agentInfo.AgentInfoService; import com.iamberry.wechat.face.porduct.ProductColorService; import com.iamberry.wechat.tools.ResultInfo; 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 org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 代理商逻辑处理类 * Created by liuzhiwei on 2017/10/11. */ @Controller @RequestMapping("/admin/agentTooth") public class AdminAgentToothHandler { @Autowired private AgentInfoService agentInfoService; @Autowired private ProductColorService productColorService; /** * 分页查询代理商优惠价配置信息 * @param request * @param pageSize * @param pageNO * @return * @throws Exception */ @RequestMapping("/select_agent_config_list") public ModelAndView selectAgentConfigList(HttpServletRequest request, @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize, @RequestParam(value = "pageNO", defaultValue = "1", required = false) Integer pageNO) throws Exception { AgentConfig config = new AgentConfig(); ModelAndView mv = new ModelAndView("admin/agentInfo/agentConfigList"); StringBuilder url = new StringBuilder("/admin/agentTooth/select_agent_config_list?pageSize="); url.append(pageSize); String agentName = request.getParameter("agentName"); String agentTel = request.getParameter("agentTel"); String productName = request.getParameter("productName"); String colorName = request.getParameter("colorName"); if (StringUtils.isNotEmpty(agentName)) { config.setAgentName(agentName); url.append("&agentName="); url.append(agentName); mv.addObject("agentName",agentName); } if (StringUtils.isNotEmpty(agentTel)) { config.setAgentTel(agentTel); url.append("&agentTel="); url.append(agentTel); mv.addObject("agentTel",agentTel); } if (StringUtils.isNotEmpty(productName)) { config.setProductName(productName); url.append("&productName="); url.append(productName); mv.addObject("productName",productName); } if (StringUtils.isNotEmpty(colorName)) { config.setColorName(colorName); url.append("&colorName="); url.append(colorName); mv.addObject("colorName",colorName); } PageBean page = new PageBean(); page.setPageSize(pageSize); page.setPageNumber(pageNO); page.initRecordBegin(); config.setPage(page); url.append("&pageNO="); //查询代理商配置金额集合 List configList = agentInfoService.listAgentConfig(config); mv.addObject("configList", configList); mv.addObject("pageNO", pageNO); mv.addObject("pageSize", agentInfoService.listAgentConfigCount(config)); mv.addObject("url",url.toString()); return mv; } /** * 进入添加代理商优惠价配置页面 * @param request * @return * @throws Exception */ @RequestMapping("/_add_agent_config") public ModelAndView addAgentConfigUI(HttpServletRequest request) throws Exception { ModelAndView mv = new ModelAndView("admin/agentInfo/addAgentConfig"); return mv; } /** * 查询商品列表 * @param request * @return * @throws Exception */ @ResponseBody @RequestMapping("/select_agent_and_product") public ResultMsg selectAgentAndProduct(HttpServletRequest request) throws Exception { ResultMsg msg = new ResultMsg(); Map map = new HashMap(); ProductColor productColor = new ProductColor(); productColor.setPage(null); //查询产品颜色集合 List colorList = productColorService.selectProductColorList(productColor); AgentTooth agent = new AgentTooth(); agent.setAgentStatus(1); //查询代理商集合 List agentList = agentInfoService.listAgentTooth(agent); map.put("colorList",colorList); map.put("agentList",agentList); msg.setData(map); msg.setStatus(true); msg.setResultCode(ResultInfo.SUCCESSCODE); return msg; } /** * 添加代理商优惠价配置信息 * @param request * @return * @throws Exception */ @ResponseBody @RequestMapping("/add_agent_config") public ResultMsg addAgentConfig(HttpServletRequest request) throws Exception { ResultMsg msg = new ResultMsg(); String productColor = request.getParameter("productColor"); String agentId = request.getParameter("sel_agent"); if (!StringUtils.isNotEmpty(productColor)) { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); msg.setMessage("您没有输入优惠价请重新输入!"); } if (!StringUtils.isNotEmpty(agentId)) { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); msg.setMessage("您没有选择代理商,请选择!"); } //拆分产品id和金额 String[] productPrice = productColor.split(","); List list = new ArrayList(); for (int i = 0;i < productPrice.length;i++) { String[] color = productPrice[i].split(":"); AgentConfig config = new AgentConfig(); config.setAgentId(Integer.parseInt(agentId)); config.setColorId(Integer.parseInt(color[0])); config.setConfigAmount(Integer.parseInt(color[1])); config.setConfigStatus(1); list.add(config); } int num = agentInfoService.addAgentConfigList(list); if (num > 0) { msg.setResultCode(ResultInfo.SUCCESSCODE); msg.setStatus(true); return msg; } else { msg.setResultCode(ResultInfo.ERRORCODE); msg.setMessage("添加代理商优惠价失败!"); msg.setStatus(false); return msg; } } /** * 进入修改代理商优惠价页面 * @param request * @return * @throws Exception */ @RequestMapping("/_update_agent_config") public ModelAndView updateAgentConfig(HttpServletRequest request) throws Exception { String configId = request.getParameter("configId"); ModelAndView mv = new ModelAndView("admin/agentInfo/updateAgentConfig"); mv.addObject("configId",configId); return mv; } /** * 获取代理商优惠价和产品信息 * @param request * @return * @throws Exception */ @ResponseBody @RequestMapping("/get_agent_config_By_Id") public ResultMsg getAgentConfigById(HttpServletRequest request) throws Exception{ ResultMsg msg = new ResultMsg(); Map map = new HashMap(); String configId = request.getParameter("configId"); if (!StringUtils.isNotEmpty(configId)) { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); msg.setMessage("该配置信息不存在!"); } AgentConfig config = new AgentConfig(); config.setConfigId(Integer.parseInt(configId)); config.setPage(null); //查询代理商配置金额集合 List configList = agentInfoService.listAgentConfig(config); ProductColor productColor = new ProductColor(); productColor.setPage(null); //查询产品颜色集合 List colorList = productColorService.selectProductColorList(productColor); AgentTooth agent = new AgentTooth(); agent.setAgentStatus(1); //查询代理商集合 List agentList = agentInfoService.listAgentTooth(agent); map.put("colorList",colorList); map.put("agentList",agentList); map.put("config",configList.get(0)); msg.setData(map); msg.setResultCode(ResultInfo.SUCCESSCODE); msg.setStatus(true); return msg; } /** * 修改代理商优惠价信息 * @param request * @param config * @return * @throws Exception */ @ResponseBody @RequestMapping("/update_agent_config") public ResultMsg updateAgentConfig(HttpServletRequest request,AgentConfig config) throws Exception{ ResultMsg msg = new ResultMsg(); if (!StringUtils.isNotEmpty(config.getConfigId().toString())) { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); msg.setMessage("修改代理商优惠价配置失败!"); } //修改代理商优惠价配置信息 int num = agentInfoService.updateAgentConfig(config); if (num > 0) { msg.setResultCode(ResultInfo.SUCCESSCODE); msg.setStatus(true); } else { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); } return msg; } /** * 修改代理商优惠价配置的状态 * @param request * @return * @throws Exception */ @ResponseBody @RequestMapping("/update_agent_config_status") public ResultMsg updateAgentConfigStatus(HttpServletRequest request) throws Exception { ResultMsg msg = new ResultMsg(); String configId = request.getParameter("configId"); String configStatus = request.getParameter("configStatus"); AgentConfig config = new AgentConfig(); if (!StringUtils.isNotEmpty(configId)) { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); return msg; } if (!StringUtils.isNotEmpty(configStatus)) { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); return msg; } config.setConfigId(Integer.parseInt(configId)); config.setConfigStatus(Integer.parseInt(configStatus)); //修改代理商优惠价配置信息 int num = agentInfoService.updateAgentConfig(config); if (num > 0) { msg.setResultCode(ResultInfo.SUCCESSCODE); msg.setStatus(true); } else { msg.setResultCode(ResultInfo.ERRORCODE); msg.setStatus(false); } return msg; } }