Authored by gemingdan

update

@@ -76,16 +76,32 @@ public class PromotionProductMqListener extends AbstractMqListener implements Ch @@ -76,16 +76,32 @@ public class PromotionProductMqListener extends AbstractMqListener implements Ch
76 public void updateData(final Map data, final String key) throws Exception { 76 public void updateData(final Map data, final String key) throws Exception {
77 long begin = System.currentTimeMillis(); 77 long begin = System.currentTimeMillis();
78 PromotionProduct promotionProduct = (PromotionProduct) ConvertUtils.transMap2Bean(PromotionProduct.class, data); 78 PromotionProduct promotionProduct = (PromotionProduct) ConvertUtils.transMap2Bean(PromotionProduct.class, data);
79 - if (promotionProduct == null || promotionProduct.getPromotionId()== null|| promotionProduct.getPromotionId()== null) { 79 + if (promotionProduct == null || promotionProduct.getPromotionId()== null|| promotionProduct.getProductSkn()== null) {
80 return; 80 return;
81 } 81 }
82 - // 1、保存至数据库 82 + boolean sknIsChange=false;
  83 + Integer oldSkn=null;
  84 + // 1、获取数据库原数据
  85 + if(promotionProduct.getId()!=null){
  86 + PromotionProduct promotionProductOld = promotionProductService.selectById(promotionProduct.getId());
  87 + if(!(promotionProductOld.getProductSkn().equals(promotionProduct.getProductSkn()))){
  88 + //修改了skn,需要改原skn的promotionIds
  89 + sknIsChange=true;
  90 + oldSkn=promotionProductOld.getProductSkn();
  91 + }
  92 + }
  93 +
  94 + // 2、保存至数据库
83 promotionProductService.saveOrUpdate(promotionProduct); 95 promotionProductService.saveOrUpdate(promotionProduct);
84 logger.info("[func=updateData][step=saveToBb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin); 96 logger.info("[func=updateData][step=saveToBb][key={}][cost={}ms]", key, System.currentTimeMillis() - begin);
85 97
86 - // 2、更新ProductIndex 98 + // 3、更新ProductIndex
87 this.updateProductIndex(promotionProduct.getProductSkn(), System.currentTimeMillis(), key); 99 this.updateProductIndex(promotionProduct.getProductSkn(), System.currentTimeMillis(), key);
88 logger.info("[func=updateData][step=updateProductIndex][productSkn={}][cost={}ms]", promotionProduct.getProductSkn(), System.currentTimeMillis() - begin); 100 logger.info("[func=updateData][step=updateProductIndex][productSkn={}][cost={}ms]", promotionProduct.getProductSkn(), System.currentTimeMillis() - begin);
  101 + if(sknIsChange){
  102 + this.updateProductIndex(oldSkn, System.currentTimeMillis(), key);
  103 + logger.info("[func=updateData][step=updateProductIndex][productSkn={}][cost={}ms]", oldSkn, System.currentTimeMillis() - begin);
  104 + }
89 105
90 } 106 }
91 107