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] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=EF=BC=8C=E5=88=86=E9=A1=B5?= =?UTF-8?q?=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