|
@@ -0,0 +1,268 @@
|
|
|
+package com.caimei.modules.newhome.web;
|
|
|
+
|
|
|
+import com.caimei.modules.newhome.entity.NewPageZone;
|
|
|
+import com.caimei.modules.newhome.service.NewPageZoneService;
|
|
|
+import com.caimei.modules.opensearch.GenerateUtils;
|
|
|
+import com.caimei.modules.product.entity.Product;
|
|
|
+import com.caimei.modules.product.service.ProductService;
|
|
|
+import com.caimei.redis.RedisService;
|
|
|
+import com.caimei.utils.AppUtils;
|
|
|
+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.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static com.caimei.modules.newhome.web.NewPageQualitySupplierController.isInteger;
|
|
|
+
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/newhome/newPageZone")
|
|
|
+public class NewPageZoneController extends BaseController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private NewPageZoneService newPageZoneService;
|
|
|
+ @Resource
|
|
|
+ private ProductService productService;
|
|
|
+ @Resource
|
|
|
+ private RedisService redisService;
|
|
|
+ @Resource
|
|
|
+ private GenerateUtils generateUtils;
|
|
|
+
|
|
|
+
|
|
|
+ @ModelAttribute
|
|
|
+ public NewPageZone get(@RequestParam(required = false) String id) {
|
|
|
+ NewPageZone entity = null;
|
|
|
+ if (StringUtils.isNotBlank(id)) {
|
|
|
+ entity = newPageZoneService.get(id);
|
|
|
+ }
|
|
|
+ if (entity == null) {
|
|
|
+ entity = new NewPageZone();
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("newhome:newPageZone:view")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(NewPageZone newPageZone, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
+ Page<NewPageZone> page = newPageZoneService.findPage(new Page<NewPageZone>(request, response), newPageZone);
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ return "modules/newhome/newPageZoneList";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "productList")
|
|
|
+ public String productList(Integer zoneId, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
+ Page<Product> page = new Page<Product>(request, response);
|
|
|
+ if (0 == page.getPageSize() || -1 == page.getPageSize()) page.setPageSize(20);
|
|
|
+ if (0 == page.getPageNo()) page.setPageNo(1);
|
|
|
+ //获取组合列表
|
|
|
+ List<Product> list = newPageZoneService.findZoneProductList(zoneId, page);
|
|
|
+ page.setList(list);
|
|
|
+ model.addAttribute("zoneId", zoneId);
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ return "modules/newhome/zoneProductList";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "toAddProduct")
|
|
|
+ public String toAddProduct(Product product, Page page, Model model) {
|
|
|
+ //获取采美所有商品
|
|
|
+ if (0 == page.getPageSize() || -1 == page.getPageSize()) page.setPageSize(30);
|
|
|
+ if (0 == page.getPageNo()) page.setPageNo(1);
|
|
|
+ product.setPage(page);
|
|
|
+ List<Product> productList = newPageZoneService.findProductList(product);
|
|
|
+ if (CollectionUtils.isNotEmpty(productList)) {
|
|
|
+ for (Product p : productList) {
|
|
|
+ p.setMainImage(AppUtils.getProductImageURL(p.getMainImage(), 0, Global.getConfig("wwwServer")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ page.setList(productList);
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ model.addAttribute("Product", product);
|
|
|
+ return "modules/newhome/toSelectProduct";
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "saveAddProduct")
|
|
|
+ public Map<String, Object> saveAddProduct(Product product) {
|
|
|
+ Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
+ try {
|
|
|
+ String[] split = product.getProductIds().split(",");
|
|
|
+ //保存商品添加的组合
|
|
|
+ newPageZoneService.addProducts(split, product.getZoneId());
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "添加成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("msg", "添加失败");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequiresPermissions("newhome:newPageZone:view")
|
|
|
+ @RequestMapping(value = "form")
|
|
|
+ public String form(NewPageZone newPageZone, Model model) {
|
|
|
+ model.addAttribute("newPageZone", newPageZone);
|
|
|
+ return "modules/newhome/newPageZoneForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "save")
|
|
|
+ public String save(Integer floor, NewPageZone newPageZone, Model model, RedirectAttributes redirectAttributes) {
|
|
|
+ if (!beanValidator(model, newPageZone)) {
|
|
|
+ return form(newPageZone, model);
|
|
|
+ }
|
|
|
+ newPageZoneService.save(newPageZone);
|
|
|
+ cleanRedisCache();
|
|
|
+ addMessage(redirectAttributes, "保存楼层管理成功");
|
|
|
+ if (floor != null) {
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/newhome/newPageZone/lists";
|
|
|
+ } else {
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/newhome/newPageZone";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
+ public String delete(Integer floor, NewPageZone newPageZone, RedirectAttributes redirectAttributes) {
|
|
|
+ newPageZoneService.delete(newPageZone);
|
|
|
+ cleanRedisCache();
|
|
|
+ addMessage(redirectAttributes, "删除楼层管理成功");
|
|
|
+ if (floor != null) {
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/newhome/newPageZone/lists";
|
|
|
+ } else {
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/newhome/newPageZone/?repage";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "updateEnabledStatus")
|
|
|
+ public Map<String, Object> updateEnabledStatus(String enabledStatus, String[] ids, String[] supplierIDs, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
+ try {
|
|
|
+ newPageZoneService.updateEnabledStatusByIds(enabledStatus, ids);
|
|
|
+ cleanRedisCache();
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "修改成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.debug(e.toString(), e);
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("msg", "修改失败");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "updateCrmEnabledStatusByIds")
|
|
|
+ public Map<String, Object> updateCrmEnabledStatusByIds(String crmEnabledStatus, String[] ids, String[] supplierIDs, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
+ try {
|
|
|
+ newPageZoneService.updateCrmEnabledStatusByIds(crmEnabledStatus, ids);
|
|
|
+ cleanRedisCache();
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "修改成功");
|
|
|
+ } 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, Integer zoneId) {
|
|
|
+ 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;
|
|
|
+ newPageZoneService.saveSort(sort, id, zoneId);
|
|
|
+ } 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;
|
|
|
+ }
|
|
|
+ newPageZoneService.saveSort(sort, id, zoneId);
|
|
|
+ } 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("/addProductImage")
|
|
|
+ public String addProductImage(Product product, Model model, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ product.setValidFlag("2");
|
|
|
+ Page<Product> page = productService.findProductImage(new Page<Product>(request, response), product);
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ model.addAttribute("productCategory", product.getProductCategory());
|
|
|
+ model.addAttribute("productIds", product.getProductIds());
|
|
|
+ return "modules/newhome/addProductImage";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "deleteProduct")
|
|
|
+ public String productDel(Integer productId, Integer zoneId, RedirectAttributes redirectAttributes) {
|
|
|
+ newPageZoneService.productDel(productId,zoneId);
|
|
|
+ addMessage(redirectAttributes, "删除成功");
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/newhome/newPageZone/productList?zoneId=" + zoneId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 有数据变动时需要清除缓存
|
|
|
+ */
|
|
|
+ public void cleanRedisCache() {
|
|
|
+ //清除活动专题缓存
|
|
|
+ redisService.removePattern("getPageFloorData*");
|
|
|
+ //清除活动专题缓存
|
|
|
+ redisService.removePattern("activityData*");
|
|
|
+ //清除产品仪器缓存
|
|
|
+ redisService.removePattern("instrumentData*");
|
|
|
+ redisService.removePattern("insCommodityData*");
|
|
|
+ //首页缓存
|
|
|
+ String homeData = "getHomeData*";
|
|
|
+ redisService.removePattern(homeData);
|
|
|
+ redisService.removePattern("getHomeCommodityData*");
|
|
|
+ // 重新生成静态首页
|
|
|
+ generateUtils.generateHome();
|
|
|
+
|
|
|
+ }
|
|
|
+}
|