mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
commit
6d00b02795
@ -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.Parameter;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
|
||||
@Tag(name = "管理后台 - 拼团活动")
|
||||
@RestController
|
||||
@ -87,6 +89,30 @@ public class CombinationActivityController {
|
||||
return success(CombinationActivityConvert.INSTANCE.convert(activity, products));
|
||||
}
|
||||
|
||||
@GetMapping("/detail-list")
|
||||
@Operation(summary = "获得拼团活动详情列表")
|
||||
@Parameter(name = "ids", description = "拼团活动编号列表", required = true, example = "[1,2,3]")
|
||||
@PreAuthorize("@ss.hasPermission('product:spu:query')")
|
||||
public CommonResult<List<CombinationActivityRespVO>> getCombinationActivityDetailList(@RequestParam("ids") Collection<Long> ids) {
|
||||
// 查询拼团活动列表
|
||||
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(ids);
|
||||
|
||||
// 转换活动列表
|
||||
List<CombinationActivityRespVO> activityVOs = CombinationActivityConvert.INSTANCE.convertList(activities);
|
||||
|
||||
// 获取拼团产品列表
|
||||
Set<Long> activityIds = activities.stream().map(CombinationActivityDO::getId).collect(Collectors.toSet());
|
||||
List<CombinationProductDO> productList = combinationActivityService.getCombinationProductListByActivityIds(activityIds);
|
||||
|
||||
// 创建SPU和产品的映射
|
||||
Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId);
|
||||
|
||||
// 往活动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')")
|
||||
|
@ -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;
|
||||
@ -26,9 +27,13 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
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.util.cache.CacheUtils.buildAsyncReloadingCache;
|
||||
@ -109,4 +114,38 @@ public class AppCombinationActivityController {
|
||||
return success(CombinationActivityConvert.INSTANCE.convert3(activity, products));
|
||||
}
|
||||
|
||||
@GetMapping("/detail-list")
|
||||
@Operation(summary = "获得拼团活动明细")
|
||||
@Parameter(name = "ids", description = "活动编号列表", required = true, example = "[1024, 1025]")
|
||||
public CommonResult<List<AppCombinationActivityDetailRespVO>> getCombinationActivityDetailList(@RequestParam("ids") Collection<Long> ids) {
|
||||
// 1. 获取活动
|
||||
List<CombinationActivityDO> combinationActivityDOList = activityService.getCombinationActivityListByIds(ids);
|
||||
|
||||
// 过滤掉无效的活动
|
||||
List<CombinationActivityDO> validActivities = combinationActivityDOList.stream()
|
||||
.filter(combinationActivityDO -> combinationActivityDO != null &&
|
||||
!ObjectUtil.equal(combinationActivityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus()))
|
||||
.toList();
|
||||
|
||||
// 如果没有有效的活动,返回空列表
|
||||
if (validActivities.isEmpty()) {
|
||||
return success(ListUtil.empty());
|
||||
}
|
||||
|
||||
// 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
Block a user