Merge branch 'wn_promotion_bulk' into gray1230
Showing
8 changed files
with
268 additions
and
53 deletions
@@ -14,6 +14,8 @@ public interface PromotionInfoMapper { | @@ -14,6 +14,8 @@ public interface PromotionInfoMapper { | ||
14 | 14 | ||
15 | List<PromotionInfo> selectValidPromotionList(Integer currentTime); | 15 | List<PromotionInfo> selectValidPromotionList(Integer currentTime); |
16 | 16 | ||
17 | + List<PromotionInfo> selectByIds(List<Integer> ids); | ||
18 | + | ||
17 | int insert(PromotionInfo record); | 19 | int insert(PromotionInfo record); |
18 | 20 | ||
19 | int updateByPrimaryKey(PromotionInfo record); | 21 | int updateByPrimaryKey(PromotionInfo record); |
@@ -22,5 +24,5 @@ public interface PromotionInfoMapper { | @@ -22,5 +24,5 @@ public interface PromotionInfoMapper { | ||
22 | 24 | ||
23 | int selectCount(); | 25 | int selectCount(); |
24 | 26 | ||
25 | - List<PromotionInfo> selectPageLists(@Param(value="start")Integer start, @Param(value="limit")Integer limit); | 27 | + List<PromotionInfo> selectPageLists(@Param(value = "start") Integer start, @Param(value = "limit") Integer limit); |
26 | } | 28 | } |
@@ -19,4 +19,6 @@ public interface PromotionParamsMapper { | @@ -19,4 +19,6 @@ public interface PromotionParamsMapper { | ||
19 | int updateByPrimaryKey(PromotionParams record); | 19 | int updateByPrimaryKey(PromotionParams record); |
20 | 20 | ||
21 | int deleteByPrimaryKey(Integer id); | 21 | int deleteByPrimaryKey(Integer id); |
22 | + | ||
23 | + List<PromotionParams> selectByIds(List<Integer> ids); | ||
22 | } | 24 | } |
@@ -72,7 +72,7 @@ | @@ -72,7 +72,7 @@ | ||
72 | 72 | ||
73 | <select id="selectPageLists" resultMap="BaseResultMap" timeout="20000"> | 73 | <select id="selectPageLists" resultMap="BaseResultMap" timeout="20000"> |
74 | select | 74 | select |
75 | - <include refid="Base_Column_List" /> | 75 | + <include refid="Base_Column_List"/> |
76 | from promotion_info | 76 | from promotion_info |
77 | where | 77 | where |
78 | status = 1 | 78 | status = 1 |
@@ -80,4 +80,14 @@ | @@ -80,4 +80,14 @@ | ||
80 | limit #{start},#{limit} | 80 | limit #{start},#{limit} |
81 | </select> | 81 | </select> |
82 | 82 | ||
83 | + <select id="selectByIds" resultMap="BaseResultMap"> | ||
84 | + select | ||
85 | + <include refid="Base_Column_List"/> | ||
86 | + from promotion_info where id in | ||
87 | + <foreach item="item" index="index" collection="list" | ||
88 | + open="(" separator="," close=")"> | ||
89 | + #{item} | ||
90 | + </foreach> | ||
91 | + </select> | ||
92 | + | ||
83 | </mapper> | 93 | </mapper> |
@@ -54,4 +54,15 @@ | @@ -54,4 +54,15 @@ | ||
54 | reject_param= #{rejectParam,jdbcType=VARCHAR} | 54 | reject_param= #{rejectParam,jdbcType=VARCHAR} |
55 | where promotion_id = #{promotionId,jdbcType=INTEGER} | 55 | where promotion_id = #{promotionId,jdbcType=INTEGER} |
56 | </update> | 56 | </update> |
57 | + | ||
58 | + <select id="selectByIds" resultMap="BaseResultMap"> | ||
59 | + select | ||
60 | + <include refid="Base_Column_List"/> | ||
61 | + from promotion_params where promotion_id in | ||
62 | + <foreach item="item" index="index" collection="list" | ||
63 | + open="(" separator="," close=")"> | ||
64 | + #{item} | ||
65 | + </foreach> | ||
66 | + </select> | ||
67 | + | ||
57 | </mapper> | 68 | </mapper> |
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
12 | 12 | ||
13 | import java.util.ArrayList; | 13 | import java.util.ArrayList; |
14 | +import java.util.HashMap; | ||
14 | import java.util.List; | 15 | import java.util.List; |
15 | import java.util.Map; | 16 | import java.util.Map; |
16 | import java.util.stream.Collectors; | 17 | import java.util.stream.Collectors; |
@@ -31,19 +32,19 @@ public class PromotionIndexIndexBuilder extends IIndexBuilder { | @@ -31,19 +32,19 @@ public class PromotionIndexIndexBuilder extends IIndexBuilder { | ||
31 | @Override | 32 | @Override |
32 | public List<?> getPageLists(int start, int limit) throws Exception { | 33 | public List<?> getPageLists(int start, int limit) throws Exception { |
33 | List<PromotionIndexBO> promotionIndexBOList = new ArrayList<>(); | 34 | List<PromotionIndexBO> promotionIndexBOList = new ArrayList<>(); |
34 | - List<PromotionInfo> promotionInfoList = promotionInfoMapper.selectPageLists(start,limit); | ||
35 | - if(CollectionUtils.isEmpty(promotionInfoList)){ | 35 | + List<PromotionInfo> promotionInfoList = promotionInfoMapper.selectPageLists(start, limit); |
36 | + if (CollectionUtils.isEmpty(promotionInfoList)) { | ||
36 | return new ArrayList<>(); | 37 | return new ArrayList<>(); |
37 | } | 38 | } |
38 | List<Integer> idList = promotionInfoList.stream().map(PromotionInfo::getId).collect(Collectors.toList()); | 39 | List<Integer> idList = promotionInfoList.stream().map(PromotionInfo::getId).collect(Collectors.toList()); |
39 | List<PromotionParams> promotionParamsList = promotionParamsMapper.selectByPromotionIdList(idList); | 40 | List<PromotionParams> promotionParamsList = promotionParamsMapper.selectByPromotionIdList(idList); |
40 | - if(CollectionUtils.isEmpty(promotionParamsList)){ | 41 | + if (CollectionUtils.isEmpty(promotionParamsList)) { |
41 | return new ArrayList<>(); | 42 | return new ArrayList<>(); |
42 | } | 43 | } |
43 | - Map<Integer,PromotionParams> promotionParamsMap = promotionParamsList.stream().parallel().collect(Collectors.toMap(PromotionParams::getPromotionId, p->p)); | ||
44 | - for(PromotionInfo promotionInfo:promotionInfoList){ | 44 | + Map<Integer, PromotionParams> promotionParamsMap = promotionParamsList.stream().parallel().collect(Collectors.toMap(PromotionParams::getPromotionId, p -> p)); |
45 | + for (PromotionInfo promotionInfo : promotionInfoList) { | ||
45 | PromotionParams promotionParams = promotionParamsMap.get(promotionInfo.getId()); | 46 | PromotionParams promotionParams = promotionParamsMap.get(promotionInfo.getId()); |
46 | - PromotionIndexBO promotionIndexBO = buildPromotionIndexBO(promotionInfo,promotionParams); | 47 | + PromotionIndexBO promotionIndexBO = buildPromotionIndexBO(promotionInfo, promotionParams); |
47 | promotionIndexBOList.add(promotionIndexBO); | 48 | promotionIndexBOList.add(promotionIndexBO); |
48 | } | 49 | } |
49 | return promotionIndexBOList; | 50 | return promotionIndexBOList; |
@@ -55,10 +56,28 @@ public class PromotionIndexIndexBuilder extends IIndexBuilder { | @@ -55,10 +56,28 @@ public class PromotionIndexIndexBuilder extends IIndexBuilder { | ||
55 | } | 56 | } |
56 | 57 | ||
57 | 58 | ||
58 | - /** | ||
59 | - * 全量建Promotionindex索引、PromotionInfoMqListener、PromotionParamsMqListener都使用 | ||
60 | - */ | ||
61 | - public PromotionIndexBO buildPromotionIndexBO(PromotionInfo promotionInfo, PromotionParams promotionParams) { | 59 | + public List<PromotionIndexBO> buildPromotionIndexBOList(List<Integer> promotionIdList) { |
60 | + List<PromotionInfo> promotionInfoList = promotionInfoMapper.selectByIds(promotionIdList); | ||
61 | + Map<Integer, PromotionInfo> promotionInfoMap = new HashMap<>(); | ||
62 | + if (CollectionUtils.isNotEmpty(promotionInfoList)) { | ||
63 | + promotionInfoMap = promotionInfoList.stream().collect(Collectors.toMap(PromotionInfo::getId, p -> p)); | ||
64 | + } | ||
65 | + List<PromotionParams> promotionParamsList = promotionParamsMapper.selectByIds(promotionIdList); | ||
66 | + Map<Integer, PromotionParams> promotionParamsMap = new HashMap<>(); | ||
67 | + if (CollectionUtils.isNotEmpty(promotionInfoList)) { | ||
68 | + promotionParamsMap = promotionParamsList.stream().collect(Collectors.toMap(PromotionParams::getPromotionId, p -> p)); | ||
69 | + } | ||
70 | + List<PromotionIndexBO> promotionIndexBOList = new ArrayList<>(); | ||
71 | + for (Integer promotionId : promotionIdList) { | ||
72 | + PromotionInfo promotionInfo = promotionInfoMap.get(promotionId); | ||
73 | + PromotionParams promotionParams = promotionParamsMap.get(promotionId); | ||
74 | + PromotionIndexBO promotionIndexBO = buildPromotionIndexBO(promotionInfo, promotionParams); | ||
75 | + promotionIndexBOList.add(promotionIndexBO); | ||
76 | + } | ||
77 | + return promotionIndexBOList; | ||
78 | + } | ||
79 | + | ||
80 | + private PromotionIndexBO buildPromotionIndexBO(PromotionInfo promotionInfo, PromotionParams promotionParams) { | ||
62 | PromotionIndexBO promotionIndexBO = new PromotionIndexBO(); | 81 | PromotionIndexBO promotionIndexBO = new PromotionIndexBO(); |
63 | if (promotionInfo != null) { | 82 | if (promotionInfo != null) { |
64 | promotionIndexBO.setId(promotionInfo.getId()); | 83 | promotionIndexBO.setId(promotionInfo.getId()); |
@@ -80,4 +99,6 @@ public class PromotionIndexIndexBuilder extends IIndexBuilder { | @@ -80,4 +99,6 @@ public class PromotionIndexIndexBuilder extends IIndexBuilder { | ||
80 | } | 99 | } |
81 | return promotionIndexBO; | 100 | return promotionIndexBO; |
82 | } | 101 | } |
102 | + | ||
103 | + | ||
83 | } | 104 | } |
index/src/main/java/com/yoho/search/consumer/index/increment/bulks/PromotionBulkService.java
0 → 100644
1 | +package com.yoho.search.consumer.index.increment.bulks; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.yoho.search.base.models.PromotionIndexBO; | ||
5 | +import com.yoho.search.base.utils.ISearchConstants; | ||
6 | +import com.yoho.search.consumer.common.IYohoIndexService; | ||
7 | +import com.yoho.search.consumer.index.fullbuild.promotion.PromotionIndexIndexBuilder; | ||
8 | +import com.yoho.search.consumer.service.utils.CostStatistics; | ||
9 | +import com.yoho.search.core.es.model.ESBluk; | ||
10 | +import org.apache.commons.collections.CollectionUtils; | ||
11 | +import org.slf4j.Logger; | ||
12 | +import org.slf4j.LoggerFactory; | ||
13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
14 | +import org.springframework.stereotype.Component; | ||
15 | + | ||
16 | +import javax.annotation.PostConstruct; | ||
17 | +import java.util.ArrayList; | ||
18 | +import java.util.List; | ||
19 | +import java.util.concurrent.ArrayBlockingQueue; | ||
20 | +import java.util.concurrent.ExecutorService; | ||
21 | +import java.util.concurrent.Executors; | ||
22 | + | ||
23 | +/** | ||
24 | + * 促销索引BULK服务 | ||
25 | + * @author wangnan | ||
26 | + * @version 2018/12/17 | ||
27 | + */ | ||
28 | +@Component | ||
29 | +public class PromotionBulkService { | ||
30 | + | ||
31 | + private static final Logger logger = LoggerFactory.getLogger(PromotionBulkService.class); | ||
32 | + private static final String INDEX_NAME_PROMOTION_INDEX = ISearchConstants.INDEX_NAME_PROMOTIONINDEX; | ||
33 | + private static final long THREAD_SLEEP_IDLE = 2000; | ||
34 | + private static final long THREAD_SLEEP_WORK = 50; | ||
35 | + | ||
36 | + @Autowired | ||
37 | + private IYohoIndexService indexService; | ||
38 | + @Autowired | ||
39 | + private PromotionIndexIndexBuilder promotionIndexIndexBuilder; | ||
40 | + | ||
41 | + private ArrayBlockingQueue<Integer> idUpdateQueue = new ArrayBlockingQueue<Integer>(200); | ||
42 | + private ArrayBlockingQueue<Integer> idDeleteQueue = new ArrayBlockingQueue<Integer>(200); | ||
43 | + | ||
44 | + private ExecutorService updateExecutorService = Executors.newSingleThreadExecutor(); | ||
45 | + private ExecutorService deleteExecutorService = Executors.newSingleThreadExecutor(); | ||
46 | + | ||
47 | + @PostConstruct | ||
48 | + void init() { | ||
49 | + updateExecutorService.submit((Runnable) () -> { | ||
50 | + while (true) { | ||
51 | + try { | ||
52 | + long threadSleep = doBulkUpdateIndex(); | ||
53 | + Thread.sleep(threadSleep); | ||
54 | + } catch (Exception e) { | ||
55 | + logger.error(e.getMessage(), e); | ||
56 | + } | ||
57 | + } | ||
58 | + }); | ||
59 | + deleteExecutorService.submit((Runnable) () -> { | ||
60 | + while (true) { | ||
61 | + try { | ||
62 | + long threadSleep = doBulkDeleteIndex(); | ||
63 | + Thread.sleep(threadSleep); | ||
64 | + } catch (Exception e) { | ||
65 | + logger.error(e.getMessage(), e); | ||
66 | + } | ||
67 | + } | ||
68 | + }); | ||
69 | + Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
70 | + updateExecutorService.shutdown(); | ||
71 | + deleteExecutorService.shutdown(); | ||
72 | + })); | ||
73 | + } | ||
74 | + | ||
75 | + public void updateIndex(Integer id) { | ||
76 | + try { | ||
77 | + if (id == null) { | ||
78 | + return; | ||
79 | + } | ||
80 | + idUpdateQueue.put(id); | ||
81 | + } catch (Exception e) { | ||
82 | + logger.error(e.getMessage(), e); | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + public void deleteIndex(Integer id) { | ||
87 | + try { | ||
88 | + if (id == null) { | ||
89 | + return; | ||
90 | + } | ||
91 | + idDeleteQueue.put(id); | ||
92 | + } catch (Exception e) { | ||
93 | + logger.error(e.getMessage(), e); | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | + private long doBulkUpdateIndex() { | ||
98 | + try { | ||
99 | + CostStatistics costStatistics = new CostStatistics(); | ||
100 | + List<PromotionIndexBO> promotionIndexBOList = new ArrayList<>(); | ||
101 | + // 1、根据id去取数据库对象 | ||
102 | + List<Integer> idList = this.getElementsFromArrayBlockingQueue(idUpdateQueue, 200); | ||
103 | + if (!idList.isEmpty()) { | ||
104 | + promotionIndexBOList = promotionIndexIndexBuilder.buildPromotionIndexBOList(idList); | ||
105 | + logger.info("doBulkUpdatePromotionIndex buildPromotionIndexBOList, size is [{}], cost [{}]ms", promotionIndexBOList.size(), costStatistics.getCost()); | ||
106 | + } | ||
107 | + // 2、没数据直接返回[并让线程休息1000ms] | ||
108 | + if (promotionIndexBOList.isEmpty()) { | ||
109 | + return THREAD_SLEEP_IDLE; | ||
110 | + } | ||
111 | + // 3、批量更新ES | ||
112 | + this.updateIndexByList(promotionIndexBOList); | ||
113 | + logger.info("doBulkUpdatePromotionIndex updateIndexByList, cost [{}]ms", costStatistics.getCost()); | ||
114 | + // 4、打印总耗时 | ||
115 | + logger.info("doBulkUpdatePromotionIndex end , costStatistics is [{}] ", costStatistics.getCostStatisticsString()); | ||
116 | + // 让线程休息50ms继续工作 | ||
117 | + return THREAD_SLEEP_WORK; | ||
118 | + } catch (Exception e) { | ||
119 | + logger.error(e.getMessage(), e); | ||
120 | + return THREAD_SLEEP_WORK; | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
124 | + private long doBulkDeleteIndex() { | ||
125 | + try { | ||
126 | + CostStatistics costStatistics = new CostStatistics(); | ||
127 | + // 1、根据id去取数据库对象 | ||
128 | + List<Integer> ids = this.getElementsFromArrayBlockingQueue(idDeleteQueue, 200); | ||
129 | + // 2、没数据直接返回[并让线程休息1000ms] | ||
130 | + if (ids.isEmpty()) { | ||
131 | + return THREAD_SLEEP_IDLE; | ||
132 | + } | ||
133 | + // 3、批量更新ES | ||
134 | + this.deleteIndexByList(ids); | ||
135 | + logger.info("doBulkDeletePromotionIndex start, ids size is [{}], cost [{}]ms", ids.size(), costStatistics.getCost()); | ||
136 | + // 4、打印总耗时 | ||
137 | + logger.info("doBulkDeletePromotionIndex end , costStatistics is [{}] ", costStatistics.getCostStatisticsString()); | ||
138 | + return THREAD_SLEEP_WORK;// 让线程休息50ms继续工作 | ||
139 | + } catch (Exception e) { | ||
140 | + logger.error(e.getMessage(), e); | ||
141 | + return THREAD_SLEEP_WORK; | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + private void updateIndexByList(List<PromotionIndexBO> promotionIndexBOList) { | ||
146 | + try { | ||
147 | + if (CollectionUtils.isEmpty(promotionIndexBOList)) { | ||
148 | + return; | ||
149 | + } | ||
150 | + List<ESBluk> results = new ArrayList<ESBluk>(); | ||
151 | + for (PromotionIndexBO promotionIndexBO : promotionIndexBOList) { | ||
152 | + results.add(new ESBluk(JSON.toJSONString(promotionIndexBO), promotionIndexBO.getId().toString(), INDEX_NAME_PROMOTION_INDEX, INDEX_NAME_PROMOTION_INDEX, false)); | ||
153 | + } | ||
154 | + indexService.bulk(results); | ||
155 | + } catch (Exception e) { | ||
156 | + logger.error(e.getMessage(), e); | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
160 | + private void deleteIndexByList(List<Integer> ids) { | ||
161 | + try { | ||
162 | + if (CollectionUtils.isEmpty(ids)) { | ||
163 | + return; | ||
164 | + } | ||
165 | + List<ESBluk> results = new ArrayList<ESBluk>(); | ||
166 | + for (Integer id : ids) { | ||
167 | + results.add(new ESBluk(null, id.toString(), INDEX_NAME_PROMOTION_INDEX, INDEX_NAME_PROMOTION_INDEX, true)); | ||
168 | + } | ||
169 | + indexService.bulk(results); | ||
170 | + } catch (Exception e) { | ||
171 | + logger.error(e.getMessage(), e); | ||
172 | + } | ||
173 | + } | ||
174 | + | ||
175 | + private <T> List<T> getElementsFromArrayBlockingQueue(ArrayBlockingQueue<T> queue, int limit) { | ||
176 | + List<T> results = new ArrayList<T>(); | ||
177 | + while (results.size() < limit && (!queue.isEmpty())) { | ||
178 | + results.add(queue.poll()); | ||
179 | + } | ||
180 | + return results; | ||
181 | + } | ||
182 | +} |
1 | package com.yoho.search.consumer.index.increment.yhb_promotion; | 1 | package com.yoho.search.consumer.index.increment.yhb_promotion; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | -import com.yoho.search.base.models.PromotionIndexBO; | ||
5 | import com.yoho.search.base.utils.ConvertUtils; | 4 | import com.yoho.search.base.utils.ConvertUtils; |
6 | import com.yoho.search.base.utils.EventReportEnum; | 5 | import com.yoho.search.base.utils.EventReportEnum; |
7 | import com.yoho.search.base.utils.ISearchConstants; | 6 | import com.yoho.search.base.utils.ISearchConstants; |
8 | import com.yoho.search.consumer.common.IYohoIndexService; | 7 | import com.yoho.search.consumer.common.IYohoIndexService; |
9 | -import com.yoho.search.consumer.index.fullbuild.promotion.PromotionIndexIndexBuilder; | ||
10 | import com.yoho.search.consumer.index.increment.AbstractMqListener; | 8 | import com.yoho.search.consumer.index.increment.AbstractMqListener; |
9 | +import com.yoho.search.consumer.index.increment.bulks.PromotionBulkService; | ||
11 | import com.yoho.search.consumer.service.daoService.PromotionInfoService; | 10 | import com.yoho.search.consumer.service.daoService.PromotionInfoService; |
12 | import com.yoho.search.core.message.beans.SearchMqConsumerListerner; | 11 | import com.yoho.search.core.message.beans.SearchMqConsumerListerner; |
13 | import com.yoho.search.dal.PromotionParamsMapper; | 12 | import com.yoho.search.dal.PromotionParamsMapper; |
14 | import com.yoho.search.dal.model.PromotionInfo; | 13 | import com.yoho.search.dal.model.PromotionInfo; |
15 | -import com.yoho.search.dal.model.PromotionParams; | ||
16 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
17 | import org.springframework.stereotype.Component; | 15 | import org.springframework.stereotype.Component; |
18 | 16 | ||
19 | @Component | 17 | @Component |
20 | -@SearchMqConsumerListerner(dbName = "yhb_promotion",tableName = "promotion_info") | 18 | +@SearchMqConsumerListerner(dbName = "yhb_promotion", tableName = "promotion_info") |
21 | public class PromotionInfoMqListener extends AbstractMqListener { | 19 | public class PromotionInfoMqListener extends AbstractMqListener { |
22 | 20 | ||
23 | @Autowired | 21 | @Autowired |
@@ -27,7 +25,7 @@ public class PromotionInfoMqListener extends AbstractMqListener { | @@ -27,7 +25,7 @@ public class PromotionInfoMqListener extends AbstractMqListener { | ||
27 | @Autowired | 25 | @Autowired |
28 | private IYohoIndexService indexService; | 26 | private IYohoIndexService indexService; |
29 | @Autowired | 27 | @Autowired |
30 | - private PromotionIndexIndexBuilder promotionIndexIndexBuilder; | 28 | + private PromotionBulkService promotionBulkService; |
31 | 29 | ||
32 | @Override | 30 | @Override |
33 | protected EventReportEnum getEventReportEnum() { | 31 | protected EventReportEnum getEventReportEnum() { |
@@ -38,6 +36,7 @@ public class PromotionInfoMqListener extends AbstractMqListener { | @@ -38,6 +36,7 @@ public class PromotionInfoMqListener extends AbstractMqListener { | ||
38 | protected void deleteData(String id) throws Exception { | 36 | protected void deleteData(String id) throws Exception { |
39 | promotionInfoService.delete(Integer.valueOf(id)); | 37 | promotionInfoService.delete(Integer.valueOf(id)); |
40 | indexService.deleteIndexData(ISearchConstants.INDEX_NAME_PROMOTIONINDEX, id); | 38 | indexService.deleteIndexData(ISearchConstants.INDEX_NAME_PROMOTIONINDEX, id); |
39 | + promotionBulkService.deleteIndex(Integer.valueOf(id)); | ||
41 | } | 40 | } |
42 | 41 | ||
43 | @Override | 42 | @Override |
@@ -49,9 +48,7 @@ public class PromotionInfoMqListener extends AbstractMqListener { | @@ -49,9 +48,7 @@ public class PromotionInfoMqListener extends AbstractMqListener { | ||
49 | //更新DB | 48 | //更新DB |
50 | promotionInfoService.saveOrUpdate(promotionInfo); | 49 | promotionInfoService.saveOrUpdate(promotionInfo); |
51 | //更新ES | 50 | //更新ES |
52 | - PromotionParams promotionParams = promotionParamsMapper.selectByPrimaryKey(promotionInfo.getId()); | ||
53 | - PromotionIndexBO promotionIndexBO = promotionIndexIndexBuilder.buildPromotionIndexBO(promotionInfo, promotionParams); | ||
54 | - indexService.updateIndexData(ISearchConstants.INDEX_NAME_PROMOTIONINDEX, promotionInfo.getId().toString(), promotionIndexBO); | 51 | + promotionBulkService.updateIndex(promotionInfo.getId()); |
55 | } | 52 | } |
56 | 53 | ||
57 | } | 54 | } |
1 | package com.yoho.search.consumer.index.increment.yhb_promotion; | 1 | package com.yoho.search.consumer.index.increment.yhb_promotion; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | -import com.yoho.search.base.models.PromotionIndexBO; | ||
5 | import com.yoho.search.base.utils.ConvertUtils; | 4 | import com.yoho.search.base.utils.ConvertUtils; |
6 | import com.yoho.search.base.utils.EventReportEnum; | 5 | import com.yoho.search.base.utils.EventReportEnum; |
7 | -import com.yoho.search.base.utils.ISearchConstants; | ||
8 | -import com.yoho.search.consumer.common.IYohoIndexService; | ||
9 | -import com.yoho.search.consumer.index.fullbuild.promotion.PromotionIndexIndexBuilder; | ||
10 | import com.yoho.search.consumer.index.increment.AbstractMqListener; | 6 | import com.yoho.search.consumer.index.increment.AbstractMqListener; |
7 | +import com.yoho.search.consumer.index.increment.bulks.PromotionBulkService; | ||
11 | import com.yoho.search.consumer.service.daoService.PromotionParamsService; | 8 | import com.yoho.search.consumer.service.daoService.PromotionParamsService; |
12 | import com.yoho.search.core.message.beans.SearchMqConsumerListerner; | 9 | import com.yoho.search.core.message.beans.SearchMqConsumerListerner; |
13 | import com.yoho.search.dal.PromotionInfoMapper; | 10 | import com.yoho.search.dal.PromotionInfoMapper; |
14 | -import com.yoho.search.dal.model.PromotionInfo; | ||
15 | import com.yoho.search.dal.model.PromotionParams; | 11 | import com.yoho.search.dal.model.PromotionParams; |
16 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
17 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
18 | 14 | ||
19 | @Component | 15 | @Component |
20 | -@SearchMqConsumerListerner(dbName = "yhb_promotion",tableName = "promotion_params") | 16 | +@SearchMqConsumerListerner(dbName = "yhb_promotion", tableName = "promotion_params") |
21 | public class PromotionParamsMqListener extends AbstractMqListener { | 17 | public class PromotionParamsMqListener extends AbstractMqListener { |
22 | 18 | ||
23 | - @Autowired | ||
24 | - private PromotionParamsService promotionParamsService; | ||
25 | @Autowired | 19 | @Autowired |
26 | - protected PromotionInfoMapper promotionInfoMapper; | 20 | + private PromotionParamsService promotionParamsService; |
27 | @Autowired | 21 | @Autowired |
28 | - private IYohoIndexService indexService; | 22 | + protected PromotionInfoMapper promotionInfoMapper; |
29 | @Autowired | 23 | @Autowired |
30 | - private PromotionIndexIndexBuilder promotionIndexIndexBuilder; | 24 | + private PromotionBulkService promotionBulkService; |
31 | 25 | ||
32 | - @Override | ||
33 | - protected EventReportEnum getEventReportEnum() { | ||
34 | - return EventReportEnum.PROMOTIONPARAMSDMQLISTENER_ONMESSAGE; | ||
35 | - } | 26 | + @Override |
27 | + protected EventReportEnum getEventReportEnum() { | ||
28 | + return EventReportEnum.PROMOTIONPARAMSDMQLISTENER_ONMESSAGE; | ||
29 | + } | ||
36 | 30 | ||
37 | - @Override | ||
38 | - protected void deleteData(String id) throws Exception { | ||
39 | - promotionParamsService.delete(Integer.valueOf(id)); | ||
40 | - } | 31 | + @Override |
32 | + protected void deleteData(String id) throws Exception { | ||
33 | + promotionParamsService.delete(Integer.valueOf(id)); | ||
34 | + promotionBulkService.updateIndex(Integer.valueOf(id)); | ||
35 | + } | ||
41 | 36 | ||
42 | - @Override | ||
43 | - protected void updateData(JSONObject data) throws Exception { | ||
44 | - PromotionParams promotionParams = ConvertUtils.toJavaObject(PromotionParams.class, data); | ||
45 | - if (promotionParams == null || promotionParams.getPromotionId() == null) { | ||
46 | - return; | ||
47 | - } | ||
48 | - //更新ES | ||
49 | - promotionParamsService.saveOrUpdate(promotionParams); | ||
50 | - //更新DB | ||
51 | - PromotionInfo promotionInfo = promotionInfoMapper.selectByPrimaryKey(promotionParams.getPromotionId()); | ||
52 | - if(promotionInfo==null){ | 37 | + @Override |
38 | + protected void updateData(JSONObject data) throws Exception { | ||
39 | + PromotionParams promotionParams = ConvertUtils.toJavaObject(PromotionParams.class, data); | ||
40 | + if (promotionParams == null || promotionParams.getPromotionId() == null) { | ||
53 | return; | 41 | return; |
54 | } | 42 | } |
55 | - PromotionIndexBO promotionIndexBO = promotionIndexIndexBuilder.buildPromotionIndexBO(promotionInfo,promotionParams); | ||
56 | - indexService.updateIndexData(ISearchConstants.INDEX_NAME_PROMOTIONINDEX, promotionInfo.getId().toString(), promotionIndexBO); | ||
57 | - } | 43 | + //更新DB |
44 | + promotionParamsService.saveOrUpdate(promotionParams); | ||
45 | + //更新ES | ||
46 | + promotionBulkService.updateIndex(promotionParams.getPromotionId()); | ||
47 | + } | ||
58 | 48 | ||
59 | } | 49 | } |
-
Please register or login to post a comment