Authored by unknown

fix price bug

... ... @@ -161,7 +161,7 @@ public class UfoToYohoIndexBuilder extends IIndexBuilder {
//尺码
ufoToYohoSizeService.build(productIndexBO, ufoProduct, ufoSizeMap, yohoSizeNameMap, ufoStorageMap);
//价格
ufoToYohoPriceService.build(productIndexBO, ufoProduct, ufoStoragePriceMap);
ufoToYohoPriceService.build(productIndexBO, ufoProduct, ufoStoragePriceMap,ufoStorageMap);
//直通车
productIndexBO.setToAddScore(ufoScoreProductRuleSet.contains(ufoProduct.getId()) ? "Y" : "N");
productIndexBOList.add(productIndexBO);
... ...
... ... @@ -8,12 +8,17 @@ import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;
import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService;
import com.yoho.search.core.es.model.ESBluk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author wangnan
* @version 2018/9/14
... ... @@ -29,6 +34,8 @@ public class UfoIndexUpdateHelper {
private CommonBulkService commonBulkService;
@Autowired
private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;
@Autowired
private ProductIndexBOToMapService productIndexBOToMapService;
public void updateUfoIndex(Integer productId) {
try {
... ... @@ -49,8 +56,8 @@ public class UfoIndexUpdateHelper {
if (productIndexBO == null) {
return;
}
JSONObject jsonObject = (JSONObject) JSON.toJSON(productIndexBO);
commonBulkService.add(new ESBluk(jsonObject.toJSONString(), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false));
Map<String, Object> dataMap = productIndexBOToMapService.beanToMap(productIndexBO);
commonBulkService.add(new ESBluk(JSON.toJSONString(dataMap), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
... ...
... ... @@ -43,38 +43,46 @@ public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder {
if (CollectionUtils.isEmpty(storagePriceList)) {
continue;
}
List<UfoStoragePrice> validStoragePriceList = new ArrayList<>();
for (UfoStoragePrice ufoStoragePrice : storagePriceList) {
if (ufoStoragePrice.getStatus() != 1) {
continue;
}
Integer storageId = ufoStoragePrice.getStorageId();
if (!ufoStorageMap.containsKey(storageId)) {
continue;
}
UfoStorage ufoStorage = ufoStorageMap.get(storageId);
BigDecimal suggestHighPrice = ufoStorage.getSuggestHighPrice();
if (suggestHighPrice == null) {
validStoragePriceList.add(ufoStoragePrice);
continue;
}
if (ufoStoragePrice.getPrice().compareTo(suggestHighPrice) <= 0) {
validStoragePriceList.add(ufoStoragePrice);
}
BigDecimal price = buildPrice(storagePriceList, ufoStorageMap);
if (price == null) {
continue;
}
if (CollectionUtils.isEmpty(validStoragePriceList)) {
ufoProductIndexBO.setPrice(price.doubleValue());
}
}
public BigDecimal buildPrice(List<UfoStoragePrice> storagePriceList, Map<Integer, UfoStorage> ufoStorageMap) {
List<UfoStoragePrice> validStoragePriceList = new ArrayList<>();
for (UfoStoragePrice ufoStoragePrice : storagePriceList) {
if (ufoStoragePrice.getStatus() != 1) {
continue;
}
validStoragePriceList = validStoragePriceList.stream().sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(validStoragePriceList)) {
Integer storageId = ufoStoragePrice.getStorageId();
if (!ufoStorageMap.containsKey(storageId)) {
continue;
}
BigDecimal price = validStoragePriceList.get(0).getPrice();
if (price == null) {
UfoStorage ufoStorage = ufoStorageMap.get(storageId);
BigDecimal suggestHighPrice = ufoStorage.getSuggestHighPrice();
if (suggestHighPrice == null) {
validStoragePriceList.add(ufoStoragePrice);
continue;
}
ufoProductIndexBO.setPrice(price.doubleValue());
if (ufoStoragePrice.getPrice().compareTo(suggestHighPrice) <= 0) {
validStoragePriceList.add(ufoStoragePrice);
}
}
if (CollectionUtils.isEmpty(validStoragePriceList)) {
return null;
}
validStoragePriceList = validStoragePriceList.stream().sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(validStoragePriceList)) {
return null;
}
BigDecimal price = validStoragePriceList.get(0).getPrice();
if (price == null) {
return null;
}
return price;
}
}
... ...
package com.yoho.search.consumer.service.logicService.ufo.yoho;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.ProductPriceBO;
import com.yoho.search.consumer.service.logicService.ufo.UfoStoragePriceFieldBuilder;
import com.yoho.search.dal.model.UfoProduct;
import com.yoho.search.dal.model.UfoStorage;
import com.yoho.search.dal.model.UfoStoragePrice;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
... ... @@ -21,19 +23,33 @@ import java.util.stream.Collectors;
@Component
public class UfoToYohoPriceService {
public void build(ProductIndexBO productIndexBO, UfoProduct ufoProduct, Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap) {
@Autowired
private UfoStoragePriceFieldBuilder ufoStoragePriceFieldBuilder;
public void build(ProductIndexBO productIndexBO, UfoProduct ufoProduct, Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap, Map<Integer, List<UfoStorage>> ufoStorageMap) {
List<UfoStorage> ufoStorageList = ufoStorageMap.get(ufoProduct.getId());
if (CollectionUtils.isEmpty(ufoStorageList)) {
productIndexBO.setStatus(0);
return;
}
Map<Integer, UfoStorage> idStorageMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(ufoStorageList)) {
idStorageMap = ufoStorageList.stream().collect(Collectors.toMap(UfoStorage::getId, p -> p));
}
List<UfoStoragePrice> ufoStoragePriceList = ufoStoragePriceMap.get(ufoProduct.getId());
if (CollectionUtils.isEmpty(ufoStoragePriceList)) {
productIndexBO.setStatus(0);
return;
}
ufoStoragePriceList = ufoStoragePriceList.stream().filter(s -> s.getStatus() == 1).sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(ufoStoragePriceList)) {
BigDecimal price = ufoStoragePriceFieldBuilder.buildPrice(ufoStoragePriceList, idStorageMap);
if (price == null) {
productIndexBO.setStatus(0);
return;
}
BigDecimal price = ufoStoragePriceList.get(0).getPrice();
productIndexBO.setMarketPrice(price);
productIndexBO.setSalesPrice(price);
ProductPriceBO productPriceBo = new ProductPriceBO(productIndexBO.getProductSkn());
productPriceBo.setMarketPrice(price);
productPriceBo.setSalesPrice(price);
productIndexBO.setProductPriceBO(productPriceBo);
}
}
... ...