123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- package com.caimei.modules.newhome.web;
- import com.caimei.modules.hehe.util.UploadPicUtils;
- import com.caimei.modules.newhome.entity.NewPageFirstNavigation;
- import com.caimei.modules.newhome.service.NewPageFirstNavigationService;
- import com.caimei.modules.opensearch.GenerateUtils;
- import com.caimei.redis.RedisService;
- import com.google.common.collect.Maps;
- import com.thinkgem.jeesite.common.config.Global;
- import com.thinkgem.jeesite.common.persistence.Page;
- import com.thinkgem.jeesite.common.utils.StringUtils;
- import com.thinkgem.jeesite.common.web.BaseController;
- import org.apache.commons.collections.CollectionUtils;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.ModelAttribute;
- 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.mvc.support.RedirectAttributes;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import static com.caimei.modules.newhome.web.NewPageQualitySupplierController.isInteger;
- /**
- * 新首页一级导航栏Controller
- *
- * @author lwt
- * @version 2019-03-14
- */
- @Controller
- @RequestMapping(value = "${adminPath}/newhome/newPageFirstNavigation")
- public class NewPageFirstNavigationController extends BaseController {
- @Resource
- private NewPageFirstNavigationService newPageFirstNavigationService;
- @Resource
- private RedisService redisService;
- @Resource
- private GenerateUtils generateUtils;
- @ModelAttribute
- public NewPageFirstNavigation get(@RequestParam(required = false) String id) {
- NewPageFirstNavigation entity = null;
- if (StringUtils.isNotBlank(id)) {
- entity = newPageFirstNavigationService.get(id);
- }
- if (entity == null) {
- entity = new NewPageFirstNavigation();
- }
- return entity;
- }
- @RequiresPermissions("newhome:newPageFirstNavigation:view")
- @RequestMapping(value = {"list", ""})
- public String list(NewPageFirstNavigation newPageFirstNavigation, HttpServletRequest request, HttpServletResponse response, Model model) {
- newPageFirstNavigation.setStatisticsType("4");
- Page<NewPageFirstNavigation> page = newPageFirstNavigationService.findPage(new Page<NewPageFirstNavigation>(request, response), newPageFirstNavigation);
- model.addAttribute("page", page);
- model.addAttribute("newPageFirstNavigation", newPageFirstNavigation);
- return "modules/newhome/newPageFirstNavigationList";
- }
- @RequiresPermissions("newhome:newPageFirstNavigation:view")
- @RequestMapping(value = "form")
- public String form(NewPageFirstNavigation newPageFirstNavigation, Model model) {
- model.addAttribute("newPageFirstNavigation", newPageFirstNavigation);
- return "modules/newhome/newPageFirstNavigationForm";
- }
- @RequiresPermissions("newhome:newPageFirstNavigation:edit")
- @RequestMapping(value = "save")
- public String save(NewPageFirstNavigation newPageFirstNavigation, Model model, RedirectAttributes redirectAttributes) {
- if (!beanValidator(model, newPageFirstNavigation)) {
- return form(newPageFirstNavigation, model);
- }
- //判断如果已经存在10条数据则不允许添加(产品控制数量显示)
- NewPageFirstNavigation navigation = new NewPageFirstNavigation();
- navigation.setType(newPageFirstNavigation.getType());
- List<NewPageFirstNavigation> list = newPageFirstNavigationService.findList(navigation);
- if (StringUtils.isEmpty(newPageFirstNavigation.getId())) {
- if (CollectionUtils.isNotEmpty(list) && list.size() >= 10) {
- addMessage(model, "最多添加10个主菜单!删除旧菜单后才能继续添加");
- return form(newPageFirstNavigation, model);
- }
- }
- //上传图片
- String image = newPageFirstNavigation.getIcon();
- image = UploadPicUtils.saveImageToServer(image);
- newPageFirstNavigation.setIcon(image);
- if (StringUtils.isEmpty(newPageFirstNavigation.getId())) {
- newPageFirstNavigation.setCreateDate(new Date());
- newPageFirstNavigationService.insert(newPageFirstNavigation);
- } else {
- newPageFirstNavigation.setUpdateDate(new Date());
- newPageFirstNavigationService.update(newPageFirstNavigation);
- }
- addMessage(redirectAttributes, "保存成功");
- cleanRedisCache();// 清理redis缓存
- return "redirect:" + Global.getAdminPath() + "/newhome/newPageFirstNavigation/?repage&type="+newPageFirstNavigation.getType();
- }
- @RequiresPermissions("newhome:newPageFirstNavigation:delete")
- @RequestMapping(value = "delete")
- public String delete(NewPageFirstNavigation newPageFirstNavigation, RedirectAttributes redirectAttributes) {
- Date date = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
- String str = sdf.format(date);
- newPageFirstNavigation.setDelFlag(str);
- newPageFirstNavigationService.delete(newPageFirstNavigation);
- addMessage(redirectAttributes, "删除成功");
- cleanRedisCache();// 清理redis缓存
- return "redirect:" + Global.getAdminPath() + "/newhome/newPageFirstNavigation/?repage&type="+newPageFirstNavigation.getType();
- }
- @RequiresPermissions("newhome:newPageFirstNavigation:edit")
- @ResponseBody
- @RequestMapping(value = "updateEnabledStatus")
- public Map<String, Object> updateEnabledStatus(String enabledStatus, String[] ids, String www, String[] supplierIDs, HttpServletRequest request, HttpServletResponse response) {
- Map<String, Object> map = Maps.newLinkedHashMap();
- try {
- newPageFirstNavigationService.updateEnabledStatusByIds(enabledStatus, ids);
- map.put("success", true);
- map.put("msg", "修改成功");
- cleanRedisCache();// 清理缓存
- } catch (Exception e) {
- logger.debug(e.toString(), e);
- map.put("success", false);
- map.put("msg", "修改失败");
- }
- return map;
- }
- @RequiresPermissions("newhome:newPageFirstNavigation:edit")
- @ResponseBody
- @RequestMapping(value = "updateCrmEnabledStatusByIds")
- public Map<String, Object> updateCrmEnabledStatusByIds(String crmEnabledStatus, String[] ids, String crm, String[] supplierIDs, HttpServletRequest request, HttpServletResponse response) {
- Map<String, Object> map = Maps.newLinkedHashMap();
- try {
- newPageFirstNavigationService.updateCrmEnabledStatusByIds(crmEnabledStatus, ids);
- map.put("success", true);
- map.put("msg", "修改成功");
- cleanRedisCache();// 清理缓存
- } catch (Exception e) {
- logger.debug(e.toString(), e);
- map.put("success", false);
- map.put("msg", "修改失败");
- }
- return map;
- }
- /**
- * 批量更新排序值
- */
- @RequestMapping(value = "batchSaveSort")
- @ResponseBody
- public Map<String, Object> batchSaveSort(String sortList) {
- Map<String, Object> map = Maps.newLinkedHashMap();
- try {
- String[] newPageLists = sortList.split(",");
- for (String list : newPageLists) {
- String[] split = list.split("-");
- if (split.length == 1 || split.length < 1) {
- String id = split[0];
- String sort = null;
- newPageFirstNavigationService.saveSort(sort, id);
- } else {
- String id = split[0];
- String sort = split[1];
- if (isInteger(sort)) {
- if (StringUtils.equals("0", sort)) {
- map.put("success", false);
- map.put("msg", "排序值只能填写大于等于1的整数");
- return map;
- }
- newPageFirstNavigationService.saveSort(sort, id);
- } else {
- map.put("success", false);
- map.put("msg", "排序值只能为数字");
- return map;
- }
- }
- }
- cleanRedisCache();
- map.put("success", true);
- map.put("msg", "更新排序成功");
- return map;
- } catch (Exception e) {
- map.put("success", false);
- map.put("msg", "更新排序失败");
- return map;
- }
- }
- /**
- * 生成静态首页
- */
- @RequestMapping(value = "updateStaticHome")
- @ResponseBody
- public Map<String, Object> updateStaticHome(){
- Map<String, Object> map = Maps.newLinkedHashMap();
- try {
- //首页缓存
- redisService.removePattern("getNavMenu*");
- redisService.removePattern("getClassify*");
- redisService.removePattern("getCommodityClassify*");
- redisService.removePattern("getHomeData*");
- redisService.removePattern("getHomeCommodityData*");
- //清除产品仪器缓存
- redisService.removePattern("instrumentData*");
- redisService.removePattern("insCommodityData*");
- // 重新生成静态首页
- generateUtils.generateHome();
- // 重新生成静态产品仪器页
- generateUtils.generateProductType(286);
- generateUtils.generateProductType(287);
- map.put("success", true);
- map.put("msg", "手动生成静态首页成功");
- return map;
- } catch (Exception e) {
- map.put("success", false);
- map.put("msg", "手动生成静态首页失败");
- return map;
- }
- }
- /**
- * 有数据变动时需要清除缓存
- */
- public void cleanRedisCache() {
- //首页导航栏缓存
- String getNavMenu = "getNavMenu*";
- redisService.removePattern(getNavMenu);
- // 重新生成静态首页
- generateUtils.generateHome();
- // 重新生成静态产品仪器页
- generateUtils.generateProductType(286);
- generateUtils.generateProductType(287);
- }
- }
|