|
|
package com.yoho.search.consumer.index.fullbuild.ufo;
|
|
|
|
|
|
import com.yoho.search.base.bo.UfoStorageMinPrice;
|
|
|
import com.yoho.search.consumer.index.fullbuild.IIndexBuilder;
|
|
|
import com.yoho.search.consumer.service.bo.ufo.UfoStorageIndexBO;
|
|
|
import com.yoho.search.consumer.service.bo.ufo.UfoStoragePriceIndexBO;
|
|
|
import com.yoho.search.dal.UfoStorageMapper;
|
|
|
import com.yoho.search.dal.UfoStoragePriceMapper;
|
|
|
import com.yoho.search.dal.model.ufo_product.*;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
|
public class UfoStorageIndexBuilder extends IIndexBuilder {
|
|
|
|
|
|
@Autowired
|
|
|
private UfoStorageMapper ufoStorageMapper;
|
|
|
@Autowired
|
|
|
private UfoStoragePriceMapper ufoStoragePriceMapper;
|
|
|
|
|
|
@Override
|
|
|
public int getTotalCount() throws Exception {
|
|
|
return ufoStorageMapper.selectCount();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<?> getPageLists(int offset, int limit) throws Exception {
|
|
|
List<Storage> storages = ufoStorageMapper.selectPageList(offset, limit);
|
|
|
return this.buildUfoStorageIndexBOList(storages);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getId(Object object) {
|
|
|
return ((UfoStoragePriceIndexBO) object).getId().toString();
|
|
|
}
|
|
|
|
|
|
public List<UfoStorageIndexBO> buildUfoStorageIndexBOListByIds(List<Integer> storagesIds) {
|
|
|
if (storagesIds == null || storagesIds.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<Storage> storages = ufoStorageMapper.selectListByStorageIdList(storagesIds);
|
|
|
return this.buildUfoStorageIndexBOList(storages);
|
|
|
}
|
|
|
|
|
|
public List<UfoStorageIndexBO> buildUfoStorageIndexBOList(List<Storage> storages) {
|
|
|
if (CollectionUtils.isEmpty(storages)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<Integer> storageIds = storages.stream().map(a -> a.getId()).collect(Collectors.toList());
|
|
|
Map<Integer, BigDecimal> availableNowPriceMap = this.buildAvailableNowPriceMap(storageIds);
|
|
|
// 构建结果
|
|
|
List<UfoStorageIndexBO> results = new ArrayList<>();
|
|
|
for (Storage storage : storages) {
|
|
|
UfoStorageIndexBO ufoStorageIndexBO = new UfoStorageIndexBO();
|
|
|
BeanUtils.copyProperties(storage, ufoStorageIndexBO);
|
|
|
ufoStorageIndexBO.setAvailableNowPrice(availableNowPriceMap.get(storage.getId()));
|
|
|
results.add(ufoStorageIndexBO);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, BigDecimal> buildAvailableNowPriceMap(List<Integer> storageIds) {
|
|
|
List<UfoStorageMinPrice> storageMinPriceList = ufoStoragePriceMapper.selectStorageMinPriceList(storageIds);
|
|
|
return storageMinPriceList.stream().collect(Collectors.toMap(UfoStorageMinPrice::getStorageId,UfoStorageMinPrice::getAvailableNowPrice));
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|