From abbb0768597ba2eaf5bd2cf0c12c45533a96b03d Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Fri, 2 Dec 2022 22:33:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=A7=92=E6=9D=80?= =?UTF-8?q?=E6=97=B6=E6=AE=B5=EF=BC=8C=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E7=9B=B8=E5=85=B3todo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/core/mapper/BaseMapperX.java | 7 +- .../SeckillActivityController.java | 4 +- .../SeckillTimeController.java | 22 ++---- .../activity}/SeckillActivityBaseVO.java | 2 +- .../activity}/SeckillActivityCreateReqVO.java | 6 +- .../SeckillActivityDetailRespVO.java | 2 +- .../activity}/SeckillActivityPageReqVO.java | 4 +- .../activity}/SeckillActivityRespVO.java | 5 +- .../activity}/SeckillActivityUpdateReqVO.java | 6 +- .../vo => vo/time}/SeckillTimeBaseVO.java | 7 +- .../time}/SeckillTimeCreateReqVO.java | 2 +- .../vo => vo/time}/SeckillTimePageReqVO.java | 12 +--- .../vo => vo/time}/SeckillTimeRespVO.java | 2 +- .../time}/SeckillTimeSimpleRespVO.java | 2 +- .../time}/SeckillTimeUpdateReqVO.java | 2 +- .../SeckillActivityConvert.java | 13 ++-- .../seckilltime/SeckillTimeConvert.java | 6 +- .../seckillactivity/SeckillActivityDO.java | 9 ++- .../seckillactivity/SeckillProductDO.java | 9 ++- .../SeckillActivityMapper.java | 8 +-- .../seckillactivity/SeckillProductMapper.java | 13 ++-- .../seckilltime/SeckillTimeMapper.java | 39 ++++------- .../SeckillActivityService.java | 10 +-- .../SeckillActivityServiceImpl.java | 68 +++++++++---------- .../seckilltime/SeckillTimeService.java | 18 +++-- .../seckilltime/SeckillTimeServiceImpl.java | 29 +++++--- .../seckillactivity/SeckillActivityMapper.xml | 13 ---- .../mapper/seckilltime/SeckillTimeMapper.xml | 13 ---- .../SeckillActivityServiceImplTest.java | 14 ++-- .../SeckillTimeServiceImplTest.java | 4 +- 30 files changed, 160 insertions(+), 191 deletions(-) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckillactivity => }/SeckillActivityController.java (99%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckilltime => }/SeckillTimeController.java (78%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckillactivity/vo => vo/activity}/SeckillActivityBaseVO.java (99%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckillactivity/vo => vo/activity}/SeckillActivityCreateReqVO.java (92%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckillactivity/vo => vo/activity}/SeckillActivityDetailRespVO.java (95%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckillactivity/vo => vo/activity}/SeckillActivityPageReqVO.java (96%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckillactivity/vo => vo/activity}/SeckillActivityRespVO.java (94%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckillactivity/vo => vo/activity}/SeckillActivityUpdateReqVO.java (91%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckilltime/vo => vo/time}/SeckillTimeBaseVO.java (80%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckilltime/vo => vo/time}/SeckillTimeCreateReqVO.java (94%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckilltime/vo => vo/time}/SeckillTimePageReqVO.java (83%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckilltime/vo => vo/time}/SeckillTimeRespVO.java (96%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckilltime/vo => vo/time}/SeckillTimeSimpleRespVO.java (84%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/{seckilltime/vo => vo/time}/SeckillTimeUpdateReqVO.java (96%) delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckillactivity/SeckillActivityMapper.xml delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index fb4af6d69..e220d011d 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.mybatis.core.mapper; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -75,9 +76,13 @@ public interface BaseMapperX extends BaseMapper { return selectList(new LambdaQueryWrapper().in(field, values)); } + default List selectList(SFunction leField, SFunction geField, Object value) { + return selectList(new LambdaQueryWrapper().le(leField, value).ge(geField, value)); + } + /** * 逐条插入,适合少量数据插入,或者对性能要求不高的场景 - * + *

* 如果大量,请使用 {@link com.baomidou.mybatisplus.extension.service.impl.ServiceImpl#saveBatch(Collection)} 方法 * 使用示例,可见 RoleMenuBatchInsertMapper、UserRoleBatchInsertMapper 类 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/SeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java similarity index 99% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/SeckillActivityController.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java index 1efeb387e..5acaf7cf0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/SeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.*; +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.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/SeckillTimeController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillTimeController.java similarity index 78% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/SeckillTimeController.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillTimeController.java index 37fbfcbea..3cb6d4ca6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/SeckillTimeController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillTimeController.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.service.seckill.seckilltime.SeckillTimeService; @@ -20,7 +20,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -// TODO @halfninety:controller 可以都放在 seckill 包下;vo 下分成 actvity 和 time @Api(tags = "管理后台 - 秒杀时段") @RestController @RequestMapping("/promotion/seckill-time") @@ -65,20 +64,9 @@ public class SeckillTimeController { @GetMapping("/list") @ApiOperation("获得所有秒杀时段列表") -// @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") - // TODO @halfninety:权限为啥注释掉呀? + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") public CommonResult> getSeckillTimeList() { List list = seckillTimeService.getSeckillTimeList(); return success(SeckillTimeConvert.INSTANCE.convertList(list)); } - - // TODO @halfninety:不用的,可以删除掉 -// @GetMapping("/page") -// @ApiOperation("获得秒杀时段分页") -// @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") -// public CommonResult> getSeckillTimePage(@Valid SeckillTimePageReqVO pageVO) { -// PageResult pageResult = seckillTimeService.getSeckillTimePage(pageVO); -// return success(SeckillTimeConvert.INSTANCE.convertPage(pageResult)); -// } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java similarity index 99% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityBaseVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java index 66128212a..774b45493 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityCreateReqVO.java similarity index 92% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityCreateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityCreateReqVO.java index 939102ac0..7324e767a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityCreateReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -28,8 +28,8 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO { // TODO halfninety:直接使用数组接口。timeIds, @ApiModelProperty(value = "秒杀时段id", required = true) - @NotBlank(message = "参与场次不能为空") - private String timeId; + @NotEmpty(message = "参与场次不能为空") + private List timeIds; /** * 商品列表 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityDetailRespVO.java similarity index 95% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityDetailRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityDetailRespVO.java index aa6343137..14bb9ff64 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityDetailRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity; import io.swagger.annotations.ApiModel; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityPageReqVO.java similarity index 96% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityPageReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityPageReqVO.java index 5aa32fac8..49cfb5a0e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity; import cn.iocoder.yudao.framework.common.pojo.PageParam; import com.fasterxml.jackson.annotation.JsonFormat; @@ -27,7 +27,7 @@ public class SeckillActivityPageReqVO extends PageParam { private Integer status; @ApiModelProperty(value = "秒杀时段id") - private String timeId; + private Long timeId; @ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java similarity index 94% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java index 220f4df6f..7201df5f1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import java.time.LocalDateTime; +import java.util.List; @ApiModel("管理后台 - 秒杀活动 Response VO") @Data @@ -27,7 +28,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { private LocalDateTime createTime; @ApiModelProperty(value = "秒杀时段id", required = true) - private String timeId; + private List timeIds; @ApiModelProperty(value = "排序", required = true) private Integer sort; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityUpdateReqVO.java similarity index 91% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityUpdateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityUpdateReqVO.java index f53bb50d8..da81a5dc9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityUpdateReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -29,8 +29,8 @@ public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO { private Integer sort; @ApiModelProperty(value = "秒杀时段id", required = true) - @NotNull(message = "秒杀时段id不能为空") - private String timeId; + @NotEmpty(message = "秒杀时段id不能为空") + private List timeIds; /** * 商品列表 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeBaseVO.java similarity index 80% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeBaseVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeBaseVO.java index fd2ea5480..5775e98c6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeBaseVO.java @@ -1,14 +1,11 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time; import lombok.*; import java.time.LocalTime; -import java.util.*; + import io.swagger.annotations.*; import javax.validation.constraints.*; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; /** * 秒杀时段 Base VO,提供给添加、修改、详细的子 VO 使用 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeCreateReqVO.java similarity index 94% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeCreateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeCreateReqVO.java index e00ad7a63..197fb8a68 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeCreateReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time; import lombok.*; import io.swagger.annotations.*; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimePageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimePageReqVO.java similarity index 83% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimePageReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimePageReqVO.java index 7fe5b07d5..7c01ce497 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimePageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimePageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.annotations.ApiModel; @@ -27,14 +27,4 @@ public class SeckillTimePageReqVO extends PageParam { @DateTimeFormat(pattern = "HH:mm:ss") private LocalTime endTime; - - - - - - -// @ApiModelProperty(value = "创建时间") -// @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) -// private Date[] createTime; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeRespVO.java similarity index 96% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeRespVO.java index c40f189d9..165993ac9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time; import lombok.*; import java.util.*; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeSimpleRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeSimpleRespVO.java similarity index 84% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeSimpleRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeSimpleRespVO.java index 25714595f..c068293da 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeSimpleRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeSimpleRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time; public class SeckillTimeSimpleRespVO { } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeUpdateReqVO.java similarity index 96% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeUpdateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeUpdateReqVO.java index 16b786c7d..50d5f03ce 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/vo/SeckillTimeUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/time/SeckillTimeUpdateReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index fda7b6e1d..cf376c20f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.*; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import org.mapstruct.Mapper; @@ -27,7 +28,7 @@ public interface SeckillActivityConvert { SeckillActivityDO convert(SeckillActivityCreateReqVO bean); - default String map(Long[] value){ + default String map(Long[] value) { return value.toString(); } @@ -39,7 +40,7 @@ public interface SeckillActivityConvert { PageResult convertPage(PageResult page); - @Mappings({@Mapping(target = "products",source = "seckillProducts")}) + @Mappings({@Mapping(target = "products", source = "seckillProducts")}) SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List seckillProducts); @@ -56,7 +57,6 @@ public interface SeckillActivityConvert { && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()) && ObjectUtil.equals(productDO.getStock(), productVO.getStock()) && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); - } /** @@ -74,4 +74,9 @@ public interface SeckillActivityConvert { && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); } + + default List convertList(List products, Long seckillActivityId, List timeIds) { + return CollectionUtils.convertList(products, product -> convert(product) + .setActivityId(seckillActivityId).setTimeIds(timeIds)); + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckilltime/SeckillTimeConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckilltime/SeckillTimeConvert.java index dda7d2c9d..4cea7a91c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckilltime/SeckillTimeConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckilltime/SeckillTimeConvert.java @@ -4,9 +4,9 @@ import java.util.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java index 0cc8e680c..c0f79bc48 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java @@ -9,11 +9,12 @@ import lombok.*; import java.math.BigDecimal; import java.time.LocalDateTime; +import java.util.List; /** * 秒杀活动 DO * - * @author 芋道源码 + * @author halfninety */ @TableName("promotion_seckill_activity") @KeySequence("promotion_seckill_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @@ -59,8 +60,7 @@ public class SeckillActivityDO extends BaseDO { /** * 秒杀时段 id */ - // TODO @halfninety 可以使用 List 存储;看下别的模块怎么做的哈 - private String timeId; + private List timeIds; /** * 付款订单数 */ @@ -69,10 +69,9 @@ public class SeckillActivityDO extends BaseDO { * 付款人数 */ private Integer userCount; - // TODO @halfninety 使用 Long 哈。单位是分 /** * 订单实付金额,单位:分 */ - private BigDecimal totalPrice; + private Long totalPrice; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java index 3ed54efa4..28a4f5e78 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java @@ -5,16 +5,21 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; + import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; +import java.util.List; + import lombok.Data; /** * 秒杀参与商品 + * + * @author halfninety * @TableName promotion_seckill_product */ -@TableName(value ="promotion_seckill_product") +@TableName(value = "promotion_seckill_product") @Data public class SeckillProductDO extends BaseDO { /** @@ -31,7 +36,7 @@ public class SeckillProductDO extends BaseDO { /** * 秒杀时段id */ - private Long timeId; + private List timeIds; /** * 商品id diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 41b7cafdc..640578746 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -3,25 +3,23 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import org.apache.ibatis.annotations.Mapper; /** * 秒杀活动 Mapper * - * @author 芋道源码 + * @author halfninety */ @Mapper public interface SeckillActivityMapper extends BaseMapperX { -// TODO: 2022/11/28 halfninety 秒杀活动通过场次查询使用like会出现问题,查询活动场次编号为1,则活动场次编号为 1,11,......的都会被查出来 default PageResult selectPage(SeckillActivityPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(SeckillActivityDO::getName, reqVO.getName()) .eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus()) - .likeIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId()) -// .like(StringUtils.hasText(reqVO.getTimeId()),SeckillActivityDO::getTimeId, reqVO.getTimeId() + ",") .betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime()) + .apply("FIND_IN_SET(" + reqVO.getTimeId() + ",time_id) > 0") .orderByDesc(SeckillActivityDO::getId)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index 3c76b45df..d434154d6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java @@ -7,15 +7,20 @@ import org.apache.ibatis.annotations.Mapper; import java.util.Collection; import java.util.List; +/** + * 秒杀活动商品 Mapper + * + * @author halfninety + */ @Mapper public interface SeckillProductMapper extends BaseMapperX { - default List selectListByActivityId(Long id){ - return selectList(SeckillProductDO::getActivityId,id); + default List selectListByActivityId(Long id) { + return selectList(SeckillProductDO::getActivityId, id); } - default List selectListBySkuIds(Collection skuIds){ - return selectList(SeckillProductDO::getSkuId,skuIds); + default List selectListBySkuIds(Collection skuIds) { + return selectList(SeckillProductDO::getSkuId, skuIds); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java index f9d903a51..19ada3356 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java @@ -8,57 +8,44 @@ import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWra import org.apache.ibatis.annotations.Mapper; import java.time.LocalTime; -import java.util.Collections; +import java.util.Collection; import java.util.List; /** * 秒杀时段 Mapper * - * @author 芋道源码 + * @author halfninety */ @Mapper public interface SeckillTimeMapper extends BaseMapperX { - // @TODO halfninety:){ 之间要有空格哈 - default List selectListWithTime(LocalTime time){ - // TODO @halfninety:mapper 层,不做空判断,业务上面自己的保证 - if (time == null) { - return Collections.emptyList(); - } - // TODO @halfninety:在 BaseMapperX 上,可以封装一个 2 个字段的检索哈 - return selectList(new LambdaQueryWrapper() - .le(SeckillTimeDO::getStartTime,time) - .ge(SeckillTimeDO::getEndTime,time)); + default List selectListByTime(LocalTime time) { + return selectList(SeckillTimeDO::getStartTime,SeckillTimeDO::getEndTime,time); } - // TODO @halfninety:selectListByXXX,使用 By 作为查询条件。 - default List selectListWithTime(LocalTime startTime, LocalTime endTime){ - // TODO @halfninety:mapper 层,不做空判断,业务上面自己的保证 - if (startTime == null && endTime == null) { - return Collections.emptyList(); - } + default List selectListByTime(LocalTime startTime, LocalTime endTime) { return selectList(new LambdaQueryWrapper() - .ge(SeckillTimeDO::getStartTime,startTime) - .le(SeckillTimeDO::getEndTime,endTime)); + .ge(SeckillTimeDO::getStartTime, startTime) + .le(SeckillTimeDO::getEndTime, endTime)); } // TODO @halfninety:updateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 - default void sekillActivityCountAdd(List ids){ - if (CollUtil.isEmpty(ids)){ + default void sekillActivityCountAdd(Collection ids) { + if (CollUtil.isEmpty(ids)) { return; } new LambdaUpdateChainWrapper(this) - .in(SeckillTimeDO::getId,ids) + .in(SeckillTimeDO::getId, ids) .setSql("`seckill_activity_count` = `seckill_activity_count` + 1 ") .update(); } - default void sekillActivityCountReduce(List ids){ - if (CollUtil.isEmpty(ids)){ + default void sekillActivityCountReduce(Collection ids) { + if (CollUtil.isEmpty(ids)) { return; } new LambdaUpdateChainWrapper(this) - .in(SeckillTimeDO::getId,ids) + .in(SeckillTimeDO::getId, ids) .setSql("`seckill_activity_count` = `seckill_activity_count` - 1 ") .update(); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java index 6b45330ba..a0ff74dc8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java @@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity; import java.util.*; import javax.validation.*; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; @@ -13,7 +13,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity. /** * 秒杀活动 Service 接口 * - * @author 芋道源码 + * @author halfninety */ public interface SeckillActivityService { @@ -34,6 +34,7 @@ public interface SeckillActivityService { /** * 关闭秒杀活动 + * * @param id 编号 */ void closeSeckillActivity(Long id); @@ -71,6 +72,7 @@ public interface SeckillActivityService { /** * 通过活动编号获取活动商品 + * * @param id 活动编号 * @return 活动商品列表 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java index 390521a07..025bf942d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java @@ -4,10 +4,10 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.string.StrUtils; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityBaseVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityBaseVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; 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.SeckillProductDO; @@ -22,7 +22,6 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -31,12 +30,13 @@ import static java.util.Arrays.asList; /** * 秒杀活动 Service 实现类 * - * @author 芋道源码 // TODO @halfninety:作者改成你自己哈 + * @author halfninety */ @Service @Validated public class SeckillActivityServiceImpl implements SeckillActivityService { - + // TODO: 2022/12/2 halfninety 当前修改时忘记秒杀商品中的秒杀时段id的设置了;需要全部修改 + // TODO: 2022/12/2 halfninety 将活动数量改为原来的商品数量 @Resource private SeckillActivityMapper seckillActivityMapper; @Resource @@ -47,25 +47,22 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { - // TODO @halfninety:多余的变量,需要删除 - List statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); // 校验商品是否冲突 validateSeckillActivityProductConflicts(null, createReqVO.getProducts()); - // TODO halfninety:要校验下,秒杀时间段存在 + // 校验秒杀时段是否存在 + seckillTimeService.validateSeckillTimeExists(createReqVO.getTimeIds()); // 插入秒杀活动 SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO) .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime())); seckillActivityMapper.insert(seckillActivity); // 插入商品 - // TODO @halfninety:是不是写成一个 convertList,通过 default 来处理下;这样可读性更好哈 - List productDOS = CollectionUtils.convertList(createReqVO.getProducts(), - product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(seckillActivity.getId())); + List productDOS = SeckillActivityConvert.INSTANCE + .convertList(createReqVO.getProducts(),seckillActivity.getId(),seckillActivity.getTimeIds()); seckillProductMapper.insertBatch(productDOS); - // TODO halfninety:最后在更新秒杀时间段的商品数量哈。【我已经改了】一般先做核心的逻辑,在做附件的逻辑。 // 更新秒杀时段的秒杀活动数量 - seckillTimeService.sekillActivityCountAdd(StrUtils.splitToLong(createReqVO.getTimeId(),",")); + seckillTimeService.sekillActivityCountAdd(createReqVO.getTimeIds()); return seckillActivity.getId(); } @@ -80,8 +77,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); // 更新秒杀时段的秒杀活动数量 - // TODO @halfninety:可以直接传递 seckillActivity 进去,不用重复查询; - updateSeckillTimeActivityCount(updateReqVO.getId(), updateReqVO.getTimeId()); + updateSeckillTimeActivityCount(seckillActivity, updateReqVO.getTimeIds()); // 更新活动 SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getStartTime(), updateReqVO.getEndTime())); @@ -91,41 +87,39 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { } // TODO @halfninety:注释写全哈; + /** * 更新秒杀时段的秒杀活动数量 * - * @param id - * @param timeId + * @param seckillActivity 查询出的秒杀活动 + * @param updateTimeIds 更新后的秒杀时段id列表 */ - private void updateSeckillTimeActivityCount(Long id, String timeId) { - List updateTimeIds = StrUtils.splitToLong(timeId, ","); - // 查出自己的 timeIds - SeckillActivityDO seckillActivityDO = seckillActivityMapper.selectById(id); - List existsTimeIds = StrUtils.splitToLong(seckillActivityDO.getTimeId(), ","); + private void updateSeckillTimeActivityCount(SeckillActivityDO seckillActivity, List updateTimeIds) { + // 查询出 timeIds + List existsTimeIds = seckillActivity.getTimeIds(); // 需要减少的时间段 // TODO @halfninety:可以使用 CollUtil.filterNew() - List reduceIds = existsTimeIds.stream() - .filter(existsTimeId -> !updateTimeIds.contains(existsTimeId)) - .collect(Collectors.toList()); + Collection reduceIds = CollUtil.filterNew(existsTimeIds, existsTimeId -> !updateTimeIds.contains(existsTimeId)); // 需要添加的时间段 - // TODO @halfninety:IDEA 一般会有告警提示,下面可以 lambada 表达式优化下;通过 command + 回车 - updateTimeIds.removeIf(updateTimeId -> existsTimeIds.contains(updateTimeId)); + updateTimeIds.removeIf(existsTimeIds::contains); // 更新减少时间段和增加时间段 - // TODO @halfninety:判断非空才操作 - seckillTimeService.sekillActivityCountAdd(updateTimeIds); - seckillTimeService.sekillActivityCountReduce(reduceIds); + if (CollUtil.isNotEmpty(updateTimeIds)) { + seckillTimeService.sekillActivityCountAdd(updateTimeIds); + } + if (CollUtil.isNotEmpty(reduceIds)) { + seckillTimeService.sekillActivityCountReduce(reduceIds); + } } /** * 更新秒杀商品 + * 后台查出的数据和前台查出的数据进行遍历, + * 1. 对前台数据进行遍历:如果不存在于后台的 sku 中需要新增 + * 2. 对后台数据进行遍历:如果不存在于前台的 sku 中需要删除 */ private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { List seckillProductDOS = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); List products = updateReqVO.getProducts(); - // TODO halfninety:下面这段,其实可以放到注释哈 - // 对后台查出的数据和前台查出的数据进行遍历, - // 1. 对前台数据进行遍历:如果不存在于后台的 sku 中需要新增 - // 2. 对后台数据进行遍历:如果不存在于前台的 sku 中需要删除 // 计算需要删除的数据 List deleteIds = CollectionUtils.convertList(seckillProductDOS, SeckillProductDO::getId, @@ -198,7 +192,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); } // 更新秒杀时段的秒杀活动数量 - seckillTimeService.sekillActivityCountReduce(StrUtils.splitToLong(seckillActivity.getTimeId(),",")); + seckillTimeService.sekillActivityCountReduce(seckillActivity.getTimeIds()); // 删除 seckillActivityMapper.deleteById(id); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java index 0256c873a..0762444f6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java @@ -1,16 +1,17 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import javax.validation.Valid; +import java.util.Collection; import java.util.List; /** * 秒杀时段 Service 接口 * - * @author 芋道源码 + * @author halfninety */ public interface SeckillTimeService { @@ -51,12 +52,19 @@ public interface SeckillTimeService { */ List getSeckillTimeList(); + /** + * 校验秒杀时段是否存在 + * + * @param timeIds 秒杀时段id集合 + */ + void validateSeckillTimeExists(Collection timeIds); + /** * 秒杀时段列表的秒杀活动数量加 1 * * @param ids 秒杀时段id列表 */ - void sekillActivityCountAdd(List ids); + void sekillActivityCountAdd(Collection ids); /** @@ -64,5 +72,5 @@ public interface SeckillTimeService { * * @param ids 秒杀时段id列表 */ - void sekillActivityCountReduce(List ids); + void sekillActivityCountReduce(Collection ids); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java index 234f40e5b..70dd521f3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime.SeckillTimeMapper; @@ -11,6 +11,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalTime; +import java.util.Collection; import java.util.List; import java.util.Objects; @@ -21,7 +22,7 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL /** * 秒杀时段 Service 实现类 * - * @author 芋道源码 // TODO @halfninety:作者改成你自己哈 + * @author halfninety */ @Service @Validated @@ -33,7 +34,7 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { @Override public Long createSeckillTime(SeckillTimeCreateReqVO createReqVO) { // 校验时间段是否冲突 - validateSeckillTimeConflict(null,createReqVO.getStartTime(), createReqVO.getEndTime()); + validateSeckillTimeConflict(null, createReqVO.getStartTime(), createReqVO.getEndTime()); // 插入 SeckillTimeDO seckillTime = SeckillTimeConvert.INSTANCE.convert(createReqVO); seckillTimeMapper.insert(seckillTime); @@ -74,10 +75,10 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { */ private void validateSeckillTimeConflict(Long id, LocalTime startTime, LocalTime endTime) { //查询开始时间,结束时间,是否在别人的时间段内 - List startTimeList = seckillTimeMapper.selectListWithTime(startTime); - List endTimeList = seckillTimeMapper.selectListWithTime(endTime); + List startTimeList = seckillTimeMapper.selectListByTime(startTime); + List endTimeList = seckillTimeMapper.selectListByTime(endTime); //查询自己时间段内是否有时间段 - List startEndTimeList = seckillTimeMapper.selectListWithTime(startTime, endTime); + List startEndTimeList = seckillTimeMapper.selectListByTime(startTime, endTime); if (id != null) { //移除自己 startTimeList.removeIf(seckillTime -> Objects.equals(seckillTime.getId(), id)); @@ -100,14 +101,24 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { return seckillTimeMapper.selectList(); } + @Override + public void validateSeckillTimeExists(Collection timeIds) { + if (CollUtil.isEmpty(timeIds)) { + return; + } + if (seckillTimeMapper.selectBatchIds(timeIds).size() != timeIds.size()) { + throw exception(SECKILL_TIME_NOT_EXISTS); + } + } + // TODO @halfninety:updateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 @Override - public void sekillActivityCountAdd(List ids) { + public void sekillActivityCountAdd(Collection ids) { seckillTimeMapper.sekillActivityCountAdd(ids); } @Override - public void sekillActivityCountReduce(List ids) { + public void sekillActivityCountReduce(Collection ids) { seckillTimeMapper.sekillActivityCountReduce(ids); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckillactivity/SeckillActivityMapper.xml b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckillactivity/SeckillActivityMapper.xml deleted file mode 100644 index 335ea77da..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckillactivity/SeckillActivityMapper.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml deleted file mode 100644 index 351eca7fb..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImplTest.java index 2ea767e97..853568077 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImplTest.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.promotion.service.seckillactivity; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper; import cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity.SeckillActivityServiceImpl; @@ -107,7 +107,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到 o.setName(null); o.setStatus(null); - o.setTimeId(null); + o.setTimeIds(null); o.setCreateTime(null); }); seckillActivityMapper.insert(dbSeckillActivity); @@ -116,7 +116,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { // 测试 status 不匹配 seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); // 测试 timeId 不匹配 - seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null))); + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeIds(null))); // 测试 createTime 不匹配 seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); // 准备参数 @@ -141,7 +141,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到 o.setName(null); o.setStatus(null); - o.setTimeId(null); + o.setTimeIds(null); o.setCreateTime(null); }); seckillActivityMapper.insert(dbSeckillActivity); @@ -150,7 +150,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { // 测试 status 不匹配 seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); // 测试 timeId 不匹配 - seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null))); + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeIds(null))); // 测试 createTime 不匹配 seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); // 准备参数 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImplTest.java index 439bcf03e..e61023c66 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImplTest.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.promotion.service.seckilltime; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.service.seckill.seckilltime.SeckillTimeServiceImpl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; From 6808d3c163fca5c699d21b50ec0c4d112b319df3 Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Sat, 3 Dec 2022 15:42:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=A7=92=E6=9D=80?= =?UTF-8?q?=E6=97=B6=E6=AE=B5todo=EF=BC=8C=E7=A7=92=E6=9D=80=E6=97=B6?= =?UTF-8?q?=E6=AE=B5=E5=95=86=E5=93=81=E6=B7=BB=E5=8A=A0timeIds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/SeckillActivityCreateReqVO.java | 2 -- .../SeckillActivityConvert.java | 5 +-- .../seckillactivity/SeckillActivityDO.java | 17 +++++----- .../seckillactivity/SeckillProductDO.java | 22 ++++++------- .../seckill/seckilltime/SeckillTimeDO.java | 7 ++-- .../SeckillActivityMapper.java | 4 +-- .../seckillactivity/SeckillProductMapper.java | 9 ++++++ .../seckilltime/SeckillTimeMapper.java | 24 +++----------- .../SeckillActivityServiceImpl.java | 32 +++++++++---------- .../seckilltime/SeckillTimeService.java | 4 +-- .../seckilltime/SeckillTimeServiceImpl.java | 11 +++---- .../seckill/seckillActivity/index.vue | 24 +++++++------- 12 files changed, 75 insertions(+), 86 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityCreateReqVO.java index 7324e767a..8ed5a3119 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityCreateReqVO.java @@ -7,7 +7,6 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import javax.validation.Valid; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List; @@ -26,7 +25,6 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO { @NotNull(message = "排序不能为空") private Integer sort; - // TODO halfninety:直接使用数组接口。timeIds, @ApiModelProperty(value = "秒杀时段id", required = true) @NotEmpty(message = "参与场次不能为空") private List timeIds; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index cf376c20f..1a00fdeb6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -75,8 +75,9 @@ public interface SeckillActivityConvert { } - default List convertList(List products, Long seckillActivityId, List timeIds) { + default List convertList(List products, SeckillActivityDO seckillActivity) { return CollectionUtils.convertList(products, product -> convert(product) - .setActivityId(seckillActivityId).setTimeIds(timeIds)); + .setActivityId(seckillActivity.getId()).setTimeIds(seckillActivity.getTimeIds())); } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java index c0f79bc48..1d3b6da27 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java @@ -1,13 +1,16 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; -import lombok.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; -import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; @@ -16,14 +19,11 @@ import java.util.List; * * @author halfninety */ -@TableName("promotion_seckill_activity") +@TableName(value = "promotion_seckill_activity", autoResultMap = true) @KeySequence("promotion_seckill_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor public class SeckillActivityDO extends BaseDO { /** @@ -37,7 +37,7 @@ public class SeckillActivityDO extends BaseDO { private String name; /** * 活动状态 - * + *

* 枚举 {@link PromotionActivityStatusEnum 对应的类} */ private Integer status; @@ -60,6 +60,7 @@ public class SeckillActivityDO extends BaseDO { /** * 秒杀时段 id */ + @TableField(typeHandler = LongListTypeHandler.class) private List timeIds; /** * 付款订单数 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java index 28a4f5e78..3783d6dda 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java @@ -1,17 +1,13 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.util.Date; -import java.util.List; - +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; +import com.baomidou.mybatisplus.annotation.*; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.List; /** * 秒杀参与商品 @@ -19,8 +15,11 @@ import lombok.Data; * @author halfninety * @TableName promotion_seckill_product */ -@TableName(value = "promotion_seckill_product") +@TableName(value = "promotion_seckill_product", autoResultMap = true) +@KeySequence("promotion_seckill_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class SeckillProductDO extends BaseDO { /** * 秒杀参与商品编号 @@ -36,6 +35,7 @@ public class SeckillProductDO extends BaseDO { /** * 秒杀时段id */ + @TableField(typeHandler = LongListTypeHandler.class) private List timeIds; /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckilltime/SeckillTimeDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckilltime/SeckillTimeDO.java index 56dc0eb93..df338c0e6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckilltime/SeckillTimeDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckilltime/SeckillTimeDO.java @@ -4,7 +4,9 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import java.time.LocalTime; @@ -18,9 +20,6 @@ import java.time.LocalTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor public class SeckillTimeDO extends BaseDO { /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 640578746..c01676c2a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -19,8 +20,7 @@ public interface SeckillActivityMapper extends BaseMapperX { .likeIfPresent(SeckillActivityDO::getName, reqVO.getName()) .eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus()) .betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime()) - .apply("FIND_IN_SET(" + reqVO.getTimeId() + ",time_id) > 0") + .apply(ObjectUtil.isNotNull(reqVO.getTimeId()),"FIND_IN_SET(" + reqVO.getTimeId() + ",time_ids) > 0") .orderByDesc(SeckillActivityDO::getId)); } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index d434154d6..a590de1a5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; @@ -23,4 +25,11 @@ public interface SeckillProductMapper extends BaseMapperX { return selectList(SeckillProductDO::getSkuId, skuIds); } + default void updateTimeIdsByActivityId(Long id, List timeIds) { + new LambdaUpdateChainWrapper<>(this) + .set(SeckillProductDO::getTimeIds, CollUtil.join(timeIds, ",")) + .eq(SeckillProductDO::getActivityId, id) + .update(); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java index 19ada3356..c34484e8c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime; -import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -20,7 +19,7 @@ import java.util.List; public interface SeckillTimeMapper extends BaseMapperX { default List selectListByTime(LocalTime time) { - return selectList(SeckillTimeDO::getStartTime,SeckillTimeDO::getEndTime,time); + return selectList(SeckillTimeDO::getStartTime, SeckillTimeDO::getEndTime, time); } default List selectListByTime(LocalTime startTime, LocalTime endTime) { @@ -29,25 +28,10 @@ public interface SeckillTimeMapper extends BaseMapperX { .le(SeckillTimeDO::getEndTime, endTime)); } - // TODO @halfninety:updateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 - default void sekillActivityCountAdd(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - new LambdaUpdateChainWrapper(this) + default void updateActivityCount(Collection ids, String type, Integer count) { + new LambdaUpdateChainWrapper<>(this) .in(SeckillTimeDO::getId, ids) - .setSql("`seckill_activity_count` = `seckill_activity_count` + 1 ") + .setSql("`seckill_activity_count` = `seckill_activity_count` " + type + count) .update(); } - - default void sekillActivityCountReduce(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - new LambdaUpdateChainWrapper(this) - .in(SeckillTimeDO::getId, ids) - .setSql("`seckill_activity_count` = `seckill_activity_count` - 1 ") - .update(); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java index 025bf942d..45581d825 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; @@ -35,13 +34,10 @@ import static java.util.Arrays.asList; @Service @Validated public class SeckillActivityServiceImpl implements SeckillActivityService { - // TODO: 2022/12/2 halfninety 当前修改时忘记秒杀商品中的秒杀时段id的设置了;需要全部修改 - // TODO: 2022/12/2 halfninety 将活动数量改为原来的商品数量 @Resource private SeckillActivityMapper seckillActivityMapper; @Resource private SeckillProductMapper seckillProductMapper; - @Resource private SeckillTimeService seckillTimeService; @@ -49,20 +45,18 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { // 校验商品是否冲突 validateSeckillActivityProductConflicts(null, createReqVO.getProducts()); - // 校验秒杀时段是否存在 seckillTimeService.validateSeckillTimeExists(createReqVO.getTimeIds()); + // 插入秒杀活动 SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO) .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime())); seckillActivityMapper.insert(seckillActivity); // 插入商品 - List productDOS = SeckillActivityConvert.INSTANCE - .convertList(createReqVO.getProducts(),seckillActivity.getId(),seckillActivity.getTimeIds()); + List productDOS = SeckillActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), seckillActivity); seckillProductMapper.insertBatch(productDOS); - // 更新秒杀时段的秒杀活动数量 - seckillTimeService.sekillActivityCountAdd(createReqVO.getTimeIds()); + seckillTimeService.sekillActivityCountIncr(createReqVO.getTimeIds()); return seckillActivity.getId(); } @@ -76,38 +70,36 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { // 校验商品是否冲突 validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); - // 更新秒杀时段的秒杀活动数量 - updateSeckillTimeActivityCount(seckillActivity, updateReqVO.getTimeIds()); // 更新活动 SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getStartTime(), updateReqVO.getEndTime())); seckillActivityMapper.updateById(updateObj); // 更新商品 updateSeckillProduct(updateReqVO); + // 更新秒杀时段的秒杀活动数量 + updateSeckillTimeActivityCount(seckillActivity, updateReqVO.getTimeIds()); } - // TODO @halfninety:注释写全哈; /** * 更新秒杀时段的秒杀活动数量 * * @param seckillActivity 查询出的秒杀活动 - * @param updateTimeIds 更新后的秒杀时段id列表 + * @param updateTimeIds 更新后的秒杀时段id列表 */ private void updateSeckillTimeActivityCount(SeckillActivityDO seckillActivity, List updateTimeIds) { // 查询出 timeIds List existsTimeIds = seckillActivity.getTimeIds(); // 需要减少的时间段 - // TODO @halfninety:可以使用 CollUtil.filterNew() Collection reduceIds = CollUtil.filterNew(existsTimeIds, existsTimeId -> !updateTimeIds.contains(existsTimeId)); // 需要添加的时间段 updateTimeIds.removeIf(existsTimeIds::contains); // 更新减少时间段和增加时间段 if (CollUtil.isNotEmpty(updateTimeIds)) { - seckillTimeService.sekillActivityCountAdd(updateTimeIds); + seckillTimeService.sekillActivityCountIncr(updateTimeIds); } if (CollUtil.isNotEmpty(reduceIds)) { - seckillTimeService.sekillActivityCountReduce(reduceIds); + seckillTimeService.sekillActivityCountDecr(reduceIds); } } @@ -116,6 +108,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { * 后台查出的数据和前台查出的数据进行遍历, * 1. 对前台数据进行遍历:如果不存在于后台的 sku 中需要新增 * 2. 对后台数据进行遍历:如果不存在于前台的 sku 中需要删除 + * 3. 最后对当前活动商品全部更新,更新秒杀时段id列表 + * + * @param updateReqVO 更新的请求VO */ private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { List seckillProductDOS = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); @@ -137,6 +132,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { if (CollUtil.isNotEmpty(newSeckillProductDOs)) { seckillProductMapper.insertBatch(newSeckillProductDOs); } + + //全量更新当前活动商品的秒杀时段id列表(timeIds) + seckillProductMapper.updateTimeIdsByActivityId(updateReqVO.getId(), updateReqVO.getTimeIds()); } /** @@ -192,7 +190,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); } // 更新秒杀时段的秒杀活动数量 - seckillTimeService.sekillActivityCountReduce(seckillActivity.getTimeIds()); + seckillTimeService.sekillActivityCountDecr(seckillActivity.getTimeIds()); // 删除 seckillActivityMapper.deleteById(id); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java index 0762444f6..2e9c21249 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeService.java @@ -64,7 +64,7 @@ public interface SeckillTimeService { * * @param ids 秒杀时段id列表 */ - void sekillActivityCountAdd(Collection ids); + void sekillActivityCountIncr(Collection ids); /** @@ -72,5 +72,5 @@ public interface SeckillTimeService { * * @param ids 秒杀时段id列表 */ - void sekillActivityCountReduce(Collection ids); + void sekillActivityCountDecr(Collection ids); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java index 70dd521f3..d38183860 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java @@ -104,22 +104,21 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { @Override public void validateSeckillTimeExists(Collection timeIds) { if (CollUtil.isEmpty(timeIds)) { - return; + throw exception(SECKILL_TIME_NOT_EXISTS); } if (seckillTimeMapper.selectBatchIds(timeIds).size() != timeIds.size()) { throw exception(SECKILL_TIME_NOT_EXISTS); } } - // TODO @halfninety:updateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 @Override - public void sekillActivityCountAdd(Collection ids) { - seckillTimeMapper.sekillActivityCountAdd(ids); + public void sekillActivityCountIncr(Collection ids) { + seckillTimeMapper.updateActivityCount(ids, "+", 1); } @Override - public void sekillActivityCountReduce(Collection ids) { - seckillTimeMapper.sekillActivityCountReduce(ids); + public void sekillActivityCountDecr(Collection ids) { + seckillTimeMapper.updateActivityCount(ids, "-", 1); } } diff --git a/yudao-ui-admin/src/views/mall/promotion/seckill/seckillActivity/index.vue b/yudao-ui-admin/src/views/mall/promotion/seckill/seckillActivity/index.vue index 3805def34..265c54749 100644 --- a/yudao-ui-admin/src/views/mall/promotion/seckill/seckillActivity/index.vue +++ b/yudao-ui-admin/src/views/mall/promotion/seckill/seckillActivity/index.vue @@ -51,10 +51,10 @@ - + @@ -107,7 +107,7 @@ - {{ item.name + ': { ' }} {{ item.startTime }} -- {{ item.endTime + @@ -186,7 +186,7 @@