Authored by wangnan9279

fix

Showing 19 changed files with 160 additions and 340 deletions
@@ -13,10 +13,7 @@ import org.springframework.context.ApplicationContext; @@ -13,10 +13,7 @@ import org.springframework.context.ApplicationContext;
13 import org.springframework.context.ApplicationContextAware; 13 import org.springframework.context.ApplicationContextAware;
14 import org.springframework.stereotype.Component; 14 import org.springframework.stereotype.Component;
15 15
16 -import java.util.ArrayList;  
17 -import java.util.Comparator;  
18 -import java.util.List;  
19 -import java.util.Map; 16 +import java.util.*;
20 import java.util.stream.Collectors; 17 import java.util.stream.Collectors;
21 18
22 /** 19 /**
@@ -61,12 +58,21 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application @@ -61,12 +58,21 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application
61 /** 58 /**
62 * 增量 59 * 增量
63 */ 60 */
64 - public List<UfoProductIndexBO> buildUfoProductIndexBOIncrease(List<Integer> idList) {  
65 - List<UfoProduct> ufoProductList = ufoProductMapper.selectByIdList(idList);  
66 - if (CollectionUtils.isEmpty(ufoProductList)) {  
67 - return new ArrayList<>(0); 61 + public UfoProductIndexBO buildUfoProductIndexBOIncrease(Integer id) {
  62 + UfoProduct ufoProduct = ufoProductMapper.selectByPrimaryKey(id);
  63 + if (ufoProduct == null) {
  64 + return null;
68 } 65 }
69 - return buildUfoProductIndexBOList(ufoProductList); 66 + List<UfoProduct> ufoProductList = Arrays.asList(ufoProduct);
  67 + List<UfoProductIndexBO> ufoProductIndexBOList = buildUfoProductIndexBOList(ufoProductList);
  68 + if (CollectionUtils.isEmpty(ufoProductIndexBOList)) {
  69 + return null;
  70 + }
  71 + UfoProductIndexBO ufoProductIndexBO = ufoProductIndexBOList.get(0);
  72 + if (ufoProductIndexBO == null) {
  73 + return null;
  74 + }
  75 + return ufoProductIndexBO;
70 } 76 }
71 77
72 /** 78 /**
@@ -77,24 +83,28 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application @@ -77,24 +83,28 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application
77 for (UfoProduct ufoProduct : ufoProductList) { 83 for (UfoProduct ufoProduct : ufoProductList) {
78 UfoProductIndexBO ufoProductIndexBO = new UfoProductIndexBO(); 84 UfoProductIndexBO ufoProductIndexBO = new UfoProductIndexBO();
79 BeanUtils.copyProperties(ufoProduct, ufoProductIndexBO); 85 BeanUtils.copyProperties(ufoProduct, ufoProductIndexBO);
80 - //基本属性  
81 - ufoProductIndexBO.setIdString(ufoProduct.getId().toString());  
82 - ufoProductIndexBO.setGenderS("男,女");  
83 - if (ufoProduct.getGender() != null) {  
84 - if (ufoProduct.getGender().equals("1")) {  
85 - ufoProductIndexBO.setGenderS("男");  
86 - }  
87 - if (ufoProduct.getGender().equals("2")) {  
88 - ufoProductIndexBO.setGenderS("女");  
89 - }  
90 - } 86 + this.buildSimpleField(ufoProduct, ufoProductIndexBO);
91 ufoProductIndexBOList.add(ufoProductIndexBO); 87 ufoProductIndexBOList.add(ufoProductIndexBO);
92 } 88 }
93 List<Integer> idList = ufoProductList.stream().map(UfoProduct::getId).collect(Collectors.toList()); 89 List<Integer> idList = ufoProductList.stream().map(UfoProduct::getId).collect(Collectors.toList());
94 //调用每个builder构建UfoProductIndexBO的各种属性数据 90 //调用每个builder构建UfoProductIndexBO的各种属性数据
95 - indexFieldBuilderList.stream().forEach(viewBuilder -> viewBuilder.build(ufoProductIndexBOList, idList)); 91 + indexFieldBuilderList.stream().forEach(builder -> builder.build(ufoProductIndexBOList, idList));
96 return ufoProductIndexBOList; 92 return ufoProductIndexBOList;
97 } 93 }
98 94
  95 + private void buildSimpleField(UfoProduct ufoProduct, UfoProductIndexBO ufoProductIndexBO) {
  96 + ufoProductIndexBO.setIdString(ufoProduct.getId().toString());
  97 + ufoProductIndexBO.setGenderS("男,女");
  98 + if (ufoProduct.getGender() == null) {
  99 + return;
  100 + }
  101 + if ("1".equals(ufoProduct.getGender())) {
  102 + ufoProductIndexBO.setGenderS("男");
  103 + }
  104 + if ("2".equals(ufoProduct.getGender())) {
  105 + ufoProductIndexBO.setGenderS("女");
  106 + }
  107 + }
  108 +
99 109
100 } 110 }
@@ -7,22 +7,13 @@ import com.yoho.search.base.utils.ISearchConstants; @@ -7,22 +7,13 @@ import com.yoho.search.base.utils.ISearchConstants;
7 import com.yoho.search.consumer.common.IYohoIndexService; 7 import com.yoho.search.consumer.common.IYohoIndexService;
8 import com.yoho.search.consumer.index.fullbuild.tbl.TblBrandIndexBuilder; 8 import com.yoho.search.consumer.index.fullbuild.tbl.TblBrandIndexBuilder;
9 import com.yoho.search.consumer.index.increment.AbstractMqListener; 9 import com.yoho.search.consumer.index.increment.AbstractMqListener;
10 -import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;  
11 import com.yoho.search.consumer.service.daoService.tbl.TblBrandService; 10 import com.yoho.search.consumer.service.daoService.tbl.TblBrandService;
12 -import com.yoho.search.consumer.service.daoService.tbl.TblProductService;  
13 import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService; 11 import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;
14 -import com.yoho.search.core.es.model.ESBluk;  
15 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 12 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
16 import com.yoho.search.dal.model.TblBrand; 13 import com.yoho.search.dal.model.TblBrand;
17 -import org.apache.commons.collections.CollectionUtils;  
18 -import org.slf4j.Logger;  
19 -import org.slf4j.LoggerFactory;  
20 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Component; 15 import org.springframework.stereotype.Component;
22 16
23 -import java.util.ArrayList;  
24 -import java.util.List;  
25 -  
26 /** 17 /**
27 * Created by wangnan on 2016/12/16. 18 * Created by wangnan on 2016/12/16.
28 */ 19 */
@@ -30,17 +21,11 @@ import java.util.List; @@ -30,17 +21,11 @@ import java.util.List;
30 @SearchMqConsumerListerner(tableName = "tbl_brand") 21 @SearchMqConsumerListerner(tableName = "tbl_brand")
31 public class TblBrandMqListener extends AbstractMqListener { 22 public class TblBrandMqListener extends AbstractMqListener {
32 23
33 - private final Logger logger = LoggerFactory.getLogger(this.getClass());  
34 -  
35 @Autowired 24 @Autowired
36 private TblBrandService tblBrandService; 25 private TblBrandService tblBrandService;
37 @Autowired 26 @Autowired
38 private IYohoIndexService indexService; 27 private IYohoIndexService indexService;
39 @Autowired 28 @Autowired
40 - private TblProductService tblProductService;  
41 - @Autowired  
42 - private GlobalIndexBulkService globalIndexBulkService;  
43 - @Autowired  
44 private BasicDataCacheService basicDataCacheService; 29 private BasicDataCacheService basicDataCacheService;
45 @Autowired 30 @Autowired
46 private TblBrandIndexBuilder tblBrandIndexBuilder; 31 private TblBrandIndexBuilder tblBrandIndexBuilder;
@@ -57,37 +42,19 @@ public class TblBrandMqListener extends AbstractMqListener { @@ -57,37 +42,19 @@ public class TblBrandMqListener extends AbstractMqListener {
57 42
58 @Override 43 @Override
59 protected void deleteData(String id) throws Exception { 44 protected void deleteData(String id) throws Exception {
60 - long begin = System.currentTimeMillis();  
61 - // update DB  
62 tblBrandService.delete(Integer.valueOf(id)); 45 tblBrandService.delete(Integer.valueOf(id));
63 - // update ES index:brand  
64 - List<ESBluk> results = new ArrayList<ESBluk>();  
65 - results.add(new ESBluk(null, "-" + id, this.getIndexName(), this.getIndexName(), true));  
66 - indexService.bulk(results);  
67 - logger.info("[func=deleteData][tableName=tblBrand][id={}][cost={}ms]", id, (System.currentTimeMillis() - begin)); 46 + indexService.deleteIndexData(this.getIndexName(), id);
68 } 47 }
69 48
70 @Override 49 @Override
71 protected void updateData(JSONObject data) throws Exception { 50 protected void updateData(JSONObject data) throws Exception {
72 - long begin = System.currentTimeMillis();  
73 TblBrand tblBrand = (TblBrand) ConvertUtils.transMap2Bean(TblBrand.class, data); 51 TblBrand tblBrand = (TblBrand) ConvertUtils.transMap2Bean(TblBrand.class, data);
74 if (tblBrand == null || tblBrand.getBrandId() == null) { 52 if (tblBrand == null || tblBrand.getBrandId() == null) {
75 return; 53 return;
76 } 54 }
77 - //update DB  
78 tblBrandService.saveOrUpdate(tblBrand); 55 tblBrandService.saveOrUpdate(tblBrand);
79 - //update TblBrand index  
80 tblBrandIndexBuilder.filterTblBrand(tblBrand); 56 tblBrandIndexBuilder.filterTblBrand(tblBrand);
81 indexService.updateIndexData(this.getIndexName(), tblBrand.getBrandId().toString(), tblBrand); 57 indexService.updateIndexData(this.getIndexName(), tblBrand.getBrandId().toString(), tblBrand);
82 - //update ProductIndex、tblProduct index  
83 - List<Integer> sknList = tblProductService.getSknsByBrandId(tblBrand.getBrandId());  
84 - if (CollectionUtils.isEmpty(sknList)) {  
85 - return;  
86 - }  
87 - for (Integer skn : sknList) {  
88 - globalIndexBulkService.updateGlobalIndex(skn);  
89 - }  
90 - logger.info("[func=updateData][tableName=tblBrand][id={}][cost={}ms]", tblBrand.getBrandId(), (System.currentTimeMillis() - begin));  
91 } 58 }
92 59
93 @Override 60 @Override
@@ -3,14 +3,11 @@ package com.yoho.search.consumer.index.increment.tbl; @@ -3,14 +3,11 @@ package com.yoho.search.consumer.index.increment.tbl;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.ConvertUtils; 4 import com.yoho.search.base.utils.ConvertUtils;
5 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
6 -import com.yoho.search.base.utils.ISearchConstants;  
7 import com.yoho.search.consumer.index.increment.AbstractMqListener; 6 import com.yoho.search.consumer.index.increment.AbstractMqListener;
8 import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService; 7 import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
9 import com.yoho.search.consumer.service.daoService.tbl.TblProductService; 8 import com.yoho.search.consumer.service.daoService.tbl.TblProductService;
10 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 9 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
11 import com.yoho.search.dal.model.TblProduct; 10 import com.yoho.search.dal.model.TblProduct;
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
16 13
@@ -21,45 +18,30 @@ import org.springframework.stereotype.Component; @@ -21,45 +18,30 @@ import org.springframework.stereotype.Component;
21 @SearchMqConsumerListerner(tableName = "tbl_product") 18 @SearchMqConsumerListerner(tableName = "tbl_product")
22 public class TblProductMqListener extends AbstractMqListener { 19 public class TblProductMqListener extends AbstractMqListener {
23 20
24 - private final Logger logger = LoggerFactory.getLogger(this.getClass());  
25 -  
26 @Autowired 21 @Autowired
27 private TblProductService tblProductService; 22 private TblProductService tblProductService;
28 @Autowired 23 @Autowired
29 private GlobalIndexBulkService globalIndexBulkService; 24 private GlobalIndexBulkService globalIndexBulkService;
30 25
31 @Override 26 @Override
32 - public String getIndexName() {  
33 - return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;  
34 - }  
35 -  
36 - @Override  
37 protected EventReportEnum getEventReportEnum() { 27 protected EventReportEnum getEventReportEnum() {
38 return EventReportEnum.TBLPRODUCTMQLISTENER_ONMESSAGE; 28 return EventReportEnum.TBLPRODUCTMQLISTENER_ONMESSAGE;
39 } 29 }
40 30
41 @Override 31 @Override
42 protected void deleteData(String id) throws Exception { 32 protected void deleteData(String id) throws Exception {
43 - long begin = System.currentTimeMillis();  
44 - // update DB  
45 tblProductService.delete(Integer.valueOf(id)); 33 tblProductService.delete(Integer.valueOf(id));
46 - // updateES Index: ProductIndex、TblProductNew  
47 globalIndexBulkService.deleteGlobalIndex(Integer.valueOf(id)); 34 globalIndexBulkService.deleteGlobalIndex(Integer.valueOf(id));
48 - logger.info("[func=deleteData][tableName=tblProduct][skn={}][cost={}ms]", Integer.valueOf(id), (System.currentTimeMillis() - begin));  
49 } 35 }
50 36
51 @Override 37 @Override
52 protected void updateData(JSONObject data) throws Exception { 38 protected void updateData(JSONObject data) throws Exception {
53 - long begin = System.currentTimeMillis();  
54 TblProduct tblProduct = (TblProduct) ConvertUtils.transMap2Bean(TblProduct.class, data); 39 TblProduct tblProduct = (TblProduct) ConvertUtils.transMap2Bean(TblProduct.class, data);
55 if (tblProduct == null || tblProduct.getProductSkn() == null) { 40 if (tblProduct == null || tblProduct.getProductSkn() == null) {
56 return; 41 return;
57 } 42 }
58 - // updateDB  
59 tblProductService.saveOrUpdate(tblProduct); 43 tblProductService.saveOrUpdate(tblProduct);
60 - // updateES Index:ProductIndex、TblProductNew  
61 globalIndexBulkService.updateGlobalIndex(tblProduct.getProductSkn()); 44 globalIndexBulkService.updateGlobalIndex(tblProduct.getProductSkn());
62 - logger.info("[func=updateData][tableName=tblProduct][skn={}][cost={}ms]", tblProduct.getProductSkn(), (System.currentTimeMillis() - begin));  
63 } 45 }
64 46
65 } 47 }
@@ -3,14 +3,11 @@ package com.yoho.search.consumer.index.increment.tbl; @@ -3,14 +3,11 @@ package com.yoho.search.consumer.index.increment.tbl;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.ConvertUtils; 4 import com.yoho.search.base.utils.ConvertUtils;
5 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
6 -import com.yoho.search.base.utils.ISearchConstants;  
7 import com.yoho.search.consumer.index.increment.AbstractMqListener; 6 import com.yoho.search.consumer.index.increment.AbstractMqListener;
8 import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService; 7 import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
9 import com.yoho.search.consumer.service.daoService.tbl.TblProductSkcService; 8 import com.yoho.search.consumer.service.daoService.tbl.TblProductSkcService;
10 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 9 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
11 import com.yoho.search.dal.model.TblProductSkc; 10 import com.yoho.search.dal.model.TblProductSkc;
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
16 13
@@ -21,49 +18,34 @@ import org.springframework.stereotype.Component; @@ -21,49 +18,34 @@ import org.springframework.stereotype.Component;
21 @SearchMqConsumerListerner(tableName = "tbl_product_skc") 18 @SearchMqConsumerListerner(tableName = "tbl_product_skc")
22 public class TblProductSkcMqListener extends AbstractMqListener { 19 public class TblProductSkcMqListener extends AbstractMqListener {
23 20
24 - private final Logger logger = LoggerFactory.getLogger(this.getClass());  
25 -  
26 - @Autowired  
27 - private TblProductSkcService tblProductSkcService;  
28 - @Autowired  
29 - private GlobalIndexBulkService globalIndexBulkService;  
30 -  
31 - @Override  
32 - public String getIndexName() {  
33 - return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;  
34 - }  
35 -  
36 - @Override  
37 - protected EventReportEnum getEventReportEnum() {  
38 - return EventReportEnum.TBLPRODUCTSKCMQLISTENER_ONMESSAGE;  
39 - }  
40 -  
41 - @Override  
42 - protected void deleteData(String id) throws Exception {  
43 - long begin = System.currentTimeMillis();  
44 - TblProductSkc tblProductSkc = tblProductSkcService.getById(Integer.valueOf(id));  
45 - if (tblProductSkc == null) {  
46 - return;  
47 - }  
48 - // delete DB  
49 - tblProductSkcService.delete(Integer.valueOf(id));  
50 - // update ES:ProductIndex、TblProductNew  
51 - globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());  
52 - logger.info("[func=deleteData][tableName=TblProductSkc][skc={}][cost={}ms]", tblProductSkc.getProductSkc(), (System.currentTimeMillis() - begin));  
53 - }  
54 -  
55 - @Override  
56 - protected void updateData(JSONObject data) throws Exception {  
57 - long begin = System.currentTimeMillis();  
58 - TblProductSkc tblProductSkc = (TblProductSkc) ConvertUtils.transMap2Bean(TblProductSkc.class, data);  
59 - if (tblProductSkc == null || tblProductSkc.getProductSkc() == null) {  
60 - return;  
61 - }  
62 - // update DB  
63 - tblProductSkcService.saveOrUpdate(tblProductSkc);  
64 - // update ES:ProductIndex、TblProductNew  
65 - globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());  
66 - logger.info("[func=updateData][tableName=TblProductSkc][skc={}][cost={}ms]", tblProductSkc.getProductSkc(), (System.currentTimeMillis() - begin));  
67 - } 21 + @Autowired
  22 + private TblProductSkcService tblProductSkcService;
  23 + @Autowired
  24 + private GlobalIndexBulkService globalIndexBulkService;
  25 +
  26 + @Override
  27 + protected EventReportEnum getEventReportEnum() {
  28 + return EventReportEnum.TBLPRODUCTSKCMQLISTENER_ONMESSAGE;
  29 + }
  30 +
  31 + @Override
  32 + protected void deleteData(String id) throws Exception {
  33 + TblProductSkc tblProductSkc = tblProductSkcService.getById(Integer.valueOf(id));
  34 + if (tblProductSkc == null) {
  35 + return;
  36 + }
  37 + tblProductSkcService.delete(Integer.valueOf(id));
  38 + globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());
  39 + }
  40 +
  41 + @Override
  42 + protected void updateData(JSONObject data) throws Exception {
  43 + TblProductSkc tblProductSkc = (TblProductSkc) ConvertUtils.transMap2Bean(TblProductSkc.class, data);
  44 + if (tblProductSkc == null || tblProductSkc.getProductSkc() == null) {
  45 + return;
  46 + }
  47 + tblProductSkcService.saveOrUpdate(tblProductSkc);
  48 + globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());
  49 + }
68 50
69 } 51 }
@@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.tbl; @@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.tbl;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.ConvertUtils; 4 import com.yoho.search.base.utils.ConvertUtils;
5 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
6 -import com.yoho.search.base.utils.ISearchConstants;  
7 import com.yoho.search.consumer.index.increment.AbstractMqListener; 6 import com.yoho.search.consumer.index.increment.AbstractMqListener;
8 import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService; 7 import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
9 import com.yoho.search.consumer.service.daoService.tbl.TblProductSkuService; 8 import com.yoho.search.consumer.service.daoService.tbl.TblProductSkuService;
@@ -23,47 +22,34 @@ public class TblProductSkuMqListener extends AbstractMqListener { @@ -23,47 +22,34 @@ public class TblProductSkuMqListener extends AbstractMqListener {
23 22
24 private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 private final Logger logger = LoggerFactory.getLogger(this.getClass());
25 24
26 - @Autowired  
27 - private TblProductSkuService tblProductSkuService;  
28 - @Autowired  
29 - private GlobalIndexBulkService globalIndexBulkService;  
30 -  
31 - @Override  
32 - public String getIndexName() {  
33 - return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;  
34 - }  
35 -  
36 - @Override  
37 - protected EventReportEnum getEventReportEnum() {  
38 - return EventReportEnum.TBLPRODUCTSKUMQLISTENER_ONMESSAGE;  
39 - }  
40 -  
41 - @Override  
42 - protected void deleteData(String id) throws Exception {  
43 - long begin = System.currentTimeMillis();  
44 - TblProductSku tblProductSku = tblProductSkuService.getById(Integer.valueOf(id));  
45 - if (tblProductSku == null) {  
46 - return;  
47 - }  
48 - // delete DB  
49 - tblProductSkuService.delete(Integer.valueOf(id));  
50 - // update ES:ProductIndex、TblProductNew  
51 - globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());  
52 - logger.info("[func=deleteData][tableName=TblProductSku][sku={}][cost={}ms]", tblProductSku.getProductSku(), (System.currentTimeMillis() - begin));  
53 - }  
54 -  
55 - @Override  
56 - protected void updateData(JSONObject data) throws Exception {  
57 - long begin = System.currentTimeMillis();  
58 - TblProductSku tblProductSku = (TblProductSku) ConvertUtils.transMap2Bean(TblProductSku.class, data);  
59 - if (tblProductSku == null || tblProductSku.getProductSku() == null) {  
60 - return;  
61 - }  
62 - // update DB  
63 - tblProductSkuService.saveOrUpdate(tblProductSku);  
64 - // update ES:ProductIndex、TblProductNew  
65 - globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());  
66 - logger.info("[func=updateData][tableName=TblProductSku][sku={}][cost={}ms]", tblProductSku.getProductSku(), (System.currentTimeMillis() - begin));  
67 - } 25 + @Autowired
  26 + private TblProductSkuService tblProductSkuService;
  27 + @Autowired
  28 + private GlobalIndexBulkService globalIndexBulkService;
  29 +
  30 + @Override
  31 + protected EventReportEnum getEventReportEnum() {
  32 + return EventReportEnum.TBLPRODUCTSKUMQLISTENER_ONMESSAGE;
  33 + }
  34 +
  35 + @Override
  36 + protected void deleteData(String id) throws Exception {
  37 + TblProductSku tblProductSku = tblProductSkuService.getById(Integer.valueOf(id));
  38 + if (tblProductSku == null) {
  39 + return;
  40 + }
  41 + tblProductSkuService.delete(Integer.valueOf(id));
  42 + globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());
  43 + }
  44 +
  45 + @Override
  46 + protected void updateData(JSONObject data) throws Exception {
  47 + TblProductSku tblProductSku = (TblProductSku) ConvertUtils.transMap2Bean(TblProductSku.class, data);
  48 + if (tblProductSku == null || tblProductSku.getProductSku() == null) {
  49 + return;
  50 + }
  51 + tblProductSkuService.saveOrUpdate(tblProductSku);
  52 + globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());
  53 + }
68 54
69 } 55 }
@@ -3,22 +3,14 @@ package com.yoho.search.consumer.index.increment.tbl; @@ -3,22 +3,14 @@ package com.yoho.search.consumer.index.increment.tbl;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.ConvertUtils; 4 import com.yoho.search.base.utils.ConvertUtils;
5 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
6 -import com.yoho.search.base.utils.ISearchConstants;  
7 import com.yoho.search.consumer.index.increment.AbstractMqListener; 6 import com.yoho.search.consumer.index.increment.AbstractMqListener;
8 -import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;  
9 -import com.yoho.search.consumer.service.daoService.tbl.TblProductService;  
10 import com.yoho.search.consumer.service.daoService.tbl.TblSiteService; 7 import com.yoho.search.consumer.service.daoService.tbl.TblSiteService;
11 import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService; 8 import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;
12 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 9 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
13 import com.yoho.search.dal.model.TblSite; 10 import com.yoho.search.dal.model.TblSite;
14 -import org.apache.commons.collections.CollectionUtils;  
15 -import org.slf4j.Logger;  
16 -import org.slf4j.LoggerFactory;  
17 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
19 13
20 -import java.util.List;  
21 -  
22 /** 14 /**
23 * Created by wangnan on 2016/12/16. 15 * Created by wangnan on 2016/12/16.
24 */ 16 */
@@ -26,65 +18,29 @@ import java.util.List; @@ -26,65 +18,29 @@ import java.util.List;
26 @SearchMqConsumerListerner(tableName = "tbl_site") 18 @SearchMqConsumerListerner(tableName = "tbl_site")
27 public class TblSiteMqListener extends AbstractMqListener { 19 public class TblSiteMqListener extends AbstractMqListener {
28 20
29 - private final Logger logger = LoggerFactory.getLogger(this.getClass());  
30 21
31 @Autowired 22 @Autowired
32 private TblSiteService tblSiteService; 23 private TblSiteService tblSiteService;
33 @Autowired 24 @Autowired
34 - private TblProductService tblProductService;  
35 - @Autowired  
36 - private GlobalIndexBulkService globalIndexBulkService;  
37 - @Autowired  
38 private BasicDataCacheService basicDataCacheService; 25 private BasicDataCacheService basicDataCacheService;
39 26
40 @Override 27 @Override
41 - public String getIndexName() {  
42 - return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;  
43 - }  
44 -  
45 - @Override  
46 protected EventReportEnum getEventReportEnum() { 28 protected EventReportEnum getEventReportEnum() {
47 return EventReportEnum.TBLSITEMQLISTENER_ONMESSAGE; 29 return EventReportEnum.TBLSITEMQLISTENER_ONMESSAGE;
48 } 30 }
49 31
50 @Override 32 @Override
51 protected void deleteData(String id) throws Exception { 33 protected void deleteData(String id) throws Exception {
52 - long begin = System.currentTimeMillis();  
53 - TblSite tblSite = tblSiteService.getById(Integer.valueOf(id));  
54 - if (tblSite == null) {  
55 - return;  
56 - }  
57 - // update DB  
58 tblSiteService.delete(Integer.valueOf(id)); 34 tblSiteService.delete(Integer.valueOf(id));
59 - // update ES:ProductIndex、TblProductNew  
60 - List<Integer> sknList = tblProductService.getSknsBySiteId(tblSite.getSiteId());  
61 - if (CollectionUtils.isEmpty(sknList)) {  
62 - return;  
63 - }  
64 - for (Integer skn : sknList) {  
65 - globalIndexBulkService.updateGlobalIndex(skn);  
66 - }  
67 - logger.info("[func=deleteData][tableName=TblSite][id={}][cost={}ms]", tblSite.getSiteId(), (System.currentTimeMillis() - begin));  
68 } 35 }
69 36
70 @Override 37 @Override
71 protected void updateData(JSONObject data) throws Exception { 38 protected void updateData(JSONObject data) throws Exception {
72 - long begin = System.currentTimeMillis();  
73 TblSite tblSite = (TblSite) ConvertUtils.transMap2Bean(TblSite.class, data); 39 TblSite tblSite = (TblSite) ConvertUtils.transMap2Bean(TblSite.class, data);
74 if (tblSite == null || tblSite.getSiteId() == null) { 40 if (tblSite == null || tblSite.getSiteId() == null) {
75 return; 41 return;
76 } 42 }
77 - // update DB  
78 tblSiteService.saveOrUpdate(tblSite); 43 tblSiteService.saveOrUpdate(tblSite);
79 - // update ES  
80 - List<Integer> sknList = tblProductService.getSknsBySiteId(tblSite.getSiteId());  
81 - if (CollectionUtils.isEmpty(sknList)) {  
82 - return;  
83 - }  
84 - for (Integer skn : sknList) {  
85 - globalIndexBulkService.updateGlobalIndex(skn);  
86 - }  
87 - logger.info("[func=updateData][tableName=TblSite][id={}][cost={}ms]", tblSite.getSiteId(), (System.currentTimeMillis() - begin));  
88 } 44 }
89 45
90 @Override 46 @Override
@@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.tbl; @@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.tbl;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.ConvertUtils; 4 import com.yoho.search.base.utils.ConvertUtils;
5 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
6 -import com.yoho.search.base.utils.ISearchConstants;  
7 import com.yoho.search.consumer.index.increment.AbstractMqListener; 6 import com.yoho.search.consumer.index.increment.AbstractMqListener;
8 import com.yoho.search.consumer.service.daoService.tbl.TblSortService; 7 import com.yoho.search.consumer.service.daoService.tbl.TblSortService;
9 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 8 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
@@ -18,31 +17,26 @@ import org.springframework.stereotype.Component; @@ -18,31 +17,26 @@ import org.springframework.stereotype.Component;
18 @SearchMqConsumerListerner(tableName = "tbl_sort") 17 @SearchMqConsumerListerner(tableName = "tbl_sort")
19 public class TblSortMqListener extends AbstractMqListener { 18 public class TblSortMqListener extends AbstractMqListener {
20 19
21 - @Autowired  
22 - private TblSortService tblSortService; 20 + @Autowired
  21 + private TblSortService tblSortService;
23 22
24 - @Override  
25 - public String getIndexName() {  
26 - return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;  
27 - }  
28 -  
29 - @Override  
30 - protected EventReportEnum getEventReportEnum() {  
31 - return EventReportEnum.TBLSORTMQLISTENER_ONMESSAGE;  
32 - } 23 + @Override
  24 + protected EventReportEnum getEventReportEnum() {
  25 + return EventReportEnum.TBLSORTMQLISTENER_ONMESSAGE;
  26 + }
33 27
34 - @Override  
35 - protected void deleteData(String id) throws Exception {  
36 - tblSortService.delete(Integer.valueOf(id));  
37 - } 28 + @Override
  29 + protected void deleteData(String id) throws Exception {
  30 + tblSortService.delete(Integer.valueOf(id));
  31 + }
38 32
39 - @Override  
40 - protected void updateData(JSONObject data) throws Exception {  
41 - TblSort tblSort = (TblSort) ConvertUtils.transMap2Bean(TblSort.class, data);  
42 - if (tblSort == null || tblSort.getSortId() == null) {  
43 - return;  
44 - }  
45 - tblSortService.saveOrUpdate(tblSort);  
46 - } 33 + @Override
  34 + protected void updateData(JSONObject data) throws Exception {
  35 + TblSort tblSort = (TblSort) ConvertUtils.transMap2Bean(TblSort.class, data);
  36 + if (tblSort == null || tblSort.getSortId() == null) {
  37 + return;
  38 + }
  39 + tblSortService.saveOrUpdate(tblSort);
  40 + }
47 41
48 } 42 }
@@ -26,8 +26,6 @@ public class UfoBrandMqListener extends AbstractMqListener { @@ -26,8 +26,6 @@ public class UfoBrandMqListener extends AbstractMqListener {
26 @Autowired 26 @Autowired
27 private IYohoIndexService indexService; 27 private IYohoIndexService indexService;
28 @Autowired 28 @Autowired
29 - private UfoIndexUpdateHelper ufoIndexUpdateHelper;  
30 - @Autowired  
31 private BasicDataCacheService basicDataCacheService; 29 private BasicDataCacheService basicDataCacheService;
32 30
33 @Override 31 @Override
@@ -42,11 +40,7 @@ public class UfoBrandMqListener extends AbstractMqListener { @@ -42,11 +40,7 @@ public class UfoBrandMqListener extends AbstractMqListener {
42 40
43 @Override 41 @Override
44 protected void deleteData(String id) throws Exception { 42 protected void deleteData(String id) throws Exception {
45 - UfoBrand ufoBrand = ufoBrandService.getById(Short.valueOf(id));  
46 ufoBrandService.delete(Short.valueOf(id)); 43 ufoBrandService.delete(Short.valueOf(id));
47 - if (ufoBrand != null) {  
48 - ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrand.getId());  
49 - }  
50 indexService.deleteIndexData(this.getIndexName(), id); 44 indexService.deleteIndexData(this.getIndexName(), id);
51 } 45 }
52 46
@@ -58,7 +52,6 @@ public class UfoBrandMqListener extends AbstractMqListener { @@ -58,7 +52,6 @@ public class UfoBrandMqListener extends AbstractMqListener {
58 } 52 }
59 ufoBrandService.saveOrUpdate(ufoBrand); 53 ufoBrandService.saveOrUpdate(ufoBrand);
60 indexService.updateIndexData(this.getIndexName(), ufoBrand.getId().toString(), ufoBrand); 54 indexService.updateIndexData(this.getIndexName(), ufoBrand.getId().toString(), ufoBrand);
61 - ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrand.getId());  
62 } 55 }
63 56
64 @Override 57 @Override
@@ -22,8 +22,6 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener { @@ -22,8 +22,6 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener {
22 @Autowired 22 @Autowired
23 private UfoBrandSeriesService ufoBrandSeriesService; 23 private UfoBrandSeriesService ufoBrandSeriesService;
24 @Autowired 24 @Autowired
25 - private UfoIndexUpdateHelper ufoIndexUpdateHelper;  
26 - @Autowired  
27 private BasicDataCacheService basicDataCacheService; 25 private BasicDataCacheService basicDataCacheService;
28 26
29 @Override 27 @Override
@@ -33,11 +31,7 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener { @@ -33,11 +31,7 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener {
33 31
34 @Override 32 @Override
35 protected void deleteData(String id) throws Exception { 33 protected void deleteData(String id) throws Exception {
36 - UfoBrandSeries ufoBrandSeries = ufoBrandSeriesService.getById(Short.valueOf(id));  
37 ufoBrandSeriesService.delete(Short.valueOf(id)); 34 ufoBrandSeriesService.delete(Short.valueOf(id));
38 - if (ufoBrandSeries != null) {  
39 - ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrandSeries.getBrandId());  
40 - }  
41 } 35 }
42 36
43 @Override 37 @Override
@@ -47,7 +41,6 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener { @@ -47,7 +41,6 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener {
47 return; 41 return;
48 } 42 }
49 ufoBrandSeriesService.saveOrUpdate(ufoBrandSeries); 43 ufoBrandSeriesService.saveOrUpdate(ufoBrandSeries);
50 - ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrandSeries.getBrandId());  
51 } 44 }
52 45
53 @Override 46 @Override
@@ -34,7 +34,8 @@ public class UfoGoodsMqListener extends AbstractMqListener { @@ -34,7 +34,8 @@ public class UfoGoodsMqListener extends AbstractMqListener {
34 UfoGoods ufoGoods = ufoGoodsService.getById(Integer.valueOf(id)); 34 UfoGoods ufoGoods = ufoGoodsService.getById(Integer.valueOf(id));
35 ufoGoodsService.delete(Integer.valueOf(id)); 35 ufoGoodsService.delete(Integer.valueOf(id));
36 if (ufoGoods != null) { 36 if (ufoGoods != null) {
37 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoGoods.getProductId()); 37 + ufoIndexUpdateHelper.updateUfoIndex(ufoGoods.getProductId());
  38 + ufoIndexUpdateHelper.updateYohoIndex(ufoGoods.getProductId());
38 } 39 }
39 } 40 }
40 41
@@ -45,6 +46,7 @@ public class UfoGoodsMqListener extends AbstractMqListener { @@ -45,6 +46,7 @@ public class UfoGoodsMqListener extends AbstractMqListener {
45 return; 46 return;
46 } 47 }
47 ufoGoodsService.saveOrUpdate(ufoGoods); 48 ufoGoodsService.saveOrUpdate(ufoGoods);
48 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoGoods.getProductId()); 49 + ufoIndexUpdateHelper.updateUfoIndex(ufoGoods.getProductId());
  50 + ufoIndexUpdateHelper.updateYohoIndex(ufoGoods.getProductId());
49 } 51 }
50 } 52 }
@@ -4,21 +4,16 @@ import com.alibaba.fastjson.JSON; @@ -4,21 +4,16 @@ import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.yoho.search.base.utils.ISearchConstants; 5 import com.yoho.search.base.utils.ISearchConstants;
6 import com.yoho.search.consumer.index.fullbuild.ufo.UfoProductIndexBuilder; 6 import com.yoho.search.consumer.index.fullbuild.ufo.UfoProductIndexBuilder;
  7 +import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;
7 import com.yoho.search.consumer.index.increment.bulks.CommonBulkService; 8 import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;
  9 +import com.yoho.search.consumer.service.bo.ProductIndexBO;
8 import com.yoho.search.consumer.service.bo.UfoProductIndexBO; 10 import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
9 import com.yoho.search.core.es.model.ESBluk; 11 import com.yoho.search.core.es.model.ESBluk;
10 -import com.yoho.search.dal.UfoProductMapper;  
11 -import com.yoho.search.dal.model.UfoProduct;  
12 -import org.apache.commons.collections.CollectionUtils;  
13 import org.slf4j.Logger; 12 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.stereotype.Component; 15 import org.springframework.stereotype.Component;
17 16
18 -import java.util.ArrayList;  
19 -import java.util.List;  
20 -import java.util.stream.Collectors;  
21 -  
22 /** 17 /**
23 * @author wangnan 18 * @author wangnan
24 * @version 2018/9/14 19 * @version 2018/9/14
@@ -29,45 +24,37 @@ public class UfoIndexUpdateHelper { @@ -29,45 +24,37 @@ public class UfoIndexUpdateHelper {
29 private final Logger logger = LoggerFactory.getLogger(this.getClass()); 24 private final Logger logger = LoggerFactory.getLogger(this.getClass());
30 25
31 @Autowired 26 @Autowired
32 - private UfoProductMapper ufoProductMapper;  
33 - @Autowired  
34 private UfoProductIndexBuilder ufoProductIndexBuilder; 27 private UfoProductIndexBuilder ufoProductIndexBuilder;
35 @Autowired 28 @Autowired
36 - protected CommonBulkService commonBulkService;  
37 -  
38 - public void updateUfoProductIndexByBrandId(Short brandId) {  
39 - List<UfoProduct> ufoProductList = ufoProductMapper.selectByBrandId(brandId);  
40 - this.updateUfoProductIndexByProductList(ufoProductList);  
41 - }  
42 -  
43 - public void updateUfoProductIndexByProductId(Integer productId) {  
44 - List<Integer> productIdList = new ArrayList<>(1);  
45 - productIdList.add(productId);  
46 - this.updateUfoProductIndexByProductIdList(productIdList);  
47 - } 29 + private CommonBulkService commonBulkService;
  30 + @Autowired
  31 + private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;
48 32
49 - private void updateUfoProductIndexByProductIdList(List<Integer> productIdList) {  
50 - List<UfoProduct> ufoProductList = ufoProductMapper.selectByIdList(productIdList);  
51 - this.updateUfoProductIndexByProductList(ufoProductList); 33 + public void updateUfoIndex(Integer productId) {
  34 + try {
  35 + UfoProductIndexBO ufoProductIndexBO = ufoProductIndexBuilder.buildUfoProductIndexBOIncrease(productId);
  36 + if (ufoProductIndexBO == null) {
  37 + return;
  38 + }
  39 + JSONObject ufoProductIndexBOJSONObject = (JSONObject) JSON.toJSON(ufoProductIndexBO);
  40 + commonBulkService.add(new ESBluk(ufoProductIndexBOJSONObject.toJSONString(), ufoProductIndexBO.getId() + "", ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, false));
  41 + } catch (Exception e) {
  42 + logger.error(e.getMessage(), e);
  43 + }
52 } 44 }
53 45
54 - private void updateUfoProductIndexByProductList(List<UfoProduct> ufoProductList) {  
55 - if (CollectionUtils.isEmpty(ufoProductList)) {  
56 - return;  
57 - }  
58 - List<Integer> idList = ufoProductList.stream().map(UfoProduct::getId).collect(Collectors.toList());  
59 - List<UfoProductIndexBO> ufoProductIndexBOList = ufoProductIndexBuilder.buildUfoProductIndexBOIncrease(idList);  
60 - if (CollectionUtils.isEmpty(ufoProductIndexBOList)) {  
61 - return;  
62 - }  
63 - ufoProductIndexBOList.stream().forEach(p -> {  
64 - try {  
65 - JSONObject jsonObject = (JSONObject) JSON.toJSON(p);  
66 - commonBulkService.add(new ESBluk(jsonObject.toJSONString(), p.getId() + "", ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, false));  
67 - } catch (Exception e) {  
68 - logger.error(e.getMessage(), e); 46 + public void updateYohoIndex(Integer id) {
  47 + try {
  48 + ProductIndexBO productIndexBO = ufoToYohoIndexBuilder.buildProductIndexBOIncrease(id);
  49 + if (productIndexBO == null) {
  50 + return;
69 } 51 }
70 - }); 52 + JSONObject jsonObject = (JSONObject) JSON.toJSON(productIndexBO);
  53 + commonBulkService.add(new ESBluk(jsonObject.toJSONString(), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false));
  54 + } catch (Exception e) {
  55 + logger.error(e.getMessage(), e);
  56 + }
71 } 57 }
72 58
  59 +
73 } 60 }
1 package com.yoho.search.consumer.index.increment.ufo; 1 package com.yoho.search.consumer.index.increment.ufo;
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.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.ufo.UfoToYohoIndexBuilder;  
10 import com.yoho.search.consumer.index.increment.AbstractMqListener; 8 import com.yoho.search.consumer.index.increment.AbstractMqListener;
11 -import com.yoho.search.consumer.service.bo.ProductIndexBO;  
12 import com.yoho.search.consumer.service.daoService.ufo.UfoProductService; 9 import com.yoho.search.consumer.service.daoService.ufo.UfoProductService;
13 -import com.yoho.search.core.es.model.ESBluk;  
14 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 10 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
15 import com.yoho.search.dal.model.UfoProduct; 11 import com.yoho.search.dal.model.UfoProduct;
16 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,8 +26,6 @@ public class UfoProductMqListener extends AbstractMqListener { @@ -30,8 +26,6 @@ public class UfoProductMqListener extends AbstractMqListener {
30 private IYohoIndexService indexService; 26 private IYohoIndexService indexService;
31 @Autowired 27 @Autowired
32 private UfoIndexUpdateHelper ufoIndexUpdateHelper; 28 private UfoIndexUpdateHelper ufoIndexUpdateHelper;
33 - @Autowired  
34 - private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;  
35 29
36 @Override 30 @Override
37 public String getIndexName() { 31 public String getIndexName() {
@@ -48,8 +42,7 @@ public class UfoProductMqListener extends AbstractMqListener { @@ -48,8 +42,7 @@ public class UfoProductMqListener extends AbstractMqListener {
48 protected void deleteData(String id) throws Exception { 42 protected void deleteData(String id) throws Exception {
49 ufoProductService.delete(Integer.valueOf(id)); 43 ufoProductService.delete(Integer.valueOf(id));
50 indexService.deleteIndexData(this.getIndexName(), id); 44 indexService.deleteIndexData(this.getIndexName(), id);
51 - //更新YOHO索引  
52 - this.updateYohoIndex(Integer.valueOf(id)); 45 + ufoIndexUpdateHelper.updateYohoIndex(Integer.valueOf(id));
53 } 46 }
54 47
55 @Override 48 @Override
@@ -59,18 +52,8 @@ public class UfoProductMqListener extends AbstractMqListener { @@ -59,18 +52,8 @@ public class UfoProductMqListener extends AbstractMqListener {
59 return; 52 return;
60 } 53 }
61 ufoProductService.saveOrUpdate(ufoProduct); 54 ufoProductService.saveOrUpdate(ufoProduct);
62 - //更新UFO索引  
63 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoProduct.getId());  
64 - //更新YOHO索引  
65 - this.updateYohoIndex(ufoProduct.getId()); 55 + ufoIndexUpdateHelper.updateUfoIndex(ufoProduct.getId());
  56 + ufoIndexUpdateHelper.updateYohoIndex(ufoProduct.getId());
66 } 57 }
67 58
68 - private void updateYohoIndex(Integer id) {  
69 - ProductIndexBO productIndexBO = ufoToYohoIndexBuilder.buildProductIndexBOIncrease(id);  
70 - if (productIndexBO == null) {  
71 - return;  
72 - }  
73 - JSONObject jsonObject = (JSONObject) JSON.toJSON(productIndexBO);  
74 - commonBulkService.add(new ESBluk(jsonObject.toJSONString(), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false));  
75 - }  
76 } 59 }
@@ -40,7 +40,7 @@ public class UfoProductPoolDetailMqListener extends AbstractMqListener { @@ -40,7 +40,7 @@ public class UfoProductPoolDetailMqListener extends AbstractMqListener {
40 UfoProductPoolDetail ufoProductPoolDetail = ufoProductPoolDetailService.getById(Integer.valueOf(id)); 40 UfoProductPoolDetail ufoProductPoolDetail = ufoProductPoolDetailService.getById(Integer.valueOf(id));
41 ufoProductPoolDetailService.delete(Integer.valueOf(id)); 41 ufoProductPoolDetailService.delete(Integer.valueOf(id));
42 if (ufoProductPoolDetail != null) { 42 if (ufoProductPoolDetail != null) {
43 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoProductPoolDetail.getProductId()); 43 + ufoIndexUpdateHelper.updateUfoIndex(ufoProductPoolDetail.getProductId());
44 } 44 }
45 } 45 }
46 46
@@ -51,6 +51,6 @@ public class UfoProductPoolDetailMqListener extends AbstractMqListener { @@ -51,6 +51,6 @@ public class UfoProductPoolDetailMqListener extends AbstractMqListener {
51 return; 51 return;
52 } 52 }
53 ufoProductPoolDetailService.saveOrUpdate(ufoProductPoolDetail); 53 ufoProductPoolDetailService.saveOrUpdate(ufoProductPoolDetail);
54 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoProductPoolDetail.getProductId()); 54 + ufoIndexUpdateHelper.updateUfoIndex(ufoProductPoolDetail.getProductId());
55 } 55 }
56 } 56 }
@@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.ufo; @@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.ufo;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.ConvertUtils; 4 import com.yoho.search.base.utils.ConvertUtils;
5 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
6 -import com.yoho.search.base.utils.ISearchConstants;  
7 import com.yoho.search.consumer.index.increment.AbstractMqListener; 6 import com.yoho.search.consumer.index.increment.AbstractMqListener;
8 import com.yoho.search.consumer.service.daoService.ufo.UfoProductPoolService; 7 import com.yoho.search.consumer.service.daoService.ufo.UfoProductPoolService;
9 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 8 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
@@ -23,12 +22,6 @@ public class UfoProductPoolMqListener extends AbstractMqListener { @@ -23,12 +22,6 @@ public class UfoProductPoolMqListener extends AbstractMqListener {
23 private UfoProductPoolService ufoProductPoolService; 22 private UfoProductPoolService ufoProductPoolService;
24 23
25 @Override 24 @Override
26 - public String getIndexName() {  
27 - return ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX;  
28 - }  
29 -  
30 -  
31 - @Override  
32 protected EventReportEnum getEventReportEnum() { 25 protected EventReportEnum getEventReportEnum() {
33 return EventReportEnum.UFOPRODUCTPOOLMQLISTENER_ONMESSAGE; 26 return EventReportEnum.UFOPRODUCTPOOLMQLISTENER_ONMESSAGE;
34 } 27 }
@@ -7,7 +7,6 @@ import com.yoho.search.base.utils.ISearchConstants; @@ -7,7 +7,6 @@ import com.yoho.search.base.utils.ISearchConstants;
7 import com.yoho.search.consumer.common.IYohoIndexService; 7 import com.yoho.search.consumer.common.IYohoIndexService;
8 import com.yoho.search.consumer.index.increment.AbstractMqListener; 8 import com.yoho.search.consumer.index.increment.AbstractMqListener;
9 import com.yoho.search.consumer.service.daoService.ufo.UfoProductSortService; 9 import com.yoho.search.consumer.service.daoService.ufo.UfoProductSortService;
10 -import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;  
11 import com.yoho.search.core.message.beans.SearchMqConsumerListerner; 10 import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
12 import com.yoho.search.dal.model.UfoProductSort; 11 import com.yoho.search.dal.model.UfoProductSort;
13 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,15 +24,12 @@ public class UfoProductSortMqListener extends AbstractMqListener { @@ -25,15 +24,12 @@ public class UfoProductSortMqListener extends AbstractMqListener {
25 private UfoProductSortService ufoProductSortService; 24 private UfoProductSortService ufoProductSortService;
26 @Autowired 25 @Autowired
27 private IYohoIndexService indexService; 26 private IYohoIndexService indexService;
28 - @Autowired  
29 - private BasicDataCacheService basicDataCacheService;  
30 27
31 @Override 28 @Override
32 public String getIndexName() { 29 public String getIndexName() {
33 return ISearchConstants.INDEX_NAME_UFO_SORT; 30 return ISearchConstants.INDEX_NAME_UFO_SORT;
34 } 31 }
35 32
36 -  
37 @Override 33 @Override
38 protected EventReportEnum getEventReportEnum() { 34 protected EventReportEnum getEventReportEnum() {
39 return EventReportEnum.UFOPRODUCTSORTMQLISTENER_ONMESSAGE; 35 return EventReportEnum.UFOPRODUCTSORTMQLISTENER_ONMESSAGE;
@@ -33,7 +33,8 @@ public class UfoStorageMqListener extends AbstractMqListener { @@ -33,7 +33,8 @@ public class UfoStorageMqListener extends AbstractMqListener {
33 UfoStorage ufoStorage = ufoStorageService.getById(Integer.valueOf(id)); 33 UfoStorage ufoStorage = ufoStorageService.getById(Integer.valueOf(id));
34 ufoStorageService.delete(Integer.valueOf(id)); 34 ufoStorageService.delete(Integer.valueOf(id));
35 if (ufoStorage != null) { 35 if (ufoStorage != null) {
36 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStorage.getProductId()); 36 + ufoIndexUpdateHelper.updateUfoIndex(ufoStorage.getProductId());
  37 + ufoIndexUpdateHelper.updateYohoIndex(ufoStorage.getProductId());
37 } 38 }
38 39
39 } 40 }
@@ -45,6 +46,7 @@ public class UfoStorageMqListener extends AbstractMqListener { @@ -45,6 +46,7 @@ public class UfoStorageMqListener extends AbstractMqListener {
45 return; 46 return;
46 } 47 }
47 ufoStorageService.saveOrUpdate(ufoStorage); 48 ufoStorageService.saveOrUpdate(ufoStorage);
48 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStorage.getProductId()); 49 + ufoIndexUpdateHelper.updateUfoIndex(ufoStorage.getProductId());
  50 + ufoIndexUpdateHelper.updateYohoIndex(ufoStorage.getProductId());
49 } 51 }
50 } 52 }
@@ -33,8 +33,10 @@ public class UfoStoragePriceMqListener extends AbstractMqListener { @@ -33,8 +33,10 @@ public class UfoStoragePriceMqListener extends AbstractMqListener {
33 UfoStoragePrice ufoStoragePrice = ufoStoragePriceService.getById(Integer.valueOf(id)); 33 UfoStoragePrice ufoStoragePrice = ufoStoragePriceService.getById(Integer.valueOf(id));
34 ufoStoragePriceService.delete(Integer.valueOf(id)); 34 ufoStoragePriceService.delete(Integer.valueOf(id));
35 if (ufoStoragePrice != null) { 35 if (ufoStoragePrice != null) {
36 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStoragePrice.getProductId()); 36 + ufoIndexUpdateHelper.updateUfoIndex(ufoStoragePrice.getProductId());
  37 + ufoIndexUpdateHelper.updateYohoIndex(ufoStoragePrice.getProductId());
37 } 38 }
  39 +
38 } 40 }
39 41
40 @Override 42 @Override
@@ -44,6 +46,7 @@ public class UfoStoragePriceMqListener extends AbstractMqListener { @@ -44,6 +46,7 @@ public class UfoStoragePriceMqListener extends AbstractMqListener {
44 return; 46 return;
45 } 47 }
46 ufoStoragePriceService.saveOrUpdate(ufoStoragePrice); 48 ufoStoragePriceService.saveOrUpdate(ufoStoragePrice);
47 - ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStoragePrice.getProductId()); 49 + ufoIndexUpdateHelper.updateUfoIndex(ufoStoragePrice.getProductId());
  50 + ufoIndexUpdateHelper.updateYohoIndex(ufoStoragePrice.getProductId());
48 } 51 }
49 } 52 }
@@ -53,8 +53,8 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware { @@ -53,8 +53,8 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
53 */ 53 */
54 public void executeYohoIndex() { 54 public void executeYohoIndex() {
55 long begin = System.currentTimeMillis(); 55 long begin = System.currentTimeMillis();
56 - logger.info("executeYohoIndex start----[begin={}]", begin);  
57 brandRelationUtils.buildBrandRelation(); 56 brandRelationUtils.buildBrandRelation();
  57 + logger.info("executeYohoIndex start----[begin={}]", begin);
58 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PROMOTIONINDEX); 58 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PROMOTIONINDEX);
59 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BRAND); 59 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BRAND);
60 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SIZE); 60 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SIZE);
@@ -95,15 +95,17 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware { @@ -95,15 +95,17 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
95 } 95 }
96 96
97 /** 97 /**
98 - * 手动调用重建ufo所有索引 98 + * 重建ufo所有索引
99 */ 99 */
100 public void executeUfoIndex() { 100 public void executeUfoIndex() {
101 - //UFO 101 + long begin = System.currentTimeMillis();
  102 + logger.info("executeUfoIndex start----[begin={}]", begin);
102 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_BRAND); 103 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_BRAND);
103 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SORT); 104 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SORT);
104 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_COLOR); 105 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_COLOR);
105 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SIZE); 106 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SIZE);
106 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX); 107 this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX);
  108 + logger.info("executeUfoIndex end----[end={}][cost={}]", System.currentTimeMillis(), (System.currentTimeMillis() - begin));
107 } 109 }
108 110
109 111
@@ -49,21 +49,10 @@ public class UfoToYohoGeneralService { @@ -49,21 +49,10 @@ public class UfoToYohoGeneralService {
49 } 49 }
50 //其他 50 //其他
51 productIndexBO.setShopId(-2); 51 productIndexBO.setShopId(-2);
52 - productIndexBO.setIsSoonSoldOut("N");  
53 - productIndexBO.setPhysicalChannels("1,2,3,4");  
54 - productIndexBO.setAgeLevel("1");  
55 - productIndexBO.setIsGlobal("N");  
56 - productIndexBO.setIslimited("N");  
57 - productIndexBO.setIsLimitbuy("N");  
58 - productIndexBO.setIsLimitTimeAdvance("N");  
59 - productIndexBO.setIsSpecial("N");  
60 productIndexBO.setIspromotion(0); 52 productIndexBO.setIspromotion(0);
61 - productIndexBO.setIsAdvance("N");  
62 - productIndexBO.setIsDepositAdvance("N");  
63 productIndexBO.setAttribute(1); 53 productIndexBO.setAttribute(1);
  54 + productIndexBO.setAgeLevel("1");
64 productIndexBO.setIsOutlets(2); 55 productIndexBO.setIsOutlets(2);
65 - productIndexBO.setIsPhraseExist("N");  
66 - productIndexBO.setIsSeckill("N");  
67 - 56 + productIndexBO.setPhysicalChannels("1,2,3,4");
68 } 57 }
69 } 58 }