Преглед на файлове

根据品牌Id更新商品索引

chao преди 3 години
родител
ревизия
ec76a1c0d6

+ 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;
     }
 
-}
+}

+ 3 - 0
src/main/java/com/caimei/modules/product/dao/ProductDao.java

@@ -176,4 +176,7 @@ public interface ProductDao extends CrudDao<Product> {
     String findProductDetail(Integer productID);
 
     String findProductDescribe(Integer productID);
+
+    List<Integer> getProductIdByBrandId(String brandId);
+
 }

+ 3 - 2
src/main/resources/mappings/modules/product/ProductMapper.xml

@@ -1370,8 +1370,9 @@
 		set  brandID = null
 		WHERE brandID = #{brandId}
 	</update>
-
-
+	<select id="getProductIdByBrandId" resultType="java.lang.Integer">
+		SELECT productID FROM product WHERE brandID = #{brandId}
+	</select>
 	<update id="updateTinyType">
 		UPDATE product
 		set tinyTypeID = #{tinyTypeID}