Authored by wangnan9279

ufo fix

@@ -8,10 +8,13 @@ @@ -8,10 +8,13 @@
8 <result column="goods_id" property="goodsId" jdbcType="INTEGER" /> 8 <result column="goods_id" property="goodsId" jdbcType="INTEGER" />
9 <result column="size_id" property="sizeId" jdbcType="SMALLINT" /> 9 <result column="size_id" property="sizeId" jdbcType="SMALLINT" />
10 <result column="storage_num" property="storageNum" jdbcType="INTEGER" /> 10 <result column="storage_num" property="storageNum" jdbcType="INTEGER" />
  11 + <result column="suggest_low_price" property="suggestLowPrice" jdbcType="DECIMAL" />
  12 + <result column="suggest_high_price" property="suggestHighPrice" jdbcType="DECIMAL" />
11 </resultMap> 13 </resultMap>
12 -  
13 - <sql id="Base_Column_List" >  
14 - id, product_id, goods_id, size_id, storage_num, update_time, create_time 14 +
  15 + <sql id="Base_Column_List" >
  16 + id, product_id, goods_id, size_id, storage_num, suggest_low_price,
  17 + suggest_high_price
15 </sql> 18 </sql>
16 19
17 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > 20 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
@@ -44,6 +47,12 @@ @@ -44,6 +47,12 @@
44 <if test="storageNum != null" > 47 <if test="storageNum != null" >
45 storage_num, 48 storage_num,
46 </if> 49 </if>
  50 + <if test="suggestLowPrice != null" >
  51 + suggest_low_price,
  52 + </if>
  53 + <if test="suggestHighPrice != null" >
  54 + suggest_high_price,
  55 + </if>
47 </trim> 56 </trim>
48 <trim prefix="values (" suffix=")" suffixOverrides="," > 57 <trim prefix="values (" suffix=")" suffixOverrides="," >
49 <if test="id != null" > 58 <if test="id != null" >
@@ -61,27 +70,39 @@ @@ -61,27 +70,39 @@
61 <if test="storageNum != null" > 70 <if test="storageNum != null" >
62 #{storageNum,jdbcType=INTEGER}, 71 #{storageNum,jdbcType=INTEGER},
63 </if> 72 </if>
  73 + <if test="suggestLowPrice != null" >
  74 + #{suggestLowPrice,jdbcType=DECIMAL},
  75 + </if>
  76 + <if test="suggestHighPrice != null" >
  77 + #{suggestHighPrice,jdbcType=DECIMAL},
  78 + </if>
64 </trim> 79 </trim>
65 </insert> 80 </insert>
66 81
67 - <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.UfoStorage" >  
68 - update ufo_storage  
69 - <set >  
70 - <if test="productId != null" >  
71 - product_id = #{productId,jdbcType=INTEGER},  
72 - </if>  
73 - <if test="goodsId != null" >  
74 - goods_id = #{goodsId,jdbcType=INTEGER},  
75 - </if>  
76 - <if test="sizeId != null" >  
77 - size_id = #{sizeId,jdbcType=SMALLINT},  
78 - </if>  
79 - <if test="storageNum != null" >  
80 - storage_num = #{storageNum,jdbcType=INTEGER},  
81 - </if>  
82 - </set>  
83 - where id = #{id,jdbcType=INTEGER}  
84 - </update> 82 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.UfoStorage" >
  83 + update ufo_storage
  84 + <set >
  85 + <if test="productId != null" >
  86 + product_id = #{productId,jdbcType=INTEGER},
  87 + </if>
  88 + <if test="goodsId != null" >
  89 + goods_id = #{goodsId,jdbcType=INTEGER},
  90 + </if>
  91 + <if test="sizeId != null" >
  92 + size_id = #{sizeId,jdbcType=SMALLINT},
  93 + </if>
  94 + <if test="storageNum != null" >
  95 + storage_num = #{storageNum,jdbcType=INTEGER},
  96 + </if>
  97 + <if test="suggestLowPrice != null" >
  98 + suggest_low_price = #{suggestLowPrice,jdbcType=DECIMAL},
  99 + </if>
  100 + <if test="suggestHighPrice != null" >
  101 + suggest_high_price = #{suggestHighPrice,jdbcType=DECIMAL},
  102 + </if>
  103 + </set>
  104 + where id = #{id,jdbcType=INTEGER}
  105 + </update>
85 106
86 <select id="selectByProductIdList" resultMap="BaseResultMap" timeout="20000"> 107 <select id="selectByProductIdList" resultMap="BaseResultMap" timeout="20000">
87 select 108 select
@@ -7,6 +7,7 @@ import org.apache.commons.collections.CollectionUtils; @@ -7,6 +7,7 @@ import org.apache.commons.collections.CollectionUtils;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
9 9
  10 +import java.util.HashMap;
10 import java.util.List; 11 import java.util.List;
11 import java.util.Map; 12 import java.util.Map;
12 import java.util.stream.Collectors; 13 import java.util.stream.Collectors;
@@ -28,22 +29,21 @@ public class UfoBrandFieldBuilder implements UfoIndexFieldBuilder { @@ -28,22 +29,21 @@ public class UfoBrandFieldBuilder implements UfoIndexFieldBuilder {
28 return; 29 return;
29 } 30 }
30 List<UfoBrand> ufoBrandList = ufoBrandMapper.selectByIdList(brandIdList); 31 List<UfoBrand> ufoBrandList = ufoBrandMapper.selectByIdList(brandIdList);
31 - if (CollectionUtils.isEmpty(ufoBrandList)) {  
32 - return; 32 + Map<Short, UfoBrand> ufoBrandMap = new HashMap<>();
  33 + if (CollectionUtils.isNotEmpty(ufoBrandList)) {
  34 + ufoBrandMap = ufoBrandList.stream().collect(Collectors.toMap(UfoBrand::getId, p -> p));
33 } 35 }
34 - Map<Short, UfoBrand> ufoBrandMap = ufoBrandList.stream().collect(Collectors.toMap(UfoBrand::getId, p -> p));  
35 - ufoProductIndexBOList.stream().forEach(p -> {  
36 - UfoBrand ufoBrand = ufoBrandMap.get(p.getBrandId());  
37 - if (ufoBrand != null) {  
38 - p.setBrandName(ufoBrand.getBrandName());  
39 - p.setBrandNameEn(ufoBrand.getBrandNameEn());  
40 - p.setBrandSearch(ufoBrand.getBrandSearch());  
41 - } else {  
42 - p.setBrandName("");  
43 - p.setBrandNameEn("");  
44 - p.setBrandSearch(""); 36 + for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
  37 + ufoProductIndexBO.setBrandName("");
  38 + ufoProductIndexBO.setBrandNameEn("");
  39 + ufoProductIndexBO.setBrandSearch("");
  40 + UfoBrand ufoBrand = ufoBrandMap.get(ufoProductIndexBO.getBrandId());
  41 + if (ufoBrand == null) {
  42 + continue;
45 } 43 }
46 - });  
47 - 44 + ufoProductIndexBO.setBrandName(ufoBrand.getBrandName());
  45 + ufoProductIndexBO.setBrandNameEn(ufoBrand.getBrandNameEn());
  46 + ufoProductIndexBO.setBrandSearch(ufoBrand.getBrandSearch());
  47 + }
48 } 48 }
49 } 49 }
@@ -7,6 +7,7 @@ import org.apache.commons.collections.CollectionUtils; @@ -7,6 +7,7 @@ import org.apache.commons.collections.CollectionUtils;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
9 9
  10 +import java.util.HashMap;
10 import java.util.List; 11 import java.util.List;
11 import java.util.Map; 12 import java.util.Map;
12 import java.util.stream.Collectors; 13 import java.util.stream.Collectors;
@@ -27,20 +28,20 @@ public class UfoBrandSeriesFieldBuilder implements UfoIndexFieldBuilder { @@ -27,20 +28,20 @@ public class UfoBrandSeriesFieldBuilder implements UfoIndexFieldBuilder {
27 if (CollectionUtils.isEmpty(seriesIdList)) { 28 if (CollectionUtils.isEmpty(seriesIdList)) {
28 return; 29 return;
29 } 30 }
  31 + Map<Short, UfoBrandSeries> ufoBrandSeriesMap = new HashMap<>();
30 List<UfoBrandSeries> ufoBrandSeriesList = ufoBrandSeriesMapper.selectByIdList(seriesIdList); 32 List<UfoBrandSeries> ufoBrandSeriesList = ufoBrandSeriesMapper.selectByIdList(seriesIdList);
31 - if (CollectionUtils.isEmpty(ufoBrandSeriesList)) {  
32 - return; 33 + if (CollectionUtils.isNotEmpty(ufoBrandSeriesList)) {
  34 + ufoBrandSeriesMap = ufoBrandSeriesList.stream().collect(Collectors.toMap(UfoBrandSeries::getId, p -> p));
33 } 35 }
34 - Map<Short, UfoBrandSeries> ufoBrandSeriesMap = ufoBrandSeriesList.stream().collect(Collectors.toMap(UfoBrandSeries::getId, p -> p));  
35 - ufoProductIndexBOList.stream().forEach(p -> {  
36 - UfoBrandSeries ufoBrandSeries = ufoBrandSeriesMap.get(p.getSeriesId());  
37 - if (ufoBrandSeries != null) {  
38 - p.setSeriesName(ufoBrandSeries.getSeriesName());  
39 - p.setSeriesSearch(ufoBrandSeries.getSeriesSearch());  
40 - }else {  
41 - p.setSeriesName("");  
42 - p.setSeriesSearch(""); 36 + for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
  37 + ufoProductIndexBO.setSeriesName("");
  38 + ufoProductIndexBO.setSeriesSearch("");
  39 + UfoBrandSeries ufoBrandSeries = ufoBrandSeriesMap.get(ufoProductIndexBO.getSeriesId());
  40 + if (ufoBrandSeries == null) {
  41 + continue;
43 } 42 }
44 - }); 43 + ufoProductIndexBO.setSeriesName(ufoBrandSeries.getSeriesName());
  44 + ufoProductIndexBO.setSeriesSearch(ufoBrandSeries.getSeriesSearch());
  45 + }
45 } 46 }
46 } 47 }
@@ -7,7 +7,6 @@ import org.apache.commons.collections.CollectionUtils; @@ -7,7 +7,6 @@ import org.apache.commons.collections.CollectionUtils;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
9 9
10 -import java.util.ArrayList;  
11 import java.util.HashMap; 10 import java.util.HashMap;
12 import java.util.List; 11 import java.util.List;
13 import java.util.Map; 12 import java.util.Map;
@@ -19,42 +18,35 @@ import java.util.stream.Collectors; @@ -19,42 +18,35 @@ import java.util.stream.Collectors;
19 */ 18 */
20 @Component 19 @Component
21 public class UfoGoodsFieldBuilder implements UfoIndexFieldBuilder { 20 public class UfoGoodsFieldBuilder implements UfoIndexFieldBuilder {
  21 +
22 @Autowired 22 @Autowired
23 private UfoGoodsMapper ufoGoodsMapper; 23 private UfoGoodsMapper ufoGoodsMapper;
24 24
25 @Override 25 @Override
26 public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) { 26 public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {
27 List<UfoGoods> ufoGoodsList = ufoGoodsMapper.selectByProductIdList(idList); 27 List<UfoGoods> ufoGoodsList = ufoGoodsMapper.selectByProductIdList(idList);
28 - Map<Integer, List<UfoGoods>> ufoGoodsMap = new HashMap<>(ufoGoodsList.size()); 28 + Map<Integer, List<UfoGoods>> ufoGoodsMap = new HashMap<>();
29 if (CollectionUtils.isNotEmpty(ufoGoodsList)) { 29 if (CollectionUtils.isNotEmpty(ufoGoodsList)) {
30 - for (UfoGoods ufoGoods : ufoGoodsList) {  
31 - if (ufoGoodsMap.containsKey(ufoGoods.getProductId())) {  
32 - List<UfoGoods> goodsList = ufoGoodsMap.get(ufoGoods.getProductId());  
33 - goodsList.add(ufoGoods);  
34 - } else {  
35 - List<UfoGoods> goodsList = new ArrayList<>();  
36 - goodsList.add(ufoGoods);  
37 - ufoGoodsMap.put(ufoGoods.getProductId(), goodsList);  
38 - }  
39 - } 30 + ufoGoodsMap = ufoGoodsList.stream().collect(Collectors.groupingBy(UfoGoods::getProductId));
40 } 31 }
41 - ufoProductIndexBOList.stream().forEach(p -> {  
42 - List<UfoGoods> goodsList = ufoGoodsMap.get(p.getId());  
43 - if (CollectionUtils.isNotEmpty(goodsList)) {  
44 - String colorIds = goodsList.stream().map(UfoGoods::getColorId).map(s -> s.toString()).collect(Collectors.joining(","));  
45 - String colorNames = goodsList.stream().map(UfoGoods::getColorName).collect(Collectors.joining(","));  
46 - goodsList.forEach(g -> {  
47 - if ("Y".equals(g.getIsDefault())) {  
48 - p.setDefaultImages(g.getColorImage());  
49 - }  
50 - });  
51 - p.setColorIds(colorIds);  
52 - p.setColorNames(colorNames);  
53 - } else {  
54 - p.setDefaultImages("");  
55 - p.setColorIds("");  
56 - p.setColorNames(""); 32 + for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
  33 + ufoProductIndexBO.setDefaultImages("");
  34 + ufoProductIndexBO.setColorIds("");
  35 + ufoProductIndexBO.setColorNames("");
  36 + List<UfoGoods> goodsList = ufoGoodsMap.get(ufoProductIndexBO.getId());
  37 + if (CollectionUtils.isEmpty(goodsList)) {
  38 + continue;
57 } 39 }
58 - }); 40 + goodsList.forEach(g -> {
  41 + if ("Y".equals(g.getIsDefault())) {
  42 + ufoProductIndexBO.setDefaultImages(g.getColorImage());
  43 + }
  44 + });
  45 + String colorIds = goodsList.stream().map(UfoGoods::getColorId).map(s -> s.toString()).collect(Collectors.joining(","));
  46 + String colorNames = goodsList.stream().map(UfoGoods::getColorName).collect(Collectors.joining(","));
  47 + ufoProductIndexBO.setColorIds(colorIds);
  48 + ufoProductIndexBO.setColorNames(colorNames);
  49 + }
59 } 50 }
60 } 51 }
  52 +
1 -package com.yoho.search.consumer.service.logicService.ufo;  
2 -  
3 -import com.yoho.search.consumer.service.bo.UfoProductIndexBO;  
4 -import com.yoho.search.dal.UfoGoodsImagesMapper;  
5 -import org.springframework.beans.factory.annotation.Autowired;  
6 -import org.springframework.stereotype.Component;  
7 -  
8 -import java.util.List;  
9 -  
10 -/**  
11 - * @author wangnan  
12 - * @version 2018/9/12  
13 - */  
14 -@Component  
15 -public class UfoGoodsImagesFieldBuilder implements UfoIndexFieldBuilder {  
16 - @Autowired  
17 - private UfoGoodsImagesMapper ufoGoodsImagesMapper;  
18 -  
19 - @Override  
20 - public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {  
21 -// List<UfoGoodsImages> ufoGoodsImagesList = ufoGoodsImagesMapper.selectByProductIdList(idList);  
22 -// if (CollectionUtils.isEmpty(ufoGoodsImagesList)) {  
23 -// return;  
24 -// }  
25 -// Map<Integer, UfoGoodsImages> ufoGoodsImagesMap = new HashMap<>();  
26 -// ufoGoodsImagesList.forEach(p-> ufoGoodsImagesMap.put(p.getProductId(),p));  
27 -// ufoProductIndexBOList.stream().forEach(p -> {  
28 -// UfoGoodsImages ufoGoodsImages = ufoGoodsImagesMap.get(p.getId());  
29 -// if (ufoGoodsImages != null) {  
30 -// p.setDefaultImages(ufoGoodsImages.getImageUrl());  
31 -// }  
32 -// });  
33 - }  
34 -}  
@@ -34,19 +34,22 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder { @@ -34,19 +34,22 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder {
34 ufoProductIndexBOList.stream().forEach(p -> { 34 ufoProductIndexBOList.stream().forEach(p -> {
35 UfoProductPoolBO ufoProductPoolBO = finalUfoProductPoolBOMap.get(p.getId()); 35 UfoProductPoolBO ufoProductPoolBO = finalUfoProductPoolBOMap.get(p.getId());
36 if (ufoProductPoolBO != null) { 36 if (ufoProductPoolBO != null) {
37 - p.setPools(ufoProductPoolBO.getPools());  
38 p.setPoolIds(ufoProductPoolBO.getPoolIds()); 37 p.setPoolIds(ufoProductPoolBO.getPoolIds());
  38 + p.setPools(ufoProductPoolBO.getPools());
39 } 39 }
40 }); 40 });
41 } 41 }
42 42
43 private List<UfoProductPoolBO> buildUfoProductPoolBOList(List<Integer> idList) { 43 private List<UfoProductPoolBO> buildUfoProductPoolBOList(List<Integer> idList) {
44 List<UfoProductPoolBO> ufoProductPoolBOList = new ArrayList<>(); 44 List<UfoProductPoolBO> ufoProductPoolBOList = new ArrayList<>();
45 - idList.stream().forEach(p -> { 45 + for (Integer id : idList) {
46 Set<Integer> poolIdSet = new HashSet<>(); 46 Set<Integer> poolIdSet = new HashSet<>();
47 List<UfoProductPoolDetail> productPoolDetailsTemp = new ArrayList<>(); 47 List<UfoProductPoolDetail> productPoolDetailsTemp = new ArrayList<>();
48 //把每个product对应的多个ProductPoolDetail的PoolId拼起来 48 //把每个product对应的多个ProductPoolDetail的PoolId拼起来
49 - List<UfoProductPoolDetail> productPoolDetails = ufoProductPoolDetailMapper.selectByProductId(p); 49 + List<UfoProductPoolDetail> productPoolDetails = ufoProductPoolDetailMapper.selectByProductId(id);
  50 + if (CollectionUtils.isEmpty(productPoolDetails)) {
  51 + continue;
  52 + }
50 //先根据poolId去重 53 //先根据poolId去重
51 for (UfoProductPoolDetail productPoolDetail : productPoolDetails) { 54 for (UfoProductPoolDetail productPoolDetail : productPoolDetails) {
52 if (!poolIdSet.contains(productPoolDetail.getPoolId())) { 55 if (!poolIdSet.contains(productPoolDetail.getPoolId())) {
@@ -54,11 +57,11 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder { @@ -54,11 +57,11 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder {
54 productPoolDetailsTemp.add(productPoolDetail); 57 productPoolDetailsTemp.add(productPoolDetail);
55 } 58 }
56 } 59 }
57 - StringBuilder poolId = new StringBuilder(); 60 + StringBuilder poolIds = new StringBuilder();
58 JSONArray pools = new JSONArray(); 61 JSONArray pools = new JSONArray();
59 for (UfoProductPoolDetail productPoolDetail : productPoolDetailsTemp) { 62 for (UfoProductPoolDetail productPoolDetail : productPoolDetailsTemp) {
60 - poolId.append(productPoolDetail.getPoolId());  
61 - poolId.append(','); 63 + poolIds.append(productPoolDetail.getPoolId());
  64 + poolIds.append(',');
62 JSONObject pool = new JSONObject(); 65 JSONObject pool = new JSONObject();
63 pool.put("id", productPoolDetail.getId()); 66 pool.put("id", productPoolDetail.getId());
64 pool.put("poolId", productPoolDetail.getPoolId()); 67 pool.put("poolId", productPoolDetail.getPoolId());
@@ -66,11 +69,11 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder { @@ -66,11 +69,11 @@ public class UfoProductPoolDetailFieldBuilder implements UfoIndexFieldBuilder {
66 pools.add(pool); 69 pools.add(pool);
67 } 70 }
68 UfoProductPoolBO ufoProductPoolBO = new UfoProductPoolBO(); 71 UfoProductPoolBO ufoProductPoolBO = new UfoProductPoolBO();
69 - ufoProductPoolBO.setProductId(p);  
70 - ufoProductPoolBO.setPoolIds(poolId.toString()); 72 + ufoProductPoolBO.setProductId(id);
  73 + ufoProductPoolBO.setPoolIds(poolIds.toString());
71 ufoProductPoolBO.setPools(pools); 74 ufoProductPoolBO.setPools(pools);
72 ufoProductPoolBOList.add(ufoProductPoolBO); 75 ufoProductPoolBOList.add(ufoProductPoolBO);
73 - }); 76 + }
74 return ufoProductPoolBOList; 77 return ufoProductPoolBOList;
75 } 78 }
76 } 79 }
@@ -39,25 +39,23 @@ public class UfoProductSortFieldBuilder implements UfoIndexFieldBuilder { @@ -39,25 +39,23 @@ public class UfoProductSortFieldBuilder implements UfoIndexFieldBuilder {
39 if (CollectionUtils.isNotEmpty(ufoProductSortList)) { 39 if (CollectionUtils.isNotEmpty(ufoProductSortList)) {
40 ufoProductSortMap = ufoProductSortList.stream().collect(Collectors.toMap(UfoProductSort::getId, p -> p)); 40 ufoProductSortMap = ufoProductSortList.stream().collect(Collectors.toMap(UfoProductSort::getId, p -> p));
41 } 41 }
42 - Map<Short, UfoProductSort> finalUfoProductSortMap = ufoProductSortMap;  
43 - ufoProductIndexBOList.stream().forEach(p -> {  
44 - UfoProductSort maxSort = finalUfoProductSortMap.get(p.getMaxSortId()); 42 + for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
  43 + UfoProductSort maxSort = ufoProductSortMap.get(ufoProductIndexBO.getMaxSortId());
45 if (maxSort != null) { 44 if (maxSort != null) {
46 - p.setMaxSortId(maxSort.getId());  
47 - p.setMaxSortName(maxSort.getSortName());  
48 - }else {  
49 - p.setMaxSortId((short) -1);  
50 - p.setMaxSortName(""); 45 + ufoProductIndexBO.setMaxSortId(maxSort.getId());
  46 + ufoProductIndexBO.setMaxSortName(maxSort.getSortName());
  47 + } else {
  48 + ufoProductIndexBO.setMaxSortId((short) -1);
  49 + ufoProductIndexBO.setMaxSortName("");
51 } 50 }
52 - UfoProductSort midSort = finalUfoProductSortMap.get(p.getMidSortId()); 51 + UfoProductSort midSort = ufoProductSortMap.get(ufoProductIndexBO.getMidSortId());
53 if (midSort != null) { 52 if (midSort != null) {
54 - p.setMidSortId(midSort.getId());  
55 - p.setMidSortName(midSort.getSortName());  
56 - }else {  
57 - p.setMidSortId((short) -1);  
58 - p.setMidSortName(""); 53 + ufoProductIndexBO.setMidSortId(midSort.getId());
  54 + ufoProductIndexBO.setMidSortName(midSort.getSortName());
  55 + } else {
  56 + ufoProductIndexBO.setMidSortId((short) -1);
  57 + ufoProductIndexBO.setMidSortName("");
59 } 58 }
60 - });  
61 - 59 + }
62 } 60 }
63 } 61 }
@@ -7,7 +7,6 @@ import org.apache.commons.collections.CollectionUtils; @@ -7,7 +7,6 @@ import org.apache.commons.collections.CollectionUtils;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
9 9
10 -import java.util.ArrayList;  
11 import java.util.HashMap; 10 import java.util.HashMap;
12 import java.util.List; 11 import java.util.List;
13 import java.util.Map; 12 import java.util.Map;
@@ -26,27 +25,19 @@ public class UfoStorageFieldBuilder implements UfoIndexFieldBuilder { @@ -26,27 +25,19 @@ public class UfoStorageFieldBuilder implements UfoIndexFieldBuilder {
26 @Override 25 @Override
27 public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) { 26 public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {
28 List<UfoStorage> ufoStorageList = ufoStorageMapper.selectByProductIdList(idList); 27 List<UfoStorage> ufoStorageList = ufoStorageMapper.selectByProductIdList(idList);
29 - Map<Integer, List<UfoStorage>> ufoStorageMap = new HashMap<>(ufoStorageList.size()); 28 + Map<Integer, List<UfoStorage>> ufoStorageMap = new HashMap<>();
30 if (CollectionUtils.isNotEmpty(ufoStorageList)) { 29 if (CollectionUtils.isNotEmpty(ufoStorageList)) {
31 - for (UfoStorage ufoStorage : ufoStorageList) {  
32 - if (ufoStorageMap.containsKey(ufoStorage.getProductId())) {  
33 - List<UfoStorage> storageList = ufoStorageMap.get(ufoStorage.getProductId());  
34 - storageList.add(ufoStorage);  
35 - } else {  
36 - List<UfoStorage> storageList = new ArrayList<>();  
37 - storageList.add(ufoStorage);  
38 - ufoStorageMap.put(ufoStorage.getProductId(), storageList);  
39 - }  
40 - } 30 + ufoStorageMap = ufoStorageList.stream().collect(Collectors.groupingBy(UfoStorage::getProductId));
41 } 31 }
42 - ufoProductIndexBOList.stream().forEach(p -> {  
43 - List<UfoStorage> storageList = ufoStorageMap.get(p.getId());  
44 - if (CollectionUtils.isNotEmpty(storageList)) {  
45 - String sizeIds = storageList.stream().map(UfoStorage::getSizeId).map(s -> s.toString()).collect(Collectors.joining(","));  
46 - p.setSizeIds(sizeIds);  
47 - } else {  
48 - p.setSizeIds(""); 32 + for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
  33 + ufoProductIndexBO.setSizeIds("");
  34 + List<UfoStorage> storageList = ufoStorageMap.get(ufoProductIndexBO.getId());
  35 + if (CollectionUtils.isEmpty(storageList)) {
  36 + continue;
49 } 37 }
50 - }); 38 + String sizeIds = storageList.stream().map(UfoStorage::getSizeId).map(s -> s.toString()).collect(Collectors.joining(","));
  39 + ufoProductIndexBO.setSizeIds(sizeIds);
  40 + }
  41 +
51 } 42 }
52 } 43 }
1 package com.yoho.search.consumer.service.logicService.ufo; 1 package com.yoho.search.consumer.service.logicService.ufo;
2 2
3 import com.yoho.search.consumer.service.bo.UfoProductIndexBO; 3 import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
  4 +import com.yoho.search.dal.UfoStorageMapper;
4 import com.yoho.search.dal.UfoStoragePriceMapper; 5 import com.yoho.search.dal.UfoStoragePriceMapper;
  6 +import com.yoho.search.dal.model.UfoStorage;
5 import com.yoho.search.dal.model.UfoStoragePrice; 7 import com.yoho.search.dal.model.UfoStoragePrice;
6 import org.apache.commons.collections.CollectionUtils; 8 import org.apache.commons.collections.CollectionUtils;
7 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
9 11
10 import java.math.BigDecimal; 12 import java.math.BigDecimal;
11 -import java.util.*; 13 +import java.util.Comparator;
  14 +import java.util.HashMap;
  15 +import java.util.List;
  16 +import java.util.Map;
12 import java.util.stream.Collectors; 17 import java.util.stream.Collectors;
13 18
14 /** 19 /**
@@ -19,36 +24,55 @@ import java.util.stream.Collectors; @@ -19,36 +24,55 @@ import java.util.stream.Collectors;
19 public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder { 24 public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder {
20 25
21 @Autowired 26 @Autowired
  27 + private UfoStorageMapper ufoStorageMapper;
  28 + @Autowired
22 private UfoStoragePriceMapper ufoStoragePriceMapper; 29 private UfoStoragePriceMapper ufoStoragePriceMapper;
23 30
24 @Override 31 @Override
25 public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) { 32 public void build(List<UfoProductIndexBO> ufoProductIndexBOList, List<Integer> idList) {
  33 + List<UfoStorage> ufoStorageList = ufoStorageMapper.selectByProductIdList(idList);
  34 + Map<Integer, List<UfoStorage>> ufoStorageMap = new HashMap<>();
  35 + if (CollectionUtils.isNotEmpty(ufoStorageList)) {
  36 + ufoStorageMap = ufoStorageList.stream().collect(Collectors.groupingBy(UfoStorage::getProductId));
  37 + }
26 List<UfoStoragePrice> ufoStoragePriceList = ufoStoragePriceMapper.selectByProductIdList(idList); 38 List<UfoStoragePrice> ufoStoragePriceList = ufoStoragePriceMapper.selectByProductIdList(idList);
27 - Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap = new HashMap<>(ufoStoragePriceList.size()); 39 + Map<Integer, List<UfoStoragePrice>> ufoStoragePriceMap = new HashMap<>();
28 if (CollectionUtils.isNotEmpty(ufoStoragePriceList)) { 40 if (CollectionUtils.isNotEmpty(ufoStoragePriceList)) {
29 - for (UfoStoragePrice ufoStoragePrice : ufoStoragePriceList) {  
30 - if (ufoStoragePriceMap.containsKey(ufoStoragePrice.getProductId())) {  
31 - List<UfoStoragePrice> storagePriceList = ufoStoragePriceMap.get(ufoStoragePrice.getProductId());  
32 - storagePriceList.add(ufoStoragePrice);  
33 - } else {  
34 - List<UfoStoragePrice> storagePriceList = new ArrayList<>();  
35 - storagePriceList.add(ufoStoragePrice);  
36 - ufoStoragePriceMap.put(ufoStoragePrice.getProductId(), storagePriceList);  
37 - }  
38 - } 41 + ufoStoragePriceMap = ufoStoragePriceList.stream().collect(Collectors.groupingBy(UfoStoragePrice::getProductId));
39 } 42 }
40 - ufoProductIndexBOList.stream().forEach(p -> {  
41 - List<UfoStoragePrice> storagePriceList = ufoStoragePriceMap.get(p.getId());  
42 - p.setPrice(-1d);  
43 - if (CollectionUtils.isNotEmpty(storagePriceList)) {  
44 - storagePriceList = storagePriceList.stream().filter(s -> s.getStatus() == 1).sorted(Comparator.comparing(UfoStoragePrice::getPrice)).collect(Collectors.toList());  
45 - if (CollectionUtils.isNotEmpty(storagePriceList)) {  
46 - BigDecimal price = storagePriceList.get(0).getPrice();  
47 - if (price != null) {  
48 - p.setPrice(price.doubleValue());  
49 - }  
50 - } 43 + Map<Integer, List<UfoStoragePrice>> finalUfoStoragePriceMap = ufoStoragePriceMap;
  44 + Map<Integer, List<UfoStorage>> finalUfoStorageMap = ufoStorageMap;
  45 + for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
  46 + List<UfoStoragePrice> storagePriceList = finalUfoStoragePriceMap.get(ufoProductIndexBO.getId());
  47 + List<UfoStorage> storageList = finalUfoStorageMap.get(ufoProductIndexBO.getId());
  48 + BigDecimal suggestLowPrice = new BigDecimal(0);
  49 + BigDecimal suggestHighPrice = new BigDecimal(Integer.MAX_VALUE);
  50 + if (CollectionUtils.isNotEmpty(storageList)) {
  51 + UfoStorage ufoStorage = storageList.get(0);
  52 + suggestLowPrice = ufoStorage.getSuggestLowPrice() == null ? suggestLowPrice : ufoStorage.getSuggestLowPrice();
  53 + suggestHighPrice = ufoStorage.getSuggestHighPrice() == null ? suggestHighPrice : ufoStorage.getSuggestHighPrice();
  54 + }
  55 + ufoProductIndexBO.setPrice(-1d);
  56 + if (CollectionUtils.isEmpty(storagePriceList)) {
  57 + continue;
51 } 58 }
52 - }); 59 + BigDecimal finalSuggestLowPrice = suggestLowPrice;
  60 + BigDecimal finalSuggestHighPrice = suggestHighPrice;
  61 + storagePriceList = storagePriceList.stream()
  62 + .filter(s -> s.getStatus() == 1)
  63 + .filter(s -> s.getPrice().compareTo(finalSuggestLowPrice) >= 0)
  64 + .filter(s -> s.getPrice().compareTo(finalSuggestHighPrice) <= 0)
  65 + .sorted(Comparator.comparing(UfoStoragePrice::getPrice))
  66 + .collect(Collectors.toList());
  67 + if (CollectionUtils.isEmpty(storagePriceList)) {
  68 + continue;
  69 + }
  70 + BigDecimal price = storagePriceList.get(0).getPrice();
  71 + if (price == null) {
  72 + continue;
  73 + }
  74 + ufoProductIndexBO.setPrice(price.doubleValue());
  75 + }
53 } 76 }
54 } 77 }
  78 +