Authored by wangnan9279

ufo fix

... ... @@ -8,10 +8,13 @@
<result column="goods_id" property="goodsId" jdbcType="INTEGER" />
<result column="size_id" property="sizeId" jdbcType="SMALLINT" />
<result column="storage_num" property="storageNum" jdbcType="INTEGER" />
<result column="suggest_low_price" property="suggestLowPrice" jdbcType="DECIMAL" />
<result column="suggest_high_price" property="suggestHighPrice" jdbcType="DECIMAL" />
</resultMap>
<sql id="Base_Column_List" >
id, product_id, goods_id, size_id, storage_num, update_time, create_time
id, product_id, goods_id, size_id, storage_num, suggest_low_price,
suggest_high_price
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
... ... @@ -44,6 +47,12 @@
<if test="storageNum != null" >
storage_num,
</if>
<if test="suggestLowPrice != null" >
suggest_low_price,
</if>
<if test="suggestHighPrice != null" >
suggest_high_price,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
... ... @@ -61,6 +70,12 @@
<if test="storageNum != null" >
#{storageNum,jdbcType=INTEGER},
</if>
<if test="suggestLowPrice != null" >
#{suggestLowPrice,jdbcType=DECIMAL},
</if>
<if test="suggestHighPrice != null" >
#{suggestHighPrice,jdbcType=DECIMAL},
</if>
</trim>
</insert>
... ... @@ -79,6 +94,12 @@
<if test="storageNum != null" >
storage_num = #{storageNum,jdbcType=INTEGER},
</if>
<if test="suggestLowPrice != null" >
suggest_low_price = #{suggestLowPrice,jdbcType=DECIMAL},
</if>
<if test="suggestHighPrice != null" >
suggest_high_price = #{suggestHighPrice,jdbcType=DECIMAL},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
... ...
... ... @@ -7,6 +7,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
... ... @@ -28,22 +29,21 @@ public class UfoBrandFieldBuilder implements UfoIndexFieldBuilder {
return;
}
List<UfoBrand> ufoBrandList = ufoBrandMapper.selectByIdList(brandIdList);
if (CollectionUtils.isEmpty(ufoBrandList)) {
return;
Map<Short, UfoBrand> ufoBrandMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(ufoBrandList)) {
ufoBrandMap = ufoBrandList.stream().collect(Collectors.toMap(UfoBrand::getId, p -> p));
}
Map<Short, UfoBrand> ufoBrandMap = ufoBrandList.stream().collect(Collectors.toMap(UfoBrand::getId, p -> p));
ufoProductIndexBOList.stream().forEach(p -> {
UfoBrand ufoBrand = ufoBrandMap.get(p.getBrandId());
if (ufoBrand != null) {
p.setBrandName(ufoBrand.getBrandName());
p.setBrandNameEn(ufoBrand.getBrandNameEn());
p.setBrandSearch(ufoBrand.getBrandSearch());
} else {
p.setBrandName("");
p.setBrandNameEn("");
p.setBrandSearch("");
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
ufoProductIndexBO.setBrandName("");
ufoProductIndexBO.setBrandNameEn("");
ufoProductIndexBO.setBrandSearch("");
UfoBrand ufoBrand = ufoBrandMap.get(ufoProductIndexBO.getBrandId());
if (ufoBrand == null) {
continue;
}
ufoProductIndexBO.setBrandName(ufoBrand.getBrandName());
ufoProductIndexBO.setBrandNameEn(ufoBrand.getBrandNameEn());
ufoProductIndexBO.setBrandSearch(ufoBrand.getBrandSearch());
}
});
}
}
... ...
... ... @@ -7,6 +7,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
... ... @@ -27,20 +28,20 @@ public class UfoBrandSeriesFieldBuilder implements UfoIndexFieldBuilder {
if (CollectionUtils.isEmpty(seriesIdList)) {
return;
}
Map<Short, UfoBrandSeries> ufoBrandSeriesMap = new HashMap<>();
List<UfoBrandSeries> ufoBrandSeriesList = ufoBrandSeriesMapper.selectByIdList(seriesIdList);
if (CollectionUtils.isEmpty(ufoBrandSeriesList)) {
return;
if (CollectionUtils.isNotEmpty(ufoBrandSeriesList)) {
ufoBrandSeriesMap = ufoBrandSeriesList.stream().collect(Collectors.toMap(UfoBrandSeries::getId, p -> p));
}
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
ufoProductIndexBO.setSeriesName("");
ufoProductIndexBO.setSeriesSearch("");
UfoBrandSeries ufoBrandSeries = ufoBrandSeriesMap.get(ufoProductIndexBO.getSeriesId());
if (ufoBrandSeries == null) {
continue;
}
Map<Short, UfoBrandSeries> ufoBrandSeriesMap = ufoBrandSeriesList.stream().collect(Collectors.toMap(UfoBrandSeries::getId, p -> p));
ufoProductIndexBOList.stream().forEach(p -> {
UfoBrandSeries ufoBrandSeries = ufoBrandSeriesMap.get(p.getSeriesId());
if (ufoBrandSeries != null) {
p.setSeriesName(ufoBrandSeries.getSeriesName());
p.setSeriesSearch(ufoBrandSeries.getSeriesSearch());
}else {
p.setSeriesName("");
p.setSeriesSearch("");
ufoProductIndexBO.setSeriesName(ufoBrandSeries.getSeriesName());
ufoProductIndexBO.setSeriesSearch(ufoBrandSeries.getSeriesSearch());
}
});
}
}
... ...
... ... @@ -7,7 +7,6 @@ import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
... ... @@ -19,42 +18,35 @@ import java.util.stream.Collectors;
*/
@Component
public class UfoGoodsFieldBuilder implements UfoIndexFieldBuilder {
@Autowired
private UfoGoodsMapper ufoGoodsMapper;
@Override
public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {
List<UfoGoods> ufoGoodsList = ufoGoodsMapper.selectByProductIdList(idList);
Map<Integer, List<UfoGoods>> ufoGoodsMap = new HashMap<>(ufoGoodsList.size());
Map<Integer, List<UfoGoods>> ufoGoodsMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(ufoGoodsList)) {
for (UfoGoods ufoGoods : ufoGoodsList) {
if (ufoGoodsMap.containsKey(ufoGoods.getProductId())) {
List<UfoGoods> goodsList = ufoGoodsMap.get(ufoGoods.getProductId());
goodsList.add(ufoGoods);
} else {
List<UfoGoods> goodsList = new ArrayList<>();
goodsList.add(ufoGoods);
ufoGoodsMap.put(ufoGoods.getProductId(), goodsList);
}
ufoGoodsMap = ufoGoodsList.stream().collect(Collectors.groupingBy(UfoGoods::getProductId));
}
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
ufoProductIndexBO.setDefaultImages("");
ufoProductIndexBO.setColorIds("");
ufoProductIndexBO.setColorNames("");
List<UfoGoods> goodsList = ufoGoodsMap.get(ufoProductIndexBO.getId());
if (CollectionUtils.isEmpty(goodsList)) {
continue;
}
ufoProductIndexBOList.stream().forEach(p -> {
List<UfoGoods> goodsList = ufoGoodsMap.get(p.getId());
if (CollectionUtils.isNotEmpty(goodsList)) {
String colorIds = goodsList.stream().map(UfoGoods::getColorId).map(s -> s.toString()).collect(Collectors.joining(","));
String colorNames = goodsList.stream().map(UfoGoods::getColorName).collect(Collectors.joining(","));
goodsList.forEach(g -> {
if ("Y".equals(g.getIsDefault())) {
p.setDefaultImages(g.getColorImage());
ufoProductIndexBO.setDefaultImages(g.getColorImage());
}
});
p.setColorIds(colorIds);
p.setColorNames(colorNames);
} else {
p.setDefaultImages("");
p.setColorIds("");
p.setColorNames("");
String colorIds = goodsList.stream().map(UfoGoods::getColorId).map(s -> s.toString()).collect(Collectors.joining(","));
String colorNames = goodsList.stream().map(UfoGoods::getColorName).collect(Collectors.joining(","));
ufoProductIndexBO.setColorIds(colorIds);
ufoProductIndexBO.setColorNames(colorNames);
}
});
}
}
... ...
package com.yoho.search.consumer.service.logicService.ufo;
import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
import com.yoho.search.dal.UfoGoodsImagesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author wangnan
* @version 2018/9/12
*/
@Component
public class UfoGoodsImagesFieldBuilder implements UfoIndexFieldBuilder {
@Autowired
private UfoGoodsImagesMapper ufoGoodsImagesMapper;
@Override
public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {
// List<UfoGoodsImages> ufoGoodsImagesList = ufoGoodsImagesMapper.selectByProductIdList(idList);
// if (CollectionUtils.isEmpty(ufoGoodsImagesList)) {
// return;
// }
// Map<Integer, UfoGoodsImages> ufoGoodsImagesMap = new HashMap<>();
// ufoGoodsImagesList.forEach(p-> ufoGoodsImagesMap.put(p.getProductId(),p));
// ufoProductIndexBOList.stream().forEach(p -> {
// UfoGoodsImages ufoGoodsImages = ufoGoodsImagesMap.get(p.getId());
// if (ufoGoodsImages != null) {
// p.setDefaultImages(ufoGoodsImages.getImageUrl());
// }
// });
}
}
... ... @@ -34,19 +34,22 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder {
ufoProductIndexBOList.stream().forEach(p -> {
UfoProductPoolBO ufoProductPoolBO = finalUfoProductPoolBOMap.get(p.getId());
if (ufoProductPoolBO != null) {
p.setPools(ufoProductPoolBO.getPools());
p.setPoolIds(ufoProductPoolBO.getPoolIds());
p.setPools(ufoProductPoolBO.getPools());
}
});
}
private List<UfoProductPoolBO> buildUfoProductPoolBOList(List<Integer> idList) {
List<UfoProductPoolBO> ufoProductPoolBOList = new ArrayList<>();
idList.stream().forEach(p -> {
for (Integer id : idList) {
Set<Integer> poolIdSet = new HashSet<>();
List<UfoProductPoolDetail> productPoolDetailsTemp = new ArrayList<>();
//把每个product对应的多个ProductPoolDetail的PoolId拼起来
List<UfoProductPoolDetail> productPoolDetails = ufoProductPoolDetailMapper.selectByProductId(p);
List<UfoProductPoolDetail> productPoolDetails = ufoProductPoolDetailMapper.selectByProductId(id);
if (CollectionUtils.isEmpty(productPoolDetails)) {
continue;
}
//先根据poolId去重
for (UfoProductPoolDetail productPoolDetail : productPoolDetails) {
if (!poolIdSet.contains(productPoolDetail.getPoolId())) {
... ... @@ -54,11 +57,11 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder {
productPoolDetailsTemp.add(productPoolDetail);
}
}
StringBuilder poolId = new StringBuilder();
StringBuilder poolIds = new StringBuilder();
JSONArray pools = new JSONArray();
for (UfoProductPoolDetail productPoolDetail : productPoolDetailsTemp) {
poolId.append(productPoolDetail.getPoolId());
poolId.append(',');
poolIds.append(productPoolDetail.getPoolId());
poolIds.append(',');
JSONObject pool = new JSONObject();
pool.put("id", productPoolDetail.getId());
pool.put("poolId", productPoolDetail.getPoolId());
... ... @@ -66,11 +69,11 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder {
pools.add(pool);
}
UfoProductPoolBO ufoProductPoolBO = new UfoProductPoolBO();
ufoProductPoolBO.setProductId(p);
ufoProductPoolBO.setPoolIds(poolId.toString());
ufoProductPoolBO.setProductId(id);
ufoProductPoolBO.setPoolIds(poolIds.toString());
ufoProductPoolBO.setPools(pools);
ufoProductPoolBOList.add(ufoProductPoolBO);
});
}
return ufoProductPoolBOList;
}
}
... ...
... ... @@ -39,25 +39,23 @@ public class UfoProductSortFieldBuilder implements UfoIndexFieldBuilder {
if (CollectionUtils.isNotEmpty(ufoProductSortList)) {
ufoProductSortMap = ufoProductSortList.stream().collect(Collectors.toMap(UfoProductSort::getId, p -> p));
}
Map<Short, UfoProductSort> finalUfoProductSortMap = ufoProductSortMap;
ufoProductIndexBOList.stream().forEach(p -> {
UfoProductSort maxSort = finalUfoProductSortMap.get(p.getMaxSortId());
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
UfoProductSort maxSort = ufoProductSortMap.get(ufoProductIndexBO.getMaxSortId());
if (maxSort != null) {
p.setMaxSortId(maxSort.getId());
p.setMaxSortName(maxSort.getSortName());
}else {
p.setMaxSortId((short) -1);
p.setMaxSortName("");
ufoProductIndexBO.setMaxSortId(maxSort.getId());
ufoProductIndexBO.setMaxSortName(maxSort.getSortName());
} else {
ufoProductIndexBO.setMaxSortId((short) -1);
ufoProductIndexBO.setMaxSortName("");
}
UfoProductSort midSort = finalUfoProductSortMap.get(p.getMidSortId());
UfoProductSort midSort = ufoProductSortMap.get(ufoProductIndexBO.getMidSortId());
if (midSort != null) {
p.setMidSortId(midSort.getId());
p.setMidSortName(midSort.getSortName());
}else {
p.setMidSortId((short) -1);
p.setMidSortName("");
ufoProductIndexBO.setMidSortId(midSort.getId());
ufoProductIndexBO.setMidSortName(midSort.getSortName());
} else {
ufoProductIndexBO.setMidSortId((short) -1);
ufoProductIndexBO.setMidSortName("");
}
}
});
}
}
\ No newline at end of file
... ...
... ... @@ -7,7 +7,6 @@ import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
... ... @@ -26,27 +25,19 @@ public class UfoStorageFieldBuilder implements UfoIndexFieldBuilder {
@Override
public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {
List<UfoStorage> ufoStorageList = ufoStorageMapper.selectByProductIdList(idList);
Map<Integer, List<UfoStorage>> ufoStorageMap = new HashMap<>(ufoStorageList.size());
Map<Integer, List<UfoStorage>> ufoStorageMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(ufoStorageList)) {
for (UfoStorage ufoStorage : ufoStorageList) {
if (ufoStorageMap.containsKey(ufoStorage.getProductId())) {
List<UfoStorage> storageList = ufoStorageMap.get(ufoStorage.getProductId());
storageList.add(ufoStorage);
} else {
List<UfoStorage> storageList = new ArrayList<>();
storageList.add(ufoStorage);
ufoStorageMap.put(ufoStorage.getProductId(), storageList);
ufoStorageMap = ufoStorageList.stream().collect(Collectors.groupingBy(UfoStorage::getProductId));
}
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
ufoProductIndexBO.setSizeIds("");
List<UfoStorage> storageList = ufoStorageMap.get(ufoProductIndexBO.getId());
if (CollectionUtils.isEmpty(storageList)) {
continue;
}
}
ufoProductIndexBOList.stream().forEach(p -> {
List<UfoStorage> storageList = ufoStorageMap.get(p.getId());
if (CollectionUtils.isNotEmpty(storageList)) {
String sizeIds = storageList.stream().map(UfoStorage::getSizeId).map(s -> s.toString()).collect(Collectors.joining(","));
p.setSizeIds(sizeIds);
} else {
p.setSizeIds("");
ufoProductIndexBO.setSizeIds(sizeIds);
}
});
}
}
... ...
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;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.*;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
... ... @@ -19,36 +24,55 @@ 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, List<UfoStorage>> ufoStorageMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(ufoStorageList)) {
ufoStorageMap = ufoStorageList.stream().collect(Collectors.groupingBy(UfoStorage::getProductId));
}
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);
}
}
}
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());
ufoStoragePriceMap = ufoStoragePriceList.stream().collect(Collectors.groupingBy(UfoStoragePrice::getProductId));
}
Map<Integer, List<UfoStoragePrice>> finalUfoStoragePriceMap = ufoStoragePriceMap;
Map<Integer, List<UfoStorage>> finalUfoStorageMap = ufoStorageMap;
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
List<UfoStoragePrice> storagePriceList = finalUfoStoragePriceMap.get(ufoProductIndexBO.getId());
List<UfoStorage> storageList = finalUfoStorageMap.get(ufoProductIndexBO.getId());
BigDecimal suggestLowPrice = new BigDecimal(0);
BigDecimal suggestHighPrice = new BigDecimal(Integer.MAX_VALUE);
if (CollectionUtils.isNotEmpty(storageList)) {
UfoStorage ufoStorage = storageList.get(0);
suggestLowPrice = ufoStorage.getSuggestLowPrice() == null ? suggestLowPrice : ufoStorage.getSuggestLowPrice();
suggestHighPrice = ufoStorage.getSuggestHighPrice() == null ? suggestHighPrice : ufoStorage.getSuggestHighPrice();
}
ufoProductIndexBO.setPrice(-1d);
if (CollectionUtils.isEmpty(storagePriceList)) {
continue;
}
BigDecimal finalSuggestLowPrice = suggestLowPrice;
BigDecimal finalSuggestHighPrice = suggestHighPrice;
storagePriceList = storagePriceList.stream()
.filter(s -> s.getStatus() == 1)
.filter(s -> s.getPrice().compareTo(finalSuggestLowPrice) >= 0)
.filter(s -> s.getPrice().compareTo(finalSuggestHighPrice) <= 0)
.sorted(Comparator.comparing(UfoStoragePrice::getPrice))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(storagePriceList)) {
continue;
}
BigDecimal price = storagePriceList.get(0).getPrice();
if (price == null) {
continue;
}
ufoProductIndexBO.setPrice(price.doubleValue());
}
});
}
}
... ...