Authored by mali

批量查询skup信息

... ... @@ -2,6 +2,7 @@ package com.yohoufo.dal.product;
import com.yohoufo.dal.product.model.StoragePrice;
import java.util.Collection;
import java.util.List;
import org.apache.ibatis.annotations.Param;
... ... @@ -44,4 +45,11 @@ public interface StoragePriceMapper {
* @return
*/
int updateBatchPrice(@Param("skupList")List<Integer> skupList, @Param("price")Double price);
/**
* 批量查询最低价
* @param skuList
* @return
*/
List<StoragePrice> selectBatchLeastPrice(@Param("skuList")Collection<Integer> skuList);
}
\ No newline at end of file
... ...
... ... @@ -137,4 +137,13 @@
#{skup}
</foreach>
</update>
<select id="selectBatchLeastPrice" resultMap="BaseResultMap">
select storage_id , min(price) as price from storage_price where
storage_id in
<foreach item="storageId" index="index" collection="skuList" open="(" separator="," close=")">
#{storageId, jdbcType=INTEGER}
</foreach> and status = 1
group by storage_id
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -436,7 +436,7 @@ public class ProductController {
return null;
}
LOG.info("in method=ufo.product.storageInfo skuList={}", skuList);
List<Storage> storageList = productService.queryStorageInfoBySkuList(skuList);
List<StorageDataResp> storageList = productService.queryStorageInfoBySkuList(skuList);
return new ApiResponse.ApiResponseBuilder().data(storageList).code(200).message("storageInfo data").build();
}
}
\ No newline at end of file
... ...
... ... @@ -39,4 +39,7 @@ public class StorageDataResp {
private BigDecimal suggestHighPrice;
private BigDecimal leastPrice;
@JSONField(name = "storage_id")
private Integer storageId;
}
... ...
... ... @@ -75,5 +75,5 @@ public interface ProductService {
List<SaleCategoryBo> querySaleCategoryDetail(Integer id);
List<Storage> queryStorageInfoBySkuList(Collection<Integer> skuList);
List<StorageDataResp> queryStorageInfoBySkuList(Collection<Integer> skuList);
}
... ...
... ... @@ -195,8 +195,31 @@ public class ProductServiceImpl implements ProductService{
}
@Override
public List<Storage> queryStorageInfoBySkuList(Collection<Integer> skuList){
return storageMapper.selectByIds(skuList);
public List<StorageDataResp> queryStorageInfoBySkuList(Collection<Integer> skuList){
if (CollectionUtils.isEmpty(skuList)) {
return Lists.newArrayList();
}
List<Storage> storageList = storageMapper.selectByIds(skuList);
if (CollectionUtils.isEmpty(storageList)) {
return Lists.newArrayList();
}
List<StoragePrice> storagePrices = storagePriceMapper.selectBatchLeastPrice(skuList);
Map<Integer, BigDecimal> priceMap = storagePrices.stream().collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice));
List<StorageDataResp> resp = Lists.newArrayList();
storageList.stream().forEach(item -> {
StorageDataResp storageDataResp = new StorageDataResp();
storageDataResp.setProductId(item.getProductId());
storageDataResp.setSuggestHighPrice(item.getSuggestHighPrice());
storageDataResp.setSuggestLowPrice(item.getSuggestLowPrice());
storageDataResp.setStorageId(item.getId());
storageDataResp.setLeastPrice(priceMap.get(item.getId()));
resp.add(storageDataResp);
});
return resp;
}
@Override
... ...