分组列表增加 商品列表字段

This commit is contained in:
2026-04-29 13:36:14 +08:00
parent 2977157b26
commit e9d02bee0c

View File

@@ -68,7 +68,20 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
public List<ProdGroupDTO> getProdGroupList(ProdGroupDTO param) { public List<ProdGroupDTO> getProdGroupList(ProdGroupDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param); QueryWrapper queryWrapper = buildQueryWrapper(param);
queryWrapper.eq(ProdGroup::getStatus, SystemConstants.OneZero.ONE); queryWrapper.eq(ProdGroup::getStatus, SystemConstants.OneZero.ONE);
return super.listAs(queryWrapper, ProdGroupDTO.class); List<ProdGroupDTO> groups = listAs(queryWrapper, ProdGroupDTO.class);
groups.forEach(group -> {
List<Long> productIdList = prodGroupRelationMapper.selectObjectListByQueryAs(query()
.select(ProdGroupRelation::getProductId).eq(ProdGroupRelation::getProdGroupId, group.getId()), Long.class);
if (CollUtil.isNotEmpty(productIdList)) {
List<ProductBriefDTO> productList = productMapper.selectListByQueryAs(query()
.select(Product::getId, Product::getCategoryId, Product::getName, Product::getCoverImg)
.in(Product::getId, productIdList), ProductBriefDTO.class);
group.setProductList(productList);
} else {
group.setProductList(new ArrayList<>());
}
});
return groups;
} }
@Override @Override
@@ -77,7 +90,9 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
ProdGroupDTO dto = super.getOneAs(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId), ProdGroupDTO.class); ProdGroupDTO dto = super.getOneAs(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId), ProdGroupDTO.class);
List<Long> productIdList = prodGroupRelationMapper.selectObjectListByQueryAs(query().select(ProdGroupRelation::getProductId).eq(ProdGroupRelation::getProdGroupId, id), Long.class); List<Long> productIdList = prodGroupRelationMapper.selectObjectListByQueryAs(query().select(ProdGroupRelation::getProductId).eq(ProdGroupRelation::getProdGroupId, id), Long.class);
if (CollUtil.isNotEmpty(productIdList)) { if (CollUtil.isNotEmpty(productIdList)) {
List<ProductBriefDTO> productList = productMapper.selectListByQueryAs(query().select(Product::getId, Product::getCategoryId, Product::getName, Product::getCoverImg).in(Product::getId, productIdList), ProductBriefDTO.class); List<ProductBriefDTO> productList = productMapper.selectListByQueryAs(query()
.select(Product::getId, Product::getCategoryId, Product::getName, Product::getCoverImg)
.in(Product::getId, productIdList), ProductBriefDTO.class);
dto.setProductList(productList); dto.setProductList(productList);
} else { } else {
dto.setProductList(new ArrayList<>()); dto.setProductList(new ArrayList<>());