Authored by hugufei

ufo增量索引优化

@@ -59,21 +59,16 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application @@ -59,21 +59,16 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application
59 /** 59 /**
60 * 增量 60 * 增量
61 */ 61 */
62 - public UfoProductIndexBO buildUfoProductIndexBOIncrease(Integer id) {  
63 - Product product = ufoProductMapper.selectByPrimaryKey(id);  
64 - if (product == null) {  
65 - return null; 62 + public List<UfoProductIndexBO> buildUfoProductIndexBOIncrease(List<Integer> ids) {
  63 + List<Product> productList = ufoProductMapper.selectByIdList(ids);
  64 + if (productList == null || productList.isEmpty()) {
  65 + return new ArrayList<>();
66 } 66 }
67 - List<Product> productList = Arrays.asList(product);  
68 List<UfoProductIndexBO> ufoProductIndexBOList = buildUfoProductIndexBOList(productList); 67 List<UfoProductIndexBO> ufoProductIndexBOList = buildUfoProductIndexBOList(productList);
69 if (CollectionUtils.isEmpty(ufoProductIndexBOList)) { 68 if (CollectionUtils.isEmpty(ufoProductIndexBOList)) {
70 - return null; 69 + return new ArrayList<>();
71 } 70 }
72 - UfoProductIndexBO ufoProductIndexBO = ufoProductIndexBOList.get(0);  
73 - if (ufoProductIndexBO == null) {  
74 - return null;  
75 - }  
76 - return ufoProductIndexBO; 71 + return ufoProductIndexBOList;
77 } 72 }
78 73
79 /** 74 /**
@@ -106,17 +106,16 @@ public class UfoToYohoIndexBuilder extends IIndexBuilder { @@ -106,17 +106,16 @@ public class UfoToYohoIndexBuilder extends IIndexBuilder {
106 /** 106 /**
107 * 增量构建 107 * 增量构建
108 */ 108 */
109 - public ProductIndexBO buildProductIndexBOIncrease(Integer ufoProductId) {  
110 - Product product = ufoProductMapper.selectByPrimaryKey(ufoProductId);  
111 - if (product == null) {  
112 - return null; 109 + public List<ProductIndexBO> buildProductIndexBOIncrease(List<Integer> ufoProductIdList) {
  110 + List<Product> ufoProductList = ufoProductMapper.selectByIdList(ufoProductIdList);
  111 + if (ufoProductList == null) {
  112 + return new ArrayList<>();
113 } 113 }
114 - List<Product> productList = new ArrayList<>(Arrays.asList(product));  
115 - List<ProductIndexBO> productIndexBOList = buildProductIndexBOList(productList); 114 + List<ProductIndexBO> productIndexBOList = buildProductIndexBOList(ufoProductList);
116 if (CollectionUtils.isEmpty(productIndexBOList)) { 115 if (CollectionUtils.isEmpty(productIndexBOList)) {
117 - return null; 116 + return new ArrayList<>();
118 } 117 }
119 - return productIndexBOList.get(0); 118 + return productIndexBOList;
120 } 119 }
121 120
122 private List<ProductIndexBO> buildProductIndexBOList(List<Product> productList) { 121 private List<ProductIndexBO> buildProductIndexBOList(List<Product> productList) {
@@ -43,31 +43,27 @@ public class CommonBulkService implements ApplicationEventPublisherAware { @@ -43,31 +43,27 @@ public class CommonBulkService implements ApplicationEventPublisherAware {
43 ExecutorService executorService = Executors.newSingleThreadExecutor(); 43 ExecutorService executorService = Executors.newSingleThreadExecutor();
44 executorService.submit(() -> { 44 executorService.submit(() -> {
45 while (true) { 45 while (true) {
46 - doBulk();  
47 - }  
48 - });  
49 - }  
50 -  
51 - private void doBulk() {  
52 - try {  
53 - long begin = System.currentTimeMillis(); 46 + try {
  47 + long begin = System.currentTimeMillis();
54 48
55 - //1、从队列中获取全部数据  
56 - List<ESBluk> blukList = new ArrayList<>();  
57 - queue.drainTo(blukList); 49 + //1、从队列中获取全部数据
  50 + List<ESBluk> blukList = new ArrayList<>();
  51 + queue.drainTo(blukList);
58 52
59 - //2、批量更新Es  
60 - if (CollectionUtils.isNotEmpty(blukList)) {  
61 - yohoIndexService.bulk(blukList);  
62 - logger.info("doBulk, the blukList size is {} and cost {} ms,", blukList.size(), System.currentTimeMillis() - begin);  
63 - Thread.sleep(50);  
64 - } else {  
65 - Thread.sleep(1000); 53 + //2、批量更新Es
  54 + if (CollectionUtils.isNotEmpty(blukList)) {
  55 + yohoIndexService.bulk(blukList);
  56 + logger.info("doBulk, the blukList size is {} and cost {} ms,", blukList.size(), System.currentTimeMillis() - begin);
  57 + Thread.sleep(50);
  58 + } else {
  59 + Thread.sleep(1000);
  60 + }
  61 + } catch (Exception e) {
  62 + logger.error(e.getMessage(), e);
  63 + publisher.publishEvent(new SearchEvent("doBulk", "CommonBulkService.doBulk", MoudleEnum.consumer, "exception", IgnoreSomeException.filterSomeException(e), null));
  64 + }
66 } 65 }
67 - } catch (Exception e) {  
68 - logger.error(e.getMessage(), e);  
69 - publisher.publishEvent(new SearchEvent("doBulk", "CommonBulkService.doBulk", MoudleEnum.consumer, "exception", IgnoreSomeException.filterSomeException(e), null));  
70 - } 66 + });
71 } 67 }
72 68
73 public void add(ESBluk esBluk) { 69 public void add(ESBluk esBluk) {
@@ -5,12 +5,12 @@ import com.yoho.error.event.SearchEvent; @@ -5,12 +5,12 @@ import com.yoho.error.event.SearchEvent;
5 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
6 import com.yoho.search.base.utils.ISearchConstants; 6 import com.yoho.search.base.utils.ISearchConstants;
7 import com.yoho.search.base.utils.MoudleEnum; 7 import com.yoho.search.base.utils.MoudleEnum;
8 -import com.yoho.search.consumer.service.utils.CostStatistics;  
9 import com.yoho.search.consumer.common.IYohoIndexService; 8 import com.yoho.search.consumer.common.IYohoIndexService;
10 import com.yoho.search.consumer.index.fullbuild.tbl.TblProductIndexNewBuilder; 9 import com.yoho.search.consumer.index.fullbuild.tbl.TblProductIndexNewBuilder;
11 import com.yoho.search.consumer.index.fullbuild.tbl.TblToYohoIndexBuilder; 10 import com.yoho.search.consumer.index.fullbuild.tbl.TblToYohoIndexBuilder;
12 import com.yoho.search.consumer.service.bo.ProductIndexBO; 11 import com.yoho.search.consumer.service.bo.ProductIndexBO;
13 import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService; 12 import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService;
  13 +import com.yoho.search.consumer.service.utils.CostStatistics;
14 import com.yoho.search.core.es.model.ESBluk; 14 import com.yoho.search.core.es.model.ESBluk;
15 import com.yoho.search.core.es.utils.IgnoreSomeException; 15 import com.yoho.search.core.es.utils.IgnoreSomeException;
16 import org.apache.commons.collections.CollectionUtils; 16 import org.apache.commons.collections.CollectionUtils;
@@ -35,6 +35,7 @@ import java.util.concurrent.Executors; @@ -35,6 +35,7 @@ import java.util.concurrent.Executors;
35 */ 35 */
36 @Component 36 @Component
37 public class GlobalIndexBulkService implements ApplicationEventPublisherAware { 37 public class GlobalIndexBulkService implements ApplicationEventPublisherAware {
  38 +
38 private static final Logger logger = LoggerFactory.getLogger(GlobalIndexBulkService.class); 39 private static final Logger logger = LoggerFactory.getLogger(GlobalIndexBulkService.class);
39 40
40 protected ApplicationEventPublisher publisher; 41 protected ApplicationEventPublisher publisher;
@@ -42,7 +43,6 @@ public class GlobalIndexBulkService implements ApplicationEventPublisherAware { @@ -42,7 +43,6 @@ public class GlobalIndexBulkService implements ApplicationEventPublisherAware {
42 private static final String indexNameProductIndex = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 43 private static final String indexNameProductIndex = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
43 private static final String indexNameTblProductNew = ISearchConstants.INDEX_NAME_TBLPRODUCT_NEW; 44 private static final String indexNameTblProductNew = ISearchConstants.INDEX_NAME_TBLPRODUCT_NEW;
44 45
45 -  
46 private static final long THREAD_SLEEP_IDLE = 2000; 46 private static final long THREAD_SLEEP_IDLE = 2000;
47 private static final long THREAD_SLEEP_WORK = 50; 47 private static final long THREAD_SLEEP_WORK = 50;
48 48
@@ -191,7 +191,7 @@ public class GlobalIndexBulkService implements ApplicationEventPublisherAware { @@ -191,7 +191,7 @@ public class GlobalIndexBulkService implements ApplicationEventPublisherAware {
191 191
192 } catch (Exception e) { 192 } catch (Exception e) {
193 logger.error(e.getMessage(), e); 193 logger.error(e.getMessage(), e);
194 - publisher.publishEvent(new SearchEvent("doBulkDeleteGlobalIndex","doBulkDeleteGlobalIndex.GlobalIndexBulkService", MoudleEnum.consumer, "exception", IgnoreSomeException.filterSomeException(e), null)); 194 + publisher.publishEvent(new SearchEvent("doBulkDeleteGlobalIndex", "doBulkDeleteGlobalIndex.GlobalIndexBulkService", MoudleEnum.consumer, "exception", IgnoreSomeException.filterSomeException(e), null));
195 return THREAD_SLEEP_WORK; 195 return THREAD_SLEEP_WORK;
196 } 196 }
197 } 197 }
@@ -179,4 +179,5 @@ public class PromotionBulkService { @@ -179,4 +179,5 @@ public class PromotionBulkService {
179 } 179 }
180 return results; 180 return results;
181 } 181 }
  182 +
182 } 183 }
  1 +package com.yoho.search.consumer.index.increment.bulks;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.yoho.error.event.SearchEvent;
  5 +import com.yoho.search.base.utils.ISearchConstants;
  6 +import com.yoho.search.base.utils.MoudleEnum;
  7 +import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;
  8 +import com.yoho.search.consumer.service.bo.ProductIndexBO;
  9 +import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService;
  10 +import com.yoho.search.core.es.model.ESBluk;
  11 +import com.yoho.search.core.es.utils.IgnoreSomeException;
  12 +import org.apache.commons.collections.CollectionUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.context.ApplicationEventPublisher;
  17 +import org.springframework.context.ApplicationEventPublisherAware;
  18 +import org.springframework.stereotype.Component;
  19 +
  20 +import javax.annotation.PostConstruct;
  21 +import java.util.ArrayList;
  22 +import java.util.List;
  23 +import java.util.Map;
  24 +import java.util.concurrent.ArrayBlockingQueue;
  25 +import java.util.concurrent.ExecutorService;
  26 +import java.util.concurrent.Executors;
  27 +
  28 +@Component
  29 +public class Ufo2YohoBulkService implements ApplicationEventPublisherAware {
  30 +
  31 + private static final Logger logger = LoggerFactory.getLogger(UfoCommonBulkService.class);
  32 +
  33 + private final ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<>(200);
  34 +
  35 + @Autowired
  36 + private CommonBulkService commonBulkService;
  37 + @Autowired
  38 + private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;
  39 + @Autowired
  40 + private ProductIndexBOToMapService productIndexBOToMapService;
  41 +
  42 + protected ApplicationEventPublisher publisher;
  43 +
  44 + @Override
  45 + public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
  46 + this.publisher = applicationEventPublisher;
  47 + }
  48 +
  49 + @PostConstruct
  50 + void init() {
  51 + // 批量更新ES
  52 + ExecutorService executorService = Executors.newSingleThreadExecutor();
  53 + executorService.submit(() -> {
  54 + while (true) {
  55 + try {
  56 + long begin = System.currentTimeMillis();
  57 +
  58 + //1、从队列中获取全部数据
  59 + List<Integer> idList = new ArrayList<>();
  60 + queue.drainTo(idList);
  61 +
  62 + //2、批量更新Es
  63 + if (CollectionUtils.isNotEmpty(idList)) {
  64 + doBulkToEs(idList);
  65 + logger.info("doBulk, the blukList size is {} and cost {} ms,", idList.size(), System.currentTimeMillis() - begin);
  66 + Thread.sleep(100);
  67 + } else {
  68 + Thread.sleep(2000);
  69 + }
  70 + } catch (Exception e) {
  71 + logger.error(e.getMessage(), e);
  72 + publisher.publishEvent(new SearchEvent("doBulk", "UfoCommonBulkByIdService.doBulkToEs", MoudleEnum.consumer, "exception", IgnoreSomeException.filterSomeException(e), null));
  73 + }
  74 + }
  75 + });
  76 + }
  77 +
  78 + private void doBulkToEs(List<Integer> ufoProductIdList) {
  79 + List<ProductIndexBO> productIndexBOList = ufoToYohoIndexBuilder.buildProductIndexBOIncrease(ufoProductIdList);
  80 + if (productIndexBOList == null || productIndexBOList.isEmpty()) {
  81 + return;
  82 + }
  83 + //转成有货索引
  84 + for (ProductIndexBO productIndexBO : productIndexBOList) {
  85 + Map<String, Object> dataMap = productIndexBOToMapService.beanToMap(productIndexBO);
  86 + commonBulkService.add(new ESBluk(JSON.toJSONString(dataMap), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false));
  87 + }
  88 + }
  89 +
  90 + public void addUpdateUfoProductId(Integer productId) {
  91 + try {
  92 + queue.put(productId);
  93 + } catch (Exception e) {
  94 + logger.error(e.getMessage(), e);
  95 + }
  96 + }
  97 +
  98 +}
1 package com.yoho.search.consumer.index.increment.bulks; 1 package com.yoho.search.consumer.index.increment.bulks;
2 2
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
3 import com.yoho.error.event.SearchEvent; 5 import com.yoho.error.event.SearchEvent;
4 import com.yoho.search.base.utils.ISearchConstants; 6 import com.yoho.search.base.utils.ISearchConstants;
5 import com.yoho.search.base.utils.MoudleEnum; 7 import com.yoho.search.base.utils.MoudleEnum;
6 import com.yoho.search.consumer.common.IYohoIndexService; 8 import com.yoho.search.consumer.common.IYohoIndexService;
  9 +import com.yoho.search.consumer.index.fullbuild.ufo.UfoProductIndexBuilder;
  10 +import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
7 import com.yoho.search.core.es.model.ESBluk; 11 import com.yoho.search.core.es.model.ESBluk;
8 import com.yoho.search.core.es.utils.IgnoreSomeException; 12 import com.yoho.search.core.es.utils.IgnoreSomeException;
9 import org.apache.commons.collections.CollectionUtils; 13 import org.apache.commons.collections.CollectionUtils;
@@ -26,10 +30,12 @@ public class UfoCommonBulkService implements ApplicationEventPublisherAware { @@ -26,10 +30,12 @@ public class UfoCommonBulkService implements ApplicationEventPublisherAware {
26 30
27 private static final Logger logger = LoggerFactory.getLogger(UfoCommonBulkService.class); 31 private static final Logger logger = LoggerFactory.getLogger(UfoCommonBulkService.class);
28 32
29 - private final ArrayBlockingQueue<ESBluk> queue = new ArrayBlockingQueue<>(200); 33 + private final ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<>(200);
30 34
31 @Autowired 35 @Autowired
32 private IYohoIndexService yohoIndexService; 36 private IYohoIndexService yohoIndexService;
  37 + @Autowired
  38 + private UfoProductIndexBuilder ufoProductIndexBuilder;
33 39
34 protected ApplicationEventPublisher publisher; 40 protected ApplicationEventPublisher publisher;
35 41
@@ -44,39 +50,59 @@ public class UfoCommonBulkService implements ApplicationEventPublisherAware { @@ -44,39 +50,59 @@ public class UfoCommonBulkService implements ApplicationEventPublisherAware {
44 ExecutorService executorService = Executors.newSingleThreadExecutor(); 50 ExecutorService executorService = Executors.newSingleThreadExecutor();
45 executorService.submit(() -> { 51 executorService.submit(() -> {
46 while (true) { 52 while (true) {
47 - doBulk(); 53 + try {
  54 + long begin = System.currentTimeMillis();
  55 +
  56 + //1、从队列中获取全部数据
  57 + List<Integer> idList = new ArrayList<>();
  58 + queue.drainTo(idList);
  59 +
  60 + //2、批量更新Es
  61 + if (CollectionUtils.isNotEmpty(idList)) {
  62 + doBulkToEs(idList);
  63 + logger.info("doBulk, the blukList size is {} and cost {} ms,", idList.size(), System.currentTimeMillis() - begin);
  64 + Thread.sleep(100);
  65 + } else {
  66 + Thread.sleep(2000);
  67 + }
  68 + } catch (Exception e) {
  69 + logger.error(e.getMessage(), e);
  70 + publisher.publishEvent(new SearchEvent("doBulk", "UfoCommonBulkByIdService.doBulkToEs", MoudleEnum.consumer, "exception", IgnoreSomeException.filterSomeException(e), null));
  71 + }
48 } 72 }
49 }); 73 });
50 } 74 }
51 75
52 - private void doBulk() {  
53 - try {  
54 - long begin = System.currentTimeMillis();  
55 -  
56 - //1、从队列中获取全部数据  
57 - List<ESBluk> blukList = new ArrayList<>();  
58 - queue.drainTo(blukList); 76 + private void doBulkToEs(List<Integer> idList) {
  77 + List<UfoProductIndexBO> ufoProductIndexBOList = ufoProductIndexBuilder.buildUfoProductIndexBOIncrease(idList);
  78 + if (ufoProductIndexBOList == null || ufoProductIndexBOList.isEmpty()) {
  79 + return;
  80 + }
  81 + List<ESBluk> esBlukList = new ArrayList<>();
  82 + for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
  83 + JSONObject ufoProductIndexBOJSONObject = (JSONObject) JSON.toJSON(ufoProductIndexBO);
  84 + ESBluk esBluk = new ESBluk(ufoProductIndexBOJSONObject.toJSONString(), ufoProductIndexBO.getId().toString(), ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, false);
  85 + esBlukList.add(esBluk);
  86 + }
  87 + yohoIndexService.bulk(esBlukList);
  88 + }
59 89
60 - //2、批量更新Es  
61 - if (CollectionUtils.isNotEmpty(blukList)) {  
62 - yohoIndexService.bulk(blukList);  
63 - logger.info("doBulk, the blukList size is {} and cost {} ms,", blukList.size(), System.currentTimeMillis() - begin);  
64 - Thread.sleep(50);  
65 - } else {  
66 - Thread.sleep(2000);  
67 - } 90 + public void addUpdateData(String jsonString, Integer productId) {
  91 + try {
  92 +// ESBluk esBluk = new ESBluk(jsonString, productId.toString(), ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, false);
  93 +// dataIncrease.put(esBluk);
  94 + queue.put(productId);
68 } catch (Exception e) { 95 } catch (Exception e) {
69 logger.error(e.getMessage(), e); 96 logger.error(e.getMessage(), e);
70 - publisher.publishEvent(new SearchEvent("doBulk", "UfoCommonBulkService.doBulk", MoudleEnum.consumer, "exception", IgnoreSomeException.filterSomeException(e), null));  
71 } 97 }
72 } 98 }
73 99
74 - public void addUpdateData(String jsonString,Integer id) { 100 + public void addUfoUpdateProductId(Integer ufoProductId) {
75 try { 101 try {
76 - ESBluk esBluk = new ESBluk(jsonString, id.toString(), ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, false);  
77 - queue.put(esBluk); 102 + queue.put(ufoProductId);
78 } catch (Exception e) { 103 } catch (Exception e) {
79 logger.error(e.getMessage(), e); 104 logger.error(e.getMessage(), e);
80 } 105 }
81 } 106 }
  107 +
82 } 108 }
@@ -34,7 +34,6 @@ public class UfoStoragePriceMqListener extends AbstractMqListener { @@ -34,7 +34,6 @@ public class UfoStoragePriceMqListener extends AbstractMqListener {
34 ufoIndexUpdateHelper.updateUfoIndexByUfoProductId(storagePrice.getProductId()); 34 ufoIndexUpdateHelper.updateUfoIndexByUfoProductId(storagePrice.getProductId());
35 ufo2YohoIndexUpdateHelper.updateYohoIndex(storagePrice.getProductId()); 35 ufo2YohoIndexUpdateHelper.updateYohoIndex(storagePrice.getProductId());
36 } 36 }
37 -  
38 } 37 }
39 38
40 @Override 39 @Override
1 package com.yoho.search.consumer.index.mix; 1 package com.yoho.search.consumer.index.mix;
2 2
3 -import com.alibaba.fastjson.JSON;  
4 -import com.alibaba.fastjson.JSONObject;  
5 -import com.yoho.search.base.utils.ISearchConstants;  
6 -import com.yoho.search.base.utils.UfoProductIndexEsField;  
7 -import com.yoho.search.consumer.index.fullbuild.ufo.UfoProductIndexBuilder;  
8 -import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;  
9 -import com.yoho.search.consumer.index.fullbuild.ufo.YohoToUfoIndexBuilder;  
10 -import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;  
11 -import com.yoho.search.consumer.index.increment.bulks.UfoCommonBulkService;  
12 -import com.yoho.search.consumer.service.bo.ProductGoodsBO;  
13 -import com.yoho.search.consumer.service.bo.ProductIndexBO;  
14 -import com.yoho.search.consumer.service.bo.UfoProductIndexBO;  
15 -import com.yoho.search.consumer.service.daoService.ProductService;  
16 -import com.yoho.search.consumer.service.logicService.ProductGoodsLogicService;  
17 -import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService;  
18 -import com.yoho.search.consumer.service.logicService.tbl.util.StringUtils;  
19 -import com.yoho.search.consumer.service.logicService.ufo.yoho2ufo.Yoho2UfoColorService;  
20 -import com.yoho.search.consumer.service.logicService.ufo.yoho2ufo.Yoho2UfoSizeService;  
21 -import com.yoho.search.core.es.model.ESBluk;  
22 -import com.yoho.search.dal.Yoho2ufoProductMapper;  
23 -import com.yoho.search.dal.model.Product;  
24 -import com.yoho.search.dal.model.ProductKeywords;  
25 -import com.yoho.search.dal.model.ufo_product.ProductColor;  
26 -import com.yoho.search.dal.model.ufo_product.Yoho2ufoProduct;  
27 -import org.apache.commons.collections.CollectionUtils; 3 +import com.yoho.search.consumer.index.increment.bulks.Ufo2YohoBulkService;
28 import org.slf4j.Logger; 4 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
32 8
33 -import java.util.Arrays;  
34 -import java.util.HashMap;  
35 -import java.util.List;  
36 -import java.util.Map;  
37 -  
38 -import static java.util.stream.Collectors.joining;  
39 -  
40 -/**  
41 - * @author wangnan  
42 - * @version 2018/9/14  
43 - */  
44 @Component 9 @Component
45 public class Ufo2YohoIndexUpdateHelper { 10 public class Ufo2YohoIndexUpdateHelper {
46 11
47 private final Logger logger = LoggerFactory.getLogger(this.getClass()); 12 private final Logger logger = LoggerFactory.getLogger(this.getClass());
48 13
49 @Autowired 14 @Autowired
50 - private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;  
51 - @Autowired  
52 - private ProductIndexBOToMapService productIndexBOToMapService;  
53 - @Autowired  
54 - private CommonBulkService commonBulkService; 15 + private Ufo2YohoBulkService ufo2YohuoBulkService;
55 16
56 /** 17 /**
57 * ufo相关表增量更新yoho索引 18 * ufo相关表增量更新yoho索引
@@ -60,12 +21,7 @@ public class Ufo2YohoIndexUpdateHelper { @@ -60,12 +21,7 @@ public class Ufo2YohoIndexUpdateHelper {
60 */ 21 */
61 public void updateYohoIndex(Integer ufoProductId) { 22 public void updateYohoIndex(Integer ufoProductId) {
62 try { 23 try {
63 - ProductIndexBO productIndexBO = ufoToYohoIndexBuilder.buildProductIndexBOIncrease(ufoProductId);  
64 - if (productIndexBO == null) {  
65 - return;  
66 - }  
67 - Map<String, Object> dataMap = productIndexBOToMapService.beanToMap(productIndexBO);  
68 - commonBulkService.add(new ESBluk(JSON.toJSONString(dataMap), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false)); 24 + ufo2YohuoBulkService.addUpdateUfoProductId(ufoProductId);
69 } catch (Exception e) { 25 } catch (Exception e) {
70 logger.error(e.getMessage(), e); 26 logger.error(e.getMessage(), e);
71 } 27 }
1 package com.yoho.search.consumer.index.mix; 1 package com.yoho.search.consumer.index.mix;
2 2
3 -import com.alibaba.fastjson.JSON;  
4 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
5 -import com.yoho.search.base.utils.ISearchConstants;  
6 -import com.yoho.search.base.utils.UfoProductIndexEsField;  
7 -import com.yoho.search.consumer.index.fullbuild.ufo.UfoProductIndexBuilder;  
8 -import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;  
9 -import com.yoho.search.consumer.index.fullbuild.ufo.YohoToUfoIndexBuilder;  
10 -import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;  
11 import com.yoho.search.consumer.index.increment.bulks.UfoCommonBulkService; 4 import com.yoho.search.consumer.index.increment.bulks.UfoCommonBulkService;
12 -import com.yoho.search.consumer.service.bo.ProductGoodsBO;  
13 -import com.yoho.search.consumer.service.bo.ProductIndexBO;  
14 -import com.yoho.search.consumer.service.bo.UfoProductIndexBO;  
15 -import com.yoho.search.consumer.service.daoService.ProductService;  
16 -import com.yoho.search.consumer.service.logicService.ProductGoodsLogicService;  
17 -import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService;  
18 -import com.yoho.search.consumer.service.logicService.tbl.util.StringUtils;  
19 -import com.yoho.search.consumer.service.logicService.ufo.yoho2ufo.Yoho2UfoColorService;  
20 -import com.yoho.search.consumer.service.logicService.ufo.yoho2ufo.Yoho2UfoSizeService;  
21 -import com.yoho.search.core.es.model.ESBluk;  
22 -import com.yoho.search.dal.Yoho2ufoProductMapper;  
23 -import com.yoho.search.dal.model.Product;  
24 -import com.yoho.search.dal.model.ProductKeywords;  
25 -import com.yoho.search.dal.model.ufo_product.ProductColor;  
26 -import com.yoho.search.dal.model.ufo_product.Yoho2ufoProduct;  
27 -import org.apache.commons.collections.CollectionUtils;  
28 import org.slf4j.Logger; 5 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
32 9
33 -import java.util.Arrays;  
34 -import java.util.HashMap;  
35 -import java.util.List;  
36 import java.util.Map; 10 import java.util.Map;
37 11
38 -import static java.util.stream.Collectors.joining;  
39 -  
40 -/**  
41 - * @author wangnan  
42 - * @version 2018/9/14  
43 - */  
44 @Component 12 @Component
45 public class UfoIndexUpdateHelper { 13 public class UfoIndexUpdateHelper {
46 14
47 private final Logger logger = LoggerFactory.getLogger(this.getClass()); 15 private final Logger logger = LoggerFactory.getLogger(this.getClass());
48 16
49 @Autowired 17 @Autowired
50 - private UfoProductIndexBuilder ufoProductIndexBuilder;  
51 - @Autowired  
52 private UfoCommonBulkService ufoCommonBulkService; 18 private UfoCommonBulkService ufoCommonBulkService;
53 19
54 /** 20 /**
55 * ufo相关表增量更新ufo索引 21 * ufo相关表增量更新ufo索引
56 */ 22 */
57 - public void updateUfoIndexByUfoProductId(Integer productId) { 23 + public void updateUfoIndexByUfoProductId(Integer ufoProductId) {
58 try { 24 try {
59 - UfoProductIndexBO ufoProductIndexBO = ufoProductIndexBuilder.buildUfoProductIndexBOIncrease(productId);  
60 - if (ufoProductIndexBO == null) {  
61 - return;  
62 - }  
63 - updateUfoIndexByBO(ufoProductIndexBO); 25 + ufoCommonBulkService.addUfoUpdateProductId(ufoProductId);
64 } catch (Exception e) { 26 } catch (Exception e) {
65 logger.error(e.getMessage(), e); 27 logger.error(e.getMessage(), e);
66 } 28 }
67 } 29 }
68 30
69 - private void updateUfoIndexByBO(UfoProductIndexBO ufoProductIndexBO) {  
70 - try {  
71 - if (ufoProductIndexBO == null) {  
72 - return;  
73 - }  
74 - JSONObject ufoProductIndexBOJSONObject = (JSONObject) JSON.toJSON(ufoProductIndexBO);  
75 - ufoCommonBulkService.addUpdateData(ufoProductIndexBOJSONObject.toJSONString(), ufoProductIndexBO.getId());  
76 - } catch (Exception e) {  
77 - logger.error(e.getMessage(), e);  
78 - }  
79 - }  
80 -  
81 - public void updateUfoIndexWithDataMap(Map<String, Object> indexData, Integer id) { 31 + /**
  32 + * ufo相关表增量更新ufo索引
  33 + */
  34 + public void updateUfoIndexWithDataMap(Map<String, Object> indexData, Integer ufoProductId) {
82 JSONObject jsonObject = new JSONObject(indexData); 35 JSONObject jsonObject = new JSONObject(indexData);
83 - ufoCommonBulkService.addUpdateData(jsonObject.toJSONString(),id); 36 + ufoCommonBulkService.addUpdateData(jsonObject.toJSONString(),ufoProductId);
84 } 37 }
85 38
86 } 39 }