fix:mall promotion SeckillActivity

This commit is contained in:
puhui999 2023-07-05 22:05:05 +08:00
parent 78b3d2a20f
commit b78f814552
9 changed files with 260 additions and 146 deletions

View File

@ -2,6 +2,9 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill;
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.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*;
import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert; import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
@ -18,6 +21,7 @@ import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -29,6 +33,8 @@ public class SeckillActivityController {
@Resource @Resource
private SeckillActivityService seckillActivityService; private SeckillActivityService seckillActivityService;
@Resource
private ProductSpuApi spuApi;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建秒杀活动") @Operation(summary = "创建秒杀活动")
@ -69,11 +75,8 @@ public class SeckillActivityController {
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')")
public CommonResult<SeckillActivityDetailRespVO> getSeckillActivity(@RequestParam("id") Long id) { public CommonResult<SeckillActivityDetailRespVO> getSeckillActivity(@RequestParam("id") Long id) {
SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id); SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id);
if (seckillActivity == null) {
return success(null);
}
List<SeckillProductDO> seckillProducts = seckillActivityService.getSeckillProductListByActivityId(id); List<SeckillProductDO> seckillProducts = seckillActivityService.getSeckillProductListByActivityId(id);
return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity,seckillProducts)); return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity, seckillProducts));
} }
@GetMapping("/list") @GetMapping("/list")
@ -90,7 +93,11 @@ public class SeckillActivityController {
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')")
public CommonResult<PageResult<SeckillActivityRespVO>> getSeckillActivityPage(@Valid SeckillActivityPageReqVO pageVO) { public CommonResult<PageResult<SeckillActivityRespVO>> getSeckillActivityPage(@Valid SeckillActivityPageReqVO pageVO) {
PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(pageVO); PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(pageVO);
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult)); Set<Long> aIds = CollectionUtils.convertSet(pageResult.getList(), SeckillActivityDO::getId);
List<SeckillProductDO> seckillProducts = seckillActivityService.getSeckillProductListByActivityId(aIds);
Set<Long> spuIds = CollectionUtils.convertSet(pageResult.getList(), SeckillActivityDO::getSpuId);
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(spuIds);
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, seckillProducts, spuList));
} }
} }

View File

@ -6,6 +6,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -19,6 +20,12 @@ import java.util.List;
@ToString(callSuper = true) @ToString(callSuper = true)
public class SeckillActivityRespVO extends SeckillActivityBaseVO { public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促")
private String picUrl;
@Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id; private Long id;
@ -28,4 +35,22 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@Schema(description = "活动状态 开启0 禁用1", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") @Schema(description = "活动状态 开启0 禁用1", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Integer status; private Integer status;
@Schema(description = "订单实付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "22354")
private Integer totalPrice;
@Schema(description = "秒杀库存", example = "10")
private Integer stock;
@Schema(description = "秒杀总库存", example = "20")
private Integer totalStock;
@Schema(description = "新增订单数", example = "20")
private Integer orderCount;
@Schema(description = "付款人数", example = "20")
private Integer userCount;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
} }

View File

@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
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.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
@ -40,9 +42,27 @@ public interface SeckillActivityConvert {
PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page); PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page);
SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List<SeckillProductDO> seckillProducts); default PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page, List<SeckillProductDO> seckillProducts, List<ProductSpuRespDTO> spuList) {
Map<Long, ProductSpuRespDTO> spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c);
PageResult<SeckillActivityRespVO> pageResult = convertPage(page);
pageResult.getList().forEach(item -> {
item.setSpuName(spuMap.get(item.getSpuId()).getName());
item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl());
item.setProducts(convertList2(seckillProducts));
});
return pageResult;
}
SeckillActivityDetailRespVO convert1(SeckillActivityDO seckillActivity);
default SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List<SeckillProductDO> seckillProducts) {
SeckillActivityDetailRespVO respVO = convert1(seckillActivity);
respVO.setProducts(convertList2(seckillProducts));
return respVO;
}
@Mappings({ @Mappings({
@Mapping(target = "id", expression = "java(null)"),
@Mapping(target = "activityId", source = "activityDO.id"), @Mapping(target = "activityId", source = "activityDO.id"),
@Mapping(target = "configIds", source = "activityDO.configIds"), @Mapping(target = "configIds", source = "activityDO.configIds"),
@Mapping(target = "spuId", source = "activityDO.spuId"), @Mapping(target = "spuId", source = "activityDO.spuId"),
@ -76,4 +96,6 @@ public interface SeckillActivityConvert {
return list; return list;
} }
List<SeckillProductRespVO> convertList2(List<SeckillProductDO> productDOs);
} }

View File

@ -21,6 +21,10 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> {
return selectList(SeckillProductDO::getActivityId, id); return selectList(SeckillProductDO::getActivityId, id);
} }
default List<SeckillProductDO> selectListByActivityId(Collection<Long> ids) {
return selectList(SeckillProductDO::getActivityId, ids);
}
default List<SeckillProductDO> selectListBySkuIds(Collection<Long> skuIds) { default List<SeckillProductDO> selectListBySkuIds(Collection<Long> skuIds) {
return selectList(SeckillProductDO::getSkuId, skuIds); return selectList(SeckillProductDO::getSkuId, skuIds);
} }

View File

@ -79,4 +79,12 @@ public interface SeckillActivityService {
*/ */
List<SeckillProductDO> getSeckillProductListByActivityId(Long id); List<SeckillProductDO> getSeckillProductListByActivityId(Long id);
/**
* 通过活动编号获取活动商品
*
* @param ids 活动编号
* @return 活动商品列表
*/
List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> ids);
} }

View File

@ -160,7 +160,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
if (CollUtil.isNotEmpty(u)) { if (CollUtil.isNotEmpty(u)) {
List<SeckillProductUpdateReqVO> vos = CollectionUtils.filterList(products, item -> u.contains(item.getSkuId())); List<SeckillProductUpdateReqVO> vos = CollectionUtils.filterList(products, item -> u.contains(item.getSkuId()));
List<SeckillProductDO> productDOs = SeckillActivityConvert.INSTANCE.convertList1(updateObj, vos, seckillProductDOs); List<SeckillProductDO> productDOs = SeckillActivityConvert.INSTANCE.convertList1(updateObj, vos, seckillProductDOs);
seckillProductMapper.insertBatch(productDOs); seckillProductMapper.updateBatch(productDOs);
} }
} }
@ -206,7 +206,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
@Override @Override
public SeckillActivityDO getSeckillActivity(Long id) { public SeckillActivityDO getSeckillActivity(Long id) {
return seckillActivityMapper.selectById(id); return validateSeckillActivityExists(id);
} }
@Override @Override
@ -224,4 +224,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
return seckillProductMapper.selectListByActivityId(id); return seckillProductMapper.selectListByActivityId(id);
} }
@Override
public List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> ids) {
return seckillProductMapper.selectListByActivityId(ids);
}
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.util; package cn.iocoder.yudao.module.promotion.util;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
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.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
@ -35,7 +36,8 @@ public class PromotionUtils {
Set<Long> skuIdsSet = CollectionUtils.convertSet(products, func); Set<Long> skuIdsSet = CollectionUtils.convertSet(products, func);
Set<Long> skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); Set<Long> skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId);
// 校验 skuId 是否存在 // 校验 skuId 是否存在
if (!skuIdsSet1.containsAll(skuIdsSet) || !skuIdsSet.containsAll(skuIdsSet1)) { List<Long> f = CollectionUtils.filterList(skuIdsSet, s -> !skuIdsSet1.contains(s));
if (CollUtil.isNotEmpty(f)) {
throw exception(SKU_NOT_EXISTS); throw exception(SKU_NOT_EXISTS);
} }
} }

View File

@ -1,7 +1,16 @@
DELETE FROM "market_activity"; DELETE
DELETE FROM "promotion_coupon_template"; FROM "market_activity";
DELETE FROM "promotion_coupon"; DELETE
DELETE FROM "promotion_reward_activity"; FROM "promotion_coupon_template";
DELETE FROM "promotion_discount_activity"; DELETE
DELETE FROM "promotion_discount_product"; FROM "promotion_coupon";
DELETE FROM "promotion_seckill_config"; DELETE
FROM "promotion_reward_activity";
DELETE
FROM "promotion_discount_activity";
DELETE
FROM "promotion_discount_product";
DELETE
FROM "promotion_seckill_config";
DELETE
FROM "promotion_combination_activity";

View File

@ -1,4 +1,5 @@
CREATE TABLE IF NOT EXISTS "market_activity" ( CREATE TABLE IF NOT EXISTS "market_activity"
(
"id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"title" varchar(50) NOT NULL, "title" varchar(50) NOT NULL,
"activity_type" tinyint(4) NOT NULL, "activity_type" tinyint(4) NOT NULL,
@ -16,9 +17,10 @@ CREATE TABLE IF NOT EXISTS "market_activity" (
"deleted" bit NOT NULL DEFAULT FALSE, "deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint(20) NOT NULL, "tenant_id" bigint(20) NOT NULL,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '促销活动'; ) COMMENT '促销活动';
CREATE TABLE IF NOT EXISTS "promotion_coupon_template" ( CREATE TABLE IF NOT EXISTS "promotion_coupon_template"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL, "name" varchar NOT NULL,
"status" int NOT NULL, "status" int NOT NULL,
@ -47,7 +49,8 @@ CREATE TABLE IF NOT EXISTS "promotion_coupon_template" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '优惠劵模板'; ) COMMENT '优惠劵模板';
CREATE TABLE IF NOT EXISTS "promotion_coupon" ( CREATE TABLE IF NOT EXISTS "promotion_coupon"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"template_id" bigint NOT NULL, "template_id" bigint NOT NULL,
"name" varchar NOT NULL, "name" varchar NOT NULL,
@ -73,7 +76,8 @@ CREATE TABLE IF NOT EXISTS "promotion_coupon" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '优惠劵'; ) COMMENT '优惠劵';
CREATE TABLE IF NOT EXISTS "promotion_reward_activity" ( CREATE TABLE IF NOT EXISTS "promotion_reward_activity"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL, "name" varchar NOT NULL,
"status" int NOT NULL, "status" int NOT NULL,
@ -92,7 +96,8 @@ CREATE TABLE IF NOT EXISTS "promotion_reward_activity" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '满减送活动'; ) COMMENT '满减送活动';
CREATE TABLE IF NOT EXISTS "promotion_discount_activity" ( CREATE TABLE IF NOT EXISTS "promotion_discount_activity"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL, "name" varchar NOT NULL,
"status" int NOT NULL, "status" int NOT NULL,
@ -108,7 +113,8 @@ CREATE TABLE IF NOT EXISTS "promotion_discount_activity" (
) COMMENT '限时折扣活动'; ) COMMENT '限时折扣活动';
-- 将该建表 SQL 语句添加到 yudao-module-promotion-biz 模块的 test/resources/sql/create_tables.sql 文件里 -- 将该建表 SQL 语句添加到 yudao-module-promotion-biz 模块的 test/resources/sql/create_tables.sql 文件里
CREATE TABLE IF NOT EXISTS "promotion_seckill_activity" ( CREATE TABLE IF NOT EXISTS "promotion_seckill_activity"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"spu_id" bigint NOT NULL, "spu_id" bigint NOT NULL,
"name" varchar NOT NULL, "name" varchar NOT NULL,
@ -134,7 +140,8 @@ CREATE TABLE IF NOT EXISTS "promotion_seckill_activity" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '秒杀活动'; ) COMMENT '秒杀活动';
CREATE TABLE IF NOT EXISTS "promotion_seckill_config" ( CREATE TABLE IF NOT EXISTS "promotion_seckill_config"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL, "name" varchar NOT NULL,
"start_time" varchar NOT NULL, "start_time" varchar NOT NULL,
@ -149,3 +156,28 @@ CREATE TABLE IF NOT EXISTS "promotion_seckill_config" (
"tenant_id" bigint NOT NULL, "tenant_id" bigint NOT NULL,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '秒杀时段配置'; ) COMMENT '秒杀时段配置';
CREATE TABLE IF NOT EXISTS "promotion_combination_activity"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL,
"spu_id" bigint,
"total_limit_count" int NOT NULL,
"single_limit_count" int NOT NULL,
"start_time" varchar NOT NULL,
"end_time" varchar NOT NULL,
"user_size" int NOT NULL,
"total_num" int NOT NULL,
"success_num" int NOT NULL,
"order_user_count" int NOT NULL,
"virtual_group" int NOT NULL,
"status" int NOT NULL,
"limit_duration" int NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '拼团活动';