|
@@ -0,0 +1,134 @@
|
|
|
|
+package com.caimei.modules.svip.web;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import com.caimei.modules.product.entity.Product;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+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 com.thinkgem.jeesite.common.config.Global;
|
|
|
|
+import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
|
+import com.thinkgem.jeesite.common.web.BaseController;
|
|
|
|
+import com.thinkgem.jeesite.common.utils.StringUtils;
|
|
|
|
+import com.caimei.modules.svip.entity.CmSvipProduct;
|
|
|
|
+import com.caimei.modules.svip.service.CmSvipProductService;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import static com.caimei.modules.newhome.web.NewPageQualitySupplierController.isInteger;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 超级会员优惠商品Controller
|
|
|
|
+ * @author Aslee
|
|
|
|
+ * @version 2021-09-23
|
|
|
|
+ */
|
|
|
|
+@Controller
|
|
|
|
+@RequestMapping(value = "${adminPath}/svip/cmSvipProduct")
|
|
|
|
+public class CmSvipProductController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CmSvipProductService cmSvipProductService;
|
|
|
|
+
|
|
|
|
+ @ModelAttribute
|
|
|
|
+ public CmSvipProduct get(@RequestParam(required=false) String id) {
|
|
|
|
+ CmSvipProduct entity = null;
|
|
|
|
+ if (StringUtils.isNotBlank(id)){
|
|
|
|
+ entity = cmSvipProductService.get(id);
|
|
|
|
+ }
|
|
|
|
+ if (entity == null){
|
|
|
|
+ entity = new CmSvipProduct();
|
|
|
|
+ }
|
|
|
|
+ return entity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
|
+ public String list(CmSvipProduct cmSvipProduct, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
|
+ Page<CmSvipProduct> page = cmSvipProductService.findPage(new Page<CmSvipProduct>(request, response), cmSvipProduct);
|
|
|
|
+ model.addAttribute("page", page);
|
|
|
|
+ return "modules/svip/cmSvipProductList";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "form")
|
|
|
|
+ public String form(CmSvipProduct cmSvipProduct, Model model) {
|
|
|
|
+ model.addAttribute("cmSvipProduct", cmSvipProduct);
|
|
|
|
+ return "modules/svip/cmSvipProductForm";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "save")
|
|
|
|
+ public String save(CmSvipProduct cmSvipProduct, Model model, RedirectAttributes redirectAttributes) {
|
|
|
|
+ if (!beanValidator(model, cmSvipProduct)){
|
|
|
|
+ return form(cmSvipProduct, model);
|
|
|
|
+ }
|
|
|
|
+ cmSvipProductService.save(cmSvipProduct);
|
|
|
|
+ addMessage(redirectAttributes, "保存商品成功");
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/svip/cmSvipProduct/?repage";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
|
+ public String delete(CmSvipProduct cmSvipProduct, RedirectAttributes redirectAttributes) {
|
|
|
|
+ cmSvipProductService.delete(cmSvipProduct);
|
|
|
|
+ addMessage(redirectAttributes, "删除商品成功");
|
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/svip/cmSvipProduct/?repage";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "findProductPage")
|
|
|
|
+ public String findProductPage(Product product, Model model, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ Page<Product> page = cmSvipProductService.findProductPage(new Page<Product>(request, response), product);
|
|
|
|
+ model.addAttribute("page", page);
|
|
|
|
+ model.addAttribute("ids", product.getIds());
|
|
|
|
+ return "modules/svip/svipAddProduct";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量更新排序值
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "batchSaveSort")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public Map<String, Object> batchSaveSort(String sortList) {
|
|
|
|
+ Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
|
+ try {
|
|
|
|
+ String[] svipProductList = sortList.split(",");
|
|
|
|
+ for (String list : svipProductList) {
|
|
|
|
+ String[] split = list.split("-");
|
|
|
|
+ if (split.length == 1 || split.length < 1) {
|
|
|
|
+ String id = split[0];
|
|
|
|
+ String sort = null;
|
|
|
|
+ cmSvipProductService.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;
|
|
|
|
+ }
|
|
|
|
+ cmSvipProductService.saveSort(sort, id);
|
|
|
|
+ } else {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "排序值只能为数字");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("success", true);
|
|
|
|
+ map.put("msg", "更新排序成功");
|
|
|
|
+ return map;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "更新排序失败");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|