|
|
package com.yoho.search.consumer.service.logicService.ufo;
|
|
|
|
|
|
import com.yoho.search.consumer.service.bo.UfoPriceBO;
|
|
|
import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
|
|
|
import com.yoho.search.dal.UfoStorageMapper;
|
|
|
import com.yoho.search.dal.UfoStoragePriceMapper;
|
...
|
...
|
@@ -40,20 +41,56 @@ public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder { |
|
|
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
|
|
|
List<StoragePrice> storagePriceList = ufoStoragePriceMap.get(ufoProductIndexBO.getId());
|
|
|
ufoProductIndexBO.setPrice(-1d);
|
|
|
ufoProductIndexBO.setAvailableNowPrice(-1d);
|
|
|
ufoProductIndexBO.setStorage(0);
|
|
|
if (CollectionUtils.isEmpty(storagePriceList)) {
|
|
|
continue;
|
|
|
}
|
|
|
BigDecimal price = buildPrice(storagePriceList, ufoStorageMap);
|
|
|
if (price == null) {
|
|
|
UfoPriceBO ufoPriceBO = buildUfoPriceBO(storagePriceList, ufoStorageMap);
|
|
|
if (ufoPriceBO.getPrice() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
ufoProductIndexBO.setPrice(price.doubleValue());
|
|
|
ufoProductIndexBO.setPrice(ufoPriceBO.getPrice().doubleValue());
|
|
|
ufoProductIndexBO.setStorage(1);
|
|
|
if (ufoPriceBO.getAvailableNowPrice() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
ufoProductIndexBO.setAvailableNowPrice(ufoPriceBO.getAvailableNowPrice().doubleValue());
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public BigDecimal buildPrice(List<StoragePrice> storagePriceList, Map<Integer, Storage> ufoStorageMap) {
|
|
|
/**
|
|
|
* 构建UfoPriceBO
|
|
|
*/
|
|
|
public UfoPriceBO buildUfoPriceBO(List<StoragePrice> storagePriceList, Map<Integer, Storage> ufoStorageMap) {
|
|
|
UfoPriceBO ufoPriceBO = new UfoPriceBO();
|
|
|
List<StoragePrice> validStoragePriceList = getValidStoragePriceList(storagePriceList, ufoStorageMap);
|
|
|
//获取所有有效库存最低价
|
|
|
if (CollectionUtils.isEmpty(validStoragePriceList)) {
|
|
|
return ufoPriceBO;
|
|
|
}
|
|
|
BigDecimal price = validStoragePriceList.get(0).getPrice();
|
|
|
if (price == null) {
|
|
|
return ufoPriceBO;
|
|
|
}
|
|
|
ufoPriceBO.setPrice(price);
|
|
|
//获取现货最低价
|
|
|
List<StoragePrice> validAvailableNowStoragePriceList = validStoragePriceList.stream().filter(p -> p.getPreSaleFlag() == 0).sorted(Comparator.comparing(StoragePrice::getPrice)).collect(Collectors.toList());
|
|
|
BigDecimal availableNowPrice = validAvailableNowStoragePriceList.get(0).getPrice();
|
|
|
if (availableNowPrice == null) {
|
|
|
return ufoPriceBO;
|
|
|
}
|
|
|
ufoPriceBO.setAvailableNowPrice(availableNowPrice);
|
|
|
return ufoPriceBO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取所有有效的StoragePrice列表
|
|
|
* 条件为:1.status为1(可售) 2.价格小于等于库存规定的最高价
|
|
|
*/
|
|
|
private List<StoragePrice> getValidStoragePriceList(List<StoragePrice> storagePriceList, Map<Integer, Storage> ufoStorageMap) {
|
|
|
List<StoragePrice> validStoragePriceList = new ArrayList<>();
|
|
|
for (StoragePrice storagePrice : storagePriceList) {
|
|
|
if (storagePrice.getStatus() != 1) {
|
...
|
...
|
@@ -76,15 +113,9 @@ public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder { |
|
|
if (CollectionUtils.isEmpty(validStoragePriceList)) {
|
|
|
return null;
|
|
|
}
|
|
|
validStoragePriceList = validStoragePriceList.stream().sorted(Comparator.comparing(StoragePrice::getPrice)).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(validStoragePriceList)) {
|
|
|
return null;
|
|
|
}
|
|
|
BigDecimal price = validStoragePriceList.get(0).getPrice();
|
|
|
if (price == null) {
|
|
|
return null;
|
|
|
}
|
|
|
return price;
|
|
|
return validStoragePriceList.stream().sorted(Comparator.comparing(StoragePrice::getPrice)).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|