# Conflicts:
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillConfigController.java
pull/140/head
YunaiV 2024-09-09 21:10:50 +08:00
commit 628cfe2296
9 changed files with 102 additions and 12 deletions

View File

@ -41,7 +41,7 @@ public interface CouponApi {
@Parameter(name = "giveCoupons", description = "key: 优惠劵模版编号value对应的数量", required = true), @Parameter(name = "giveCoupons", description = "key: 优惠劵模版编号value对应的数量", required = true),
@Parameter(name = "userId", description = "用户编号", required = true) @Parameter(name = "userId", description = "用户编号", required = true)
}) })
CommonResult<List<Long>> takeCouponsByAdmin(@RequestParam("giveCoupons") Map<Long, Integer> giveCoupons, CommonResult<List<Long>> takeCouponsByAdmin(@RequestBody Map<Long, Integer> giveCoupons,
@RequestParam("userId") Long userId); @RequestParam("userId") Long userId);
@PostMapping(PREFIX + "/invalidate-by-admin") @PostMapping(PREFIX + "/invalidate-by-admin")

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill; package cn.iocoder.yudao.module.promotion.controller.admin.seckill;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
@ -13,15 +14,17 @@ import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService;
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 javax.annotation.Resource; import java.util.Collections;
import javax.validation.Valid;
import java.util.List; import java.util.List;
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.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@Tag(name = "管理后台 - 秒杀活动") @Tag(name = "管理后台 - 秒杀活动")
@ -89,11 +92,28 @@ public class SeckillActivityController {
} }
// 拼接数据 // 拼接数据
List<SeckillProductDO> products = seckillActivityService.getSeckillProductListByActivityId( List<SeckillProductDO> products = seckillActivityService.getSeckillProductListByActivityIds(
convertSet(pageResult.getList(), SeckillActivityDO::getId)); convertSet(pageResult.getList(), SeckillActivityDO::getId));
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList( List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(
convertSet(pageResult.getList(), SeckillActivityDO::getSpuId)).getCheckedData(); convertSet(pageResult.getList(), SeckillActivityDO::getSpuId)).getCheckedData();
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, products, spuList)); return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, products, spuList));
} }
@GetMapping("/list-by-ids")
@Operation(summary = "获得秒杀活动列表,基于活动编号数组")
@Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
public CommonResult<List<SeckillActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
// 1. 获得开启的活动列表
List<SeckillActivityDO> activityList = seckillActivityService.getSeckillActivityListByIds(ids);
activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
if (CollUtil.isEmpty(activityList)) {
return success(Collections.emptyList());
}
// 2. 拼接返回
List<SeckillProductDO> productList = seckillActivityService.getSeckillProductListByActivityIds(
convertList(activityList, SeckillActivityDO::getId));
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)).getCheckedData();
return success(SeckillActivityConvert.INSTANCE.convertList(activityList, productList, spuList));
}
} }

View File

@ -10,12 +10,12 @@ import cn.iocoder.yudao.module.promotion.service.seckill.SeckillConfigService;
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 javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

View File

@ -54,4 +54,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
example = "50") example = "50")
private Integer marketPrice; private Integer marketPrice;
@Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer seckillPrice; // 从 products 获取最小 price 读取
} }

View File

@ -35,10 +35,11 @@ import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Collections;
import java.util.List; import java.util.List;
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.buildCache; import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
@ -52,7 +53,7 @@ public class AppSeckillActivityController {
/** /**
* {@link AppSeckillActivityNowRespVO} {@link #getNowSeckillActivity()} * {@link AppSeckillActivityNowRespVO} {@link #getNowSeckillActivity()}
*/ */
private final LoadingCache<String, AppSeckillActivityNowRespVO> nowSeckillActivityCache = buildCache(Duration.ofSeconds(10L), private final LoadingCache<String, AppSeckillActivityNowRespVO> nowSeckillActivityCache = buildAsyncReloadingCache(Duration.ofSeconds(10L),
new CacheLoader<String, AppSeckillActivityNowRespVO>() { new CacheLoader<String, AppSeckillActivityNowRespVO>() {
@Override @Override
@ -86,7 +87,7 @@ public class AppSeckillActivityController {
// 2.1 查询满足当前阶段的活动 // 2.1 查询满足当前阶段的活动
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus()); List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus());
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId( List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
convertList(activityList, SeckillActivityDO::getId)); convertList(activityList, SeckillActivityDO::getId));
// 2.2 获取 spu 信息 // 2.2 获取 spu 信息
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)).getCheckedData(); List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)).getCheckedData();
@ -101,7 +102,7 @@ public class AppSeckillActivityController {
if (CollUtil.isEmpty(pageResult.getList())) { if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal())); return success(PageResult.empty(pageResult.getTotal()));
} }
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId( List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
convertList(pageResult.getList(), SeckillActivityDO::getId)); convertList(pageResult.getList(), SeckillActivityDO::getId));
// 2. 拼接数据 // 2. 拼接数据
@ -149,4 +150,21 @@ public class AppSeckillActivityController {
return success(SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime)); 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)).getCheckedData();
return success(SeckillActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList));
}
} }

View File

@ -16,6 +16,9 @@ public class AppSeckillActivityRespVO {
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long spuId; private Long spuId;
@Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "一个白菜")
private String spuName; // 从 SPU 的 name 读取
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取
example = "https://www.iocoder.cn/xx.png") example = "https://www.iocoder.cn/xx.png")
private String picUrl; private String picUrl;

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.seckill;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinRespDTO; import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
@ -87,6 +88,38 @@ public interface SeckillActivityConvert {
return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus())); return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus()));
} }
default List<SeckillActivityRespVO> convertList(List<SeckillActivityDO> list,
List<SeckillProductDO> productList,
List<ProductSpuRespDTO> spuList) {
List<SeckillActivityRespVO> activityList = BeanUtils.toBean(list, SeckillActivityRespVO.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;
});
}
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<SeckillProductRespVO> convertList2(List<SeckillProductDO> list);
List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList); List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList);

View File

@ -98,7 +98,7 @@ public interface SeckillActivityService {
* @param activityIds * @param activityIds
* @return * @return
*/ */
List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> activityIds); List<SeckillProductDO> getSeckillProductListByActivityIds(Collection<Long> activityIds);
/** /**
* status * status
@ -139,4 +139,12 @@ public interface SeckillActivityService {
*/ */
List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection<Long> spuIds, Integer status, LocalDateTime dateTime); List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection<Long> spuIds, Integer status, LocalDateTime dateTime);
/**
*
*
* @param ids
* @return
*/
List<SeckillActivityDO> getSeckillActivityListByIds(Collection<Long> ids);
} }

View File

@ -276,7 +276,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
} }
@Override @Override
public List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> activityIds) { public List<SeckillProductDO> getSeckillProductListByActivityIds(Collection<Long> activityIds) {
return seckillProductMapper.selectListByActivityId(activityIds); return seckillProductMapper.selectListByActivityId(activityIds);
} }
@ -336,4 +336,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime); convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime);
} }
@Override
public List<SeckillActivityDO> getSeckillActivityListByIds(Collection<Long> ids) {
return seckillActivityMapper.selectList(SeckillActivityDO::getId, ids);
}
} }