Commit cd62c4d22094dddb9feb9bf3c9ae845d023c48ef
1 parent
ea2a57f0
秒杀时段相关
Showing
22 changed files
with
1119 additions
and
1 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java
| @@ -25,6 +25,8 @@ public class DateUtils { | @@ -25,6 +25,8 @@ public class DateUtils { | ||
| 25 | 25 | ||
| 26 | public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; | 26 | public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; |
| 27 | 27 | ||
| 28 | + public static final String FORMAT_HOUR_MINUTE_SECOND = "HH:mm:ss"; | ||
| 29 | + | ||
| 28 | /** | 30 | /** |
| 29 | * 将 LocalDateTime 转换成 Date | 31 | * 将 LocalDateTime 转换成 Date |
| 30 | * | 32 | * |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.jackson.core.databind; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; | ||
| 4 | + | ||
| 5 | +import java.time.ZoneId; | ||
| 6 | +import java.time.format.DateTimeFormatter; | ||
| 7 | + | ||
| 8 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; | ||
| 9 | + | ||
| 10 | +public class LocalTimeDeserializable { | ||
| 11 | + // TODO: 2022/11/15 修改名字 | ||
| 12 | + public static final LocalTimeDeserializer INSTANCE = new LocalTimeDeserializer(DateTimeFormatter | ||
| 13 | + .ofPattern(FORMAT_HOUR_MINUTE_SECOND) | ||
| 14 | + .withZone(ZoneId.systemDefault())); | ||
| 15 | + | ||
| 16 | +} |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.jackson.core.databind; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; | ||
| 4 | + | ||
| 5 | +import java.time.ZoneId; | ||
| 6 | +import java.time.format.DateTimeFormatter; | ||
| 7 | + | ||
| 8 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; | ||
| 9 | + | ||
| 10 | +public class LocalTimeSerializable { | ||
| 11 | + // TODO: 2022/11/15 修改名称 | ||
| 12 | + | ||
| 13 | + public static final LocalTimeSerializer INSTANCE = new LocalTimeSerializer(DateTimeFormatter | ||
| 14 | + .ofPattern(FORMAT_HOUR_MINUTE_SECOND) | ||
| 15 | + .withZone(ZoneId.systemDefault())); | ||
| 16 | + | ||
| 17 | +} |
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 { | @@ -47,5 +47,5 @@ public interface ErrorCodeConstants { | ||
| 47 | 47 | ||
| 48 | // ========== 秒杀活动 1003008000 ========== | 48 | // ========== 秒杀活动 1003008000 ========== |
| 49 | ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1003008000, "秒杀活动不存在"); | 49 | ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1003008000, "秒杀活动不存在"); |
| 50 | - | 50 | + ErrorCode SECKILL_TIME_NOT_EXISTS = new ErrorCode(1003008001, "秒杀时段不存在"); |
| 51 | } | 51 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/SeckillTimeController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime; | ||
| 2 | + | ||
| 3 | +import org.springframework.web.bind.annotation.*; | ||
| 4 | +import javax.annotation.Resource; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | +import io.swagger.annotations.*; | ||
| 8 | + | ||
| 9 | +import javax.validation.constraints.*; | ||
| 10 | +import javax.validation.*; | ||
| 11 | +import javax.servlet.http.*; | ||
| 12 | +import java.util.*; | ||
| 13 | +import java.io.IOException; | ||
| 14 | + | ||
| 15 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 16 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 17 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 18 | + | ||
| 19 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 20 | + | ||
| 21 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 22 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | ||
| 23 | + | ||
| 24 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; | ||
| 25 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; | ||
| 26 | +import cn.iocoder.yudao.module.promotion.convert.seckilltime.SeckillTimeConvert; | ||
| 27 | +import cn.iocoder.yudao.module.promotion.service.seckilltime.SeckillTimeService; | ||
| 28 | + | ||
| 29 | +@Api(tags = "管理后台 - 秒杀时段") | ||
| 30 | +@RestController | ||
| 31 | +@RequestMapping("/promotion/seckill-time") | ||
| 32 | +@Validated | ||
| 33 | +public class SeckillTimeController { | ||
| 34 | + | ||
| 35 | + @Resource | ||
| 36 | + private SeckillTimeService seckillTimeService; | ||
| 37 | + | ||
| 38 | + @PostMapping("/create") | ||
| 39 | + @ApiOperation("创建秒杀时段") | ||
| 40 | + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:create')") | ||
| 41 | + public CommonResult<Long> createSeckillTime(@Valid @RequestBody SeckillTimeCreateReqVO createReqVO) { | ||
| 42 | + return success(seckillTimeService.createSeckillTime(createReqVO)); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @PutMapping("/update") | ||
| 46 | + @ApiOperation("更新秒杀时段") | ||
| 47 | + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:update')") | ||
| 48 | + public CommonResult<Boolean> updateSeckillTime(@Valid @RequestBody SeckillTimeUpdateReqVO updateReqVO) { | ||
| 49 | + seckillTimeService.updateSeckillTime(updateReqVO); | ||
| 50 | + return success(true); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @DeleteMapping("/delete") | ||
| 54 | + @ApiOperation("删除秒杀时段") | ||
| 55 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | ||
| 56 | + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:delete')") | ||
| 57 | + public CommonResult<Boolean> deleteSeckillTime(@RequestParam("id") Long id) { | ||
| 58 | + seckillTimeService.deleteSeckillTime(id); | ||
| 59 | + return success(true); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @GetMapping("/get") | ||
| 63 | + @ApiOperation("获得秒杀时段") | ||
| 64 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | ||
| 65 | + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") | ||
| 66 | + public CommonResult<SeckillTimeRespVO> getSeckillTime(@RequestParam("id") Long id) { | ||
| 67 | + SeckillTimeDO seckillTime = seckillTimeService.getSeckillTime(id); | ||
| 68 | + return success(SeckillTimeConvert.INSTANCE.convert(seckillTime)); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @GetMapping("/list") | ||
| 72 | + @ApiOperation("获得所有秒杀时段列表") | ||
| 73 | +// @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") | ||
| 74 | + public CommonResult<List<SeckillTimeRespVO>> getSeckillTimeList() { | ||
| 75 | + List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList(); | ||
| 76 | + return success(SeckillTimeConvert.INSTANCE.convertList(list)); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | +// @GetMapping("/page") | ||
| 80 | +// @ApiOperation("获得秒杀时段分页") | ||
| 81 | +// @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") | ||
| 82 | +// public CommonResult<PageResult<SeckillTimeRespVO>> getSeckillTimePage(@Valid SeckillTimePageReqVO pageVO) { | ||
| 83 | +// PageResult<SeckillTimeDO> pageResult = seckillTimeService.getSeckillTimePage(pageVO); | ||
| 84 | +// return success(SeckillTimeConvert.INSTANCE.convertPage(pageResult)); | ||
| 85 | +// } | ||
| 86 | + | ||
| 87 | + @GetMapping("/export-excel") | ||
| 88 | + @ApiOperation("导出秒杀时段 Excel") | ||
| 89 | + @PreAuthorize("@ss.hasPermission('promotion:seckill-time:export')") | ||
| 90 | + @OperateLog(type = EXPORT) | ||
| 91 | + public void exportSeckillTimeExcel(@Valid SeckillTimeExportReqVO exportReqVO, | ||
| 92 | + HttpServletResponse response) throws IOException { | ||
| 93 | + List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList(exportReqVO); | ||
| 94 | + // 导出 Excel | ||
| 95 | + List<SeckillTimeExcelVO> datas = SeckillTimeConvert.INSTANCE.convertList02(list); | ||
| 96 | + ExcelUtils.write(response, "秒杀时段.xls", "数据", SeckillTimeExcelVO.class, datas); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeBaseVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | + | ||
| 5 | +import java.time.LocalTime; | ||
| 6 | +import java.util.*; | ||
| 7 | +import io.swagger.annotations.*; | ||
| 8 | +import javax.validation.constraints.*; | ||
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 10 | + | ||
| 11 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | +* 秒杀时段 Base VO,提供给添加、修改、详细的子 VO 使用 | ||
| 15 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||
| 16 | +*/ | ||
| 17 | +@Data | ||
| 18 | +public class SeckillTimeBaseVO { | ||
| 19 | + | ||
| 20 | + @ApiModelProperty(value = "秒杀时段名称", required = true) | ||
| 21 | + @NotNull(message = "秒杀时段名称不能为空") | ||
| 22 | + private String name; | ||
| 23 | + | ||
| 24 | + @ApiModelProperty(value = "开始时间点", required = true) | ||
| 25 | + @NotNull(message = "开始时间点不能为空") | ||
| 26 | + private LocalTime startTime; | ||
| 27 | + | ||
| 28 | + @ApiModelProperty(value = "结束时间点", required = true) | ||
| 29 | + @NotNull(message = "结束时间点不能为空") | ||
| 30 | + private LocalTime endTime; | ||
| 31 | + | ||
| 32 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import java.util.*; | ||
| 5 | +import io.swagger.annotations.*; | ||
| 6 | +import javax.validation.constraints.*; | ||
| 7 | + | ||
| 8 | +@ApiModel("管理后台 - 秒杀时段创建 Request VO") | ||
| 9 | +@Data | ||
| 10 | +@EqualsAndHashCode(callSuper = true) | ||
| 11 | +@ToString(callSuper = true) | ||
| 12 | +public class SeckillTimeCreateReqVO extends SeckillTimeBaseVO { | ||
| 13 | + | ||
| 14 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | + | ||
| 5 | +import java.time.LocalTime; | ||
| 6 | +import java.util.*; | ||
| 7 | +import io.swagger.annotations.*; | ||
| 8 | + | ||
| 9 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 秒杀时段 Excel VO | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +@Data | ||
| 17 | +public class SeckillTimeExcelVO { | ||
| 18 | + | ||
| 19 | + @ExcelProperty("编号") | ||
| 20 | + private Long id; | ||
| 21 | + | ||
| 22 | + @ExcelProperty("秒杀时段名称") | ||
| 23 | + private String name; | ||
| 24 | + | ||
| 25 | + @ExcelProperty("开始时间点") | ||
| 26 | + private LocalTime startTime; | ||
| 27 | + | ||
| 28 | + @ExcelProperty("结束时间点") | ||
| 29 | + private LocalTime endTime; | ||
| 30 | + | ||
| 31 | + @ExcelProperty("商品数量") | ||
| 32 | + private Integer productCount; | ||
| 33 | + | ||
| 34 | + @ExcelProperty("创建时间") | ||
| 35 | + private Date createTime; | ||
| 36 | + | ||
| 37 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeExportReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | + | ||
| 5 | +import java.time.LocalTime; | ||
| 6 | +import java.util.*; | ||
| 7 | +import io.swagger.annotations.*; | ||
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 10 | + | ||
| 11 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 12 | + | ||
| 13 | +@ApiModel(value = "管理后台 - 秒杀时段 Excel 导出 Request VO", description = "参数和 SeckillTimePageReqVO 是一致的") | ||
| 14 | +@Data | ||
| 15 | +public class SeckillTimeExportReqVO { | ||
| 16 | + | ||
| 17 | + @ApiModelProperty(value = "秒杀时段名称") | ||
| 18 | + private String name; | ||
| 19 | + | ||
| 20 | + @ApiModelProperty(value = "开始时间点") | ||
| 21 | + private LocalTime[] startTime; | ||
| 22 | + | ||
| 23 | + @ApiModelProperty(value = "结束时间点") | ||
| 24 | + private LocalTime[] endTime; | ||
| 25 | + | ||
| 26 | + @ApiModelProperty(value = "创建时间") | ||
| 27 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 28 | + private Date[] createTime; | ||
| 29 | + | ||
| 30 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import io.swagger.annotations.ApiModel; | ||
| 5 | +import io.swagger.annotations.ApiModelProperty; | ||
| 6 | +import lombok.Data; | ||
| 7 | +import lombok.EqualsAndHashCode; | ||
| 8 | +import lombok.ToString; | ||
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 10 | + | ||
| 11 | +import java.time.LocalTime; | ||
| 12 | + | ||
| 13 | +@ApiModel("管理后台 - 秒杀时段分页 Request VO") | ||
| 14 | +@Data | ||
| 15 | +@EqualsAndHashCode(callSuper = true) | ||
| 16 | +@ToString(callSuper = true) | ||
| 17 | +public class SeckillTimePageReqVO extends PageParam { | ||
| 18 | + | ||
| 19 | + @ApiModelProperty(value = "秒杀时段名称") | ||
| 20 | + private String name; | ||
| 21 | + | ||
| 22 | + @ApiModelProperty(value = "开始时间点") | ||
| 23 | + @DateTimeFormat(pattern = "HH:mm:ss") | ||
| 24 | + private LocalTime startTime; | ||
| 25 | + | ||
| 26 | + @ApiModelProperty(value = "结束时间点") | ||
| 27 | + @DateTimeFormat(pattern = "HH:mm:ss") | ||
| 28 | + private LocalTime endTime; | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + | ||
| 36 | +// @ApiModelProperty(value = "创建时间") | ||
| 37 | +// @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 38 | +// private Date[] createTime; | ||
| 39 | + | ||
| 40 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import java.util.*; | ||
| 5 | +import io.swagger.annotations.*; | ||
| 6 | + | ||
| 7 | +@ApiModel("管理后台 - 秒杀时段 Response VO") | ||
| 8 | +@Data | ||
| 9 | +@EqualsAndHashCode(callSuper = true) | ||
| 10 | +@ToString(callSuper = true) | ||
| 11 | +public class SeckillTimeRespVO extends SeckillTimeBaseVO { | ||
| 12 | + | ||
| 13 | + @ApiModelProperty(value = "编号", required = true) | ||
| 14 | + private Long id; | ||
| 15 | + | ||
| 16 | + @ApiModelProperty(value = "商品数量", required = true) | ||
| 17 | + private Integer productCount; | ||
| 18 | + | ||
| 19 | + @ApiModelProperty(value = "创建时间", required = true) | ||
| 20 | + private Date createTime; | ||
| 21 | + | ||
| 22 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeSimpleRespVO.java
0 → 100644
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckilltime/vo/SeckillTimeUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | + | ||
| 9 | +import javax.validation.constraints.NotNull; | ||
| 10 | + | ||
| 11 | +@ApiModel("管理后台 - 秒杀时段更新 Request VO") | ||
| 12 | +@Data | ||
| 13 | +@EqualsAndHashCode(callSuper = true) | ||
| 14 | +@ToString(callSuper = true) | ||
| 15 | +public class SeckillTimeUpdateReqVO extends SeckillTimeBaseVO { | ||
| 16 | + | ||
| 17 | + @ApiModelProperty(value = "编号", required = true) | ||
| 18 | + @NotNull(message = "编号不能为空") | ||
| 19 | + private Long id; | ||
| 20 | + | ||
| 21 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckilltime/SeckillTimeConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.convert.seckilltime; | ||
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | + | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | + | ||
| 7 | +import org.mapstruct.Mapper; | ||
| 8 | +import org.mapstruct.factory.Mappers; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; | ||
| 10 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 秒杀时段 Convert | ||
| 14 | + * | ||
| 15 | + * @author 芋道源码 | ||
| 16 | + */ | ||
| 17 | +@Mapper | ||
| 18 | +public interface SeckillTimeConvert { | ||
| 19 | + | ||
| 20 | + SeckillTimeConvert INSTANCE = Mappers.getMapper(SeckillTimeConvert.class); | ||
| 21 | + | ||
| 22 | + SeckillTimeDO convert(SeckillTimeCreateReqVO bean); | ||
| 23 | + | ||
| 24 | + SeckillTimeDO convert(SeckillTimeUpdateReqVO bean); | ||
| 25 | + | ||
| 26 | + SeckillTimeRespVO convert(SeckillTimeDO bean); | ||
| 27 | + | ||
| 28 | + List<SeckillTimeRespVO> convertList(List<SeckillTimeDO> list); | ||
| 29 | + | ||
| 30 | + PageResult<SeckillTimeRespVO> convertPage(PageResult<SeckillTimeDO> page); | ||
| 31 | + | ||
| 32 | + List<SeckillTimeExcelVO> convertList02(List<SeckillTimeDO> list); | ||
| 33 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckilltime/SeckillTimeDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | + | ||
| 5 | +import java.time.LocalTime; | ||
| 6 | +import java.util.*; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.*; | ||
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 秒杀时段 DO | ||
| 12 | + * | ||
| 13 | + * @author 芋道源码 | ||
| 14 | + */ | ||
| 15 | +@TableName("promotion_seckill_time") | ||
| 16 | +@KeySequence("promotion_seckill_time_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 17 | +@Data | ||
| 18 | +@EqualsAndHashCode(callSuper = true) | ||
| 19 | +@ToString(callSuper = true) | ||
| 20 | +@Builder | ||
| 21 | +@NoArgsConstructor | ||
| 22 | +@AllArgsConstructor | ||
| 23 | +public class SeckillTimeDO extends BaseDO { | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 编号 | ||
| 27 | + */ | ||
| 28 | + @TableId | ||
| 29 | + private Long id; | ||
| 30 | + /** | ||
| 31 | + * 秒杀时段名称 | ||
| 32 | + */ | ||
| 33 | + private String name; | ||
| 34 | + /** | ||
| 35 | + * 开始时间点 | ||
| 36 | + */ | ||
| 37 | + private LocalTime startTime; | ||
| 38 | + /** | ||
| 39 | + * 结束时间点 | ||
| 40 | + */ | ||
| 41 | + private LocalTime endTime; | ||
| 42 | + /** | ||
| 43 | + * 商品数量 | ||
| 44 | + */ | ||
| 45 | + private Integer productCount; | ||
| 46 | + | ||
| 47 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckilltime/SeckillTimeMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime; | ||
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | + | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; | ||
| 9 | +import org.apache.ibatis.annotations.Mapper; | ||
| 10 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 秒杀时段 Mapper | ||
| 14 | + * | ||
| 15 | + * @author 芋道源码 | ||
| 16 | + */ | ||
| 17 | +@Mapper | ||
| 18 | +public interface SeckillTimeMapper extends BaseMapperX<SeckillTimeDO> { | ||
| 19 | + | ||
| 20 | +// default PageResult<SeckillTimeDO> selectPage(SeckillTimePageReqVO reqVO) { | ||
| 21 | +// return selectPage(reqVO, new LambdaQueryWrapperX<SeckillTimeDO>() | ||
| 22 | +// .likeIfPresent(SeckillTimeDO::getName, reqVO.getName()) | ||
| 23 | +// .geIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) | ||
| 24 | +// .leIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) | ||
| 25 | +//// .betweenIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) | ||
| 26 | +//// .betweenIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) | ||
| 27 | +//// .betweenIfPresent(SeckillTimeDO::getCreateTime, reqVO.getCreateTime()) | ||
| 28 | +// .orderByDesc(SeckillTimeDO::getId)); | ||
| 29 | +// } | ||
| 30 | + | ||
| 31 | + default List<SeckillTimeDO> selectList(SeckillTimeExportReqVO reqVO) { | ||
| 32 | + return selectList(new LambdaQueryWrapperX<SeckillTimeDO>() | ||
| 33 | + .likeIfPresent(SeckillTimeDO::getName, reqVO.getName()) | ||
| 34 | + .betweenIfPresent(SeckillTimeDO::getStartTime, reqVO.getStartTime()) | ||
| 35 | + .betweenIfPresent(SeckillTimeDO::getEndTime, reqVO.getEndTime()) | ||
| 36 | + .betweenIfPresent(SeckillTimeDO::getCreateTime, reqVO.getCreateTime()) | ||
| 37 | + .orderByDesc(SeckillTimeDO::getId)); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.seckilltime; | ||
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | +import javax.validation.*; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; | ||
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 秒杀时段 Service 接口 | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +public interface SeckillTimeService { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 创建秒杀时段 | ||
| 18 | + * | ||
| 19 | + * @param createReqVO 创建信息 | ||
| 20 | + * @return 编号 | ||
| 21 | + */ | ||
| 22 | + Long createSeckillTime(@Valid SeckillTimeCreateReqVO createReqVO); | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 更新秒杀时段 | ||
| 26 | + * | ||
| 27 | + * @param updateReqVO 更新信息 | ||
| 28 | + */ | ||
| 29 | + void updateSeckillTime(@Valid SeckillTimeUpdateReqVO updateReqVO); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 删除秒杀时段 | ||
| 33 | + * | ||
| 34 | + * @param id 编号 | ||
| 35 | + */ | ||
| 36 | + void deleteSeckillTime(Long id); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 获得秒杀时段 | ||
| 40 | + * | ||
| 41 | + * @param id 编号 | ||
| 42 | + * @return 秒杀时段 | ||
| 43 | + */ | ||
| 44 | + SeckillTimeDO getSeckillTime(Long id); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 获得所有秒杀时段列表 | ||
| 48 | + * | ||
| 49 | + * @return 所有秒杀时段列表 | ||
| 50 | + */ | ||
| 51 | + List<SeckillTimeDO> getSeckillTimeList(); | ||
| 52 | + | ||
| 53 | +// /** | ||
| 54 | +// * 获得秒杀时段分页 | ||
| 55 | +// * | ||
| 56 | +// * @param pageReqVO 分页查询 | ||
| 57 | +// * @return 秒杀时段分页 | ||
| 58 | +// */ | ||
| 59 | +// PageResult<SeckillTimeDO> getSeckillTimePage(SeckillTimePageReqVO pageReqVO); | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 获得秒杀时段列表, 用于 Excel 导出 | ||
| 63 | + * | ||
| 64 | + * @param exportReqVO 查询条件 | ||
| 65 | + * @return 秒杀时段列表 | ||
| 66 | + */ | ||
| 67 | + List<SeckillTimeDO> getSeckillTimeList(SeckillTimeExportReqVO exportReqVO); | ||
| 68 | + | ||
| 69 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.seckilltime; | ||
| 2 | + | ||
| 3 | +import org.springframework.stereotype.Service; | ||
| 4 | +import javax.annotation.Resource; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | + | ||
| 7 | +import java.util.*; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; | ||
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 11 | + | ||
| 12 | +import cn.iocoder.yudao.module.promotion.convert.seckilltime.SeckillTimeConvert; | ||
| 13 | +import cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime.SeckillTimeMapper; | ||
| 14 | + | ||
| 15 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 16 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 秒杀时段 Service 实现类 | ||
| 20 | + * | ||
| 21 | + * @author 芋道源码 | ||
| 22 | + */ | ||
| 23 | +@Service | ||
| 24 | +@Validated | ||
| 25 | +public class SeckillTimeServiceImpl implements SeckillTimeService { | ||
| 26 | + | ||
| 27 | + @Resource | ||
| 28 | + private SeckillTimeMapper seckillTimeMapper; | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public Long createSeckillTime(SeckillTimeCreateReqVO createReqVO) { | ||
| 32 | + // 插入 | ||
| 33 | + SeckillTimeDO seckillTime = SeckillTimeConvert.INSTANCE.convert(createReqVO); | ||
| 34 | + seckillTimeMapper.insert(seckillTime); | ||
| 35 | + // 返回 | ||
| 36 | + return seckillTime.getId(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void updateSeckillTime(SeckillTimeUpdateReqVO updateReqVO) { | ||
| 41 | + // 校验存在 | ||
| 42 | + this.validateSeckillTimeExists(updateReqVO.getId()); | ||
| 43 | + // 更新 | ||
| 44 | + SeckillTimeDO updateObj = SeckillTimeConvert.INSTANCE.convert(updateReqVO); | ||
| 45 | + seckillTimeMapper.updateById(updateObj); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @Override | ||
| 49 | + public void deleteSeckillTime(Long id) { | ||
| 50 | + // 校验存在 | ||
| 51 | + this.validateSeckillTimeExists(id); | ||
| 52 | + // 删除 | ||
| 53 | + seckillTimeMapper.deleteById(id); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + private void validateSeckillTimeExists(Long id) { | ||
| 57 | + if (seckillTimeMapper.selectById(id) == null) { | ||
| 58 | + throw exception(SECKILL_TIME_NOT_EXISTS); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public SeckillTimeDO getSeckillTime(Long id) { | ||
| 64 | + return seckillTimeMapper.selectById(id); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public List<SeckillTimeDO> getSeckillTimeList() { | ||
| 69 | + return seckillTimeMapper.selectList(); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | +// @Override | ||
| 73 | +// public PageResult<SeckillTimeDO> getSeckillTimePage(SeckillTimePageReqVO pageReqVO) { | ||
| 74 | +// return seckillTimeMapper.selectPage(pageReqVO); | ||
| 75 | +// } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public List<SeckillTimeDO> getSeckillTimeList(SeckillTimeExportReqVO exportReqVO) { | ||
| 79 | + return seckillTimeMapper.selectList(exportReqVO); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | +<mapper namespace="cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime.SeckillTimeMapper"> | ||
| 4 | + | ||
| 5 | + <!-- | ||
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | ||
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | ||
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | ||
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | ||
| 10 | + --> | ||
| 11 | + | ||
| 12 | +</mapper> |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckilltime/SeckillTimeServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.seckilltime; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 5 | +import org.junit.jupiter.api.Disabled; | ||
| 6 | +import org.junit.jupiter.api.Test; | ||
| 7 | +import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 8 | + | ||
| 9 | +import javax.annotation.Resource; | ||
| 10 | + | ||
| 11 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 12 | + | ||
| 13 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckilltime.vo.*; | ||
| 14 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckilltime.SeckillTimeDO; | ||
| 15 | +import cn.iocoder.yudao.module.promotion.dal.mysql.seckilltime.SeckillTimeMapper; | ||
| 16 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 17 | + | ||
| 18 | +import javax.annotation.Resource; | ||
| 19 | +import org.springframework.context.annotation.Import; | ||
| 20 | + | ||
| 21 | +import java.time.LocalTime; | ||
| 22 | +import java.util.*; | ||
| 23 | + | ||
| 24 | +import static cn.hutool.core.util.RandomUtil.*; | ||
| 25 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | ||
| 26 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | ||
| 27 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | ||
| 28 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | ||
| 29 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | ||
| 30 | +import static org.junit.jupiter.api.Assertions.*; | ||
| 31 | +import static org.mockito.Mockito.*; | ||
| 32 | + | ||
| 33 | +/** | ||
| 34 | +* {@link SeckillTimeServiceImpl} 的单元测试类 | ||
| 35 | +* | ||
| 36 | +* @author 芋道源码 | ||
| 37 | +*/ | ||
| 38 | +@Import(SeckillTimeServiceImpl.class) | ||
| 39 | +public class SeckillTimeServiceImplTest extends BaseDbUnitTest { | ||
| 40 | + | ||
| 41 | + @Resource | ||
| 42 | + private SeckillTimeServiceImpl seckillTimeService; | ||
| 43 | + | ||
| 44 | + @Resource | ||
| 45 | + private SeckillTimeMapper seckillTimeMapper; | ||
| 46 | + | ||
| 47 | + @Resource | ||
| 48 | + private ObjectMapper objectMapper; | ||
| 49 | + | ||
| 50 | + @Test | ||
| 51 | + public void testJacksonSerializ(){ | ||
| 52 | + | ||
| 53 | + // 准备参数 | ||
| 54 | + SeckillTimeCreateReqVO reqVO = randomPojo(SeckillTimeCreateReqVO.class); | ||
| 55 | +// ObjectMapper objectMapper = new ObjectMapper(); | ||
| 56 | + try { | ||
| 57 | + String string = objectMapper.writeValueAsString(reqVO); | ||
| 58 | + System.out.println(string); | ||
| 59 | + } catch (JsonProcessingException e) { | ||
| 60 | + e.printStackTrace(); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Test | ||
| 67 | + public void testCreateSeckillTime_success() { | ||
| 68 | + // 准备参数 | ||
| 69 | + SeckillTimeCreateReqVO reqVO = randomPojo(SeckillTimeCreateReqVO.class); | ||
| 70 | + | ||
| 71 | + // 调用 | ||
| 72 | + Long seckillTimeId = seckillTimeService.createSeckillTime(reqVO); | ||
| 73 | + // 断言 | ||
| 74 | + assertNotNull(seckillTimeId); | ||
| 75 | + // 校验记录的属性是否正确 | ||
| 76 | + SeckillTimeDO seckillTime = seckillTimeMapper.selectById(seckillTimeId); | ||
| 77 | + assertPojoEquals(reqVO, seckillTime); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @Test | ||
| 81 | + public void testUpdateSeckillTime_success() { | ||
| 82 | + // mock 数据 | ||
| 83 | + SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class); | ||
| 84 | + seckillTimeMapper.insert(dbSeckillTime);// @Sql: 先插入出一条存在的数据 | ||
| 85 | + // 准备参数 | ||
| 86 | + SeckillTimeUpdateReqVO reqVO = randomPojo(SeckillTimeUpdateReqVO.class, o -> { | ||
| 87 | + o.setId(dbSeckillTime.getId()); // 设置更新的 ID | ||
| 88 | + }); | ||
| 89 | + | ||
| 90 | + // 调用 | ||
| 91 | + seckillTimeService.updateSeckillTime(reqVO); | ||
| 92 | + // 校验是否更新正确 | ||
| 93 | + SeckillTimeDO seckillTime = seckillTimeMapper.selectById(reqVO.getId()); // 获取最新的 | ||
| 94 | + assertPojoEquals(reqVO, seckillTime); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Test | ||
| 98 | + public void testUpdateSeckillTime_notExists() { | ||
| 99 | + // 准备参数 | ||
| 100 | + SeckillTimeUpdateReqVO reqVO = randomPojo(SeckillTimeUpdateReqVO.class); | ||
| 101 | + | ||
| 102 | + // 调用, 并断言异常 | ||
| 103 | + assertServiceException(() -> seckillTimeService.updateSeckillTime(reqVO), SECKILL_TIME_NOT_EXISTS); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Test | ||
| 107 | + public void testDeleteSeckillTime_success() { | ||
| 108 | + // mock 数据 | ||
| 109 | + SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class); | ||
| 110 | + seckillTimeMapper.insert(dbSeckillTime);// @Sql: 先插入出一条存在的数据 | ||
| 111 | + // 准备参数 | ||
| 112 | + Long id = dbSeckillTime.getId(); | ||
| 113 | + | ||
| 114 | + // 调用 | ||
| 115 | + seckillTimeService.deleteSeckillTime(id); | ||
| 116 | + // 校验数据不存在了 | ||
| 117 | + assertNull(seckillTimeMapper.selectById(id)); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Test | ||
| 121 | + public void testDeleteSeckillTime_notExists() { | ||
| 122 | + // 准备参数 | ||
| 123 | + Long id = randomLongId(); | ||
| 124 | + | ||
| 125 | + // 调用, 并断言异常 | ||
| 126 | + assertServiceException(() -> seckillTimeService.deleteSeckillTime(id), SECKILL_TIME_NOT_EXISTS); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + @Test | ||
| 130 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||
| 131 | + public void testGetSeckillTimePage() { | ||
| 132 | + // mock 数据 | ||
| 133 | +// SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class, o -> { // 等会查询到 | ||
| 134 | +// o.setName(null); | ||
| 135 | +// o.setStartTime(null); | ||
| 136 | +// o.setEndTime(null); | ||
| 137 | +// o.setCreateTime(null); | ||
| 138 | +// }); | ||
| 139 | +// seckillTimeMapper.insert(dbSeckillTime); | ||
| 140 | +// // 测试 name 不匹配 | ||
| 141 | +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setName(null))); | ||
| 142 | +// // 测试 startTime 不匹配 | ||
| 143 | +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setStartTime(null))); | ||
| 144 | +// // 测试 endTime 不匹配 | ||
| 145 | +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setEndTime(null))); | ||
| 146 | +// // 测试 createTime 不匹配 | ||
| 147 | +// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setCreateTime(null))); | ||
| 148 | +// // 准备参数 | ||
| 149 | +// SeckillTimePageReqVO reqVO = new SeckillTimePageReqVO(); | ||
| 150 | +// reqVO.setName(null); | ||
| 151 | +//// reqVO.setStartTime((new LocalTime())); | ||
| 152 | +//// reqVO.setEndTime((new LocalTime[]{})); | ||
| 153 | +//// reqVO.setCreateTime((new Date[]{})); | ||
| 154 | +// | ||
| 155 | +// // 调用 | ||
| 156 | +// PageResult<SeckillTimeDO> pageResult = seckillTimeService.getSeckillTimePage(reqVO); | ||
| 157 | +// // 断言 | ||
| 158 | +// assertEquals(1, pageResult.getTotal()); | ||
| 159 | +// assertEquals(1, pageResult.getList().size()); | ||
| 160 | +// assertPojoEquals(dbSeckillTime, pageResult.getList().get(0)); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + @Test | ||
| 164 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||
| 165 | + public void testGetSeckillTimeList() { | ||
| 166 | + // mock 数据 | ||
| 167 | + SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class, o -> { // 等会查询到 | ||
| 168 | + o.setName(null); | ||
| 169 | + o.setStartTime(null); | ||
| 170 | + o.setEndTime(null); | ||
| 171 | + o.setCreateTime(null); | ||
| 172 | + }); | ||
| 173 | + seckillTimeMapper.insert(dbSeckillTime); | ||
| 174 | + // 测试 name 不匹配 | ||
| 175 | + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setName(null))); | ||
| 176 | + // 测试 startTime 不匹配 | ||
| 177 | + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setStartTime(null))); | ||
| 178 | + // 测试 endTime 不匹配 | ||
| 179 | + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setEndTime(null))); | ||
| 180 | + // 测试 createTime 不匹配 | ||
| 181 | + seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setCreateTime(null))); | ||
| 182 | + // 准备参数 | ||
| 183 | + SeckillTimeExportReqVO reqVO = new SeckillTimeExportReqVO(); | ||
| 184 | + reqVO.setName(null); | ||
| 185 | + reqVO.setStartTime((new LocalTime[]{})); | ||
| 186 | + reqVO.setEndTime((new LocalTime[]{})); | ||
| 187 | + reqVO.setCreateTime((new Date[]{})); | ||
| 188 | + | ||
| 189 | + // 调用 | ||
| 190 | + List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList(reqVO); | ||
| 191 | + // 断言 | ||
| 192 | + assertEquals(1, list.size()); | ||
| 193 | + assertPojoEquals(dbSeckillTime, list.get(0)); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | +} |
yudao-ui-admin/src/api/promotion/seckillTime.js
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 创建秒杀时段 | ||
| 4 | +export function createSeckillTime(data) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/promotion/seckill-time/create', | ||
| 7 | + method: 'post', | ||
| 8 | + data: data | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +// 更新秒杀时段 | ||
| 13 | +export function updateSeckillTime(data) { | ||
| 14 | + return request({ | ||
| 15 | + url: '/promotion/seckill-time/update', | ||
| 16 | + method: 'put', | ||
| 17 | + data: data | ||
| 18 | + }) | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// 删除秒杀时段 | ||
| 22 | +export function deleteSeckillTime(id) { | ||
| 23 | + return request({ | ||
| 24 | + url: '/promotion/seckill-time/delete?id=' + id, | ||
| 25 | + method: 'delete' | ||
| 26 | + }) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// 获得秒杀时段 | ||
| 30 | +export function getSeckillTime(id) { | ||
| 31 | + return request({ | ||
| 32 | + url: '/promotion/seckill-time/get?id=' + id, | ||
| 33 | + method: 'get' | ||
| 34 | + }) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// 获得秒杀时段分页 | ||
| 38 | +export function getSeckillTimePage(query) { | ||
| 39 | + return request({ | ||
| 40 | + url: '/promotion/seckill-time/page', | ||
| 41 | + method: 'get', | ||
| 42 | + params: query | ||
| 43 | + }) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// 获取所有的秒杀时段 | ||
| 47 | +export function getSeckillTimeList() { | ||
| 48 | + return request({ | ||
| 49 | + url: '/promotion/seckill-time/list', | ||
| 50 | + method: 'get' | ||
| 51 | + }) | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +// 导出秒杀时段 Excel | ||
| 55 | +export function exportSeckillTimeExcel(query) { | ||
| 56 | + return request({ | ||
| 57 | + url: '/promotion/seckill-time/export-excel', | ||
| 58 | + method: 'get', | ||
| 59 | + params: query, | ||
| 60 | + responseType: 'blob' | ||
| 61 | + }) | ||
| 62 | +} |
yudao-ui-admin/src/views/promotion/seckillTime/index.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="app-container"> | ||
| 3 | + | ||
| 4 | + <!-- 搜索工作栏 --> | ||
| 5 | + <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px"> | ||
| 6 | + <el-form-item label="秒杀时段名称" prop="name"> | ||
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入秒杀时段名称" clearable @keyup.enter.native="handleQuery" /> | ||
| 8 | + </el-form-item> | ||
| 9 | + | ||
| 10 | + <el-form-item label="开始时间点" prop="startTime"> | ||
| 11 | + <el-time-picker v-model="queryParams.startTime" placeholder="选择开始时间" value-format="HH:mm:ss" /> | ||
| 12 | + </el-form-item> | ||
| 13 | + | ||
| 14 | + <el-form-item label="结束时间点" prop="endTime"> | ||
| 15 | + <el-time-picker v-model="queryParams.endTime" placeholder="选择结束时间" value-format="HH:mm:ss" /> | ||
| 16 | + </el-form-item> | ||
| 17 | + | ||
| 18 | + <el-form-item> | ||
| 19 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | ||
| 20 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | ||
| 21 | + </el-form-item> | ||
| 22 | + </el-form> --> | ||
| 23 | + | ||
| 24 | + <!-- 操作工具栏 --> | ||
| 25 | + <el-row :gutter="10" class="mb8"> | ||
| 26 | + <el-col :span="1.5"> | ||
| 27 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | ||
| 28 | + v-hasPermi="['promotion:seckill-time:create']">新增</el-button> | ||
| 29 | + </el-col> | ||
| 30 | + <!-- <el-col :span="1.5"> | ||
| 31 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" | ||
| 32 | + :loading="exportLoading" v-hasPermi="['promotion:seckill-time:export']">导出</el-button> | ||
| 33 | + </el-col> --> | ||
| 34 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | ||
| 35 | + </el-row> | ||
| 36 | + | ||
| 37 | + <!-- 列表 --> | ||
| 38 | + <el-table v-loading="loading" :data="list"> | ||
| 39 | + <el-table-column label="秒杀时段名称" align="center" prop="name" /> | ||
| 40 | + <el-table-column label="开始时间点" align="center" prop="startTime" width="180"> | ||
| 41 | + <template slot-scope="scope"> | ||
| 42 | + <span>{{ scope.row.startTime }}</span> | ||
| 43 | + </template> | ||
| 44 | + </el-table-column> | ||
| 45 | + <el-table-column label="结束时间点" align="center" prop="endTime" width="180"> | ||
| 46 | + <template slot-scope="scope"> | ||
| 47 | + <span>{{ scope.row.endTime }}</span> | ||
| 48 | + </template> | ||
| 49 | + </el-table-column> | ||
| 50 | + <el-table-column label="商品数量" align="center" prop="productCount" /> | ||
| 51 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | ||
| 52 | + <template slot-scope="scope"> | ||
| 53 | + <span>{{ parseTime(scope.row.createTime) }}</span> | ||
| 54 | + </template> | ||
| 55 | + </el-table-column> | ||
| 56 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 57 | + <template slot-scope="scope"> | ||
| 58 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | ||
| 59 | + v-hasPermi="['promotion:seckill-time:update']">修改</el-button> | ||
| 60 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | ||
| 61 | + v-hasPermi="['promotion:seckill-time:delete']">删除</el-button> | ||
| 62 | + </template> | ||
| 63 | + </el-table-column> | ||
| 64 | + </el-table> | ||
| 65 | + <!-- 分页组件 --> | ||
| 66 | + <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | ||
| 67 | + @pagination="getList" /> --> | ||
| 68 | + | ||
| 69 | + <!-- 对话框(添加 / 修改) --> | ||
| 70 | + <el-dialog :title="title" :visible.sync="open" width="600px" v-dialogDrag append-to-body> | ||
| 71 | + <el-form ref="form" :model="form" :rules="rules" label-width="140px"> | ||
| 72 | + <el-form-item label="秒杀场次名称" prop="name"> | ||
| 73 | + <el-input v-model="form.name" placeholder="请输入秒杀时段名称" clearable /> | ||
| 74 | + </el-form-item> | ||
| 75 | + <el-form-item label="秒杀时间段" prop="startAndEndTime"> | ||
| 76 | + <el-time-picker is-range v-model="form.startAndEndTime" range-separator="至" start-placeholder="开始时间" | ||
| 77 | + end-placeholder="结束时间" placeholder="选择时间范围" value-format="HH:mm:ss"> | ||
| 78 | + </el-time-picker> | ||
| 79 | + </el-form-item> | ||
| 80 | + </el-form> | ||
| 81 | + <div slot="footer" class="dialog-footer"> | ||
| 82 | + <el-button type="primary" @click="submitForm">确 定</el-button> | ||
| 83 | + <el-button @click="cancel">取 消</el-button> | ||
| 84 | + </div> | ||
| 85 | + </el-dialog> | ||
| 86 | + </div> | ||
| 87 | +</template> | ||
| 88 | + | ||
| 89 | +<script> | ||
| 90 | +import { createSeckillTime, updateSeckillTime, deleteSeckillTime, getSeckillTime, getSeckillTimePage, exportSeckillTimeExcel, getSeckillTimeList } from "@/api/promotion/seckillTime"; | ||
| 91 | +import { deepClone } from "@/utils"; | ||
| 92 | + | ||
| 93 | +export default { | ||
| 94 | + name: "SeckillTime", | ||
| 95 | + components: { | ||
| 96 | + }, | ||
| 97 | + data() { | ||
| 98 | + return { | ||
| 99 | + // 遮罩层 | ||
| 100 | + loading: true, | ||
| 101 | + // 导出遮罩层 | ||
| 102 | + exportLoading: false, | ||
| 103 | + // 显示搜索条件 | ||
| 104 | + showSearch: true, | ||
| 105 | + // 总条数 | ||
| 106 | + // total: 0, | ||
| 107 | + // 秒杀时段列表 | ||
| 108 | + list: [], | ||
| 109 | + // 弹出层标题 | ||
| 110 | + title: "", | ||
| 111 | + // 是否显示弹出层 | ||
| 112 | + open: false, | ||
| 113 | + // 查询参数 | ||
| 114 | + // queryParams: { | ||
| 115 | + // pageNo: 1, | ||
| 116 | + // pageSize: 10, | ||
| 117 | + // name: null, | ||
| 118 | + // startTime: null, | ||
| 119 | + // endTime: null, | ||
| 120 | + // }, | ||
| 121 | + // 表单参数 | ||
| 122 | + form: {}, | ||
| 123 | + // 表单校验 | ||
| 124 | + rules: { | ||
| 125 | + name: [{ required: true, message: "秒杀时段名称不能为空", trigger: "blur" }], | ||
| 126 | + startAndEndTime: [{ required: true, message: "秒杀时间段不能为空", trigger: "blur" }], | ||
| 127 | + } | ||
| 128 | + }; | ||
| 129 | + }, | ||
| 130 | + created() { | ||
| 131 | + this.getList(); | ||
| 132 | + }, | ||
| 133 | + methods: { | ||
| 134 | + /** 查询列表 */ | ||
| 135 | + getList() { | ||
| 136 | + this.loading = true; | ||
| 137 | + // 执行查询 | ||
| 138 | + getSeckillTimeList().then(response => { | ||
| 139 | + console.log(response, "返回的数据") | ||
| 140 | + this.list = response.data; | ||
| 141 | + // this.total = response.data.total; | ||
| 142 | + this.loading = false; | ||
| 143 | + }); | ||
| 144 | + }, | ||
| 145 | + /** 取消按钮 */ | ||
| 146 | + cancel() { | ||
| 147 | + this.open = false; | ||
| 148 | + this.reset(); | ||
| 149 | + }, | ||
| 150 | + /** 表单重置 */ | ||
| 151 | + reset() { | ||
| 152 | + this.form = { | ||
| 153 | + id: undefined, | ||
| 154 | + name: undefined, | ||
| 155 | + startAndEndTime: undefined, | ||
| 156 | + startTime: undefined, | ||
| 157 | + endTime: undefined, | ||
| 158 | + }; | ||
| 159 | + this.resetForm("form"); | ||
| 160 | + }, | ||
| 161 | + /** 搜索按钮操作 */ | ||
| 162 | + handleQuery() { | ||
| 163 | + // this.queryParams.pageNo = 1; | ||
| 164 | + this.getList(); | ||
| 165 | + }, | ||
| 166 | + /** 重置按钮操作 */ | ||
| 167 | + resetQuery() { | ||
| 168 | + this.resetForm("queryForm"); | ||
| 169 | + this.handleQuery(); | ||
| 170 | + }, | ||
| 171 | + /** 新增按钮操作 */ | ||
| 172 | + handleAdd() { | ||
| 173 | + this.reset(); | ||
| 174 | + console.log(this.form, "点击新增时的form"); | ||
| 175 | + this.open = true; | ||
| 176 | + this.title = "添加秒杀时段"; | ||
| 177 | + }, | ||
| 178 | + /** 修改按钮操作 */ | ||
| 179 | + handleUpdate(row) { | ||
| 180 | + this.reset(); | ||
| 181 | + const id = row.id; | ||
| 182 | + getSeckillTime(id).then(response => { | ||
| 183 | + response.data.startAndEndTime = [response.data.startTime, response.data.endTime] | ||
| 184 | + this.form = response.data; | ||
| 185 | + this.open = true; | ||
| 186 | + this.title = "修改秒杀时段"; | ||
| 187 | + }); | ||
| 188 | + }, | ||
| 189 | + /** 提交按钮 */ | ||
| 190 | + submitForm() { | ||
| 191 | + this.$refs["form"].validate(valid => { | ||
| 192 | + console.log(valid, "是否通过"); | ||
| 193 | + if (!valid) { | ||
| 194 | + return; | ||
| 195 | + } | ||
| 196 | + // 处理数据 | ||
| 197 | + const data = deepClone(this.form); | ||
| 198 | + data.startTime = this.form.startAndEndTime[0]; | ||
| 199 | + data.endTime = this.form.startAndEndTime[1]; | ||
| 200 | + // 修改的提交 | ||
| 201 | + if (this.form.id != null) { | ||
| 202 | + updateSeckillTime(data).then(response => { | ||
| 203 | + this.$modal.msgSuccess("修改成功"); | ||
| 204 | + this.open = false; | ||
| 205 | + this.getList(); | ||
| 206 | + }); | ||
| 207 | + return; | ||
| 208 | + } | ||
| 209 | + // 添加的提交 | ||
| 210 | + createSeckillTime(data).then(response => { | ||
| 211 | + this.$modal.msgSuccess("新增成功"); | ||
| 212 | + this.open = false; | ||
| 213 | + this.getList(); | ||
| 214 | + }); | ||
| 215 | + }); | ||
| 216 | + }, | ||
| 217 | + /** 删除按钮操作 */ | ||
| 218 | + handleDelete(row) { | ||
| 219 | + const id = row.id; | ||
| 220 | + this.$modal.confirm('是否确认删除秒杀时段编号为"' + id + '"的数据项?').then(function () { | ||
| 221 | + return deleteSeckillTime(id); | ||
| 222 | + }).then(() => { | ||
| 223 | + this.getList(); | ||
| 224 | + this.$modal.msgSuccess("删除成功"); | ||
| 225 | + }).catch(() => { }); | ||
| 226 | + }, | ||
| 227 | + /** 导出按钮操作 */ | ||
| 228 | + // handleExport() { | ||
| 229 | + // // 处理查询参数 | ||
| 230 | + // let params = { ...this.queryParams }; | ||
| 231 | + // params.pageNo = undefined; | ||
| 232 | + // params.pageSize = undefined; | ||
| 233 | + // this.$modal.confirm('是否确认导出所有秒杀时段数据项?').then(() => { | ||
| 234 | + // this.exportLoading = true; | ||
| 235 | + // return exportSeckillTimeExcel(params); | ||
| 236 | + // }).then(response => { | ||
| 237 | + // this.$download.excel(response, '秒杀时段.xls'); | ||
| 238 | + // this.exportLoading = false; | ||
| 239 | + // }).catch(() => { }); | ||
| 240 | + // } | ||
| 241 | + } | ||
| 242 | +}; | ||
| 243 | +</script> |