Showing
5 changed files
with
60 additions
and
21 deletions
@@ -23,4 +23,7 @@ public interface ActivityTagMapper { | @@ -23,4 +23,7 @@ public interface ActivityTagMapper { | ||
23 | List<ActivityTag> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize); | 23 | List<ActivityTag> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize); |
24 | 24 | ||
25 | int selectCount(); | 25 | int selectCount(); |
26 | + | ||
27 | + List<ActivityTag> selectLists(); | ||
28 | + | ||
26 | } | 29 | } |
@@ -179,4 +179,7 @@ | @@ -179,4 +179,7 @@ | ||
179 | <select id="selectCount" resultType="java.lang.Integer" timeout="20000" > | 179 | <select id="selectCount" resultType="java.lang.Integer" timeout="20000" > |
180 | SELECT count(1) FROM activity_tag | 180 | SELECT count(1) FROM activity_tag |
181 | </select> | 181 | </select> |
182 | + <select id="selectLists" resultMap="BaseResultMap" timeout="20000"> | ||
183 | + select <include refid="Base_Column_List" /> from activity_tag where status = 1 | ||
184 | + </select> | ||
182 | </mapper> | 185 | </mapper> |
@@ -7,6 +7,7 @@ import com.yoho.search.base.utils.ISearchConstants; | @@ -7,6 +7,7 @@ import com.yoho.search.base.utils.ISearchConstants; | ||
7 | import com.yoho.search.consumer.index.common.IYohoIndexService; | 7 | import com.yoho.search.consumer.index.common.IYohoIndexService; |
8 | import com.yoho.search.consumer.index.increment.AbstractIndexMqListener; | 8 | import com.yoho.search.consumer.index.increment.AbstractIndexMqListener; |
9 | import com.yoho.search.consumer.service.daoService.ActivityTagService; | 9 | import com.yoho.search.consumer.service.daoService.ActivityTagService; |
10 | +import com.yoho.search.consumer.service.logicService.productIndex.ProductCustomizeTagBuilder; | ||
10 | import com.yoho.search.dal.model.ActivityTag; | 11 | import com.yoho.search.dal.model.ActivityTag; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
@@ -21,6 +22,8 @@ public class ActivityTagMqListener extends AbstractIndexMqListener { | @@ -21,6 +22,8 @@ public class ActivityTagMqListener extends AbstractIndexMqListener { | ||
21 | private ActivityTagService activityTagService; | 22 | private ActivityTagService activityTagService; |
22 | @Autowired | 23 | @Autowired |
23 | private IYohoIndexService indexService; | 24 | private IYohoIndexService indexService; |
25 | + @Autowired | ||
26 | + private ProductCustomizeTagBuilder productCustomizeTagBuilder; | ||
24 | 27 | ||
25 | @Override | 28 | @Override |
26 | protected String getIndexName() { | 29 | protected String getIndexName() { |
@@ -35,6 +38,7 @@ public class ActivityTagMqListener extends AbstractIndexMqListener { | @@ -35,6 +38,7 @@ public class ActivityTagMqListener extends AbstractIndexMqListener { | ||
35 | @Override | 38 | @Override |
36 | protected void deleteData(String id) throws Exception { | 39 | protected void deleteData(String id) throws Exception { |
37 | activityTagService.delete(Integer.valueOf(id)); | 40 | activityTagService.delete(Integer.valueOf(id)); |
41 | + productCustomizeTagBuilder.buildActivityTagsMap(); | ||
38 | indexService.deleteIndexData(this.getIndexName(), id); | 42 | indexService.deleteIndexData(this.getIndexName(), id); |
39 | } | 43 | } |
40 | 44 | ||
@@ -45,6 +49,7 @@ public class ActivityTagMqListener extends AbstractIndexMqListener { | @@ -45,6 +49,7 @@ public class ActivityTagMqListener extends AbstractIndexMqListener { | ||
45 | return; | 49 | return; |
46 | } | 50 | } |
47 | activityTagService.saveOrUpdate(activityTag); | 51 | activityTagService.saveOrUpdate(activityTag); |
52 | + productCustomizeTagBuilder.buildActivityTagsMap(); | ||
48 | JSONObject jsonObject = new JSONObject(); | 53 | JSONObject jsonObject = new JSONObject(); |
49 | jsonObject.put("id",activityTag.getId()); | 54 | jsonObject.put("id",activityTag.getId()); |
50 | jsonObject.put("activityName",activityTag.getActivityName()); | 55 | jsonObject.put("activityName",activityTag.getActivityName()); |
@@ -9,12 +9,11 @@ import com.yoho.search.consumer.common.CostStatistics; | @@ -9,12 +9,11 @@ import com.yoho.search.consumer.common.CostStatistics; | ||
9 | import com.yoho.search.consumer.index.common.IYohoIndexService; | 9 | import com.yoho.search.consumer.index.common.IYohoIndexService; |
10 | import com.yoho.search.consumer.index.fullbuild.ProductIndexIndexBuilder; | 10 | import com.yoho.search.consumer.index.fullbuild.ProductIndexIndexBuilder; |
11 | import com.yoho.search.consumer.index.increment.AbstractIndexMqListener; | 11 | import com.yoho.search.consumer.index.increment.AbstractIndexMqListener; |
12 | -import com.yoho.search.consumer.service.daoService.ProductPriceService; | ||
13 | import com.yoho.search.consumer.service.daoService.ProductService; | 12 | import com.yoho.search.consumer.service.daoService.ProductService; |
14 | import com.yoho.search.consumer.service.bo.ProductIBO; | 13 | import com.yoho.search.consumer.service.bo.ProductIBO; |
15 | import com.yoho.search.consumer.service.bo.ProductPriceBO; | 14 | import com.yoho.search.consumer.service.bo.ProductPriceBO; |
16 | import com.yoho.search.consumer.service.logicService.ProductPriceBOLogicService; | 15 | import com.yoho.search.consumer.service.logicService.ProductPriceBOLogicService; |
17 | -import com.yoho.search.consumer.service.logicService.productIndex.ProductPriceBuilder; | 16 | +import com.yoho.search.consumer.service.logicService.productIndex.ProductCustomizeTagBuilder; |
18 | import com.yoho.search.dal.model.Product; | 17 | import com.yoho.search.dal.model.Product; |
19 | import org.apache.commons.collections.CollectionUtils; | 18 | import org.apache.commons.collections.CollectionUtils; |
20 | import org.slf4j.Logger; | 19 | import org.slf4j.Logger; |
@@ -34,15 +33,13 @@ public class ProductMqListener extends AbstractIndexMqListener { | @@ -34,15 +33,13 @@ public class ProductMqListener extends AbstractIndexMqListener { | ||
34 | @Autowired | 33 | @Autowired |
35 | private ProductService productService; | 34 | private ProductService productService; |
36 | @Autowired | 35 | @Autowired |
37 | - private ProductPriceService productPriceService; | ||
38 | - @Autowired | ||
39 | private ProductIndexMqListener productIndexMqListener; | 36 | private ProductIndexMqListener productIndexMqListener; |
40 | @Autowired | 37 | @Autowired |
41 | - private ProductPriceBuilder productPriceBuilder; | ||
42 | - @Autowired | ||
43 | private ProductIndexIndexBuilder productIndexIndexBuilder; | 38 | private ProductIndexIndexBuilder productIndexIndexBuilder; |
44 | @Autowired | 39 | @Autowired |
45 | private ProductPriceBOLogicService productPriceBOLogicService; | 40 | private ProductPriceBOLogicService productPriceBOLogicService; |
41 | + @Autowired | ||
42 | + private ProductCustomizeTagBuilder productCustomizeTagBuilder; | ||
46 | 43 | ||
47 | @Override | 44 | @Override |
48 | public String getIndexName() { | 45 | public String getIndexName() { |
@@ -106,6 +103,8 @@ public class ProductMqListener extends AbstractIndexMqListener { | @@ -106,6 +103,8 @@ public class ProductMqListener extends AbstractIndexMqListener { | ||
106 | if(productPriceBO!=null){ | 103 | if(productPriceBO!=null){ |
107 | jsonObject.putAll((JSONObject) JSON.toJSON(productPriceBO)); | 104 | jsonObject.putAll((JSONObject) JSON.toJSON(productPriceBO)); |
108 | } | 105 | } |
106 | + | ||
107 | + jsonObject.put("customizeTags", productCustomizeTagBuilder.buildCustomizeTagByProductId(productId)); | ||
109 | // 4、更新到ES | 108 | // 4、更新到ES |
110 | try { | 109 | try { |
111 | this.updateProductIndexWithDataMap(jsonObject, productId); | 110 | this.updateProductIndexWithDataMap(jsonObject, productId); |
@@ -9,13 +9,14 @@ import com.yoho.search.dal.model.ActivityTag; | @@ -9,13 +9,14 @@ import com.yoho.search.dal.model.ActivityTag; | ||
9 | import com.yoho.search.dal.model.Product; | 9 | import com.yoho.search.dal.model.Product; |
10 | import org.apache.commons.collections.CollectionUtils; | 10 | import org.apache.commons.collections.CollectionUtils; |
11 | import org.apache.commons.lang.StringUtils; | 11 | import org.apache.commons.lang.StringUtils; |
12 | +import org.springframework.beans.BeansException; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
13 | import org.springframework.stereotype.Component; | 14 | import org.springframework.stereotype.Component; |
14 | 15 | ||
16 | +import javax.annotation.PostConstruct; | ||
15 | import java.util.HashMap; | 17 | import java.util.HashMap; |
16 | import java.util.List; | 18 | import java.util.List; |
17 | import java.util.Map; | 19 | import java.util.Map; |
18 | -import java.util.stream.Collectors; | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * Created by wangnan on 2017/9/11. | 22 | * Created by wangnan on 2017/9/11. |
@@ -28,21 +29,15 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { | @@ -28,21 +29,15 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { | ||
28 | @Autowired | 29 | @Autowired |
29 | private ProductMapper productMapper; | 30 | private ProductMapper productMapper; |
30 | 31 | ||
31 | - @Override | ||
32 | - public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) { | ||
33 | - List<Product> productList = productMapper.selectListByIds(ids); | ||
34 | - if (CollectionUtils.isEmpty(productList)) { | ||
35 | - return; | ||
36 | - } | ||
37 | - List<Integer> promotionIdList = productList.stream().map(Product::getIsPromotion).distinct().collect(Collectors.toList()); | ||
38 | - if (CollectionUtils.isEmpty(promotionIdList)) { | ||
39 | - return; | ||
40 | - } | ||
41 | - List<ActivityTag> activityTagList = activityTagMapper.selectByIsPromotionIdList(promotionIdList); | 32 | + private static Map<Integer, ActivityTag> activityTagsMap = new HashMap<>(); |
33 | + | ||
34 | + @PostConstruct | ||
35 | + public void buildActivityTagsMap() throws BeansException { | ||
36 | + activityTagsMap.clear(); | ||
37 | + List<ActivityTag> activityTagList = activityTagMapper.selectLists(); | ||
42 | if (CollectionUtils.isEmpty(activityTagList)) { | 38 | if (CollectionUtils.isEmpty(activityTagList)) { |
43 | return; | 39 | return; |
44 | } | 40 | } |
45 | - Map<Integer, ActivityTag> activityTagMap = new HashMap<>(); | ||
46 | for (ActivityTag activityTag : activityTagList) { | 41 | for (ActivityTag activityTag : activityTagList) { |
47 | String[] isPromotionIdArray = activityTag.getIsPromotionIds().split(","); | 42 | String[] isPromotionIdArray = activityTag.getIsPromotionIds().split(","); |
48 | if (isPromotionIdArray.length == 0) { | 43 | if (isPromotionIdArray.length == 0) { |
@@ -50,12 +45,21 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { | @@ -50,12 +45,21 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { | ||
50 | } | 45 | } |
51 | for (String promotionId : isPromotionIdArray) { | 46 | for (String promotionId : isPromotionIdArray) { |
52 | if (StringUtils.isNotBlank(promotionId)) { | 47 | if (StringUtils.isNotBlank(promotionId)) { |
53 | - activityTagMap.put(Integer.valueOf(promotionId), activityTag); | 48 | + activityTagsMap.put(Integer.valueOf(promotionId), activityTag); |
54 | } | 49 | } |
55 | } | 50 | } |
56 | } | 51 | } |
52 | + } | ||
53 | + | ||
54 | + | ||
55 | + @Override | ||
56 | + public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) { | ||
57 | + List<Product> productList = productMapper.selectListByIds(ids); | ||
58 | + if (CollectionUtils.isEmpty(productList)) { | ||
59 | + return; | ||
60 | + } | ||
57 | productIndexBOs.stream().forEach(productIndexBO -> { | 61 | productIndexBOs.stream().forEach(productIndexBO -> { |
58 | - ActivityTag activityTag = activityTagMap.get(productIndexBO.getIspromotion()); | 62 | + ActivityTag activityTag = activityTagsMap.get(productIndexBO.getIspromotion()); |
59 | if (activityTag != null) { | 63 | if (activityTag != null) { |
60 | JSONObject customizeTag = new JSONObject(); | 64 | JSONObject customizeTag = new JSONObject(); |
61 | customizeTag.put("id", activityTag.getId()); | 65 | customizeTag.put("id", activityTag.getId()); |
@@ -67,4 +71,29 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { | @@ -67,4 +71,29 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { | ||
67 | } | 71 | } |
68 | }); | 72 | }); |
69 | } | 73 | } |
74 | + | ||
75 | + public JSONArray buildCustomizeTagByProductId(Integer productId) { | ||
76 | + Product product = productMapper.selectByPrimaryKey(productId); | ||
77 | + if (product == null) { | ||
78 | + return new JSONArray(0); | ||
79 | + } | ||
80 | + Integer promotionId = product.getIsPromotion(); | ||
81 | + if (promotionId == null) { | ||
82 | + return new JSONArray(0); | ||
83 | + } | ||
84 | + | ||
85 | + ActivityTag activityTag = activityTagsMap.get(promotionId); | ||
86 | + if (activityTag != null) { | ||
87 | + JSONObject customizeTag = new JSONObject(); | ||
88 | + customizeTag.put("id", activityTag.getId()); | ||
89 | + customizeTag.put("name", activityTag.getActivityName()); | ||
90 | + customizeTag.put("url", activityTag.getTagUrl()); | ||
91 | + JSONArray customizeTags = new JSONArray(); | ||
92 | + customizeTags.add(customizeTag); | ||
93 | + | ||
94 | + return customizeTags; | ||
95 | + } | ||
96 | + return new JSONArray(0); | ||
97 | + } | ||
98 | + | ||
70 | } | 99 | } |
-
Please register or login to post a comment