diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index 2a8f6b9dd..883ff2ffc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -1,9 +1,13 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination; +import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.*; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; @@ -22,6 +26,7 @@ import javax.validation.Valid; import java.io.IOException; import java.util.Collection; import java.util.List; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @@ -34,6 +39,8 @@ public class CombinationActivityController { @Resource private CombinationActivityService combinationActivityService; + @Resource + private ProductSpuApi spuApi; @PostMapping("/create") @Operation(summary = "创建拼团活动") @@ -65,7 +72,7 @@ public class CombinationActivityController { @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") public CommonResult getCombinationActivity(@RequestParam("id") Long id) { CombinationActivityDO combinationActivity = combinationActivityService.getCombinationActivity(id); - List productDOs = combinationActivityService.getProductsByActivityId(id); + List productDOs = combinationActivityService.getProductsByActivityIds(CollectionUtil.newArrayList(id)); return success(CombinationActivityConvert.INSTANCE.convert(combinationActivity, productDOs)); } @@ -83,7 +90,11 @@ public class CombinationActivityController { @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") public CommonResult> getCombinationActivityPage(@Valid CombinationActivityPageReqVO pageVO) { PageResult pageResult = combinationActivityService.getCombinationActivityPage(pageVO); - return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult)); + Set aIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getId); + List productDOs = combinationActivityService.getProductsByActivityIds(aIds); + Set spuIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getSpuId); + List spuList = spuApi.getSpuList(spuIds); + return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, productDOs, spuList)); } @GetMapping("/export-excel") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java index 31ffad293..3d95ef704 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java @@ -17,6 +17,12 @@ import java.util.List; @ToString(callSuper = true) public class CombinationActivityRespVO extends CombinationActivityBaseVO { + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") + private String spuName; + + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") + private String picUrl; + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") private Long id; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java index 680a26cf5..ad78a9464 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java @@ -18,7 +18,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") private String spuName; - @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") private String picUrl; @Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 0ddd81580..dc8f161b3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.combination; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExcelVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; @@ -63,11 +64,7 @@ public interface CombinationActivityConvert { default CombinationActivityRespVO convert(CombinationActivityDO bean, List productDOs) { CombinationActivityRespVO respVO = convert(bean); - ArrayList vos = new ArrayList<>(); - productDOs.forEach(item -> { - vos.add(convert(item)); - }); - respVO.setProducts(vos); + respVO.setProducts(convertList2(productDOs)); return respVO; } @@ -75,6 +72,19 @@ public interface CombinationActivityConvert { PageResult convertPage(PageResult page); + default PageResult convertPage(PageResult page, List productDOList, List spuList) { + Map spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c); + PageResult pageResult = convertPage(page); + pageResult.getList().forEach(item -> { + item.setSpuName(spuMap.get(item.getSpuId()).getName()); + item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl()); + item.setProducts(convertList2(productDOList)); + }); + return pageResult; + } + + List convertList2(List productDOs); + List convertList02(List list); @Mappings({ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index 7e004c4c2..689ddb17c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -62,7 +62,7 @@ public interface SeckillActivityConvert { } @Mappings({ - @Mapping(target = "id", expression = "java(null)"), + @Mapping(target = "id", ignore = true), @Mapping(target = "activityId", source = "activityDO.id"), @Mapping(target = "configIds", source = "activityDO.configIds"), @Mapping(target = "spuId", source = "activityDO.spuId"), diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java index f236e135a..ced6de6d4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; import org.apache.ibatis.annotations.Mapper; +import java.util.Collection; import java.util.List; /** @@ -44,8 +45,8 @@ public interface CombinationProductMapper extends BaseMapperX selectListByActivityId(Long id) { - return selectList(CombinationProductDO::getActivityId, id); + default List selectListByActivityIds(Collection ids) { + return selectList(CombinationProductDO::getActivityId, ids); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index 4b0f7b1ee..01e3a0663 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -76,8 +76,8 @@ public interface CombinationActivityService { /** * 获得拼团活动商品列表 * - * @param id 拼团活动 ID + * @param ids 拼团活动 ids * @return 拼团活动的商品列表 */ - List getProductsByActivityId(Long id); + List getProductsByActivityIds(Collection ids); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 16bd79ded..7fb377d11 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -129,7 +129,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic * @param products 商品配置 */ private void updateCombinationProduct(CombinationActivityDO updateObj, List products) { - List combinationProductDOs = combinationProductMapper.selectListByActivityId(updateObj.getId()); + List combinationProductDOs = combinationProductMapper.selectListByActivityIds(CollUtil.newArrayList(updateObj.getId())); // 数据库中的活动商品 Set convertSet = CollectionUtils.convertSet(combinationProductDOs, CombinationProductDO::getSkuId); // 前端传过来的活动商品 @@ -197,8 +197,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public List getProductsByActivityId(Long id) { - return combinationProductMapper.selectListByActivityId(id); + public List getProductsByActivityIds(Collection ids) { + return combinationProductMapper.selectListByActivityIds(ids); } }