商品模块代码提交

This commit is contained in:
Tankaikai 2025-02-19 15:33:41 +08:00
parent 742d2df3fc
commit 90788acc58
1 changed files with 15 additions and 1 deletions

View File

@ -117,7 +117,21 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Override
public List<ProductDTO> getProductList(ProductDTO param) {
QueryWrapper queryWrapper = buildFullQueryWrapper(param);
return super.listAs(queryWrapper, ProductDTO.class);
List<ProductDTO> records = super.listAs(queryWrapper, ProductDTO.class);
List<Long> prodIdList = records.stream().map(ProductDTO::getId).distinct().toList();
List<ProdSkuDTO> skuList = prodSkuMapper.selectListByQueryAs(query().in(ProdSku::getProductId, prodIdList).eq(ProdSku::getIsDel, DeleteEnum.NORMAL.value()), ProdSkuDTO.class);
Map<Long, List<ProdSkuDTO>> collect = skuList.stream().collect(Collectors.groupingBy(ProdSkuDTO::getProductId));
for (ProductDTO record : records) {
List<ProdSkuDTO> list = collect.getOrDefault(record.getId(), Collections.emptyList());
Optional<BigDecimal> lowPriceIsPresent = list.stream().map(ProdSkuDTO::getSalePrice).min(BigDecimal::compareTo);
lowPriceIsPresent.ifPresent(record::setLowPrice);
Optional<BigDecimal> lowMemberPriceIsPresent = list.stream().map(ProdSkuDTO::getMemberPrice).min(BigDecimal::compareTo);
lowMemberPriceIsPresent.ifPresent(record::setLowMemberPrice);
record.setSkuList(list);
}
return records;
}
@Override