Showing
6 changed files
with
47 additions
and
4 deletions
@@ -2,6 +2,7 @@ package com.yohoufo.dal.product; | @@ -2,6 +2,7 @@ package com.yohoufo.dal.product; | ||
2 | 2 | ||
3 | import com.yohoufo.dal.product.model.StoragePrice; | 3 | import com.yohoufo.dal.product.model.StoragePrice; |
4 | 4 | ||
5 | +import java.util.Collection; | ||
5 | import java.util.List; | 6 | import java.util.List; |
6 | 7 | ||
7 | import org.apache.ibatis.annotations.Param; | 8 | import org.apache.ibatis.annotations.Param; |
@@ -44,4 +45,11 @@ public interface StoragePriceMapper { | @@ -44,4 +45,11 @@ public interface StoragePriceMapper { | ||
44 | * @return | 45 | * @return |
45 | */ | 46 | */ |
46 | int updateBatchPrice(@Param("skupList")List<Integer> skupList, @Param("price")Double price); | 47 | int updateBatchPrice(@Param("skupList")List<Integer> skupList, @Param("price")Double price); |
48 | + | ||
49 | + /** | ||
50 | + * 批量查询最低价 | ||
51 | + * @param skuList | ||
52 | + * @return | ||
53 | + */ | ||
54 | + List<StoragePrice> selectBatchLeastPrice(@Param("skuList")Collection<Integer> skuList); | ||
47 | } | 55 | } |
@@ -137,4 +137,13 @@ | @@ -137,4 +137,13 @@ | ||
137 | #{skup} | 137 | #{skup} |
138 | </foreach> | 138 | </foreach> |
139 | </update> | 139 | </update> |
140 | + | ||
141 | + <select id="selectBatchLeastPrice" resultMap="BaseResultMap"> | ||
142 | + select storage_id , min(price) as price from storage_price where | ||
143 | + storage_id in | ||
144 | + <foreach item="storageId" index="index" collection="skuList" open="(" separator="," close=")"> | ||
145 | + #{storageId, jdbcType=INTEGER} | ||
146 | + </foreach> and status = 1 | ||
147 | + group by storage_id | ||
148 | + </select> | ||
140 | </mapper> | 149 | </mapper> |
@@ -436,7 +436,7 @@ public class ProductController { | @@ -436,7 +436,7 @@ public class ProductController { | ||
436 | return null; | 436 | return null; |
437 | } | 437 | } |
438 | LOG.info("in method=ufo.product.storageInfo skuList={}", skuList); | 438 | LOG.info("in method=ufo.product.storageInfo skuList={}", skuList); |
439 | - List<Storage> storageList = productService.queryStorageInfoBySkuList(skuList); | 439 | + List<StorageDataResp> storageList = productService.queryStorageInfoBySkuList(skuList); |
440 | return new ApiResponse.ApiResponseBuilder().data(storageList).code(200).message("storageInfo data").build(); | 440 | return new ApiResponse.ApiResponseBuilder().data(storageList).code(200).message("storageInfo data").build(); |
441 | } | 441 | } |
442 | } | 442 | } |
@@ -39,4 +39,7 @@ public class StorageDataResp { | @@ -39,4 +39,7 @@ public class StorageDataResp { | ||
39 | private BigDecimal suggestHighPrice; | 39 | private BigDecimal suggestHighPrice; |
40 | 40 | ||
41 | private BigDecimal leastPrice; | 41 | private BigDecimal leastPrice; |
42 | + | ||
43 | + @JSONField(name = "storage_id") | ||
44 | + private Integer storageId; | ||
42 | } | 45 | } |
@@ -75,5 +75,5 @@ public interface ProductService { | @@ -75,5 +75,5 @@ public interface ProductService { | ||
75 | 75 | ||
76 | List<SaleCategoryBo> querySaleCategoryDetail(Integer id); | 76 | List<SaleCategoryBo> querySaleCategoryDetail(Integer id); |
77 | 77 | ||
78 | - List<Storage> queryStorageInfoBySkuList(Collection<Integer> skuList); | 78 | + List<StorageDataResp> queryStorageInfoBySkuList(Collection<Integer> skuList); |
79 | } | 79 | } |
@@ -195,8 +195,31 @@ public class ProductServiceImpl implements ProductService{ | @@ -195,8 +195,31 @@ public class ProductServiceImpl implements ProductService{ | ||
195 | } | 195 | } |
196 | 196 | ||
197 | @Override | 197 | @Override |
198 | - public List<Storage> queryStorageInfoBySkuList(Collection<Integer> skuList){ | ||
199 | - return storageMapper.selectByIds(skuList); | 198 | + public List<StorageDataResp> queryStorageInfoBySkuList(Collection<Integer> skuList){ |
199 | + if (CollectionUtils.isEmpty(skuList)) { | ||
200 | + return Lists.newArrayList(); | ||
201 | + } | ||
202 | + | ||
203 | + List<Storage> storageList = storageMapper.selectByIds(skuList); | ||
204 | + if (CollectionUtils.isEmpty(storageList)) { | ||
205 | + return Lists.newArrayList(); | ||
206 | + } | ||
207 | + | ||
208 | + List<StoragePrice> storagePrices = storagePriceMapper.selectBatchLeastPrice(skuList); | ||
209 | + | ||
210 | + Map<Integer, BigDecimal> priceMap = storagePrices.stream().collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice)); | ||
211 | + List<StorageDataResp> resp = Lists.newArrayList(); | ||
212 | + storageList.stream().forEach(item -> { | ||
213 | + StorageDataResp storageDataResp = new StorageDataResp(); | ||
214 | + storageDataResp.setProductId(item.getProductId()); | ||
215 | + storageDataResp.setSuggestHighPrice(item.getSuggestHighPrice()); | ||
216 | + storageDataResp.setSuggestLowPrice(item.getSuggestLowPrice()); | ||
217 | + storageDataResp.setStorageId(item.getId()); | ||
218 | + storageDataResp.setLeastPrice(priceMap.get(item.getId())); | ||
219 | + resp.add(storageDataResp); | ||
220 | + }); | ||
221 | + | ||
222 | + return resp; | ||
200 | } | 223 | } |
201 | 224 | ||
202 | @Override | 225 | @Override |
-
Please register or login to post a comment