mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
【代码优化】拼团活动和SPU详情分开查询
This commit is contained in:
parent
efd0a86007
commit
39a6eb4792
@ -100,32 +100,19 @@ public class CombinationActivityController {
|
||||
// 转换活动列表
|
||||
List<CombinationActivityRespVO> activityVOs = CombinationActivityConvert.INSTANCE.convertList(activities);
|
||||
|
||||
// 获取商品SPU列表和拼团产品列表
|
||||
Set<Long> spuIds = activities.stream().map(CombinationActivityDO::getSpuId).collect(Collectors.toSet());
|
||||
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(spuIds);
|
||||
|
||||
// 获取拼团产品列表
|
||||
Set<Long> activityIds = activities.stream().map(CombinationActivityDO::getId).collect(Collectors.toSet());
|
||||
List<CombinationProductDO> productList = combinationActivityService.getCombinationProductListByActivityIds(activityIds);
|
||||
|
||||
// 创建SPU和产品的映射
|
||||
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
|
||||
Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId);
|
||||
|
||||
// 更新VO列表
|
||||
activityVOs.forEach(vo -> {
|
||||
ProductSpuRespDTO spu = spuMap.get(vo.getSpuId());
|
||||
if (spu != null) {
|
||||
vo.setSpuName(spu.getName())
|
||||
.setPicUrl(spu.getPicUrl())
|
||||
.setMarketPrice(spu.getMarketPrice());
|
||||
}
|
||||
vo.setProducts(CombinationActivityConvert.INSTANCE.convertList2(productMap.get(vo.getId())));
|
||||
});
|
||||
// 往活动VO赋值产品列表
|
||||
activityVOs.forEach(vo -> vo.setProducts(CombinationActivityConvert.INSTANCE.convertList2(productMap.get(vo.getId()))));
|
||||
|
||||
return success(activityVOs);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得拼团活动分页")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
|
||||
|
@ -27,16 +27,4 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO {
|
||||
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<CombinationProductRespVO> products;
|
||||
|
||||
// ========== 商品字段 ==========
|
||||
|
||||
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取
|
||||
example = "618大促")
|
||||
private String spuName;
|
||||
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取
|
||||
example = "https://www.iocoder.cn/xx.png")
|
||||
private String picUrl;
|
||||
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取
|
||||
example = "50")
|
||||
private Integer marketPrice;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.app.combination;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
@ -126,9 +127,9 @@ public class AppCombinationActivityController {
|
||||
!ObjectUtil.equal(combinationActivityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus()))
|
||||
.toList();
|
||||
|
||||
// 如果没有有效的活动,返回 null 或者适当的错误信息
|
||||
// 如果没有有效的活动,返回空列表
|
||||
if (validActivities.isEmpty()) {
|
||||
return success(null);
|
||||
return success(ListUtil.empty());
|
||||
}
|
||||
|
||||
// 2. 构建结果列表
|
||||
|
Loading…
Reference in New Issue
Block a user