【功能优化】拼团装修重构;
This commit is contained in:
parent
0ce0c3f3d2
commit
b8c653d18b
|
@ -16,19 +16,21 @@ import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordSe
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import java.util.Collection;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.hutool.core.collection.CollectionUtil.newArrayList;
|
import static cn.hutool.core.collection.CollectionUtil.newArrayList;
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 拼团活动")
|
@Tag(name = "管理后台 - 拼团活动")
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -87,6 +89,43 @@ public class CombinationActivityController {
|
||||||
return success(CombinationActivityConvert.INSTANCE.convert(activity, products));
|
return success(CombinationActivityConvert.INSTANCE.convert(activity, products));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "获得拼团活动详情列表")
|
||||||
|
@Parameter(name = "combinationActivityIds", description = "拼团活动编号列表", required = true, example = "[1,2,3]")
|
||||||
|
@PreAuthorize("@ss.hasPermission('product:spu:query')")
|
||||||
|
public CommonResult<List<CombinationActivityRespVO>> getCombinationActivityDetailList(@RequestParam("combinationActivityIds") Collection<Long> combinationActivityIds) {
|
||||||
|
// 查询拼团活动列表
|
||||||
|
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(combinationActivityIds);
|
||||||
|
|
||||||
|
// 转换活动列表
|
||||||
|
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())));
|
||||||
|
});
|
||||||
|
|
||||||
|
return success(activityVOs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "获得拼团活动分页")
|
@Operation(summary = "获得拼团活动分页")
|
||||||
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
|
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
|
||||||
|
|
|
@ -27,4 +27,16 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO {
|
||||||
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private List<CombinationProductRespVO> products;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,13 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
|
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
|
||||||
|
@ -109,4 +113,38 @@ public class AppCombinationActivityController {
|
||||||
return success(CombinationActivityConvert.INSTANCE.convert3(activity, products));
|
return success(CombinationActivityConvert.INSTANCE.convert3(activity, products));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-detail-list")
|
||||||
|
@Operation(summary = "获得拼团活动明细")
|
||||||
|
@Parameter(name = "combinationActivityIds", description = "活动编号列表", required = true, example = "[1024, 1025]")
|
||||||
|
public CommonResult<List<AppCombinationActivityDetailRespVO>> getCombinationActivityDetailList(@RequestParam("combinationActivityIds") Collection<Long> combinationActivityIds) {
|
||||||
|
// 1. 获取活动
|
||||||
|
List<CombinationActivityDO> combinationActivityDOList = activityService.getCombinationActivityListByIds(combinationActivityIds);
|
||||||
|
|
||||||
|
// 过滤掉无效的活动
|
||||||
|
List<CombinationActivityDO> validActivities = combinationActivityDOList.stream()
|
||||||
|
.filter(combinationActivityDO -> combinationActivityDO != null &&
|
||||||
|
!ObjectUtil.equal(combinationActivityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus()))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// 如果没有有效的活动,返回 null 或者适当的错误信息
|
||||||
|
if (validActivities.isEmpty()) {
|
||||||
|
return success(null); // 或者 return error("没有有效的活动");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 构建结果列表
|
||||||
|
List<AppCombinationActivityDetailRespVO> detailRespVOList = new ArrayList<>();
|
||||||
|
for (CombinationActivityDO activity : validActivities) {
|
||||||
|
// 获取活动商品
|
||||||
|
List<CombinationProductDO> products = activityService.getCombinationProductsByActivityId(activity.getId());
|
||||||
|
|
||||||
|
// 调用转换方法并添加到结果列表
|
||||||
|
AppCombinationActivityDetailRespVO detailRespVO = CombinationActivityConvert.INSTANCE.convert3(activity, products);
|
||||||
|
detailRespVOList.add(detailRespVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 返回转换后的结果
|
||||||
|
return success(detailRespVOList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue