|
@@ -0,0 +1,135 @@
|
|
|
|
+package com.caimei.modules.newhome.web;
|
|
|
|
+
|
|
|
|
+import com.caimei.modules.newhome.service.NewPageRecommendProductService;
|
|
|
|
+import com.caimei.modules.product.entity.Product;
|
|
|
|
+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 org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+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/recommendProduct")
|
|
|
|
+public class NewPageRecommendProductController {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private NewPageRecommendProductService newPageRecommendProductService;
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
|
+ public String recommendProductList(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 = newPageRecommendProductService.findRecommendList(page);
|
|
|
|
+ page.setList(list);
|
|
|
|
+ model.addAttribute("page", page);
|
|
|
|
+ return "modules/newhome/recommendProductList";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "batchSaveSort")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public Map<String, Object> batchSaveSorts(String newProducSorttList, HttpServletRequest request, Model model, RedirectAttributes redirectAttributes) {
|
|
|
|
+ Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
|
+ try {
|
|
|
|
+ String[] newPageLists = newProducSorttList.split(",");
|
|
|
|
+ for (String list : newPageLists) {
|
|
|
|
+ String[] split = list.split("-");
|
|
|
|
+ if (split.length == 1 || split.length < 1) {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "排序值不能为空!");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ String s = split[1];
|
|
|
|
+ //判断是否是数字,或者为空
|
|
|
|
+ if (StringUtils.isNotEmpty(s)) {
|
|
|
|
+ if (isInteger(s)) {
|
|
|
|
+ String id = split[0];
|
|
|
|
+ String sort = split[1];
|
|
|
|
+ //保存数据,
|
|
|
|
+ newPageRecommendProductService.saveBatchSort(sort, id);
|
|
|
|
+ } else {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "排序值只能为数字");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "排序值不能为空!");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("success", true);
|
|
|
|
+ map.put("msg", "更新排序成功");
|
|
|
|
+ return map;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "更新排序失败");
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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 = newPageRecommendProductService.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(String productIds, Integer id) {
|
|
|
|
+ Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
|
+ try {
|
|
|
|
+ String[] split = productIds.split(",");
|
|
|
|
+ //保存商品添加的组合
|
|
|
|
+ newPageRecommendProductService.addProducts(split);
|
|
|
|
+ map.put("success", true);
|
|
|
|
+ map.put("msg", "添加成功");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ map.put("success", false);
|
|
|
|
+ map.put("msg", "添加失败");
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "deleteProduct")
|
|
|
|
+ public String productDel(Integer productId, RedirectAttributes redirectAttributes) {
|
|
|
|
+ newPageRecommendProductService.productDel(productId);
|
|
|
|
+ addMessage(redirectAttributes, "删除成功");
|
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/newhome/recommendProduct/list";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void addMessage(RedirectAttributes redirectAttributes, String... messages) {
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ for (String message : messages) {
|
|
|
|
+ sb.append(message).append(messages.length > 1 ? "<br/>" : "");
|
|
|
|
+ }
|
|
|
|
+ redirectAttributes.addFlashAttribute("message", sb.toString());
|
|
|
|
+ }
|
|
|
|
+}
|