【代码补全】商城:uni-app端秒杀列表的接口
This commit is contained in:
parent
19c4a5c961
commit
8283f203dd
|
@ -35,6 +35,7 @@ import java.time.Duration;
|
|||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
@ -149,4 +150,21 @@ public class AppSeckillActivityController {
|
|||
return success(SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime));
|
||||
}
|
||||
|
||||
@GetMapping("/list-by-ids")
|
||||
@Operation(summary = "获得拼团活动列表,基于活动编号数组")
|
||||
@Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
|
||||
public CommonResult<List<AppSeckillActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
|
||||
// 1. 获得开启的活动列表
|
||||
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByIds(ids);
|
||||
activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
|
||||
if (CollUtil.isEmpty(activityList)) {
|
||||
return success(Collections.emptyList());
|
||||
}
|
||||
// 2. 拼接返回
|
||||
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
|
||||
convertList(activityList, SeckillActivityDO::getId));
|
||||
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
|
||||
return success(SeckillActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ public class AppSeckillActivityRespVO {
|
|||
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "一个白菜")
|
||||
private String spuName; // 从 SPU 的 name 读取
|
||||
|
||||
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取
|
||||
example = "https://www.iocoder.cn/xx.png")
|
||||
private String picUrl;
|
||||
|
|
|
@ -104,6 +104,22 @@ public interface SeckillActivityConvert {
|
|||
});
|
||||
}
|
||||
|
||||
default List<AppSeckillActivityRespVO> convertAppList(List<SeckillActivityDO> list,
|
||||
List<SeckillProductDO> productList,
|
||||
List<ProductSpuRespDTO> spuList) {
|
||||
List<AppSeckillActivityRespVO> activityList = BeanUtils.toBean(list, AppSeckillActivityRespVO.class);
|
||||
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
|
||||
Map<Long, List<SeckillProductDO>> productMap = convertMultiMap(productList, SeckillProductDO::getActivityId);
|
||||
return CollectionUtils.convertList(activityList, item -> {
|
||||
// 设置 product 信息
|
||||
item.setSeckillPrice(getMinValue(productMap.get(item.getId()), SeckillProductDO::getSeckillPrice));
|
||||
// 设置 SPU 信息
|
||||
findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName())
|
||||
.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
List<SeckillProductRespVO> convertList2(List<SeckillProductDO> list);
|
||||
|
||||
List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList);
|
||||
|
|
Loading…
Reference in New Issue