Authored by wangnan

优化mqlinster代码结构,减少重复代码

1 -package com.yoho.search.consumer.index.increment.productIndex; 1 +package com.yoho.search.consumer.index.increment.db;
2 2
3 import com.rabbitmq.client.Channel; 3 import com.rabbitmq.client.Channel;
4 import com.yoho.error.event.SearchEvent; 4 import com.yoho.error.event.SearchEvent;
1 -package com.yoho.search.consumer.index.increment.productIndex; 1 +package com.yoho.search.consumer.index.increment.db;
2 2
3 import com.rabbitmq.client.Channel; 3 import com.rabbitmq.client.Channel;
4 import com.yoho.error.event.SearchEvent; 4 import com.yoho.error.event.SearchEvent;
5 import com.yoho.search.base.utils.ConvertUtils; 5 import com.yoho.search.base.utils.ConvertUtils;
6 import com.yoho.search.base.utils.EventReportEnum; 6 import com.yoho.search.base.utils.EventReportEnum;
7 import com.yoho.search.consumer.index.increment.AbstractMqListener; 7 import com.yoho.search.consumer.index.increment.AbstractMqListener;
  8 +import com.yoho.search.consumer.index.increment.productIndex.ProductAttributePropertyValuesMqListener;
8 import com.yoho.search.consumer.service.base.ProductAttributeService; 9 import com.yoho.search.consumer.service.base.ProductAttributeService;
9 import com.yoho.search.core.es.utils.IgnoreSomeException; 10 import com.yoho.search.core.es.utils.IgnoreSomeException;
10 import com.yoho.search.dal.model.ProductAttribute; 11 import com.yoho.search.dal.model.ProductAttribute;
1 -package com.yoho.search.consumer.index.increment.productIndex; 1 +package com.yoho.search.consumer.index.increment.db;
2 2
3 import com.rabbitmq.client.Channel; 3 import com.rabbitmq.client.Channel;
4 import com.yoho.error.event.SearchEvent; 4 import com.yoho.error.event.SearchEvent;
@@ -67,7 +67,7 @@ public class ProductExtMqListener extends AbstractMqListener implements ChannelA @@ -67,7 +67,7 @@ public class ProductExtMqListener extends AbstractMqListener implements ChannelA
67 Map<String, Object> esData = new HashMap<String, Object>(); 67 Map<String, Object> esData = new HashMap<String, Object>();
68 esData.put("sknDefaultImg", productExtWithBLOBs.getSknDefaultImg() == null ? "" : productExtWithBLOBs.getSknDefaultImg()); 68 esData.put("sknDefaultImg", productExtWithBLOBs.getSknDefaultImg() == null ? "" : productExtWithBLOBs.getSknDefaultImg());
69 indexService.updateIndexData(indexName, product.getId().toString(), esData); 69 indexService.updateIndexData(indexName, product.getId().toString(), esData);
70 - logger.info("[func=updateData][step=success][indexName={}][skn={}][cost={}ms]", indexName, productExtWithBLOBs.getProductSkn(), (System.currentTimeMillis() - begin)); 70 + logger.info("[func=updateData][indexName={}][skn={}][cost={}ms]", indexName, productExtWithBLOBs.getProductSkn(), (System.currentTimeMillis() - begin));
71 } 71 }
72 72
73 @Override 73 @Override
@@ -88,7 +88,7 @@ public class ProductExtMqListener extends AbstractMqListener implements ChannelA @@ -88,7 +88,7 @@ public class ProductExtMqListener extends AbstractMqListener implements ChannelA
88 Map<String, Object> data = new HashMap<String, Object>(); 88 Map<String, Object> data = new HashMap<String, Object>();
89 data.put("sknDefaultImg", ""); 89 data.put("sknDefaultImg", "");
90 indexService.updateIndexData(indexName, product.getId().toString(), data); 90 indexService.updateIndexData(indexName, product.getId().toString(), data);
91 - logger.info("[func=deleteData][step=success][indexName={}][skn={}][cost={}ms]", indexName, skn, (System.currentTimeMillis() - begin)); 91 + logger.info("[func=deleteData][indexName={}][skn={}][cost={}ms]", indexName, skn, (System.currentTimeMillis() - begin));
92 } 92 }
93 93
94 @Override 94 @Override
@@ -55,7 +55,7 @@ public class ProductKeywordsMqListener extends AbstractMqListener implements Cha @@ -55,7 +55,7 @@ public class ProductKeywordsMqListener extends AbstractMqListener implements Cha
55 return; 55 return;
56 } 56 }
57 productKeywordsService.saveOrUpdate(productKeywords); 57 productKeywordsService.saveOrUpdate(productKeywords);
58 - logger.info("[func=updateData][step=saveToBb][key={}][cost={}ms]", key, this.getCost(begin)); 58 + logger.info("[func=updateData][key={}][cost={}ms]", key, this.getCost(begin));
59 updateProductIndex(productId, productKeywords.getProductKeyword(), System.currentTimeMillis(), key); 59 updateProductIndex(productId, productKeywords.getProductKeyword(), System.currentTimeMillis(), key);
60 } 60 }
61 61
@@ -70,8 +70,8 @@ public class ProductKeywordsMqListener extends AbstractMqListener implements Cha @@ -70,8 +70,8 @@ public class ProductKeywordsMqListener extends AbstractMqListener implements Cha
70 return; 70 return;
71 } 71 }
72 productKeywordsService.delete(productId); 72 productKeywordsService.delete(productId);
73 - logger.info("[func=deleteData][step=success][key={}][indexName={}][id={}][cost={}ms]", key, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, id, this.getCost(begin));  
74 - updateProductIndex(productId, null, System.currentTimeMillis(), key); 73 + logger.info("[func=deleteData][key={}][indexName={}][id={}][cost={}ms]", key, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, id, this.getCost(begin));
  74 + updateProductIndex(productId, "", System.currentTimeMillis(), key);
75 } 75 }
76 76
77 @Override 77 @Override
@@ -73,10 +73,10 @@ public class ProductPoolDetailMqListener extends AbstractMqListener implements C @@ -73,10 +73,10 @@ public class ProductPoolDetailMqListener extends AbstractMqListener implements C
73 } 73 }
74 // 1)更新DB 74 // 1)更新DB
75 productPoolDetailService.saveOrUpdate(productPoolDetail); 75 productPoolDetailService.saveOrUpdate(productPoolDetail);
76 - logger.info("[func=updateData][step(1)of(2)saveToBb][key={}][cost={}ms]", key, costStatistics.getCost()); 76 + logger.info("[func=updateData][step(1/2)saveToBb][key={}][cost={}ms]", key, costStatistics.getCost());
77 // 2)更新ProductIndex 77 // 2)更新ProductIndex
78 updateProductIndex(productPoolDetail, System.currentTimeMillis(), key); 78 updateProductIndex(productPoolDetail, System.currentTimeMillis(), key);
79 - logger.info("[func=updateData][step(2)of(2)update ProductIndexBO][key={}][indexName={}][skn={}][cost={}ms]", key, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, 79 + logger.info("[func=updateData][step(2/2)update ProductIndex][key={}][indexName={}][skn={}][cost={}ms]", key, ISearchConstants.INDEX_NAME_PRODUCT_INDEX,
80 productPoolDetail.getProductSkn(), costStatistics.getCost()); 80 productPoolDetail.getProductSkn(), costStatistics.getCost());
81 } 81 }
82 82
@@ -92,11 +92,11 @@ public class ProductPoolDetailMqListener extends AbstractMqListener implements C @@ -92,11 +92,11 @@ public class ProductPoolDetailMqListener extends AbstractMqListener implements C
92 } 92 }
93 // 1)从DB中删除 93 // 1)从DB中删除
94 productPoolDetailService.deleteByPrimaryKey(Integer.valueOf(id)); 94 productPoolDetailService.deleteByPrimaryKey(Integer.valueOf(id));
95 - logger.info("[func=deleteData][step(1)of(2)deleteFromBb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin); 95 + logger.info("[func=deleteData][step(1/2)deleteFromBb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin);
96 // 2)删除ProductIndex中poolId字段 96 // 2)删除ProductIndex中poolId字段
97 if (productPoolDetail != null && productPoolDetail.getProductSkn() != null) { 97 if (productPoolDetail != null && productPoolDetail.getProductSkn() != null) {
98 updateProductIndex(productPoolDetail, begin, key); 98 updateProductIndex(productPoolDetail, begin, key);
99 - logger.info("[func=deleteData][step(2)of(2) delete ProductIndexBO][key={}][indexName={}][id={}][cost={}ms]", key, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, id, 99 + logger.info("[func=deleteData][step(2/2)update ProductIndex][key={}][indexName={}][id={}][cost={}ms]", key, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, id,
100 (System.currentTimeMillis() - begin)); 100 (System.currentTimeMillis() - begin));
101 } 101 }
102 } 102 }
@@ -32,7 +32,7 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem @@ -32,7 +32,7 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem
32 try { 32 try {
33 final String key = UUID.randomUUID().toString(); 33 final String key = UUID.randomUUID().toString();
34 String messageStr = new String(message.getBody(), "UTF-8"); 34 String messageStr = new String(message.getBody(), "UTF-8");
35 - logger.info("[model=ProductStandardRelationMqListener][key={}][message={}]", key, messageStr); 35 + logger.info("[key={}][message={}]", key, messageStr);
36 // 如果在重建索引等待 36 // 如果在重建索引等待
37 this.waitingRebuildingIndex(); 37 this.waitingRebuildingIndex();
38 JSONObject json = JSONObject.parseObject(messageStr); 38 JSONObject json = JSONObject.parseObject(messageStr);
@@ -52,7 +52,6 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem @@ -52,7 +52,6 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem
52 } 52 }
53 } 53 }
54 54
55 - @SuppressWarnings({ "rawtypes", "unchecked" })  
56 public void updateData(final Map data, final String key) { 55 public void updateData(final Map data, final String key) {
57 long begin = System.currentTimeMillis(); 56 long begin = System.currentTimeMillis();
58 ProductStandardRelation productStandardRelation = new ProductStandardRelation(); 57 ProductStandardRelation productStandardRelation = new ProductStandardRelation();
@@ -62,11 +61,10 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem @@ -62,11 +61,10 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem
62 return; 61 return;
63 } 62 }
64 productStandardRelationService.saveOrUpdate(productStandardRelation); 63 productStandardRelationService.saveOrUpdate(productStandardRelation);
65 - logger.info("[func=updateData][step=saveToBb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin); 64 + logger.info("[func=updateData][key={}][cost={}ms]", key, System.currentTimeMillis() - begin);
66 this.updateProductIndex(productId, System.currentTimeMillis(), key); 65 this.updateProductIndex(productId, System.currentTimeMillis(), key);
67 } 66 }
68 67
69 - @SuppressWarnings({ "rawtypes", "unchecked" })  
70 public void deleteData(final Map data, final String key) { 68 public void deleteData(final Map data, final String key) {
71 long begin = System.currentTimeMillis(); 69 long begin = System.currentTimeMillis();
72 ProductStandardRelation psr = new ProductStandardRelation(); 70 ProductStandardRelation psr = new ProductStandardRelation();
@@ -77,11 +75,10 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem @@ -77,11 +75,10 @@ public class ProductStandardRelationMqListener extends AbstractMqListener implem
77 int productId = psr.getProductId(); 75 int productId = psr.getProductId();
78 Integer standardId = psr.getStandardId(); 76 Integer standardId = psr.getStandardId();
79 productStandardRelationService.delete(productId, standardId); 77 productStandardRelationService.delete(productId, standardId);
80 - logger.info("[func=deleteData][step=deleteFromBb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin); 78 + logger.info("[func=deleteData][key={}][cost={}ms]", key, System.currentTimeMillis() - begin);
81 this.updateProductIndex(productId, System.currentTimeMillis(), key); 79 this.updateProductIndex(productId, System.currentTimeMillis(), key);
82 } 80 }
83 81
84 - @SuppressWarnings("rawtypes")  
85 private void updateProductIndex(Integer productId, long begin, final String key) { 82 private void updateProductIndex(Integer productId, long begin, final String key) {
86 List<Map> productStandards = productStandardRelationService.getStandardListByProductId(productId); 83 List<Map> productStandards = productStandardRelationService.getStandardListByProductId(productId);
87 Set<String> standardIdSet = new HashSet<String>(); 84 Set<String> standardIdSet = new HashSet<String>();
@@ -52,7 +52,7 @@ public class ProductStyleRelationMqListener extends AbstractMqListener implement @@ -52,7 +52,7 @@ public class ProductStyleRelationMqListener extends AbstractMqListener implement
52 return; 52 return;
53 } 53 }
54 productStyleRelationService.saveOrUpdate(productStyleRelation); 54 productStyleRelationService.saveOrUpdate(productStyleRelation);
55 - logger.info("[func=updateData][step=saveToBb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin); 55 + logger.info("[func=updateData][key={}][cost={}ms]", key, System.currentTimeMillis() - begin);
56 updateProductIndex(productId, System.currentTimeMillis(), key); 56 updateProductIndex(productId, System.currentTimeMillis(), key);
57 } 57 }
58 58
@@ -76,7 +76,7 @@ public class ProductStyleRelationMqListener extends AbstractMqListener implement @@ -76,7 +76,7 @@ public class ProductStyleRelationMqListener extends AbstractMqListener implement
76 return; 76 return;
77 } 77 }
78 productStyleRelationService.delete(relationId); 78 productStyleRelationService.delete(relationId);
79 - logger.info("[func=deleteData][step=deleteFromDb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin); 79 + logger.info("[func=deleteData][key={}][cost={}ms]", key, System.currentTimeMillis() - begin);
80 updateProductIndex(productId, begin, key); 80 updateProductIndex(productId, begin, key);
81 } 81 }
82 82
@@ -95,6 +95,6 @@ public class ProductStyleRelationMqListener extends AbstractMqListener implement @@ -95,6 +95,6 @@ public class ProductStyleRelationMqListener extends AbstractMqListener implement
95 indexData.put("productId", productId); 95 indexData.put("productId", productId);
96 indexData.put("styleIds", StringUtils.join(styleIdSet, ",")); 96 indexData.put("styleIds", StringUtils.join(styleIdSet, ","));
97 this.updateProductIndexWithDataMap(indexData, productId, key, begin); 97 this.updateProductIndexWithDataMap(indexData, productId, key, begin);
98 - logger.info("[func=updateProductIndex][step=updateProductIndex][key={}][productId={}][cost={}ms]", key, productId,System.currentTimeMillis() - begin); 98 + logger.info("[func=updateProductIndex][key={}][productId={}][cost={}ms]", key, productId,System.currentTimeMillis() - begin);
99 } 99 }
100 } 100 }