Authored by unknown

fix price bug

@@ -161,7 +161,7 @@ public class UfoToYohoIndexBuilder extends IIndexBuilder { @@ -161,7 +161,7 @@ public class UfoToYohoIndexBuilder extends IIndexBuilder {
161 //尺码 161 //尺码
162 ufoToYohoSizeService.build(productIndexBO, ufoProduct, ufoSizeMap, yohoSizeNameMap, ufoStorageMap); 162 ufoToYohoSizeService.build(productIndexBO, ufoProduct, ufoSizeMap, yohoSizeNameMap, ufoStorageMap);
163 //价格 163 //价格
164 - ufoToYohoPriceService.build(productIndexBO, ufoProduct, ufoStoragePriceMap); 164 + ufoToYohoPriceService.build(productIndexBO, ufoProduct, ufoStoragePriceMap,ufoStorageMap);
165 //直通车 165 //直通车
166 productIndexBO.setToAddScore(ufoScoreProductRuleSet.contains(ufoProduct.getId()) ? "Y" : "N"); 166 productIndexBO.setToAddScore(ufoScoreProductRuleSet.contains(ufoProduct.getId()) ? "Y" : "N");
167 productIndexBOList.add(productIndexBO); 167 productIndexBOList.add(productIndexBO);
@@ -8,12 +8,17 @@ import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder; @@ -8,12 +8,17 @@ import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;
8 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; 9 import com.yoho.search.consumer.service.bo.ProductIndexBO;
10 import com.yoho.search.consumer.service.bo.UfoProductIndexBO; 10 import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
  11 +import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService;
11 import com.yoho.search.core.es.model.ESBluk; 12 import com.yoho.search.core.es.model.ESBluk;
12 import org.slf4j.Logger; 13 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Component; 16 import org.springframework.stereotype.Component;
16 17
  18 +import java.util.ArrayList;
  19 +import java.util.List;
  20 +import java.util.Map;
  21 +
17 /** 22 /**
18 * @author wangnan 23 * @author wangnan
19 * @version 2018/9/14 24 * @version 2018/9/14
@@ -29,6 +34,8 @@ public class UfoIndexUpdateHelper { @@ -29,6 +34,8 @@ public class UfoIndexUpdateHelper {
29 private CommonBulkService commonBulkService; 34 private CommonBulkService commonBulkService;
30 @Autowired 35 @Autowired
31 private UfoToYohoIndexBuilder ufoToYohoIndexBuilder; 36 private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;
  37 + @Autowired
  38 + private ProductIndexBOToMapService productIndexBOToMapService;
32 39
33 public void updateUfoIndex(Integer productId) { 40 public void updateUfoIndex(Integer productId) {
34 try { 41 try {
@@ -49,8 +56,8 @@ public class UfoIndexUpdateHelper { @@ -49,8 +56,8 @@ public class UfoIndexUpdateHelper {
49 if (productIndexBO == null) { 56 if (productIndexBO == null) {
50 return; 57 return;
51 } 58 }
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)); 59 + Map<String, Object> dataMap = productIndexBOToMapService.beanToMap(productIndexBO);
  60 + commonBulkService.add(new ESBluk(JSON.toJSONString(dataMap), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false));
54 } catch (Exception e) { 61 } catch (Exception e) {
55 logger.error(e.getMessage(), e); 62 logger.error(e.getMessage(), e);
56 } 63 }
@@ -43,38 +43,46 @@ public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder { @@ -43,38 +43,46 @@ public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder {
43 if (CollectionUtils.isEmpty(storagePriceList)) { 43 if (CollectionUtils.isEmpty(storagePriceList)) {
44 continue; 44 continue;
45 } 45 }
46 - List<UfoStoragePrice> validStoragePriceList = new ArrayList<>();  
47 - for (UfoStoragePrice ufoStoragePrice : storagePriceList) {  
48 - if (ufoStoragePrice.getStatus() != 1) {  
49 - continue;  
50 - }  
51 - Integer storageId = ufoStoragePrice.getStorageId();  
52 - if (!ufoStorageMap.containsKey(storageId)) {  
53 - continue;  
54 - }  
55 - UfoStorage ufoStorage = ufoStorageMap.get(storageId);  
56 - BigDecimal suggestHighPrice = ufoStorage.getSuggestHighPrice();  
57 - if (suggestHighPrice == null) {  
58 - validStoragePriceList.add(ufoStoragePrice);  
59 - continue;  
60 - }  
61 - if (ufoStoragePrice.getPrice().compareTo(suggestHighPrice) <= 0) {  
62 - validStoragePriceList.add(ufoStoragePrice);  
63 - } 46 + BigDecimal price = buildPrice(storagePriceList, ufoStorageMap);
  47 + if (price == null) {
  48 + continue;
64 } 49 }
65 - if (CollectionUtils.isEmpty(validStoragePriceList)) { 50 + ufoProductIndexBO.setPrice(price.doubleValue());
  51 + }
  52 + }
  53 +
  54 + public BigDecimal buildPrice(List<UfoStoragePrice> storagePriceList, Map<Integer, UfoStorage> ufoStorageMap) {
  55 + List<UfoStoragePrice> validStoragePriceList = new ArrayList<>();
  56 + for (UfoStoragePrice ufoStoragePrice : storagePriceList) {
  57 + if (ufoStoragePrice.getStatus() != 1) {
66 continue; 58 continue;
67 } 59 }
68 - validStoragePriceList = validStoragePriceList.stream().sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());  
69 - if (CollectionUtils.isEmpty(validStoragePriceList)) { 60 + Integer storageId = ufoStoragePrice.getStorageId();
  61 + if (!ufoStorageMap.containsKey(storageId)) {
70 continue; 62 continue;
71 } 63 }
72 - BigDecimal price = validStoragePriceList.get(0).getPrice();  
73 - if (price == null) { 64 + UfoStorage ufoStorage = ufoStorageMap.get(storageId);
  65 + BigDecimal suggestHighPrice = ufoStorage.getSuggestHighPrice();
  66 + if (suggestHighPrice == null) {
  67 + validStoragePriceList.add(ufoStoragePrice);
74 continue; 68 continue;
75 } 69 }
76 - ufoProductIndexBO.setPrice(price.doubleValue()); 70 + if (ufoStoragePrice.getPrice().compareTo(suggestHighPrice) <= 0) {
  71 + validStoragePriceList.add(ufoStoragePrice);
  72 + }
  73 + }
  74 + if (CollectionUtils.isEmpty(validStoragePriceList)) {
  75 + return null;
  76 + }
  77 + validStoragePriceList = validStoragePriceList.stream().sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());
  78 + if (CollectionUtils.isEmpty(validStoragePriceList)) {
  79 + return null;
  80 + }
  81 + BigDecimal price = validStoragePriceList.get(0).getPrice();
  82 + if (price == null) {
  83 + return null;
77 } 84 }
  85 + return price;
78 } 86 }
79 } 87 }
80 88
1 package com.yoho.search.consumer.service.logicService.ufo.yoho; 1 package com.yoho.search.consumer.service.logicService.ufo.yoho;
2 2
3 import com.yoho.search.consumer.service.bo.ProductIndexBO; 3 import com.yoho.search.consumer.service.bo.ProductIndexBO;
  4 +import com.yoho.search.consumer.service.bo.ProductPriceBO;
  5 +import com.yoho.search.consumer.service.logicService.ufo.UfoStoragePriceFieldBuilder;
4 import com.yoho.search.dal.model.UfoProduct; 6 import com.yoho.search.dal.model.UfoProduct;
  7 +import com.yoho.search.dal.model.UfoStorage;
5 import com.yoho.search.dal.model.UfoStoragePrice; 8 import com.yoho.search.dal.model.UfoStoragePrice;
6 import org.apache.commons.collections.CollectionUtils; 9 import org.apache.commons.collections.CollectionUtils;
  10 +import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Component; 11 import org.springframework.stereotype.Component;
8 12
9 import java.math.BigDecimal; 13 import java.math.BigDecimal;
10 -import java.util.Comparator;  
11 -import java.util.List;  
12 -import java.util.Map; 14 +import java.util.*;
13 import java.util.stream.Collectors; 15 import java.util.stream.Collectors;
14 16
15 /** 17 /**
@@ -21,19 +23,33 @@ import java.util.stream.Collectors; @@ -21,19 +23,33 @@ import java.util.stream.Collectors;
21 @Component 23 @Component
22 public class UfoToYohoPriceService { 24 public class UfoToYohoPriceService {
23 25
24 - public void build(ProductIndexBO productIndexBO, UfoProduct ufoProduct, Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap) { 26 +
  27 + @Autowired
  28 + private UfoStoragePriceFieldBuilder ufoStoragePriceFieldBuilder;
  29 +
  30 + public void build(ProductIndexBO productIndexBO, UfoProduct ufoProduct, Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap, Map<Integer, List<UfoStorage>> ufoStorageMap) {
  31 + List<UfoStorage> ufoStorageList = ufoStorageMap.get(ufoProduct.getId());
  32 + if (CollectionUtils.isEmpty(ufoStorageList)) {
  33 + productIndexBO.setStatus(0);
  34 + return;
  35 + }
  36 + Map<Integer, UfoStorage> idStorageMap = new HashMap<>();
  37 + if (CollectionUtils.isNotEmpty(ufoStorageList)) {
  38 + idStorageMap = ufoStorageList.stream().collect(Collectors.toMap(UfoStorage::getId, p -> p));
  39 + }
25 List<UfoStoragePrice> ufoStoragePriceList = ufoStoragePriceMap.get(ufoProduct.getId()); 40 List<UfoStoragePrice> ufoStoragePriceList = ufoStoragePriceMap.get(ufoProduct.getId());
26 if (CollectionUtils.isEmpty(ufoStoragePriceList)) { 41 if (CollectionUtils.isEmpty(ufoStoragePriceList)) {
27 productIndexBO.setStatus(0); 42 productIndexBO.setStatus(0);
28 return; 43 return;
29 } 44 }
30 - ufoStoragePriceList = ufoStoragePriceList.stream().filter(s -> s.getStatus() == 1).sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());  
31 - if (CollectionUtils.isEmpty(ufoStoragePriceList)) { 45 + BigDecimal price = ufoStoragePriceFieldBuilder.buildPrice(ufoStoragePriceList, idStorageMap);
  46 + if (price == null) {
32 productIndexBO.setStatus(0); 47 productIndexBO.setStatus(0);
33 return; 48 return;
34 } 49 }
35 - BigDecimal price = ufoStoragePriceList.get(0).getPrice();  
36 - productIndexBO.setMarketPrice(price);  
37 - productIndexBO.setSalesPrice(price); 50 + ProductPriceBO productPriceBo = new ProductPriceBO(productIndexBO.getProductSkn());
  51 + productPriceBo.setMarketPrice(price);
  52 + productPriceBo.setSalesPrice(price);
  53 + productIndexBO.setProductPriceBO(productPriceBo);
38 } 54 }
39 } 55 }