zhijiezhao 3 years ago
parent
commit
1c51c4781a

+ 2 - 0
src/main/java/com/caimei365/commodity/mapper/SearchMapper.java

@@ -249,4 +249,6 @@ public interface SearchMapper {
 
     List<Integer> findPromotionId(Integer p_id);
 
+    List<Integer> findShopPromotion(Integer p_id);
+
 }

+ 8 - 0
src/main/java/com/caimei365/commodity/service/impl/SearchIndexServiceImpl.java

@@ -208,6 +208,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         if (promotionIds != null && promotionIds.size() > 0) {
             product.setP_promotions_id(promotionIds.get(0));
         }
+        List<Integer> shopPromotionIds = searchMapper.findShopPromotion(product.getP_id());
+        if (shopPromotionIds != null && shopPromotionIds.size() > 0) {
+            product.setP_promotions_id(shopPromotionIds.get(0));
+        }
         // product p_promotions_id
         if (null != product) {
             // 定义星范商品数据
@@ -1137,6 +1141,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         if (promotionIds != null && promotionIds.size() > 0) {
             product.setP_promotions_id(promotionIds.get(0));
         }
+        List<Integer> shopPromotionIds = searchMapper.findShopPromotion(product.getP_id());
+        if (shopPromotionIds != null && shopPromotionIds.size() > 0) {
+            product.setP_promotions_id(shopPromotionIds.get(0));
+        }
         productDoc.setCmd("add");
         productDoc.setFields(product);
         productList.add(productDoc);

+ 9 - 4
src/main/resources/mapper/SearchMapper.xml

@@ -39,7 +39,7 @@
         left join shop as sh on p.shopID = sh.shopID
     </sql>
     <select id="searchProductById" resultType="com.caimei365.commodity.model.search.ProductDO">
-        select <include refid="Search_Product_List"/>, p.productCategory
+        select<include refid="Search_Product_List"/>, p.productCategory
         from product p
         <include refid="Product_Joins"/>
         where p.validFlag in (2,3,9) and p.productCategory = 1
@@ -531,9 +531,14 @@
     <select id="findPromotionId" resultType="java.lang.Integer">
         select cpp.promotionsId
         from cm_promotions_product cpp
-        left join cm_promotions cp on cp.id=cpp.promotionsId
+                 left join cm_promotions cp on cp.id = cpp.promotionsId
         where cpp.productId = #{p_id}
-        and (cp.endTime>now() or cp.status='1')
-        and cp.delflag = 0
+          and (cp.endTime > now() or cp.status = '1')
+          and cp.delflag = 0
+    </select>
+    <select id="findShopPromotion" resultType="java.lang.Integer">
+        SELECT promotionsId
+        FROM cm_promotions_product
+        WHERE supplierId = (SELECT shopID FROM product WHERE productID = #{p_id})
     </select>
 </mapper>