From 83ee1c61291fd94060f95462d4a6970b3fb8cbbc Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Sat, 19 Nov 2022 14:25:36 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=EF=BC=8C=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 3 + .../SeckillActivityController.java | 100 ++++++++++ .../vo/SeckillActivityBaseVO.java | 41 +++++ .../vo/SeckillActivityCreateReqVO.java | 25 +++ .../vo/SeckillActivityExcelVO.java | 46 +++++ .../vo/SeckillActivityExportReqVO.java | 28 +++ .../vo/SeckillActivityPageReqVO.java | 30 +++ .../vo/SeckillActivityRespVO.java | 25 +++ .../vo/SeckillActivityUpdateReqVO.java | 29 +++ .../SeckillActivityConvert.java | 34 ++++ .../seckillactivity/SeckillActivityDO.java | 72 ++++++++ .../SeckillActivityMapper.java | 38 ++++ .../SeckillActivityService.java | 70 +++++++ .../SeckillActivityServiceImpl.java | 82 +++++++++ .../seckillactivity/SeckillActivityMapper.xml | 12 ++ .../SeckillActivityServiceImplTest.java | 173 ++++++++++++++++++ .../src/api/promotion/seckillActivity.js | 54 ++++++ .../views/promotion/seckillActivity/index.vue | 0 18 files changed, 862 insertions(+) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityService.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckillactivity/SeckillActivityMapper.xml create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImplTest.java create mode 100644 yudao-ui-admin/src/api/promotion/seckillActivity.js create mode 100644 yudao-ui-admin/src/views/promotion/seckillActivity/index.vue diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 7e8fadede..b6ac66757 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -45,4 +45,7 @@ public interface ErrorCodeConstants { // ========== Price 相关 1003007000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1003007000, "支付价格计算异常,原因:价格小于等于 0"); + // ========== 秒杀活动 1003008000 ========== + ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1003008000, "秒杀活动不存在"); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java new file mode 100644 index 000000000..7ddcd3b55 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java @@ -0,0 +1,100 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.annotations.*; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert; +import cn.iocoder.yudao.module.promotion.service.seckillactivity.SeckillActivityService; + +@Api(tags = "管理后台 - 秒杀活动") +@RestController +@RequestMapping("/promotion/seckill-activity") +@Validated +public class SeckillActivityController { + + @Resource + private SeckillActivityService seckillActivityService; + + @PostMapping("/create") + @ApiOperation("创建秒杀活动") + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:create')") + public CommonResult createSeckillActivity(@Valid @RequestBody SeckillActivityCreateReqVO createReqVO) { + return success(seckillActivityService.createSeckillActivity(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新秒杀活动") + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:update')") + public CommonResult updateSeckillActivity(@Valid @RequestBody SeckillActivityUpdateReqVO updateReqVO) { + seckillActivityService.updateSeckillActivity(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除秒杀活动") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:delete')") + public CommonResult deleteSeckillActivity(@RequestParam("id") Long id) { + seckillActivityService.deleteSeckillActivity(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得秒杀活动") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") + public CommonResult getSeckillActivity(@RequestParam("id") Long id) { + SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id); + return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity)); + } + + @GetMapping("/list") + @ApiOperation("获得秒杀活动列表") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") + public CommonResult> getSeckillActivityList(@RequestParam("ids") Collection ids) { + List list = seckillActivityService.getSeckillActivityList(ids); + return success(SeckillActivityConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得秒杀活动分页") + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") + public CommonResult> getSeckillActivityPage(@Valid SeckillActivityPageReqVO pageVO) { + PageResult pageResult = seckillActivityService.getSeckillActivityPage(pageVO); + return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出秒杀活动 Excel") + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:export')") + @OperateLog(type = EXPORT) + public void exportSeckillActivityExcel(@Valid SeckillActivityExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = seckillActivityService.getSeckillActivityList(exportReqVO); + // 导出 Excel + List datas = SeckillActivityConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "秒杀活动.xls", "数据", SeckillActivityExcelVO.class, datas); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java new file mode 100644 index 000000000..88f0d2cc7 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +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 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class SeckillActivityBaseVO { + + @ApiModelProperty(value = "秒杀活动名称", required = true, example = "晚九点限时秒杀") + @NotNull(message = "秒杀活动名称不能为空") + private String name; + + @ApiModelProperty(value = "活动状态", required = true, example = "进行中") + @NotNull(message = "活动状态不能为空") + private Integer status; + + @ApiModelProperty(value = "活动开始时间", required = true) + @NotNull(message = "活动开始时间不能为空") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date startTime; + + @ApiModelProperty(value = "活动结束时间", required = true) + @NotNull(message = "活动结束时间不能为空") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date endTime; + + @ApiModelProperty(value = "订单实付金额,单位:分", required = true) + @NotNull(message = "订单实付金额,单位:分不能为空") + private BigDecimal totalPrice; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java new file mode 100644 index 000000000..81028573f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 秒杀活动创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO { + + @ApiModelProperty(value = "备注", example = "限时秒杀活动") + private String remark; + + @ApiModelProperty(value = "排序", required = true) + @NotNull(message = "排序不能为空") + private Integer sort; + + @ApiModelProperty(value = "秒杀时段id", required = true) + @NotNull(message = "秒杀时段id不能为空") + private Long timeId; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java new file mode 100644 index 000000000..ea0d5f49f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; + + +/** + * 秒杀活动 Excel VO + * + * @author 芋道源码 + */ +@Data +public class SeckillActivityExcelVO { + + @ExcelProperty("秒杀活动名称") + private String name; + + @ExcelProperty(value = "活动状态", converter = DictConvert.class) + @DictFormat("promotion_activity_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private Integer status; + + @ExcelProperty("活动开始时间") + private Date startTime; + + @ExcelProperty("活动结束时间") + private Date endTime; + + @ExcelProperty("付款订单数") + private Integer orderCount; + + @ExcelProperty("付款人数") + private Integer userCount; + + @ExcelProperty("订单实付金额,单位:分") + private BigDecimal totalPrice; + + @ExcelProperty("创建时间") + private Date createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java new file mode 100644 index 000000000..a589af74e --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "管理后台 - 秒杀活动 Excel 导出 Request VO", description = "参数和 SeckillActivityPageReqVO 是一致的") +@Data +public class SeckillActivityExportReqVO { + + @ApiModelProperty(value = "秒杀活动名称", example = "晚九点限时秒杀") + private String name; + + @ApiModelProperty(value = "活动状态", example = "进行中") + private Integer status; + + @ApiModelProperty(value = "秒杀时段id") + private Long timeId; + + @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/seckillactivity/vo/SeckillActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java new file mode 100644 index 000000000..650010ae1 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 秒杀活动分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillActivityPageReqVO extends PageParam { + + @ApiModelProperty(value = "秒杀活动名称", example = "晚九点限时秒杀") + private String name; + + @ApiModelProperty(value = "活动状态", example = "进行中") + private Integer status; + + @ApiModelProperty(value = "秒杀时段id") + private Long timeId; + + @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/seckillactivity/vo/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java new file mode 100644 index 000000000..444d74eee --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 秒杀活动 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillActivityRespVO extends SeckillActivityBaseVO { + + @ApiModelProperty(value = "秒杀活动id", required = true, example = "1") + private Long id; + + @ApiModelProperty(value = "付款订单数", required = true) + private Integer orderCount; + + @ApiModelProperty(value = "付款人数", required = true) + private Integer userCount; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java new file mode 100644 index 000000000..e86e398f5 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 秒杀活动更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO { + + @ApiModelProperty(value = "秒杀活动编号", required = true, example = "224") + @NotNull(message = "秒杀活动编号不能为空") + private Long id; + + @ApiModelProperty(value = "备注", example = "限时秒杀活动") + private String remark; + + @ApiModelProperty(value = "排序", required = true) + @NotNull(message = "排序不能为空") + private Integer sort; + + @ApiModelProperty(value = "秒杀时段id", required = true) + @NotNull(message = "秒杀时段id不能为空") + private Long timeId; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java new file mode 100644 index 000000000..8e416aef4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.promotion.convert.seckillactivity; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; + +/** + * 秒杀活动 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface SeckillActivityConvert { + + SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class); + + SeckillActivityDO convert(SeckillActivityCreateReqVO bean); + + SeckillActivityDO convert(SeckillActivityUpdateReqVO bean); + + SeckillActivityRespVO convert(SeckillActivityDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java new file mode 100644 index 000000000..c52990721 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java @@ -0,0 +1,72 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity; + +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 秒杀活动 DO + * + * @author 芋道源码 + */ +@TableName("promotion_seckill_activity") +@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 { + + /** + * 秒杀活动编号 + */ + @TableId + private Long id; + /** + * 秒杀活动名称 + */ + private String name; + /** + * 活动状态 + * + * 枚举 {@link TODO promotion_activity_status 对应的类} + */ + private Integer status; + /** + * 备注 + */ + private String remark; + /** + * 活动开始时间 + */ + private Date startTime; + /** + * 活动结束时间 + */ + private Date endTime; + /** + * 排序 + */ + private Integer sort; + /** + * 秒杀时段id + */ + private Long timeId; + /** + * 付款订单数 + */ + private Integer orderCount; + /** + * 付款人数 + */ + private Integer userCount; + /** + * 订单实付金额,单位:分 + */ + private BigDecimal totalPrice; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java new file mode 100644 index 000000000..6b3319361 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; + +/** + * 秒杀活动 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface SeckillActivityMapper extends BaseMapperX { + + default PageResult selectPage(SeckillActivityPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(SeckillActivityDO::getName, reqVO.getName()) + .eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus()) + .eqIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId()) + .betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SeckillActivityDO::getId)); + } + + default List selectList(SeckillActivityExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(SeckillActivityDO::getName, reqVO.getName()) + .eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus()) + .eqIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId()) + .betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SeckillActivityDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityService.java new file mode 100644 index 000000000..6ff337fe4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.promotion.service.seckillactivity; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 秒杀活动 Service 接口 + * + * @author 芋道源码 + */ +public interface SeckillActivityService { + + /** + * 创建秒杀活动 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createSeckillActivity(@Valid SeckillActivityCreateReqVO createReqVO); + + /** + * 更新秒杀活动 + * + * @param updateReqVO 更新信息 + */ + void updateSeckillActivity(@Valid SeckillActivityUpdateReqVO updateReqVO); + + /** + * 删除秒杀活动 + * + * @param id 编号 + */ + void deleteSeckillActivity(Long id); + + /** + * 获得秒杀活动 + * + * @param id 编号 + * @return 秒杀活动 + */ + SeckillActivityDO getSeckillActivity(Long id); + + /** + * 获得秒杀活动列表 + * + * @param ids 编号 + * @return 秒杀活动列表 + */ + List getSeckillActivityList(Collection ids); + + /** + * 获得秒杀活动分页 + * + * @param pageReqVO 分页查询 + * @return 秒杀活动分页 + */ + PageResult getSeckillActivityPage(SeckillActivityPageReqVO pageReqVO); + + /** + * 获得秒杀活动列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 秒杀活动列表 + */ + List getSeckillActivityList(SeckillActivityExportReqVO exportReqVO); + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java new file mode 100644 index 000000000..9e23e0e29 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.promotion.service.seckillactivity; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert; +import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; + +/** + * 秒杀活动 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class SeckillActivityServiceImpl implements SeckillActivityService { + + @Resource + private SeckillActivityMapper seckillActivityMapper; + + @Override + public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { + // 插入 + SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO); + seckillActivityMapper.insert(seckillActivity); + // 返回 + return seckillActivity.getId(); + } + + @Override + public void updateSeckillActivity(SeckillActivityUpdateReqVO updateReqVO) { + // 校验存在 + this.validateSeckillActivityExists(updateReqVO.getId()); + // 更新 + SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO); + seckillActivityMapper.updateById(updateObj); + } + + @Override + public void deleteSeckillActivity(Long id) { + // 校验存在 + this.validateSeckillActivityExists(id); + // 删除 + seckillActivityMapper.deleteById(id); + } + + private void validateSeckillActivityExists(Long id) { + if (seckillActivityMapper.selectById(id) == null) { + throw exception(SECKILL_ACTIVITY_NOT_EXISTS); + } + } + + @Override + public SeckillActivityDO getSeckillActivity(Long id) { + return seckillActivityMapper.selectById(id); + } + + @Override + public List getSeckillActivityList(Collection ids) { + return seckillActivityMapper.selectBatchIds(ids); + } + + @Override + public PageResult getSeckillActivityPage(SeckillActivityPageReqVO pageReqVO) { + return seckillActivityMapper.selectPage(pageReqVO); + } + + @Override + public List getSeckillActivityList(SeckillActivityExportReqVO exportReqVO) { + return seckillActivityMapper.selectList(exportReqVO); + } + +} 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 new file mode 100644 index 000000000..a9134c696 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckillactivity/SeckillActivityMapper.xml @@ -0,0 +1,12 @@ + + + + + + + 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 new file mode 100644 index 000000000..b95c8a0e4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImplTest.java @@ -0,0 +1,173 @@ +package cn.iocoder.yudao.module.promotion.service.seckillactivity; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** +* {@link SeckillActivityServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(SeckillActivityServiceImpl.class) +public class SeckillActivityServiceImplTest extends BaseDbUnitTest { + + @Resource + private SeckillActivityServiceImpl seckillActivityService; + + @Resource + private SeckillActivityMapper seckillActivityMapper; + + @Test + public void testCreateSeckillActivity_success() { + // 准备参数 + SeckillActivityCreateReqVO reqVO = randomPojo(SeckillActivityCreateReqVO.class); + + // 调用 + Long seckillActivityId = seckillActivityService.createSeckillActivity(reqVO); + // 断言 + assertNotNull(seckillActivityId); + // 校验记录的属性是否正确 + SeckillActivityDO seckillActivity = seckillActivityMapper.selectById(seckillActivityId); + assertPojoEquals(reqVO, seckillActivity); + } + + @Test + public void testUpdateSeckillActivity_success() { + // mock 数据 + SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class); + seckillActivityMapper.insert(dbSeckillActivity);// @Sql: 先插入出一条存在的数据 + // 准备参数 + SeckillActivityUpdateReqVO reqVO = randomPojo(SeckillActivityUpdateReqVO.class, o -> { + o.setId(dbSeckillActivity.getId()); // 设置更新的 ID + }); + + // 调用 + seckillActivityService.updateSeckillActivity(reqVO); + // 校验是否更新正确 + SeckillActivityDO seckillActivity = seckillActivityMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, seckillActivity); + } + + @Test + public void testUpdateSeckillActivity_notExists() { + // 准备参数 + SeckillActivityUpdateReqVO reqVO = randomPojo(SeckillActivityUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> seckillActivityService.updateSeckillActivity(reqVO), SECKILL_ACTIVITY_NOT_EXISTS); + } + + @Test + public void testDeleteSeckillActivity_success() { + // mock 数据 + SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class); + seckillActivityMapper.insert(dbSeckillActivity);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbSeckillActivity.getId(); + + // 调用 + seckillActivityService.deleteSeckillActivity(id); + // 校验数据不存在了 + assertNull(seckillActivityMapper.selectById(id)); + } + + @Test + public void testDeleteSeckillActivity_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> seckillActivityService.deleteSeckillActivity(id), SECKILL_ACTIVITY_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSeckillActivityPage() { + // mock 数据 + SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到 + o.setName(null); + o.setStatus(null); + o.setTimeId(null); + o.setCreateTime(null); + }); + seckillActivityMapper.insert(dbSeckillActivity); + // 测试 name 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setName(null))); + // 测试 status 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); + // 测试 timeId 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null))); + // 测试 createTime 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); + // 准备参数 + SeckillActivityPageReqVO reqVO = new SeckillActivityPageReqVO(); + reqVO.setName(null); + reqVO.setStatus(null); + reqVO.setTimeId(null); + reqVO.setCreateTime((new Date[]{})); + + // 调用 + PageResult pageResult = seckillActivityService.getSeckillActivityPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbSeckillActivity, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSeckillActivityList() { + // mock 数据 + SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到 + o.setName(null); + o.setStatus(null); + o.setTimeId(null); + o.setCreateTime(null); + }); + seckillActivityMapper.insert(dbSeckillActivity); + // 测试 name 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setName(null))); + // 测试 status 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); + // 测试 timeId 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null))); + // 测试 createTime 不匹配 + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); + // 准备参数 + SeckillActivityExportReqVO reqVO = new SeckillActivityExportReqVO(); + reqVO.setName(null); + reqVO.setStatus(null); + reqVO.setTimeId(null); + reqVO.setCreateTime((new Date[]{})); + + // 调用 + List list = seckillActivityService.getSeckillActivityList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbSeckillActivity, list.get(0)); + } + +} diff --git a/yudao-ui-admin/src/api/promotion/seckillActivity.js b/yudao-ui-admin/src/api/promotion/seckillActivity.js new file mode 100644 index 000000000..9b74081c0 --- /dev/null +++ b/yudao-ui-admin/src/api/promotion/seckillActivity.js @@ -0,0 +1,54 @@ +import request from '@/utils/request' + +// 创建秒杀活动 +export function createSeckillActivity(data) { + return request({ + url: '/promotion/seckill-activity/create', + method: 'post', + data: data + }) +} + +// 更新秒杀活动 +export function updateSeckillActivity(data) { + return request({ + url: '/promotion/seckill-activity/update', + method: 'put', + data: data + }) +} + +// 删除秒杀活动 +export function deleteSeckillActivity(id) { + return request({ + url: '/promotion/seckill-activity/delete?id=' + id, + method: 'delete' + }) +} + +// 获得秒杀活动 +export function getSeckillActivity(id) { + return request({ + url: '/promotion/seckill-activity/get?id=' + id, + method: 'get' + }) +} + +// 获得秒杀活动分页 +export function getSeckillActivityPage(query) { + return request({ + url: '/promotion/seckill-activity/page', + method: 'get', + params: query + }) +} + +// 导出秒杀活动 Excel +export function exportSeckillActivityExcel(query) { + return request({ + url: '/promotion/seckill-activity/export-excel', + method: 'get', + params: query, + responseType: 'blob' + }) +} diff --git a/yudao-ui-admin/src/views/promotion/seckillActivity/index.vue b/yudao-ui-admin/src/views/promotion/seckillActivity/index.vue new file mode 100644 index 000000000..e69de29bb From ea2a57f0a00b8a592cb8fa430c7c8cdd32a5e93b Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Sun, 20 Nov 2022 16:48:56 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A7=92=E6=9D=80?= =?UTF-8?q?=E6=97=B6=E6=AE=B5id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SeckillActivityController.java | 7 + .../vo/SeckillActivityCreateReqVO.java | 2 +- .../vo/SeckillActivityExportReqVO.java | 2 +- .../vo/SeckillActivityPageReqVO.java | 2 +- .../vo/SeckillActivityRespVO.java | 5 + .../vo/SeckillActivityUpdateReqVO.java | 2 +- .../seckillactivity/SeckillActivityDO.java | 2 +- .../views/promotion/seckillActivity/index.vue | 497 ++++++++++++++++++ 8 files changed, 514 insertions(+), 5 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java index 7ddcd3b55..419ae8e61 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity; import org.springframework.web.bind.annotation.*; + import javax.annotation.Resource; + import org.springframework.validation.annotation.Validated; import org.springframework.security.access.prepost.PreAuthorize; import io.swagger.annotations.*; @@ -14,11 +16,13 @@ import java.io.IOException; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; + import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; @@ -65,6 +69,9 @@ public class SeckillActivityController { @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") public CommonResult getSeckillActivity(@RequestParam("id") Long id) { SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id); + if (seckillActivity == null) { + return success(null); + } return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java index 81028573f..e397bd57c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java @@ -20,6 +20,6 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO { @ApiModelProperty(value = "秒杀时段id", required = true) @NotNull(message = "秒杀时段id不能为空") - private Long timeId; + private String timeId; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java index a589af74e..e8a5e459b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java @@ -19,7 +19,7 @@ public class SeckillActivityExportReqVO { private Integer status; @ApiModelProperty(value = "秒杀时段id") - private Long timeId; + private String 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/seckillactivity/vo/SeckillActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java index 650010ae1..ebfb9bb2a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java @@ -21,7 +21,7 @@ public class SeckillActivityPageReqVO extends PageParam { private Integer status; @ApiModelProperty(value = "秒杀时段id") - private Long timeId; + private String 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/seckillactivity/vo/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java index 444d74eee..3e75f5c16 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java @@ -4,6 +4,8 @@ import lombok.*; import java.util.*; import io.swagger.annotations.*; +import javax.validation.constraints.NotNull; + @ApiModel("管理后台 - 秒杀活动 Response VO") @Data @EqualsAndHashCode(callSuper = true) @@ -22,4 +24,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { @ApiModelProperty(value = "创建时间", required = true) private Date createTime; + @ApiModelProperty(value = "秒杀时段id", required = true) + private String timeId; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java index e86e398f5..f75a5294a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java @@ -24,6 +24,6 @@ public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO { @ApiModelProperty(value = "秒杀时段id", required = true) @NotNull(message = "秒杀时段id不能为空") - private Long timeId; + private String timeId; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java index c52990721..69edb1ff6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java @@ -55,7 +55,7 @@ public class SeckillActivityDO extends BaseDO { /** * 秒杀时段id */ - private Long timeId; + private String timeId; /** * 付款订单数 */ diff --git a/yudao-ui-admin/src/views/promotion/seckillActivity/index.vue b/yudao-ui-admin/src/views/promotion/seckillActivity/index.vue index e69de29bb..7fff0106f 100644 --- a/yudao-ui-admin/src/views/promotion/seckillActivity/index.vue +++ b/yudao-ui-admin/src/views/promotion/seckillActivity/index.vue @@ -0,0 +1,497 @@ + + + From cd62c4d22094dddb9feb9bf3c9ae845d023c48ef Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Sun, 20 Nov 2022 16:53:57 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=97=B6=E6=AE=B5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/date/DateUtils.java | 2 + .../databind/LocalTimeDeserializable.java | 16 ++ .../core/databind/LocalTimeSerializable.java | 17 ++ .../promotion/enums/ErrorCodeConstants.java | 2 +- .../seckilltime/SeckillTimeController.java | 99 +++++++ .../seckilltime/vo/SeckillTimeBaseVO.java | 32 +++ .../vo/SeckillTimeCreateReqVO.java | 14 + .../seckilltime/vo/SeckillTimeExcelVO.java | 37 +++ .../vo/SeckillTimeExportReqVO.java | 30 +++ .../seckilltime/vo/SeckillTimePageReqVO.java | 40 +++ .../seckilltime/vo/SeckillTimeRespVO.java | 22 ++ .../vo/SeckillTimeSimpleRespVO.java | 4 + .../vo/SeckillTimeUpdateReqVO.java | 21 ++ .../seckilltime/SeckillTimeConvert.java | 33 +++ .../dataobject/seckilltime/SeckillTimeDO.java | 47 ++++ .../mysql/seckilltime/SeckillTimeMapper.java | 40 +++ .../seckilltime/SeckillTimeService.java | 69 +++++ .../seckilltime/SeckillTimeServiceImpl.java | 82 ++++++ .../mapper/seckilltime/SeckillTimeMapper.xml | 12 + .../SeckillTimeServiceImplTest.java | 196 ++++++++++++++ .../src/api/promotion/seckillTime.js | 62 +++++ .../src/views/promotion/seckillTime/index.vue | 243 ++++++++++++++++++ 22 files changed, 1119 insertions(+), 1 deletion(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java create mode 100644 yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeBaseVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeCreateReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimePageReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeSimpleRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeUpdateReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImplTest.java create mode 100644 yudao-ui-admin/src/api/promotion/seckillTime.js create mode 100644 yudao-ui-admin/src/views/promotion/seckillTime/index.vue diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java index b4cb94e1f..466dfb050 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java @@ -25,6 +25,8 @@ public class DateUtils { public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; + public static final String FORMAT_HOUR_MINUTE_SECOND = "HH:mm:ss"; + /** * 将 LocalDateTime 转换成 Date * diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java new file mode 100644 index 000000000..9735438b1 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.framework.jackson.core.databind; + +import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; + +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; + +public class LocalTimeDeserializable { + // TODO: 2022/11/15 修改名字 + public static final LocalTimeDeserializer INSTANCE = new LocalTimeDeserializer(DateTimeFormatter + .ofPattern(FORMAT_HOUR_MINUTE_SECOND) + .withZone(ZoneId.systemDefault())); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java new file mode 100644 index 000000000..d6eaed819 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.framework.jackson.core.databind; + +import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; + +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; + +public class LocalTimeSerializable { + // TODO: 2022/11/15 修改名称 + + public static final LocalTimeSerializer INSTANCE = new LocalTimeSerializer(DateTimeFormatter + .ofPattern(FORMAT_HOUR_MINUTE_SECOND) + .withZone(ZoneId.systemDefault())); + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index b6ac66757..4f25810d3 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -47,5 +47,5 @@ public interface ErrorCodeConstants { // ========== 秒杀活动 1003008000 ========== ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1003008000, "秒杀活动不存在"); - + ErrorCode SECKILL_TIME_NOT_EXISTS = new ErrorCode(1003008001, "秒杀时段不存在"); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java new file mode 100644 index 000000000..1f66fb1c6 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java @@ -0,0 +1,99 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.annotations.*; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; +import cn.iocoder.yudao.module.promotion.convert.seckilltime.SeckillTimeConvert; +import cn.iocoder.yudao.module.promotion.service.seckilltime.SeckillTimeService; + +@Api(tags = "管理后台 - 秒杀时段") +@RestController +@RequestMapping("/promotion/seckill-time") +@Validated +public class SeckillTimeController { + + @Resource + private SeckillTimeService seckillTimeService; + + @PostMapping("/create") + @ApiOperation("创建秒杀时段") + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:create')") + public CommonResult createSeckillTime(@Valid @RequestBody SeckillTimeCreateReqVO createReqVO) { + return success(seckillTimeService.createSeckillTime(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新秒杀时段") + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:update')") + public CommonResult updateSeckillTime(@Valid @RequestBody SeckillTimeUpdateReqVO updateReqVO) { + seckillTimeService.updateSeckillTime(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除秒杀时段") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:delete')") + public CommonResult deleteSeckillTime(@RequestParam("id") Long id) { + seckillTimeService.deleteSeckillTime(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得秒杀时段") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") + public CommonResult getSeckillTime(@RequestParam("id") Long id) { + SeckillTimeDO seckillTime = seckillTimeService.getSeckillTime(id); + return success(SeckillTimeConvert.INSTANCE.convert(seckillTime)); + } + + @GetMapping("/list") + @ApiOperation("获得所有秒杀时段列表") +// @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") + public CommonResult> getSeckillTimeList() { + List list = seckillTimeService.getSeckillTimeList(); + return success(SeckillTimeConvert.INSTANCE.convertList(list)); + } + +// @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)); +// } + + @GetMapping("/export-excel") + @ApiOperation("导出秒杀时段 Excel") + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:export')") + @OperateLog(type = EXPORT) + public void exportSeckillTimeExcel(@Valid SeckillTimeExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = seckillTimeService.getSeckillTimeList(exportReqVO); + // 导出 Excel + List datas = SeckillTimeConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "秒杀时段.xls", "数据", SeckillTimeExcelVO.class, datas); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeBaseVO.java new file mode 100644 index 000000000..5d9e3e2b4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeBaseVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +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 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class SeckillTimeBaseVO { + + @ApiModelProperty(value = "秒杀时段名称", required = true) + @NotNull(message = "秒杀时段名称不能为空") + private String name; + + @ApiModelProperty(value = "开始时间点", required = true) + @NotNull(message = "开始时间点不能为空") + private LocalTime startTime; + + @ApiModelProperty(value = "结束时间点", required = true) + @NotNull(message = "结束时间点不能为空") + private LocalTime endTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeCreateReqVO.java new file mode 100644 index 000000000..f69d5ab8c --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 秒杀时段创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillTimeCreateReqVO extends SeckillTimeBaseVO { + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java new file mode 100644 index 000000000..4b7f436da --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +import lombok.*; + +import java.time.LocalTime; +import java.util.*; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 秒杀时段 Excel VO + * + * @author 芋道源码 + */ +@Data +public class SeckillTimeExcelVO { + + @ExcelProperty("编号") + private Long id; + + @ExcelProperty("秒杀时段名称") + private String name; + + @ExcelProperty("开始时间点") + private LocalTime startTime; + + @ExcelProperty("结束时间点") + private LocalTime endTime; + + @ExcelProperty("商品数量") + private Integer productCount; + + @ExcelProperty("创建时间") + private Date createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java new file mode 100644 index 000000000..f364db21d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +import lombok.*; + +import java.time.LocalTime; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "管理后台 - 秒杀时段 Excel 导出 Request VO", description = "参数和 SeckillTimePageReqVO 是一致的") +@Data +public class SeckillTimeExportReqVO { + + @ApiModelProperty(value = "秒杀时段名称") + private String name; + + @ApiModelProperty(value = "开始时间点") + private LocalTime[] startTime; + + @ApiModelProperty(value = "结束时间点") + 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/seckilltime/vo/SeckillTimePageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimePageReqVO.java new file mode 100644 index 000000000..6fe13e0ed --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimePageReqVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalTime; + +@ApiModel("管理后台 - 秒杀时段分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillTimePageReqVO extends PageParam { + + @ApiModelProperty(value = "秒杀时段名称") + private String name; + + @ApiModelProperty(value = "开始时间点") + @DateTimeFormat(pattern = "HH:mm:ss") + private LocalTime startTime; + + @ApiModelProperty(value = "结束时间点") + @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/seckilltime/vo/SeckillTimeRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeRespVO.java new file mode 100644 index 000000000..09c01da55 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 秒杀时段 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillTimeRespVO extends SeckillTimeBaseVO { + + @ApiModelProperty(value = "编号", required = true) + private Long id; + + @ApiModelProperty(value = "商品数量", required = true) + private Integer productCount; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeSimpleRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeSimpleRespVO.java new file mode 100644 index 000000000..ae8288a26 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeSimpleRespVO.java @@ -0,0 +1,4 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +public class SeckillTimeSimpleRespVO { +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeUpdateReqVO.java new file mode 100644 index 000000000..84a5f0204 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeUpdateReqVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@ApiModel("管理后台 - 秒杀时段更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillTimeUpdateReqVO extends SeckillTimeBaseVO { + + @ApiModelProperty(value = "编号", required = true) + @NotNull(message = "编号不能为空") + private Long id; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java new file mode 100644 index 000000000..a983485e5 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.promotion.convert.seckilltime; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; + +/** + * 秒杀时段 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface SeckillTimeConvert { + + SeckillTimeConvert INSTANCE = Mappers.getMapper(SeckillTimeConvert.class); + + SeckillTimeDO convert(SeckillTimeCreateReqVO bean); + + SeckillTimeDO convert(SeckillTimeUpdateReqVO bean); + + SeckillTimeRespVO convert(SeckillTimeDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java new file mode 100644 index 000000000..4e06151d5 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime; + +import lombok.*; + +import java.time.LocalTime; +import java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 秒杀时段 DO + * + * @author 芋道源码 + */ +@TableName("promotion_seckill_time") +@KeySequence("promotion_seckill_time_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SeckillTimeDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 秒杀时段名称 + */ + private String name; + /** + * 开始时间点 + */ + private LocalTime startTime; + /** + * 结束时间点 + */ + private LocalTime endTime; + /** + * 商品数量 + */ + private Integer productCount; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java new file mode 100644 index 000000000..d9a902c01 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; + +/** + * 秒杀时段 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface SeckillTimeMapper extends BaseMapperX { + +// default PageResult selectPage(SeckillTimePageReqVO reqVO) { +// return selectPage(reqVO, new LambdaQueryWrapperX() +// .likeIfPresent(SeckillTimeDO::getName, reqVO.getName()) +// .geIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) +// .leIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) +//// .betweenIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) +//// .betweenIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) +//// .betweenIfPresent(SeckillTimeDO::getCreateTime, reqVO.getCreateTime()) +// .orderByDesc(SeckillTimeDO::getId)); +// } + + default List selectList(SeckillTimeExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(SeckillTimeDO::getName, reqVO.getName()) + .betweenIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) + .betweenIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) + .betweenIfPresent(SeckillTimeDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SeckillTimeDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java new file mode 100644 index 000000000..5c5011dd0 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java @@ -0,0 +1,69 @@ +package cn.iocoder.yudao.module.promotion.service.seckilltime; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 秒杀时段 Service 接口 + * + * @author 芋道源码 + */ +public interface SeckillTimeService { + + /** + * 创建秒杀时段 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createSeckillTime(@Valid SeckillTimeCreateReqVO createReqVO); + + /** + * 更新秒杀时段 + * + * @param updateReqVO 更新信息 + */ + void updateSeckillTime(@Valid SeckillTimeUpdateReqVO updateReqVO); + + /** + * 删除秒杀时段 + * + * @param id 编号 + */ + void deleteSeckillTime(Long id); + + /** + * 获得秒杀时段 + * + * @param id 编号 + * @return 秒杀时段 + */ + SeckillTimeDO getSeckillTime(Long id); + + /** + * 获得所有秒杀时段列表 + * + * @return 所有秒杀时段列表 + */ + List getSeckillTimeList(); + +// /** +// * 获得秒杀时段分页 +// * +// * @param pageReqVO 分页查询 +// * @return 秒杀时段分页 +// */ +// PageResult getSeckillTimePage(SeckillTimePageReqVO pageReqVO); + + /** + * 获得秒杀时段列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 秒杀时段列表 + */ + List getSeckillTimeList(SeckillTimeExportReqVO exportReqVO); + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java new file mode 100644 index 000000000..de4becc15 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.promotion.service.seckilltime; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.promotion.convert.seckilltime.SeckillTimeConvert; +import cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime.SeckillTimeMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; + +/** + * 秒杀时段 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class SeckillTimeServiceImpl implements SeckillTimeService { + + @Resource + private SeckillTimeMapper seckillTimeMapper; + + @Override + public Long createSeckillTime(SeckillTimeCreateReqVO createReqVO) { + // 插入 + SeckillTimeDO seckillTime = SeckillTimeConvert.INSTANCE.convert(createReqVO); + seckillTimeMapper.insert(seckillTime); + // 返回 + return seckillTime.getId(); + } + + @Override + public void updateSeckillTime(SeckillTimeUpdateReqVO updateReqVO) { + // 校验存在 + this.validateSeckillTimeExists(updateReqVO.getId()); + // 更新 + SeckillTimeDO updateObj = SeckillTimeConvert.INSTANCE.convert(updateReqVO); + seckillTimeMapper.updateById(updateObj); + } + + @Override + public void deleteSeckillTime(Long id) { + // 校验存在 + this.validateSeckillTimeExists(id); + // 删除 + seckillTimeMapper.deleteById(id); + } + + private void validateSeckillTimeExists(Long id) { + if (seckillTimeMapper.selectById(id) == null) { + throw exception(SECKILL_TIME_NOT_EXISTS); + } + } + + @Override + public SeckillTimeDO getSeckillTime(Long id) { + return seckillTimeMapper.selectById(id); + } + + @Override + public List getSeckillTimeList() { + return seckillTimeMapper.selectList(); + } + +// @Override +// public PageResult getSeckillTimePage(SeckillTimePageReqVO pageReqVO) { +// return seckillTimeMapper.selectPage(pageReqVO); +// } + + @Override + public List getSeckillTimeList(SeckillTimeExportReqVO exportReqVO) { + return seckillTimeMapper.selectList(exportReqVO); + } + +} 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 new file mode 100644 index 000000000..eef757f86 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml @@ -0,0 +1,12 @@ + + + + + + + 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 new file mode 100644 index 000000000..d5379212d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImplTest.java @@ -0,0 +1,196 @@ +package cn.iocoder.yudao.module.promotion.service.seckilltime; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime.SeckillTimeMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; + +import java.time.LocalTime; +import java.util.*; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** +* {@link SeckillTimeServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(SeckillTimeServiceImpl.class) +public class SeckillTimeServiceImplTest extends BaseDbUnitTest { + + @Resource + private SeckillTimeServiceImpl seckillTimeService; + + @Resource + private SeckillTimeMapper seckillTimeMapper; + + @Resource + private ObjectMapper objectMapper; + + @Test + public void testJacksonSerializ(){ + + // 准备参数 + SeckillTimeCreateReqVO reqVO = randomPojo(SeckillTimeCreateReqVO.class); +// ObjectMapper objectMapper = new ObjectMapper(); + try { + String string = objectMapper.writeValueAsString(reqVO); + System.out.println(string); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + + } + + @Test + public void testCreateSeckillTime_success() { + // 准备参数 + SeckillTimeCreateReqVO reqVO = randomPojo(SeckillTimeCreateReqVO.class); + + // 调用 + Long seckillTimeId = seckillTimeService.createSeckillTime(reqVO); + // 断言 + assertNotNull(seckillTimeId); + // 校验记录的属性是否正确 + SeckillTimeDO seckillTime = seckillTimeMapper.selectById(seckillTimeId); + assertPojoEquals(reqVO, seckillTime); + } + + @Test + public void testUpdateSeckillTime_success() { + // mock 数据 + SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class); + seckillTimeMapper.insert(dbSeckillTime);// @Sql: 先插入出一条存在的数据 + // 准备参数 + SeckillTimeUpdateReqVO reqVO = randomPojo(SeckillTimeUpdateReqVO.class, o -> { + o.setId(dbSeckillTime.getId()); // 设置更新的 ID + }); + + // 调用 + seckillTimeService.updateSeckillTime(reqVO); + // 校验是否更新正确 + SeckillTimeDO seckillTime = seckillTimeMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, seckillTime); + } + + @Test + public void testUpdateSeckillTime_notExists() { + // 准备参数 + SeckillTimeUpdateReqVO reqVO = randomPojo(SeckillTimeUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> seckillTimeService.updateSeckillTime(reqVO), SECKILL_TIME_NOT_EXISTS); + } + + @Test + public void testDeleteSeckillTime_success() { + // mock 数据 + SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class); + seckillTimeMapper.insert(dbSeckillTime);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbSeckillTime.getId(); + + // 调用 + seckillTimeService.deleteSeckillTime(id); + // 校验数据不存在了 + assertNull(seckillTimeMapper.selectById(id)); + } + + @Test + public void testDeleteSeckillTime_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> seckillTimeService.deleteSeckillTime(id), SECKILL_TIME_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSeckillTimePage() { + // mock 数据 +// SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class, o -> { // 等会查询到 +// o.setName(null); +// o.setStartTime(null); +// o.setEndTime(null); +// o.setCreateTime(null); +// }); +// seckillTimeMapper.insert(dbSeckillTime); +// // 测试 name 不匹配 +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setName(null))); +// // 测试 startTime 不匹配 +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setStartTime(null))); +// // 测试 endTime 不匹配 +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setEndTime(null))); +// // 测试 createTime 不匹配 +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setCreateTime(null))); +// // 准备参数 +// SeckillTimePageReqVO reqVO = new SeckillTimePageReqVO(); +// reqVO.setName(null); +//// reqVO.setStartTime((new LocalTime())); +//// reqVO.setEndTime((new LocalTime[]{})); +//// reqVO.setCreateTime((new Date[]{})); +// +// // 调用 +// PageResult pageResult = seckillTimeService.getSeckillTimePage(reqVO); +// // 断言 +// assertEquals(1, pageResult.getTotal()); +// assertEquals(1, pageResult.getList().size()); +// assertPojoEquals(dbSeckillTime, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSeckillTimeList() { + // mock 数据 + SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class, o -> { // 等会查询到 + o.setName(null); + o.setStartTime(null); + o.setEndTime(null); + o.setCreateTime(null); + }); + seckillTimeMapper.insert(dbSeckillTime); + // 测试 name 不匹配 + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setName(null))); + // 测试 startTime 不匹配 + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setStartTime(null))); + // 测试 endTime 不匹配 + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setEndTime(null))); + // 测试 createTime 不匹配 + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setCreateTime(null))); + // 准备参数 + SeckillTimeExportReqVO reqVO = new SeckillTimeExportReqVO(); + reqVO.setName(null); + reqVO.setStartTime((new LocalTime[]{})); + reqVO.setEndTime((new LocalTime[]{})); + reqVO.setCreateTime((new Date[]{})); + + // 调用 + List list = seckillTimeService.getSeckillTimeList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbSeckillTime, list.get(0)); + } + +} diff --git a/yudao-ui-admin/src/api/promotion/seckillTime.js b/yudao-ui-admin/src/api/promotion/seckillTime.js new file mode 100644 index 000000000..ae3c8a8ca --- /dev/null +++ b/yudao-ui-admin/src/api/promotion/seckillTime.js @@ -0,0 +1,62 @@ +import request from '@/utils/request' + +// 创建秒杀时段 +export function createSeckillTime(data) { + return request({ + url: '/promotion/seckill-time/create', + method: 'post', + data: data + }) +} + +// 更新秒杀时段 +export function updateSeckillTime(data) { + return request({ + url: '/promotion/seckill-time/update', + method: 'put', + data: data + }) +} + +// 删除秒杀时段 +export function deleteSeckillTime(id) { + return request({ + url: '/promotion/seckill-time/delete?id=' + id, + method: 'delete' + }) +} + +// 获得秒杀时段 +export function getSeckillTime(id) { + return request({ + url: '/promotion/seckill-time/get?id=' + id, + method: 'get' + }) +} + +// 获得秒杀时段分页 +export function getSeckillTimePage(query) { + return request({ + url: '/promotion/seckill-time/page', + method: 'get', + params: query + }) +} + +// 获取所有的秒杀时段 +export function getSeckillTimeList() { + return request({ + url: '/promotion/seckill-time/list', + method: 'get' + }) +} + +// 导出秒杀时段 Excel +export function exportSeckillTimeExcel(query) { + return request({ + url: '/promotion/seckill-time/export-excel', + method: 'get', + params: query, + responseType: 'blob' + }) +} diff --git a/yudao-ui-admin/src/views/promotion/seckillTime/index.vue b/yudao-ui-admin/src/views/promotion/seckillTime/index.vue new file mode 100644 index 000000000..c41dba309 --- /dev/null +++ b/yudao-ui-admin/src/views/promotion/seckillTime/index.vue @@ -0,0 +1,243 @@ + + + From 7bc1ae5f35e3e095a0950020658772421b701cc8 Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Mon, 28 Nov 2022 20:45:54 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 5 + .../SeckillActivityController.java | 65 ++++---- .../vo/SeckillActivityBaseVO.java | 53 +++++-- .../vo/SeckillActivityCreateReqVO.java | 24 ++- .../vo/SeckillActivityDetailRespVO.java | 21 +++ .../vo/SeckillActivityExcelVO.java | 46 ------ .../vo/SeckillActivityExportReqVO.java | 28 ---- .../vo/SeckillActivityPageReqVO.java | 15 +- .../vo/SeckillActivityRespVO.java | 21 ++- .../vo/SeckillActivityUpdateReqVO.java | 21 ++- .../SeckillActivityConvert.java | 55 ++++++- .../seckillactivity/SeckillActivityDO.java | 18 ++- .../seckillactivity/SeckillProductDO.java | 60 ++++++++ .../SeckillActivityMapper.java | 20 +-- .../seckillactivity/SeckillProductMapper.java | 21 +++ .../SeckillActivityService.java | 17 +- .../SeckillActivityServiceImpl.java | 145 +++++++++++++++--- .../SeckillActivityServiceImplTest.java | 56 ++++--- .../src/api/promotion/seckillActivity.js | 18 +-- 19 files changed, 473 insertions(+), 236 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityDetailRespVO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillProductDO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillProductMapper.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 4f25810d3..5e21b568c 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -48,4 +48,9 @@ public interface ErrorCodeConstants { // ========== 秒杀活动 1003008000 ========== ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1003008000, "秒杀活动不存在"); ErrorCode SECKILL_TIME_NOT_EXISTS = new ErrorCode(1003008001, "秒杀时段不存在"); + ErrorCode SECKILL_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1003008001, "存在商品参加了其它秒杀活动"); + ErrorCode SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1003006002, "秒杀活动已关闭,不能修改"); + ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED = new ErrorCode(1003006003, "秒杀活动未关闭,不能删除"); + ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1003006004, "秒杀活动已关闭,不能重复关闭"); + ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_END = new ErrorCode(1003006004, "秒杀活动已结束,不能关闭"); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java index 419ae8e61..a6434a501 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java @@ -1,35 +1,26 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; +import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillProductDO; +import cn.iocoder.yudao.module.promotion.service.seckillactivity.SeckillActivityService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; - -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.annotations.*; - -import javax.validation.constraints.*; -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; - -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - -import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; -import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; -import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert; -import cn.iocoder.yudao.module.promotion.service.seckillactivity.SeckillActivityService; - @Api(tags = "管理后台 - 秒杀活动") @RestController @RequestMapping("/promotion/seckill-activity") @@ -54,6 +45,15 @@ public class SeckillActivityController { return success(true); } + @PutMapping("/close") + @ApiOperation("关闭秒杀活动") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:close')") + public CommonResult closeSeckillActivity(@RequestParam("id") Long id) { + seckillActivityService.closeSeckillActivity(id); + return success(true); + } + @DeleteMapping("/delete") @ApiOperation("删除秒杀活动") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @@ -67,12 +67,13 @@ public class SeckillActivityController { @ApiOperation("获得秒杀活动") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") - public CommonResult getSeckillActivity(@RequestParam("id") Long id) { + public CommonResult getSeckillActivity(@RequestParam("id") Long id) { SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id); if (seckillActivity == null) { return success(null); } - return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity)); + List seckillProducts = seckillActivityService.getSeckillProductListByActivityId(id); + return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity,seckillProducts)); } @GetMapping("/list") @@ -92,16 +93,4 @@ public class SeckillActivityController { return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult)); } - @GetMapping("/export-excel") - @ApiOperation("导出秒杀活动 Excel") - @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:export')") - @OperateLog(type = EXPORT) - public void exportSeckillActivityExcel(@Valid SeckillActivityExportReqVO exportReqVO, - HttpServletResponse response) throws IOException { - List list = seckillActivityService.getSeckillActivityList(exportReqVO); - // 导出 Excel - List datas = SeckillActivityConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "秒杀活动.xls", "数据", SeckillActivityExcelVO.class, datas); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java index 88f0d2cc7..62ed1fa2d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityBaseVO.java @@ -1,13 +1,17 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; -import lombok.*; -import java.util.*; -import java.math.BigDecimal; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; /** * 秒杀活动 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -20,22 +24,43 @@ public class SeckillActivityBaseVO { @NotNull(message = "秒杀活动名称不能为空") private String name; - @ApiModelProperty(value = "活动状态", required = true, example = "进行中") - @NotNull(message = "活动状态不能为空") - private Integer status; - @ApiModelProperty(value = "活动开始时间", required = true) @NotNull(message = "活动开始时间不能为空") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private Date startTime; + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) + private LocalDateTime startTime; @ApiModelProperty(value = "活动结束时间", required = true) @NotNull(message = "活动结束时间不能为空") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private Date endTime; + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) + private LocalDateTime endTime; - @ApiModelProperty(value = "订单实付金额,单位:分", required = true) - @NotNull(message = "订单实付金额,单位:分不能为空") - private BigDecimal totalPrice; + + @ApiModel("商品") + @Data + public static class Product { + + @ApiModelProperty(value = "商品 SPU 编号", required = true, example = "1") + @NotNull(message = "商品 SPU 编号不能为空") + private Long spuId; + + @ApiModelProperty(value = "商品 SKU 编号", required = true, example = "1") + @NotNull(message = "商品 SKU 编号不能为空") + private Long skuId; + + @ApiModelProperty(value = "秒杀金额", required = true, example = "12.00") + @NotNull(message = "秒杀金额不能为空") + private Integer seckillPrice; + + @ApiModelProperty(value = "秒杀库存", example = "80") + @Min(value = 0, message = "秒杀库存需要大于等于 0") + private Integer stock; + + @ApiModelProperty(value = "每人限购", example = "10", notes = "如果为0则不限购") + @Min(value = 0, message = "每人限购需要大于等于 0") + private Integer limitBuyCount; + + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java index e397bd57c..2cd21af9e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java @@ -1,9 +1,16 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +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; @ApiModel("管理后台 - 秒杀活动创建 Request VO") @Data @@ -19,7 +26,14 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO { private Integer sort; @ApiModelProperty(value = "秒杀时段id", required = true) - @NotNull(message = "秒杀时段id不能为空") + @NotBlank(message = "参与场次不能为空") private String timeId; + /** + * 商品列表 + */ + @NotEmpty(message = "商品列表不能为空") + @Valid + private List products; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityDetailRespVO.java new file mode 100644 index 000000000..97da65df8 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityDetailRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.List; + +@ApiModel("管理后台 - 秒杀活动的详细 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SeckillActivityDetailRespVO extends SeckillActivityRespVO{ + + /** + * 商品列表 + */ + private List products; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java deleted file mode 100644 index ea0d5f49f..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExcelVO.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; - -import lombok.*; -import java.util.*; -import java.math.BigDecimal; -import io.swagger.annotations.*; - -import com.alibaba.excel.annotation.ExcelProperty; -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; - - -/** - * 秒杀活动 Excel VO - * - * @author 芋道源码 - */ -@Data -public class SeckillActivityExcelVO { - - @ExcelProperty("秒杀活动名称") - private String name; - - @ExcelProperty(value = "活动状态", converter = DictConvert.class) - @DictFormat("promotion_activity_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 - private Integer status; - - @ExcelProperty("活动开始时间") - private Date startTime; - - @ExcelProperty("活动结束时间") - private Date endTime; - - @ExcelProperty("付款订单数") - private Integer orderCount; - - @ExcelProperty("付款人数") - private Integer userCount; - - @ExcelProperty("订单实付金额,单位:分") - private BigDecimal totalPrice; - - @ExcelProperty("创建时间") - private Date createTime; - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java deleted file mode 100644 index e8a5e459b..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@ApiModel(value = "管理后台 - 秒杀活动 Excel 导出 Request VO", description = "参数和 SeckillActivityPageReqVO 是一致的") -@Data -public class SeckillActivityExportReqVO { - - @ApiModelProperty(value = "秒杀活动名称", example = "晚九点限时秒杀") - private String name; - - @ApiModelProperty(value = "活动状态", example = "进行中") - private Integer status; - - @ApiModelProperty(value = "秒杀时段id") - private String timeId; - - @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/seckillactivity/vo/SeckillActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java index ebfb9bb2a..102877d2b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java @@ -1,12 +1,18 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; @ApiModel("管理后台 - 秒杀活动分页 Request VO") @Data @@ -25,6 +31,7 @@ public class SeckillActivityPageReqVO extends PageParam { @ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private Date[] createTime; + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) + private LocalDateTime[] createTime; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java index 3e75f5c16..91db8565b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; -import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; @ApiModel("管理后台 - 秒杀活动 Response VO") @Data @@ -22,9 +24,18 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { private Integer userCount; @ApiModelProperty(value = "创建时间", required = true) - private Date createTime; + private LocalDateTime createTime; @ApiModelProperty(value = "秒杀时段id", required = true) private String timeId; + @ApiModelProperty(value = "排序", required = true) + private Integer sort; + + @ApiModelProperty(value = "备注", example = "限时秒杀活动") + private String remark; + + @ApiModelProperty(value = "活动状态", example = "进行中") + private Integer status; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java index f75a5294a..d8471594c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java @@ -1,9 +1,15 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; @ApiModel("管理后台 - 秒杀活动更新 Request VO") @Data @@ -26,4 +32,11 @@ public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO { @NotNull(message = "秒杀时段id不能为空") private String timeId; + /** + * 商品列表 + */ + @NotEmpty(message = "商品列表不能为空") + @Valid + private List products; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java index 8e416aef4..90db545c2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckillactivity/SeckillActivityConvert.java @@ -1,13 +1,16 @@ package cn.iocoder.yudao.module.promotion.convert.seckillactivity; -import java.util.*; - +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillProductDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; /** * 秒杀活动 Convert @@ -19,8 +22,15 @@ public interface SeckillActivityConvert { SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class); + SeckillProductDO convert(SeckillActivityBaseVO.Product product); + + SeckillActivityDO convert(SeckillActivityCreateReqVO bean); + default String map(Long[] value){ + return value.toString(); + } + SeckillActivityDO convert(SeckillActivityUpdateReqVO bean); SeckillActivityRespVO convert(SeckillActivityDO bean); @@ -29,6 +39,39 @@ public interface SeckillActivityConvert { PageResult convertPage(PageResult page); - List convertList02(List list); + @Mappings({@Mapping(target = "products",source = "seckillProducts")}) + SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity,List seckillProducts); + + /** + * 比较两个秒杀商品对象是否相等 + * + * @param productDO 数据库中的商品 + * @param productVO 前端传入的商品 + * @return 是否匹配 + */ + default boolean isEquals(SeckillProductDO productDO, SeckillActivityBaseVO.Product productVO) { + return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId()) + && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) + && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()) + && ObjectUtil.equals(productDO.getStock(), productVO.getStock()) + && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); + + } + + /** + * 比较两个秒杀商品对象是否相等 + * + * @param productDO 商品1 + * @param productVO 商品2 + * @return 是否匹配 + */ + default boolean isEquals(SeckillProductDO productDO, SeckillProductDO productVO) { + return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId()) + && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) + && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()) + && ObjectUtil.equals(productDO.getStock(), productVO.getStock()) + && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); + + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java index 69edb1ff6..2ff3b1b4c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java @@ -1,10 +1,14 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity; -import lombok.*; -import java.util.*; -import java.math.BigDecimal; -import com.baomidou.mybatisplus.annotation.*; 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 cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; +import lombok.*; + +import java.math.BigDecimal; +import java.time.LocalDateTime; /** * 秒杀活动 DO @@ -33,7 +37,7 @@ public class SeckillActivityDO extends BaseDO { /** * 活动状态 * - * 枚举 {@link TODO promotion_activity_status 对应的类} + * 枚举 {@link PromotionActivityStatusEnum 对应的类} */ private Integer status; /** @@ -43,11 +47,11 @@ public class SeckillActivityDO extends BaseDO { /** * 活动开始时间 */ - private Date startTime; + private LocalDateTime startTime; /** * 活动结束时间 */ - private Date endTime; + private LocalDateTime endTime; /** * 排序 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillProductDO.java new file mode 100644 index 000000000..e6e8f6a9f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillProductDO.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.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 lombok.Data; + +/** + * 秒杀参与商品 + * @TableName promotion_seckill_product + */ +@TableName(value ="promotion_seckill_product") +@Data +public class SeckillProductDO extends BaseDO { + /** + * 秒杀参与商品编号 + */ + @TableId(type = IdType.AUTO) + private Long id; + + /** + * 秒杀活动id + */ + private Long activityId; + + /** + * 秒杀时段id + */ + private Long timeId; + + /** + * 商品id + */ + private Long spuId; + + /** + * 商品sku_id + */ + private Long skuId; + + /** + * 秒杀金额 + */ + private Integer seckillPrice; + + /** + * 秒杀库存 + */ + private Integer stock; + + /** + * 每人限购 + */ + private Integer limitBuyCount; +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java index 6b3319361..12cc179b3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillActivityMapper.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity; -import java.util.*; - import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 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.seckillactivity.vo.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; /** * 秒杀活动 Mapper @@ -16,21 +14,13 @@ import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; */ @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()) - .eqIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId()) - .betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(SeckillActivityDO::getId)); - } - - default List selectList(SeckillActivityExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(SeckillActivityDO::getName, reqVO.getName()) - .eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus()) - .eqIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId()) + .likeIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId()) +// .like(StringUtils.hasText(reqVO.getTimeId()),SeckillActivityDO::getTimeId, reqVO.getTimeId() + ",") .betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(SeckillActivityDO::getId)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillProductMapper.java new file mode 100644 index 000000000..d1d609982 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckillactivity/SeckillProductMapper.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillProductDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.Collection; +import java.util.List; + +@Mapper +public interface SeckillProductMapper extends BaseMapperX { + + default List selectListByActivityId(Long id){ + return selectList(SeckillProductDO::getActivityId,id); + } + + 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/service/seckillactivity/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityService.java index 6ff337fe4..1b3060d52 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityService.java @@ -5,6 +5,7 @@ import javax.validation.*; import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillProductDO; /** * 秒杀活动 Service 接口 @@ -28,6 +29,12 @@ public interface SeckillActivityService { */ void updateSeckillActivity(@Valid SeckillActivityUpdateReqVO updateReqVO); + /** + * 关闭秒杀活动 + * @param id 编号 + */ + void closeSeckillActivity(Long id); + /** * 删除秒杀活动 * @@ -60,11 +67,9 @@ public interface SeckillActivityService { PageResult getSeckillActivityPage(SeckillActivityPageReqVO pageReqVO); /** - * 获得秒杀活动列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 秒杀活动列表 + * 通过活动编号获取活动商品 + * @param id 活动编号 + * @return 活动商品列表 */ - List getSeckillActivityList(SeckillActivityExportReqVO exportReqVO); - + List getSeckillProductListByActivityId(Long id); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java index 9e23e0e29..63c1bd13d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java @@ -1,19 +1,29 @@ package cn.iocoder.yudao.module.promotion.service.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.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityBaseVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillProductDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper; +import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillProductMapper; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; +import cn.iocoder.yudao.module.promotion.util.PromotionUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; -import java.util.*; -import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; -import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert; -import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper; +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; +import static java.util.Arrays.asList; /** * 秒杀活动 Service 实现类 @@ -27,11 +37,24 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Resource private SeckillActivityMapper seckillActivityMapper; + @Resource + private SeckillProductMapper seckillProductMapper; + @Override public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { - // 插入 - SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO); +// validateSeckillActivityProductConflicts(null,createReqVO.getProducts()); + List statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); + // 校验商品是否冲突 + validateSeckillActivityProductConflicts(null, createReqVO.getProducts()); + // 插入秒杀活动 + SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO) + .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime()));; seckillActivityMapper.insert(seckillActivity); + + // 插入商品 + List productDOS = CollectionUtils.convertList(createReqVO.getProducts(), + product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(seckillActivity.getId())); + seckillProductMapper.insertBatch(productDOS); // 返回 return seckillActivity.getId(); } @@ -39,24 +62,110 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override public void updateSeckillActivity(SeckillActivityUpdateReqVO updateReqVO) { // 校验存在 - this.validateSeckillActivityExists(updateReqVO.getId()); - // 更新 - SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO); + SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(updateReqVO.getId()); + if (PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { + throw exception(SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); + } + List statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); + // 校验商品是否冲突 + validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); + // 更新活动 + SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) + .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getStartTime(), updateReqVO.getEndTime())); seckillActivityMapper.updateById(updateObj); + // 更新商品 + updateSeckillProduct(updateReqVO); + } + + /** + * 更新秒杀商品 + */ + private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { + List seckillProductDOS = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); + List products = updateReqVO.getProducts(); + //对后台查出的数据和前台查出的数据进行遍历, + //1.对前台数据进行遍历:如果不存在于后台的sku中需要新增 + //2.对后台数据进行遍历:如果不存在于前台的sku中需要删除 + //计算需要删除的数据 + List deleteIds = CollectionUtils.convertList(seckillProductDOS, SeckillProductDO::getId, + seckillProductDO -> products.stream() + .noneMatch(product -> SeckillActivityConvert.INSTANCE.isEquals(seckillProductDO, product))); + if (CollUtil.isNotEmpty(deleteIds)) { + seckillProductMapper.deleteBatchIds(deleteIds); + } + //计算需要新增的数据 + List newSeckillProductDOs = CollectionUtils.convertList(products, + product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(updateReqVO.getId())); + newSeckillProductDOs.removeIf(product -> seckillProductDOS.stream() + .anyMatch(seckillProduct -> SeckillActivityConvert.INSTANCE.isEquals(seckillProduct, product))); + if (CollUtil.isNotEmpty(newSeckillProductDOs)) { + seckillProductMapper.insertBatch(newSeckillProductDOs); + } + } + + /** + * 校验商品是否冲突 + * + * @param id 秒杀活动编号 + * @param products 商品列表 + */ + public void validateSeckillActivityProductConflicts(Long id, List products) { + if (CollUtil.isEmpty(products)) { + return; + } + List seckillProductDOS = seckillProductMapper + .selectListBySkuIds(CollectionUtils.convertSet(products, SeckillActivityBaseVO.Product::getSkuId)); + if (CollUtil.isEmpty(seckillProductDOS)) { + return; + } + List seckillActivityDOS = seckillActivityMapper + .selectBatchIds(CollectionUtils.convertSet(seckillProductDOS, SeckillProductDO::getActivityId)); + if (id != null) {// 排除自己这个活动 + seckillActivityDOS.removeIf(item -> id.equals(item.getId())); + } + // 排除不满足status的活动 + List statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); + seckillActivityDOS.removeIf(item -> !statuses.contains(item.getStatus())); + //如果非空,则说明冲突 + if (CollUtil.isNotEmpty(seckillActivityDOS)) { + throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); + } + + } + + @Override + public void closeSeckillActivity(Long id) { + // 校验存在 + SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(id); + if (PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { + throw exception(SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED); + } + if (PromotionActivityStatusEnum.END.getStatus().equals(seckillActivity.getStatus())) { + throw exception(SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_END); + } + // 更新 + SeckillActivityDO updateObj = new SeckillActivityDO().setId(id).setStatus(PromotionActivityStatusEnum.CLOSE.getStatus()); + seckillActivityMapper.updateById(updateObj); + } @Override public void deleteSeckillActivity(Long id) { // 校验存在 - this.validateSeckillActivityExists(id); + SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(id); + if (!PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { + throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED); + } // 删除 seckillActivityMapper.deleteById(id); } - private void validateSeckillActivityExists(Long id) { - if (seckillActivityMapper.selectById(id) == null) { + private SeckillActivityDO validateSeckillActivityExists(Long id) { + SeckillActivityDO seckillActivity = seckillActivityMapper.selectById(id); + if (seckillActivity == null) { throw exception(SECKILL_ACTIVITY_NOT_EXISTS); } + return seckillActivity; } @Override @@ -75,8 +184,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { } @Override - public List getSeckillActivityList(SeckillActivityExportReqVO exportReqVO) { - return seckillActivityMapper.selectList(exportReqVO); + public List getSeckillProductListByActivityId(Long id) { + return seckillProductMapper.selectListByActivityId(id); } } 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 b95c8a0e4..2492fb0ac 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 @@ -1,30 +1,26 @@ package cn.iocoder.yudao.module.promotion.service.seckillactivity; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.mock.mockito.MockBean; - -import javax.annotation.Resource; - +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.seckillactivity.vo.*; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper; -import cn.iocoder.yudao.framework.common.pojo.PageResult; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import org.springframework.context.annotation.Import; -import java.util.*; +import java.time.LocalDateTime; -import static cn.hutool.core.util.RandomUtil.*; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; /** * {@link SeckillActivityServiceImpl} 的单元测试类 @@ -127,7 +123,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { reqVO.setName(null); reqVO.setStatus(null); reqVO.setTimeId(null); - reqVO.setCreateTime((new Date[]{})); + reqVO.setCreateTime((new LocalDateTime[]{})); // 调用 PageResult pageResult = seckillActivityService.getSeckillActivityPage(reqVO); @@ -157,17 +153,17 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { // 测试 createTime 不匹配 seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); // 准备参数 - SeckillActivityExportReqVO reqVO = new SeckillActivityExportReqVO(); - reqVO.setName(null); - reqVO.setStatus(null); - reqVO.setTimeId(null); - reqVO.setCreateTime((new Date[]{})); - - // 调用 - List list = seckillActivityService.getSeckillActivityList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbSeckillActivity, list.get(0)); +// SeckillActivityExportReqVO reqVO = new SeckillActivityExportReqVO(); +// reqVO.setName(null); +// reqVO.setStatus(null); +// reqVO.setTimeId(null); +// reqVO.setCreateTime((new Date[]{})); +// +// // 调用 +// List list = seckillActivityService.getSeckillActivityList(reqVO); +// // 断言 +// assertEquals(1, list.size()); +// assertPojoEquals(dbSeckillActivity, list.get(0)); } } diff --git a/yudao-ui-admin/src/api/promotion/seckillActivity.js b/yudao-ui-admin/src/api/promotion/seckillActivity.js index 9b74081c0..fa67a739c 100644 --- a/yudao-ui-admin/src/api/promotion/seckillActivity.js +++ b/yudao-ui-admin/src/api/promotion/seckillActivity.js @@ -18,6 +18,14 @@ export function updateSeckillActivity(data) { }) } +// 关闭限时折扣活动 +export function closeSeckillActivity(id) { + return request({ + url: '/promotion/seckill-activity/close?id=' + id, + method: 'put' + }) +} + // 删除秒杀活动 export function deleteSeckillActivity(id) { return request({ @@ -42,13 +50,3 @@ export function getSeckillActivityPage(query) { params: query }) } - -// 导出秒杀活动 Excel -export function exportSeckillActivityExcel(query) { - return request({ - url: '/promotion/seckill-activity/export-excel', - method: 'get', - params: query, - responseType: 'blob' - }) -} From 54baad165de937ac4853bd4470ca92205b62dd1d Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Mon, 28 Nov 2022 23:32:23 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=97=B6=E6=AE=B5?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=E6=AE=B5?= =?UTF-8?q?=E5=86=B2=E7=AA=81=E6=A0=A1=E9=AA=8C=E3=80=82=20=E7=A7=92?= =?UTF-8?q?=E6=9D=80=E6=B4=BB=E5=8A=A8=E6=96=B0=E5=A2=9E=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E5=88=A0=E9=99=A4=E6=97=B6=E5=AF=B9=E7=A7=92?= =?UTF-8?q?=E6=9D=80=E6=97=B6=E6=AE=B5=E7=9A=84=E7=A7=92=E6=9D=80=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E6=95=B0=E9=87=8F=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 16 ++++-- .../seckilltime/SeckillTimeController.java | 50 ++++++---------- .../seckilltime/vo/SeckillTimeExcelVO.java | 37 ------------ .../vo/SeckillTimeExportReqVO.java | 30 ---------- .../seckilltime/vo/SeckillTimeRespVO.java | 4 +- .../seckilltime/SeckillTimeConvert.java | 1 - .../dataobject/seckilltime/SeckillTimeDO.java | 11 ++-- .../mysql/seckilltime/SeckillTimeMapper.java | 57 +++++++++++++------ .../SeckillActivityServiceImpl.java | 48 +++++++++++++--- .../seckilltime/SeckillTimeService.java | 31 +++++----- .../seckilltime/SeckillTimeServiceImpl.java | 48 +++++++++++++--- .../SeckillTimeServiceImplTest.java | 22 +++---- .../src/views/promotion/seckillTime/index.vue | 2 +- 13 files changed, 181 insertions(+), 176 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 5e21b568c..47ce28b4b 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -47,10 +47,14 @@ public interface ErrorCodeConstants { // ========== 秒杀活动 1003008000 ========== ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1003008000, "秒杀活动不存在"); - ErrorCode SECKILL_TIME_NOT_EXISTS = new ErrorCode(1003008001, "秒杀时段不存在"); - ErrorCode SECKILL_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1003008001, "存在商品参加了其它秒杀活动"); - ErrorCode SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1003006002, "秒杀活动已关闭,不能修改"); - ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED = new ErrorCode(1003006003, "秒杀活动未关闭,不能删除"); - ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1003006004, "秒杀活动已关闭,不能重复关闭"); - ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_END = new ErrorCode(1003006004, "秒杀活动已结束,不能关闭"); + ErrorCode SECKILL_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1003008002, "存在商品参加了其它秒杀活动"); + ErrorCode SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1003008003, "秒杀活动已关闭,不能修改"); + ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1003008004, "秒杀活动未关闭或未结束,不能删除"); + ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1003008005, "秒杀活动已关闭,不能重复关闭"); + ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_END = new ErrorCode(1003008006, "秒杀活动已结束,不能关闭"); + + // ========== 秒杀时段 1003009000 ========== + ErrorCode SECKILL_TIME_NOT_EXISTS = new ErrorCode(1003009000, "秒杀时段不存在"); + ErrorCode SECKILL_TIME_CONFLICTS = new ErrorCode(1003009001, "秒杀时段冲突"); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java index 1f66fb1c6..96524c65d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java @@ -1,30 +1,24 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.annotations.*; - -import javax.validation.constraints.*; -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - -import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; -import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.SeckillTimeCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.SeckillTimeRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.seckilltime.SeckillTimeConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.service.seckilltime.SeckillTimeService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Api(tags = "管理后台 - 秒杀时段") @RestController @@ -84,16 +78,4 @@ public class SeckillTimeController { // return success(SeckillTimeConvert.INSTANCE.convertPage(pageResult)); // } - @GetMapping("/export-excel") - @ApiOperation("导出秒杀时段 Excel") - @PreAuthorize("@ss.hasPermission('promotion:seckill-time:export')") - @OperateLog(type = EXPORT) - public void exportSeckillTimeExcel(@Valid SeckillTimeExportReqVO exportReqVO, - HttpServletResponse response) throws IOException { - List list = seckillTimeService.getSeckillTimeList(exportReqVO); - // 导出 Excel - List datas = SeckillTimeConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "秒杀时段.xls", "数据", SeckillTimeExcelVO.class, datas); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java deleted file mode 100644 index 4b7f436da..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; - -import lombok.*; - -import java.time.LocalTime; -import java.util.*; -import io.swagger.annotations.*; - -import com.alibaba.excel.annotation.ExcelProperty; - -/** - * 秒杀时段 Excel VO - * - * @author 芋道源码 - */ -@Data -public class SeckillTimeExcelVO { - - @ExcelProperty("编号") - private Long id; - - @ExcelProperty("秒杀时段名称") - private String name; - - @ExcelProperty("开始时间点") - private LocalTime startTime; - - @ExcelProperty("结束时间点") - private LocalTime endTime; - - @ExcelProperty("商品数量") - private Integer productCount; - - @ExcelProperty("创建时间") - private Date createTime; - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java deleted file mode 100644 index f364db21d..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; - -import lombok.*; - -import java.time.LocalTime; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@ApiModel(value = "管理后台 - 秒杀时段 Excel 导出 Request VO", description = "参数和 SeckillTimePageReqVO 是一致的") -@Data -public class SeckillTimeExportReqVO { - - @ApiModelProperty(value = "秒杀时段名称") - private String name; - - @ApiModelProperty(value = "开始时间点") - private LocalTime[] startTime; - - @ApiModelProperty(value = "结束时间点") - 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/seckilltime/vo/SeckillTimeRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeRespVO.java index 09c01da55..b7b679a5d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeRespVO.java @@ -13,8 +13,8 @@ public class SeckillTimeRespVO extends SeckillTimeBaseVO { @ApiModelProperty(value = "编号", required = true) private Long id; - @ApiModelProperty(value = "商品数量", required = true) - private Integer productCount; + @ApiModelProperty(value = "秒杀活动数量", required = true) + private Integer seckillActivityCount; @ApiModelProperty(value = "创建时间", required = true) private Date createTime; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java index a983485e5..9c61206c7 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java @@ -29,5 +29,4 @@ public interface SeckillTimeConvert { PageResult convertPage(PageResult page); - List convertList02(List list); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java index 4e06151d5..b9f4d4bc0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java @@ -1,11 +1,12 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime; +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 java.time.LocalTime; -import java.util.*; -import com.baomidou.mybatisplus.annotation.*; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; /** * 秒杀时段 DO @@ -40,8 +41,8 @@ public class SeckillTimeDO extends BaseDO { */ private LocalTime endTime; /** - * 商品数量 + * 秒杀活动数量 */ - private Integer productCount; + private Integer seckillActivityCount; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java index d9a902c01..30af96a85 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java @@ -1,11 +1,17 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime; +import java.time.LocalTime; import java.util.*; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; +import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper; import org.apache.ibatis.annotations.Mapper; import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; @@ -16,25 +22,42 @@ import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; */ @Mapper public interface SeckillTimeMapper extends BaseMapperX { + default List selectListWithTime(LocalTime time){ + if (time == null) { + return Collections.emptyList(); + } + return selectList(new LambdaQueryWrapper() + .le(SeckillTimeDO::getStartTime,time) + .ge(SeckillTimeDO::getEndTime,time)); + } + + default List selectListWithTime(LocalTime startTime, LocalTime endTime){ + if (startTime == null && endTime == null) { + return Collections.emptyList(); + } + return selectList(new LambdaQueryWrapper() + .ge(SeckillTimeDO::getStartTime,startTime) + .le(SeckillTimeDO::getEndTime,endTime)); + } -// default PageResult selectPage(SeckillTimePageReqVO reqVO) { -// return selectPage(reqVO, new LambdaQueryWrapperX() -// .likeIfPresent(SeckillTimeDO::getName, reqVO.getName()) -// .geIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) -// .leIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) -//// .betweenIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) -//// .betweenIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) -//// .betweenIfPresent(SeckillTimeDO::getCreateTime, reqVO.getCreateTime()) -// .orderByDesc(SeckillTimeDO::getId)); -// } + default void sekillActivityCountAdd(List ids){ + if (CollUtil.isEmpty(ids)){ + return; + } + new LambdaUpdateChainWrapper(this) + .in(SeckillTimeDO::getId,ids) + .setSql("`seckill_activity_count` = `seckill_activity_count` + 1 ") + .update(); + } - default List selectList(SeckillTimeExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(SeckillTimeDO::getName, reqVO.getName()) - .betweenIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) - .betweenIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) - .betweenIfPresent(SeckillTimeDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(SeckillTimeDO::getId)); + default void sekillActivityCountReduce(List 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/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java index 63c1bd13d..d49655a54 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImpl.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.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.seckillactivity.vo.SeckillActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.SeckillActivityPageReqVO; @@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillP import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillProductMapper; import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; +import cn.iocoder.yudao.module.promotion.service.seckilltime.SeckillTimeService; import cn.iocoder.yudao.module.promotion.util.PromotionUtils; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -20,6 +22,7 @@ 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.*; @@ -40,22 +43,24 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Resource private SeckillProductMapper seckillProductMapper; + @Resource + private SeckillTimeService seckillTimeService; + @Override public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { -// validateSeckillActivityProductConflicts(null,createReqVO.getProducts()); List statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); // 校验商品是否冲突 validateSeckillActivityProductConflicts(null, createReqVO.getProducts()); + // 更新秒杀时段的秒杀活动数量 + seckillTimeService.sekillActivityCountAdd(StrUtils.splitToLong(createReqVO.getTimeId(),",")); // 插入秒杀活动 SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO) - .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime()));; + .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime())); seckillActivityMapper.insert(seckillActivity); - // 插入商品 List productDOS = CollectionUtils.convertList(createReqVO.getProducts(), product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(seckillActivity.getId())); seckillProductMapper.insertBatch(productDOS); - // 返回 return seckillActivity.getId(); } @@ -66,9 +71,10 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { if (PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { throw exception(SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); } - List statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); // 校验商品是否冲突 validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); + // 更新秒杀时段的秒杀活动数量 + updateSeckillTimeActivityCount(updateReqVO.getId(), updateReqVO.getTimeId()); // 更新活动 SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getStartTime(), updateReqVO.getEndTime())); @@ -77,6 +83,28 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { updateSeckillProduct(updateReqVO); } + /** + * 更新秒杀时段的秒杀活动数量 + * + * @param id + * @param timeId + */ + private void updateSeckillTimeActivityCount(Long id, String timeId) { + List updateTimeIds = StrUtils.splitToLong(timeId, ","); + // 查出自己的timeIds + SeckillActivityDO seckillActivityDO = seckillActivityMapper.selectById(id); + List existsTimeIds = StrUtils.splitToLong(seckillActivityDO.getTimeId(), ","); + //需要减少的时间段 + List reduceIds = existsTimeIds.stream() + .filter(existsTimeId -> !updateTimeIds.contains(existsTimeId)) + .collect(Collectors.toList()); + //需要添加的时间段 + updateTimeIds.removeIf(updateTimeId -> existsTimeIds.contains(updateTimeId)); + //更新减少时间段和增加时间段 + seckillTimeService.sekillActivityCountAdd(updateTimeIds); + seckillTimeService.sekillActivityCountReduce(reduceIds); + } + /** * 更新秒杀商品 */ @@ -109,7 +137,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { * @param id 秒杀活动编号 * @param products 商品列表 */ - public void validateSeckillActivityProductConflicts(Long id, List products) { + private void validateSeckillActivityProductConflicts(Long id, List products) { if (CollUtil.isEmpty(products)) { return; } @@ -146,16 +174,18 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { // 更新 SeckillActivityDO updateObj = new SeckillActivityDO().setId(id).setStatus(PromotionActivityStatusEnum.CLOSE.getStatus()); seckillActivityMapper.updateById(updateObj); - } @Override public void deleteSeckillActivity(Long id) { // 校验存在 SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(id); - if (!PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { - throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED); + List statuses = asList(PromotionActivityStatusEnum.CLOSE.getStatus(), PromotionActivityStatusEnum.END.getStatus()); + if (!statuses.contains(seckillActivity.getStatus())) { + throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); } + // 更新秒杀时段的秒杀活动数量 + seckillTimeService.sekillActivityCountReduce(StrUtils.splitToLong(seckillActivity.getTimeId(),",")); // 删除 seckillActivityMapper.deleteById(id); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java index 5c5011dd0..da12983d3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java @@ -1,10 +1,11 @@ package cn.iocoder.yudao.module.promotion.service.seckilltime; -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.SeckillTimeCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.validation.Valid; +import java.util.List; /** * 秒杀时段 Service 接口 @@ -50,20 +51,18 @@ public interface SeckillTimeService { */ List getSeckillTimeList(); -// /** -// * 获得秒杀时段分页 -// * -// * @param pageReqVO 分页查询 -// * @return 秒杀时段分页 -// */ -// PageResult getSeckillTimePage(SeckillTimePageReqVO pageReqVO); + /** + * 秒杀时段列表的秒杀活动数量加 1 + * + * @param ids 秒杀时段id列表 + */ + void sekillActivityCountAdd(List ids); + /** - * 获得秒杀时段列表, 用于 Excel 导出 + * 秒杀时段列表的秒杀活动数量减 1 * - * @param exportReqVO 查询条件 - * @return 秒杀时段列表 + * @param ids 秒杀时段id列表 */ - List getSeckillTimeList(SeckillTimeExportReqVO exportReqVO); - + void sekillActivityCountReduce(List ids); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java index de4becc15..687e81b7a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java @@ -1,13 +1,17 @@ package cn.iocoder.yudao.module.promotion.service.seckilltime; +import cn.hutool.core.collection.CollUtil; import org.springframework.stereotype.Service; + import javax.annotation.Resource; + import org.springframework.validation.annotation.Validated; +import java.time.LocalTime; import java.util.*; + import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.convert.seckilltime.SeckillTimeConvert; import cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime.SeckillTimeMapper; @@ -24,11 +28,14 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @Validated public class SeckillTimeServiceImpl implements SeckillTimeService { + @Resource private SeckillTimeMapper seckillTimeMapper; @Override public Long createSeckillTime(SeckillTimeCreateReqVO createReqVO) { + // 校验时间段是否冲突 + validateSeckillTimeConflict(null,createReqVO.getStartTime(), createReqVO.getEndTime()); // 插入 SeckillTimeDO seckillTime = SeckillTimeConvert.INSTANCE.convert(createReqVO); seckillTimeMapper.insert(seckillTime); @@ -40,6 +47,8 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { public void updateSeckillTime(SeckillTimeUpdateReqVO updateReqVO) { // 校验存在 this.validateSeckillTimeExists(updateReqVO.getId()); + // 校验时间段是否冲突 + validateSeckillTimeConflict(updateReqVO.getId(), updateReqVO.getStartTime(), updateReqVO.getEndTime()); // 更新 SeckillTimeDO updateObj = SeckillTimeConvert.INSTANCE.convert(updateReqVO); seckillTimeMapper.updateById(updateObj); @@ -59,6 +68,31 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { } } + /** + * 校验时间是否存在冲突 + * + * @param startTime 开始时间 + * @param endTime 结束时间 + */ + private void validateSeckillTimeConflict(Long id, LocalTime startTime, LocalTime endTime) { + //查询开始时间,结束时间,是否在别人的时间段内 + List startTimeList = seckillTimeMapper.selectListWithTime(startTime); + List endTimeList = seckillTimeMapper.selectListWithTime(endTime); + //查询自己时间段内是否有时间段 + List startEndTimeList = seckillTimeMapper.selectListWithTime(startTime, endTime); + if (id != null) { + //移除自己 + startTimeList.removeIf(seckillTime -> Objects.equals(seckillTime.getId(), id)); + endTimeList.removeIf(seckillTime -> Objects.equals(seckillTime.getId(), id)); + startEndTimeList.removeIf(seckillTime -> Objects.equals(seckillTime.getId(), id)); + } + if (CollUtil.isNotEmpty(startTimeList) || CollUtil.isNotEmpty(endTimeList) + || CollUtil.isNotEmpty(startEndTimeList)) { + throw exception(SECKILL_TIME_CONFLICTS); + } + } + + @Override public SeckillTimeDO getSeckillTime(Long id) { return seckillTimeMapper.selectById(id); @@ -69,14 +103,14 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { return seckillTimeMapper.selectList(); } -// @Override -// public PageResult getSeckillTimePage(SeckillTimePageReqVO pageReqVO) { -// return seckillTimeMapper.selectPage(pageReqVO); -// } + @Override + public void sekillActivityCountAdd(List ids) { + seckillTimeMapper.sekillActivityCountAdd(ids); + } @Override - public List getSeckillTimeList(SeckillTimeExportReqVO exportReqVO) { - return seckillTimeMapper.selectList(exportReqVO); + public void sekillActivityCountReduce(List ids) { + seckillTimeMapper.sekillActivityCountReduce(ids); } } 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 d5379212d..8afb5dda5 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 @@ -180,17 +180,17 @@ public class SeckillTimeServiceImplTest extends BaseDbUnitTest { // 测试 createTime 不匹配 seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setCreateTime(null))); // 准备参数 - SeckillTimeExportReqVO reqVO = new SeckillTimeExportReqVO(); - reqVO.setName(null); - reqVO.setStartTime((new LocalTime[]{})); - reqVO.setEndTime((new LocalTime[]{})); - reqVO.setCreateTime((new Date[]{})); - - // 调用 - List list = seckillTimeService.getSeckillTimeList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbSeckillTime, list.get(0)); +// SeckillTimeExportReqVO reqVO = new SeckillTimeExportReqVO(); +// reqVO.setName(null); +// reqVO.setStartTime((new LocalTime[]{})); +// reqVO.setEndTime((new LocalTime[]{})); +// reqVO.setCreateTime((new Date[]{})); +// +// // 调用 +// List list = seckillTimeService.getSeckillTimeList(reqVO); +// // 断言 +// assertEquals(1, list.size()); +// assertPojoEquals(dbSeckillTime, list.get(0)); } } diff --git a/yudao-ui-admin/src/views/promotion/seckillTime/index.vue b/yudao-ui-admin/src/views/promotion/seckillTime/index.vue index c41dba309..df829582b 100644 --- a/yudao-ui-admin/src/views/promotion/seckillTime/index.vue +++ b/yudao-ui-admin/src/views/promotion/seckillTime/index.vue @@ -47,7 +47,7 @@ {{ scope.row.endTime }} - +