Authored by 胡古飞

ufostorageprice支持showChannel参数过滤

... ... @@ -4,14 +4,13 @@ import com.yoho.search.consumer.index.fullbuild.IIndexBuilder;
import com.yoho.search.consumer.service.bo.ufo.UfoStoragePriceIndexBO;
import com.yoho.search.consumer.service.logicService.cache.UfoBasicDataCacheService;
import com.yoho.search.consumer.service.logicService.tbl.util.StringUtils;
import com.yoho.search.dal.UfoProductMapper;
import com.yoho.search.dal.UfoSecondhandImagesMapper;
import com.yoho.search.dal.UfoStorageMapper;
import com.yoho.search.dal.UfoStoragePriceMapper;
import com.yoho.search.dal.model.ufo_product.SecondhandImages;
import com.yoho.search.dal.model.ufo_product.Size;
import com.yoho.search.dal.model.ufo_product.Storage;
import com.yoho.search.dal.model.ufo_product.StoragePrice;
import com.yoho.search.dal.model.ufo_product.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -23,6 +22,8 @@ import java.util.stream.Collectors;
public class UfoStoragePriceIndexBuilder extends IIndexBuilder {
@Autowired
private UfoProductMapper ufoProductMapper;
@Autowired
private UfoStoragePriceMapper ufoStoragePriceMapper;
@Autowired
private UfoSecondhandImagesMapper ufoSecondhandImagesMapper;
... ... @@ -48,7 +49,7 @@ public class UfoStoragePriceIndexBuilder extends IIndexBuilder {
}
public List<UfoStoragePriceIndexBO> buildUfoStoragePriceIndexBOListByStoragePriceIds(List<Integer> storagePriceIds) {
if(storagePriceIds==null || storagePriceIds.isEmpty()){
if (storagePriceIds == null || storagePriceIds.isEmpty()) {
return new ArrayList<>();
}
List<StoragePrice> storagePrices = ufoStoragePriceMapper.selectListByPrimaryKeys(storagePriceIds);
... ... @@ -59,25 +60,31 @@ public class UfoStoragePriceIndexBuilder extends IIndexBuilder {
if (CollectionUtils.isEmpty(storagePrices)) {
return new ArrayList<>();
}
List<Integer> skupIds = new ArrayList<>();
List<Integer> productIds = new ArrayList<>();
List<Integer> storageIds = new ArrayList<>();
List<Integer> skupIds = new ArrayList<>();
for (StoragePrice storagePrice : storagePrices) {
skupIds.add(storagePrice.getSkup());
productIds.add(storagePrice.getProductId());
storageIds.add(storagePrice.getStorageId());
skupIds.add(storagePrice.getSkup());
}
// 获取show_channel信息
Map<Integer, String> showChannelMap = this.buildShowChannelMap(productIds);
// 构建尺码信息
Map<Integer, Short> storageId2SizeId = this.buildStorageId2SizeId(storageIds);
// 构建二手图片信息
Map<Integer, String> skupSecondhandImageMap = this.buildSkupSecondhandImageMap(skupIds);
// 获取尺码信息
Map<Short, Size> sizeMap = ufoBasicDataCacheService.getUfoSize();
// 构建结果
List<UfoStoragePriceIndexBO> results = new ArrayList<>();
for (StoragePrice storagePrice : storagePrices) {
UfoStoragePriceIndexBO ufoStoragePriceIndexBO = new UfoStoragePriceIndexBO();
BeanUtils.copyProperties(storagePrice, ufoStoragePriceIndexBO);
// 处理尺码
// 1) 处理showChannel
String showChannel = MapUtils.getString(showChannelMap, storagePrice.getProductId(), "");
ufoStoragePriceIndexBO.setShowChannel(showChannel);
// 2) 处理尺码
Short sizeId = storageId2SizeId.get(storagePrice.getStorageId());
if (sizeId != null) {
ufoStoragePriceIndexBO.setSizeId(Integer.valueOf(sizeId));
... ... @@ -87,14 +94,23 @@ public class UfoStoragePriceIndexBuilder extends IIndexBuilder {
ufoStoragePriceIndexBO.setSizeId(-1);
ufoStoragePriceIndexBO.setSizeName("");
}
// 处理二手图片
// 3) 处理二手图片
String imageUrl = skupSecondhandImageMap.get(storagePrice.getSkup());
ufoStoragePriceIndexBO.setSecondhandImage(imageUrl == null ? "" : imageUrl);
// 4) 添加结果
results.add(ufoStoragePriceIndexBO);
}
return results;
}
private Map<Integer, String> buildShowChannelMap(List<Integer> productIds) {
if (CollectionUtils.isEmpty(productIds)) {
return new HashMap<>();
}
List<Product> productList = ufoProductMapper.selectByIdList(productIds);
return productList.stream().collect(Collectors.toMap(Product::getId, Product::getShowChannel));
}
private Map<Integer, Short> buildStorageId2SizeId(List<Integer> storageIdList) {
if (CollectionUtils.isEmpty(storageIdList)) {
return new HashMap<>();
... ... @@ -120,7 +136,7 @@ public class UfoStoragePriceIndexBuilder extends IIndexBuilder {
continue;
}
// 兜底
if(!skupSecondhandImageMap.containsKey(secondhandImages.getSkup())){
if (!skupSecondhandImageMap.containsKey(secondhandImages.getSkup())) {
skupSecondhandImageMap.put(secondhandImages.getSkup(), secondhandImages.getImageUrl());
}
}
... ...
... ... @@ -47,6 +47,10 @@
"sizeName": {
"type": "text",
"index": "no"
},
"showChannel": {
"type": "text",
"analyzer": "comma_spliter"
}
}
}
... ...
... ... @@ -19,6 +19,9 @@ public class UfoStoragePriceIndexBO {
private Integer preSaleFlag;
private Integer region;
//from ufo_product
private String showChannel;
// 二手图片 from secondhand_images
private String secondhandImage;
... ...