AdminAgentToothHandler.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. package com.iamberry.wechat.handles.admin;
  2. import com.iamberry.wechat.core.entity.PageBean;
  3. import com.iamberry.wechat.core.entity.ResultMsg;
  4. import com.iamberry.wechat.core.entity.agentInfo.AgentConfig;
  5. import com.iamberry.wechat.core.entity.agentInfo.AgentTooth;
  6. import com.iamberry.wechat.core.entity.product.ProductColor;
  7. import com.iamberry.wechat.face.agentInfo.AgentInfoService;
  8. import com.iamberry.wechat.face.porduct.ProductColorService;
  9. import com.iamberry.wechat.tools.ResultInfo;
  10. import org.apache.commons.lang.StringUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import org.springframework.web.servlet.ModelAndView;
  17. import javax.servlet.http.HttpServletRequest;
  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. /**
  23. * 代理商逻辑处理类
  24. * Created by liuzhiwei on 2017/10/11.
  25. */
  26. @Controller
  27. @RequestMapping("/admin/agentTooth")
  28. public class AdminAgentToothHandler {
  29. @Autowired
  30. private AgentInfoService agentInfoService;
  31. @Autowired
  32. private ProductColorService productColorService;
  33. /**
  34. * 分页查询代理商优惠价配置信息
  35. * @param request
  36. * @param pageSize
  37. * @param pageNO
  38. * @return
  39. * @throws Exception
  40. */
  41. @RequestMapping("/select_agent_config_list")
  42. public ModelAndView selectAgentConfigList(HttpServletRequest request,
  43. @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize,
  44. @RequestParam(value = "pageNO", defaultValue = "1", required = false) Integer pageNO) throws Exception {
  45. AgentConfig config = new AgentConfig();
  46. ModelAndView mv = new ModelAndView("admin/agentInfo/agentConfigList");
  47. StringBuilder url = new StringBuilder("/admin/agentTooth/select_agent_config_list?pageSize=");
  48. url.append(pageSize);
  49. String agentName = request.getParameter("agentName");
  50. String agentTel = request.getParameter("agentTel");
  51. String productName = request.getParameter("productName");
  52. String colorName = request.getParameter("colorName");
  53. if (StringUtils.isNotEmpty(agentName)) {
  54. config.setAgentName(agentName);
  55. url.append("&agentName=");
  56. url.append(agentName);
  57. mv.addObject("agentName",agentName);
  58. }
  59. if (StringUtils.isNotEmpty(agentTel)) {
  60. config.setAgentTel(agentTel);
  61. url.append("&agentTel=");
  62. url.append(agentTel);
  63. mv.addObject("agentTel",agentTel);
  64. }
  65. if (StringUtils.isNotEmpty(productName)) {
  66. config.setProductName(productName);
  67. url.append("&productName=");
  68. url.append(productName);
  69. mv.addObject("productName",productName);
  70. }
  71. if (StringUtils.isNotEmpty(colorName)) {
  72. config.setColorName(colorName);
  73. url.append("&colorName=");
  74. url.append(colorName);
  75. mv.addObject("colorName",colorName);
  76. }
  77. PageBean page = new PageBean();
  78. page.setPageSize(pageSize);
  79. page.setPageNumber(pageNO);
  80. page.initRecordBegin();
  81. config.setPage(page);
  82. url.append("&pageNO=");
  83. //查询代理商配置金额集合
  84. List<AgentConfig> configList = agentInfoService.listAgentConfig(config);
  85. mv.addObject("configList", configList);
  86. mv.addObject("pageNO", pageNO);
  87. mv.addObject("pageSize", agentInfoService.listAgentConfigCount(config));
  88. mv.addObject("url",url.toString());
  89. return mv;
  90. }
  91. /**
  92. * 进入添加代理商优惠价配置页面
  93. * @param request
  94. * @return
  95. * @throws Exception
  96. */
  97. @RequestMapping("/_add_agent_config")
  98. public ModelAndView addAgentConfigUI(HttpServletRequest request) throws Exception {
  99. ModelAndView mv = new ModelAndView("admin/agentInfo/addAgentConfig");
  100. return mv;
  101. }
  102. /**
  103. * 查询商品列表
  104. * @param request
  105. * @return
  106. * @throws Exception
  107. */
  108. @ResponseBody
  109. @RequestMapping("/select_agent_and_product")
  110. public ResultMsg selectAgentAndProduct(HttpServletRequest request) throws Exception {
  111. ResultMsg msg = new ResultMsg();
  112. Map<String,Object> map = new HashMap<String,Object>();
  113. ProductColor productColor = new ProductColor();
  114. productColor.setPage(null);
  115. //查询产品颜色集合
  116. List<ProductColor> colorList = productColorService.selectProductColorList(productColor);
  117. AgentTooth agent = new AgentTooth();
  118. agent.setAgentStatus(1);
  119. //查询代理商集合
  120. List<AgentTooth> agentList = agentInfoService.listAgentTooth(agent);
  121. map.put("colorList",colorList);
  122. map.put("agentList",agentList);
  123. msg.setData(map);
  124. msg.setStatus(true);
  125. msg.setResultCode(ResultInfo.SUCCESSCODE);
  126. return msg;
  127. }
  128. /**
  129. * 添加代理商优惠价配置信息
  130. * @param request
  131. * @return
  132. * @throws Exception
  133. */
  134. @ResponseBody
  135. @RequestMapping("/add_agent_config")
  136. public ResultMsg addAgentConfig(HttpServletRequest request) throws Exception {
  137. ResultMsg msg = new ResultMsg();
  138. String productColor = request.getParameter("productColor");
  139. String agentId = request.getParameter("sel_agent");
  140. if (!StringUtils.isNotEmpty(productColor)) {
  141. msg.setResultCode(ResultInfo.ERRORCODE);
  142. msg.setStatus(false);
  143. msg.setMessage("您没有输入优惠价请重新输入!");
  144. }
  145. if (!StringUtils.isNotEmpty(agentId)) {
  146. msg.setResultCode(ResultInfo.ERRORCODE);
  147. msg.setStatus(false);
  148. msg.setMessage("您没有选择代理商,请选择!");
  149. }
  150. //拆分产品id和金额
  151. String[] productPrice = productColor.split(",");
  152. List<AgentConfig> list = new ArrayList<AgentConfig>();
  153. for (int i = 0;i < productPrice.length;i++) {
  154. String[] color = productPrice[i].split(":");
  155. AgentConfig config = new AgentConfig();
  156. config.setAgentId(Integer.parseInt(agentId));
  157. config.setColorId(Integer.parseInt(color[0]));
  158. config.setConfigAmount(Integer.parseInt(color[1]));
  159. config.setConfigStatus(1);
  160. list.add(config);
  161. }
  162. int num = agentInfoService.addAgentConfigList(list);
  163. if (num > 0) {
  164. msg.setResultCode(ResultInfo.SUCCESSCODE);
  165. msg.setStatus(true);
  166. return msg;
  167. } else {
  168. msg.setResultCode(ResultInfo.ERRORCODE);
  169. msg.setMessage("添加代理商优惠价失败!");
  170. msg.setStatus(false);
  171. return msg;
  172. }
  173. }
  174. /**
  175. * 进入修改代理商优惠价页面
  176. * @param request
  177. * @return
  178. * @throws Exception
  179. */
  180. @RequestMapping("/_update_agent_config")
  181. public ModelAndView updateAgentConfig(HttpServletRequest request) throws Exception {
  182. String configId = request.getParameter("configId");
  183. ModelAndView mv = new ModelAndView("admin/agentInfo/updateAgentConfig");
  184. mv.addObject("configId",configId);
  185. return mv;
  186. }
  187. /**
  188. * 获取代理商优惠价和产品信息
  189. * @param request
  190. * @return
  191. * @throws Exception
  192. */
  193. @ResponseBody
  194. @RequestMapping("/get_agent_config_By_Id")
  195. public ResultMsg getAgentConfigById(HttpServletRequest request) throws Exception{
  196. ResultMsg msg = new ResultMsg();
  197. Map<String,Object> map = new HashMap<String,Object>();
  198. String configId = request.getParameter("configId");
  199. if (!StringUtils.isNotEmpty(configId)) {
  200. msg.setResultCode(ResultInfo.ERRORCODE);
  201. msg.setStatus(false);
  202. msg.setMessage("该配置信息不存在!");
  203. }
  204. AgentConfig config = new AgentConfig();
  205. config.setConfigId(Integer.parseInt(configId));
  206. config.setPage(null);
  207. //查询代理商配置金额集合
  208. List<AgentConfig> configList = agentInfoService.listAgentConfig(config);
  209. ProductColor productColor = new ProductColor();
  210. productColor.setPage(null);
  211. //查询产品颜色集合
  212. List<ProductColor> colorList = productColorService.selectProductColorList(productColor);
  213. AgentTooth agent = new AgentTooth();
  214. agent.setAgentStatus(1);
  215. //查询代理商集合
  216. List<AgentTooth> agentList = agentInfoService.listAgentTooth(agent);
  217. map.put("colorList",colorList);
  218. map.put("agentList",agentList);
  219. map.put("config",configList.get(0));
  220. msg.setData(map);
  221. msg.setResultCode(ResultInfo.SUCCESSCODE);
  222. msg.setStatus(true);
  223. return msg;
  224. }
  225. /**
  226. * 修改代理商优惠价信息
  227. * @param request
  228. * @param config
  229. * @return
  230. * @throws Exception
  231. */
  232. @ResponseBody
  233. @RequestMapping("/update_agent_config")
  234. public ResultMsg updateAgentConfig(HttpServletRequest request,AgentConfig config) throws Exception{
  235. ResultMsg msg = new ResultMsg();
  236. if (!StringUtils.isNotEmpty(config.getConfigId().toString())) {
  237. msg.setResultCode(ResultInfo.ERRORCODE);
  238. msg.setStatus(false);
  239. msg.setMessage("修改代理商优惠价配置失败!");
  240. }
  241. //修改代理商优惠价配置信息
  242. int num = agentInfoService.updateAgentConfig(config);
  243. if (num > 0) {
  244. msg.setResultCode(ResultInfo.SUCCESSCODE);
  245. msg.setStatus(true);
  246. } else {
  247. msg.setResultCode(ResultInfo.ERRORCODE);
  248. msg.setStatus(false);
  249. }
  250. return msg;
  251. }
  252. /**
  253. * 修改代理商优惠价配置的状态
  254. * @param request
  255. * @return
  256. * @throws Exception
  257. */
  258. @ResponseBody
  259. @RequestMapping("/update_agent_config_status")
  260. public ResultMsg updateAgentConfigStatus(HttpServletRequest request) throws Exception {
  261. ResultMsg msg = new ResultMsg();
  262. String configId = request.getParameter("configId");
  263. String configStatus = request.getParameter("configStatus");
  264. AgentConfig config = new AgentConfig();
  265. if (!StringUtils.isNotEmpty(configId)) {
  266. msg.setResultCode(ResultInfo.ERRORCODE);
  267. msg.setStatus(false);
  268. return msg;
  269. }
  270. if (!StringUtils.isNotEmpty(configStatus)) {
  271. msg.setResultCode(ResultInfo.ERRORCODE);
  272. msg.setStatus(false);
  273. return msg;
  274. }
  275. config.setConfigId(Integer.parseInt(configId));
  276. config.setConfigStatus(Integer.parseInt(configStatus));
  277. //修改代理商优惠价配置信息
  278. int num = agentInfoService.updateAgentConfig(config);
  279. if (num > 0) {
  280. msg.setResultCode(ResultInfo.SUCCESSCODE);
  281. msg.setStatus(true);
  282. } else {
  283. msg.setResultCode(ResultInfo.ERRORCODE);
  284. msg.setStatus(false);
  285. }
  286. return msg;
  287. }
  288. }