|
|
package com.yoho.search.consumer.service.logicService.ufo;
|
|
|
|
|
|
import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
|
|
|
import com.yoho.search.dal.UfoStorageMapper;
|
|
|
import com.yoho.search.dal.UfoStoragePriceMapper;
|
|
|
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;
|
...
|
...
|
@@ -19,36 +21,60 @@ import java.util.stream.Collectors; |
|
|
public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder {
|
|
|
|
|
|
@Autowired
|
|
|
private UfoStorageMapper ufoStorageMapper;
|
|
|
@Autowired
|
|
|
private UfoStoragePriceMapper ufoStoragePriceMapper;
|
|
|
|
|
|
@Override
|
|
|
public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {
|
|
|
List<UfoStorage> ufoStorageList = ufoStorageMapper.selectByProductIdList(idList);
|
|
|
Map<Integer, UfoStorage> ufoStorageMap = new HashMap<>();
|
|
|
if (CollectionUtils.isNotEmpty(ufoStorageList)) {
|
|
|
ufoStorageMap = ufoStorageList.stream().collect(Collectors.toMap(UfoStorage::getId, p -> p));
|
|
|
}
|
|
|
List<UfoStoragePrice> ufoStoragePriceList = ufoStoragePriceMapper.selectByProductIdList(idList);
|
|
|
Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap = new HashMap<>(ufoStoragePriceList.size());
|
|
|
Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap = new HashMap<>();
|
|
|
if (CollectionUtils.isNotEmpty(ufoStoragePriceList)) {
|
|
|
for (UfoStoragePrice ufoStoragePrice : ufoStoragePriceList) {
|
|
|
if (ufoStoragePriceMap.containsKey(ufoStoragePrice.getProductId())) {
|
|
|
List<UfoStoragePrice> storagePriceList = ufoStoragePriceMap.get(ufoStoragePrice.getProductId());
|
|
|
storagePriceList.add(ufoStoragePrice);
|
|
|
} else {
|
|
|
List<UfoStoragePrice> storagePriceList = new ArrayList<>();
|
|
|
storagePriceList.add(ufoStoragePrice);
|
|
|
ufoStoragePriceMap.put(ufoStoragePrice.getProductId(), storagePriceList);
|
|
|
}
|
|
|
}
|
|
|
ufoStoragePriceMap = ufoStoragePriceList.stream().collect(Collectors.groupingBy(UfoStoragePrice::getProductId));
|
|
|
}
|
|
|
ufoProductIndexBOList.stream().forEach(p -> {
|
|
|
List<UfoStoragePrice> storagePriceList = ufoStoragePriceMap.get(p.getId());
|
|
|
p.setPrice(-1d);
|
|
|
if (CollectionUtils.isNotEmpty(storagePriceList)) {
|
|
|
storagePriceList = storagePriceList.stream().filter(s -> s.getStatus() == 1).sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isNotEmpty(storagePriceList)) {
|
|
|
BigDecimal price = storagePriceList.get(0).getPrice();
|
|
|
if (price != null) {
|
|
|
p.setPrice(price.doubleValue());
|
|
|
}
|
|
|
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
|
|
|
List<UfoStoragePrice> storagePriceList = ufoStoragePriceMap.get(ufoProductIndexBO.getId());
|
|
|
ufoProductIndexBO.setPrice(-1d);
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(validStoragePriceList)) {
|
|
|
continue;
|
|
|
}
|
|
|
validStoragePriceList = validStoragePriceList.stream().sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(validStoragePriceList)) {
|
|
|
continue;
|
|
|
}
|
|
|
});
|
|
|
BigDecimal price = validStoragePriceList.get(0).getPrice();
|
|
|
if (price == null) {
|
|
|
continue;
|
|
|
}
|
|
|
ufoProductIndexBO.setPrice(price.doubleValue());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|