NewPageFirstNavigationController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package com.caimei.modules.newhome.web;
  2. import com.caimei.modules.hehe.util.UploadPicUtils;
  3. import com.caimei.modules.newhome.entity.NewPageFirstNavigation;
  4. import com.caimei.modules.newhome.service.NewPageFirstNavigationService;
  5. import com.caimei.modules.opensearch.GenerateUtils;
  6. import com.caimei.modules.utils.DateUtil;
  7. import com.caimei.redis.RedisService;
  8. import com.google.common.collect.Maps;
  9. import com.thinkgem.jeesite.common.config.Global;
  10. import com.thinkgem.jeesite.common.persistence.Page;
  11. import com.thinkgem.jeesite.common.utils.StringUtils;
  12. import com.thinkgem.jeesite.common.web.BaseController;
  13. import org.apache.commons.collections.CollectionUtils;
  14. import org.apache.shiro.authz.annotation.RequiresPermissions;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.ui.Model;
  17. import org.springframework.web.bind.annotation.ModelAttribute;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestParam;
  20. import org.springframework.web.bind.annotation.ResponseBody;
  21. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  22. import javax.annotation.Resource;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.text.SimpleDateFormat;
  26. import java.util.Date;
  27. import java.util.List;
  28. import java.util.Map;
  29. import static com.caimei.modules.newhome.web.NewPageQualitySupplierController.isInteger;
  30. /**
  31. * 新首页一级导航栏Controller
  32. *
  33. * @author lwt
  34. * @version 2019-03-14
  35. */
  36. @Controller
  37. @RequestMapping(value = "${adminPath}/newhome/newPageFirstNavigation")
  38. public class NewPageFirstNavigationController extends BaseController {
  39. @Resource
  40. private NewPageFirstNavigationService newPageFirstNavigationService;
  41. @Resource
  42. private RedisService redisService;
  43. @Resource
  44. private GenerateUtils generateUtils;
  45. @ModelAttribute
  46. public NewPageFirstNavigation get(@RequestParam(required = false) String id) {
  47. NewPageFirstNavigation entity = null;
  48. if (StringUtils.isNotBlank(id)) {
  49. entity = newPageFirstNavigationService.get(id);
  50. }
  51. if (entity == null) {
  52. entity = new NewPageFirstNavigation();
  53. }
  54. return entity;
  55. }
  56. @RequiresPermissions("newhome:newPageFirstNavigation:view")
  57. @RequestMapping(value = {"list", ""})
  58. public String list(NewPageFirstNavigation newPageFirstNavigation, HttpServletRequest request, HttpServletResponse response, Model model) {
  59. if (null != newPageFirstNavigation.getEndPvCreateTime()) {
  60. newPageFirstNavigation.setEndPvCreateTime(DateUtil.getEndTime(newPageFirstNavigation.getEndPvCreateTime()));
  61. }
  62. newPageFirstNavigation.setStatisticsType("4");
  63. Page<NewPageFirstNavigation> page = newPageFirstNavigationService.findPage(new Page<NewPageFirstNavigation>(request, response), newPageFirstNavigation);
  64. model.addAttribute("page", page);
  65. model.addAttribute("newPageFirstNavigation", newPageFirstNavigation);
  66. return "modules/newhome/newPageFirstNavigationList";
  67. }
  68. @RequiresPermissions("newhome:newPageFirstNavigation:view")
  69. @RequestMapping(value = "form")
  70. public String form(NewPageFirstNavigation newPageFirstNavigation, Model model) {
  71. model.addAttribute("newPageFirstNavigation", newPageFirstNavigation);
  72. return "modules/newhome/newPageFirstNavigationForm";
  73. }
  74. @RequiresPermissions("newhome:newPageFirstNavigation:edit")
  75. @RequestMapping(value = "save")
  76. public String save(NewPageFirstNavigation newPageFirstNavigation, Model model, RedirectAttributes redirectAttributes) {
  77. if (!beanValidator(model, newPageFirstNavigation)) {
  78. return form(newPageFirstNavigation, model);
  79. }
  80. //判断如果已经存在10条数据则不允许添加(产品控制数量显示)
  81. NewPageFirstNavigation navigation = new NewPageFirstNavigation();
  82. navigation.setType(newPageFirstNavigation.getType());
  83. List<NewPageFirstNavigation> list = newPageFirstNavigationService.findList(navigation);
  84. if (StringUtils.isEmpty(newPageFirstNavigation.getId())) {
  85. if (CollectionUtils.isNotEmpty(list) && list.size() >= 10) {
  86. addMessage(model, "最多添加10个主菜单!删除旧菜单后才能继续添加");
  87. return form(newPageFirstNavigation, model);
  88. }
  89. }
  90. //上传图片
  91. String image = newPageFirstNavigation.getIcon();
  92. image = UploadPicUtils.saveImageToServer(image);
  93. newPageFirstNavigation.setIcon(image);
  94. if (StringUtils.isEmpty(newPageFirstNavigation.getId())) {
  95. newPageFirstNavigation.setCreateDate(new Date());
  96. newPageFirstNavigationService.insert(newPageFirstNavigation);
  97. } else {
  98. newPageFirstNavigation.setUpdateDate(new Date());
  99. newPageFirstNavigationService.update(newPageFirstNavigation);
  100. }
  101. addMessage(redirectAttributes, "保存成功");
  102. cleanRedisCache();// 清理redis缓存
  103. return "redirect:" + Global.getAdminPath() + "/newhome/newPageFirstNavigation/?repage&type="+newPageFirstNavigation.getType();
  104. }
  105. @RequiresPermissions("newhome:newPageFirstNavigation:delete")
  106. @RequestMapping(value = "delete")
  107. public String delete(NewPageFirstNavigation newPageFirstNavigation, RedirectAttributes redirectAttributes) {
  108. Date date = new Date();
  109. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  110. String str = sdf.format(date);
  111. newPageFirstNavigation.setDelFlag(str);
  112. newPageFirstNavigationService.delete(newPageFirstNavigation);
  113. addMessage(redirectAttributes, "删除成功");
  114. cleanRedisCache();// 清理redis缓存
  115. return "redirect:" + Global.getAdminPath() + "/newhome/newPageFirstNavigation/?repage&type="+newPageFirstNavigation.getType();
  116. }
  117. @RequiresPermissions("newhome:newPageFirstNavigation:edit")
  118. @ResponseBody
  119. @RequestMapping(value = "updateEnabledStatus")
  120. public Map<String, Object> updateEnabledStatus(String enabledStatus, String[] ids, String www, String[] supplierIDs, HttpServletRequest request, HttpServletResponse response) {
  121. Map<String, Object> map = Maps.newLinkedHashMap();
  122. try {
  123. newPageFirstNavigationService.updateEnabledStatusByIds(enabledStatus, ids);
  124. map.put("success", true);
  125. map.put("msg", "修改成功");
  126. cleanRedisCache();// 清理缓存
  127. } catch (Exception e) {
  128. logger.debug(e.toString(), e);
  129. map.put("success", false);
  130. map.put("msg", "修改失败");
  131. }
  132. return map;
  133. }
  134. @RequiresPermissions("newhome:newPageFirstNavigation:edit")
  135. @ResponseBody
  136. @RequestMapping(value = "updateCrmEnabledStatusByIds")
  137. public Map<String, Object> updateCrmEnabledStatusByIds(String crmEnabledStatus, String[] ids, String crm, String[] supplierIDs, HttpServletRequest request, HttpServletResponse response) {
  138. Map<String, Object> map = Maps.newLinkedHashMap();
  139. try {
  140. newPageFirstNavigationService.updateCrmEnabledStatusByIds(crmEnabledStatus, ids);
  141. map.put("success", true);
  142. map.put("msg", "修改成功");
  143. cleanRedisCache();// 清理缓存
  144. } catch (Exception e) {
  145. logger.debug(e.toString(), e);
  146. map.put("success", false);
  147. map.put("msg", "修改失败");
  148. }
  149. return map;
  150. }
  151. /**
  152. * 批量更新排序值
  153. */
  154. @RequestMapping(value = "batchSaveSort")
  155. @ResponseBody
  156. public Map<String, Object> batchSaveSort(String sortList) {
  157. Map<String, Object> map = Maps.newLinkedHashMap();
  158. try {
  159. String[] newPageLists = sortList.split(",");
  160. for (String list : newPageLists) {
  161. String[] split = list.split("-");
  162. if (split.length == 1 || split.length < 1) {
  163. String id = split[0];
  164. String sort = null;
  165. newPageFirstNavigationService.saveSort(sort, id);
  166. } else {
  167. String id = split[0];
  168. String sort = split[1];
  169. if (isInteger(sort)) {
  170. if (StringUtils.equals("0", sort)) {
  171. map.put("success", false);
  172. map.put("msg", "排序值只能填写大于等于1的整数");
  173. return map;
  174. }
  175. newPageFirstNavigationService.saveSort(sort, id);
  176. } else {
  177. map.put("success", false);
  178. map.put("msg", "排序值只能为数字");
  179. return map;
  180. }
  181. }
  182. }
  183. cleanRedisCache();
  184. map.put("success", true);
  185. map.put("msg", "更新排序成功");
  186. return map;
  187. } catch (Exception e) {
  188. map.put("success", false);
  189. map.put("msg", "更新排序失败");
  190. return map;
  191. }
  192. }
  193. /**
  194. * 生成静态首页
  195. */
  196. @RequestMapping(value = "updateStaticHome")
  197. @ResponseBody
  198. public Map<String, Object> updateStaticHome(){
  199. Map<String, Object> map = Maps.newLinkedHashMap();
  200. try {
  201. //首页缓存
  202. redisService.removePattern("getNavMenu*");
  203. redisService.removePattern("getClassify*");
  204. redisService.removePattern("getCommodityClassify*");
  205. redisService.removePattern("getHomeData*");
  206. redisService.removePattern("getHomeCommodityData*");
  207. //清除产品仪器缓存
  208. redisService.removePattern("instrumentData*");
  209. redisService.removePattern("insCommodityData*");
  210. // 重新生成静态首页
  211. generateUtils.generateHome();
  212. // 重新生成静态产品仪器页
  213. generateUtils.generateProductType(286);
  214. generateUtils.generateProductType(287);
  215. map.put("success", true);
  216. map.put("msg", "手动生成静态首页成功");
  217. return map;
  218. } catch (Exception e) {
  219. map.put("success", false);
  220. map.put("msg", "手动生成静态首页失败");
  221. return map;
  222. }
  223. }
  224. /**
  225. * 有数据变动时需要清除缓存
  226. */
  227. public void cleanRedisCache() {
  228. //首页导航栏缓存
  229. String getNavMenu = "getNavMenu*";
  230. redisService.removePattern(getNavMenu);
  231. // 重新生成静态首页
  232. generateUtils.generateHome();
  233. // 重新生成静态产品仪器页
  234. generateUtils.generateProductType(286);
  235. generateUtils.generateProductType(287);
  236. }
  237. }