Bläddra i källkod

根据品牌Id更新商品索引

chao 3 år sedan
förälder
incheckning
028cfec5a9

+ 23 - 4
src/main/java/com/caimei/modules/brand/web/CmBrandController.java

@@ -3,6 +3,7 @@ package com.caimei.modules.brand.web;
 import com.caimei.modules.brand.entity.BrandAndProductType;
 import com.caimei.modules.brand.entity.CmBrand;
 import com.caimei.modules.brand.service.CmBrandService;
+import com.caimei.modules.opensearch.CoreServiceUitls;
 import com.caimei.modules.product.dao.ProductDao;
 import com.caimei.modules.product.entity.Product;
 import com.caimei.modules.sys.utils.SMSUtils;
@@ -59,7 +60,8 @@ public class CmBrandController extends BaseController {
     private CmBrandService cmBrandService;
     @Autowired
     private ProductDao productDao;
-
+    @Autowired
+    private CoreServiceUitls coreServiceUitls;
     @ModelAttribute
     public CmBrand get(@RequestParam(required = false) String id) {
         CmBrand entity = null;
@@ -150,17 +152,32 @@ public class CmBrandController extends BaseController {
                         }
                     }
                 }
-
             }
 
-
             cmBrand.setUpdateDate(new Date());
             cmBrandService.save(cmBrand);
+            // 更新商品索引
+            updateProductIndexByBrand(cmBrand.getId());
+
             addMessage(redirectAttributes, "保存品牌成功");
         }
         return "redirect:" + Global.getAdminPath() + "/brand/cmBrand/";
     }
 
+    /**
+     * 根据品牌Id更新商品索引
+     * @param brandId
+     */
+    private void updateProductIndexByBrand(String brandId) {
+        // 更新商品索引
+        List<Integer> productIds = productDao.getProductIdByBrandId(brandId);
+        for (Integer productId : productIds) {
+            if (null != productId) {
+                coreServiceUitls.updateProductIndex(productId);
+            }
+        }
+    }
+
     @RequiresPermissions("brand:cmBrand:delete")
     @RequestMapping(value = "delete")
     public String delete(CmBrand cmBrand, RedirectAttributes redirectAttributes) {
@@ -171,6 +188,8 @@ public class CmBrandController extends BaseController {
         cmBrandService.delete(cmBrand);
         //清理对应品牌商品信息(标记品牌为null)
         productDao.updateProductByBrandId(Integer.parseInt(cmBrand.getId()));
+        // 更新商品索引
+        updateProductIndexByBrand(cmBrand.getId());
         addMessage(redirectAttributes, "删除品牌成功");
         return "redirect:" + Global.getAdminPath() + "/brand/cmBrand/?repage";
     }
@@ -502,4 +521,4 @@ public class CmBrandController extends BaseController {
         this.errorMsg = errorMsg;
     }
 
-}
+}

+ 4 - 1
src/main/java/com/caimei/modules/product/dao/ProductDao.java

@@ -77,7 +77,7 @@ public interface ProductDao extends CrudDao<Product> {
 
     public int insertProductPriceRecord(ProductPriceRecord productPriceRecord);
 
-/*    public int updateCRMFlag(String enabledStatus, String[] ids);*/
+    /*    public int updateCRMFlag(String enabledStatus, String[] ids);*/
 
     public int updatePostFlag(String enabledStatus, String[] ids);
 
@@ -176,4 +176,7 @@ public interface ProductDao extends CrudDao<Product> {
     String findProductDetail(Integer productID);
 
     String findProductDescribe(Integer productID);
+
+    List<Integer> getProductIdByBrandId(String brandId);
+
 }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 476 - 476
src/main/resources/mappings/modules/product/ProductMapper.xml


Vissa filer visades inte eftersom för många filer har ändrats