|
|
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);
|
|
|
}
|
|
|
} |
...
|
...
|
|