From 405bf497ef5ae3f80fd76db6428895c28dccfee8 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 17 Aug 2022 01:10:13 +0800 Subject: [PATCH] =?UTF-8?q?mall=EF=BC=9A=E6=96=B0=E5=A2=9E=20discount=20?= =?UTF-8?q?=E9=99=90=E6=97=B6=E6=8A=98=E6=89=A3=E3=80=81reward=20=E6=BB=A1?= =?UTF-8?q?=E5=87=8F=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/MarketActivityStatusEnum.java | 51 ----- .../common/PromotionActivityStatusEnum.java | 39 ++++ .../common/PromotionConditionTypeEnum.java | 37 ++++ .../common/PromotionProductScopeEnum.java | 38 ++++ .../enums/common/PromotionTypeEnum.java | 4 +- .../admin/MarketTestController.java | 25 --- .../admin/activity/ActivityController.java | 77 ------- .../admin/activity/vo/ActivityBaseVO.java | 59 ------ .../activity/vo/ActivityCreateReqVO.java | 17 -- .../admin/activity/vo/ActivityPageReqVO.java | 57 ----- .../admin/activity/vo/ActivityRespVO.java | 19 -- .../activity/vo/ActivityUpdateReqVO.java | 18 -- .../admin/discount/package-info.java | 4 + .../convert/activity/ActivityConvert.java | 32 --- .../market/convert/discount/package-info.java | 4 + .../dal/dataobject/activity/ActivityDO.java | 64 ------ .../discount/DiscountActivityDO.java | 55 +++++ .../discount/DiscountProductDO.java | 65 ++++++ .../dataobject/reward/RewardActivityDO.java | 116 +++++++++++ .../dal/mysql/activity/ActivityMapper.java | 35 ---- .../dal/mysql/discount/package-info.java | 4 + .../yudao/module/market/package-info.java | 6 +- .../service/activity/ActivityService.java | 62 ------ .../service/activity/ActivityServiceImpl.java | 77 ------- .../market/service/discount/package-info.java | 4 + .../activity/ActivityServiceImplTest.java | 197 ------------------ 26 files changed, 371 insertions(+), 795 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/activity/MarketActivityStatusEnum.java create mode 100644 yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionActivityStatusEnum.java create mode 100644 yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionConditionTypeEnum.java create mode 100644 yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionProductScopeEnum.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/MarketTestController.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/ActivityController.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityBaseVO.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityPageReqVO.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityRespVO.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityUpdateReqVO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/discount/package-info.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/activity/ActivityConvert.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/discount/package-info.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/activity/ActivityDO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountActivityDO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountProductDO.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/reward/RewardActivityDO.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/activity/ActivityMapper.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/discount/package-info.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityService.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/discount/package-info.java delete mode 100644 yudao-module-mall/yudao-module-market-biz/src/test/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImplTest.java diff --git a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/activity/MarketActivityStatusEnum.java b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/activity/MarketActivityStatusEnum.java deleted file mode 100644 index a02b0269c..000000000 --- a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/activity/MarketActivityStatusEnum.java +++ /dev/null @@ -1,51 +0,0 @@ -package cn.iocoder.yudao.module.market.enums.activity; - -import cn.iocoder.yudao.framework.common.core.IntArrayValuable; - -import java.util.Arrays; - -/** - * 促销活动状态枚举 - */ -public enum MarketActivityStatusEnum implements IntArrayValuable { - - WAIT(10, "未开始"), - RUN(20, "进行中"), - END(30, "已结束"), - /** - * 1. WAIT、RUN、END 可以转换成 INVALID 状态。 - * 2. INVALID 只可以转换成 DELETED 状态。 - */ - INVALID(40, "已撤销"), - DELETED(50, "已删除"), - ; - - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MarketActivityStatusEnum::getValue).toArray(); - - /** - * 状态值 - */ - private final Integer value; - /** - * 状态名 - */ - private final String name; - - MarketActivityStatusEnum(Integer value, String name) { - this.value = value; - this.name = name; - } - - public Integer getValue() { - return value; - } - - public String getName() { - return name; - } - - @Override - public int[] array() { - return ARRAYS; - } -} diff --git a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionActivityStatusEnum.java b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionActivityStatusEnum.java new file mode 100644 index 000000000..9577841aa --- /dev/null +++ b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionActivityStatusEnum.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.market.enums.common; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 促销活动的状态枚举 + * + * @author 芋道源码 + */ +@AllArgsConstructor +@Getter +public enum PromotionActivityStatusEnum implements IntArrayValuable { + + WAIT(10, "未开始"), + RUN(20, "进行中"), + END(30, "已结束"), + CLOSE(40, "已关闭"); + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionActivityStatusEnum::getStatus).toArray(); + + /** + * 状态值 + */ + private final Integer status; + /** + * 状态名 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionConditionTypeEnum.java b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionConditionTypeEnum.java new file mode 100644 index 000000000..4df0e6957 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionConditionTypeEnum.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.market.enums.common; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 营销的条件类型枚举 + * + * @author 芋道源码 + */ +@AllArgsConstructor +@Getter +public enum PromotionConditionTypeEnum implements IntArrayValuable { + + PRICE(10, "满 N 元"), + COUNT(20, "满 N 件"); + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionConditionTypeEnum::getType).toArray(); + + /** + * 类型值 + */ + private final Integer type; + /** + * 类型名 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionProductScopeEnum.java b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionProductScopeEnum.java new file mode 100644 index 000000000..e1792ee67 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionProductScopeEnum.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.market.enums.common; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 营销的商品范围枚举 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public enum PromotionProductScopeEnum implements IntArrayValuable { + + ALL(1, "全部商品参与"), + SPU(2, "指定商品参与"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionProductScopeEnum::getScope).toArray(); + + /** + * 范围值 + */ + private final Integer scope; + /** + * 范围名 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionTypeEnum.java b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionTypeEnum.java index 6ac3d65ba..f3f5cc882 100644 --- a/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionTypeEnum.java +++ b/yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionTypeEnum.java @@ -15,8 +15,8 @@ import java.util.Arrays; @AllArgsConstructor public enum PromotionTypeEnum implements IntArrayValuable { - TIME_LIMITED_DISCOUNT(1, "限时折扣"), - FULL_PRIVILEGE(2, "满减送"), + DISCOUNT(1, "限时折扣"), + REWARD(2, "满减送"), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray(); diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/MarketTestController.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/MarketTestController.java deleted file mode 100644 index 49b83b6c9..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/MarketTestController.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.market.controller.admin; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Api(tags = "管理后台 - 营销") -@RestController -@RequestMapping("/market/test") -@Validated -public class MarketTestController { - - @GetMapping("/get") - @ApiOperation("获取 market 信息") - public CommonResult get() { - return success("true"); - } - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/ActivityController.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/ActivityController.java deleted file mode 100644 index dac4211a6..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/ActivityController.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.yudao.module.market.controller.admin.activity; - -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.*; -import java.util.*; -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.module.market.controller.admin.activity.vo.*; -import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO; -import cn.iocoder.yudao.module.market.convert.activity.ActivityConvert; -import cn.iocoder.yudao.module.market.service.activity.ActivityService; - -@Api(tags = "管理后台 - 促销活动") -@RestController -@RequestMapping("/market/activity") -@Validated -public class ActivityController { - - @Resource - private ActivityService activityService; - - @PostMapping("/create") - @ApiOperation("创建促销活动") - @PreAuthorize("@ss.hasPermission('market:activity:create')") - public CommonResult createActivity(@Valid @RequestBody ActivityCreateReqVO createReqVO) { - return success(activityService.createActivity(createReqVO)); - } - - @PutMapping("/update") - @ApiOperation("更新促销活动") - @PreAuthorize("@ss.hasPermission('market:activity:update')") - public CommonResult updateActivity(@Valid @RequestBody ActivityUpdateReqVO updateReqVO) { - activityService.updateActivity(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @ApiOperation("删除促销活动") - @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) - @PreAuthorize("@ss.hasPermission('market:activity:delete')") - public CommonResult deleteActivity(@RequestParam("id") Long id) { - activityService.deleteActivity(id); - return success(true); - } - - @GetMapping("/get") - @ApiOperation("获得促销活动") - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) - @PreAuthorize("@ss.hasPermission('market:activity:query')") - public CommonResult getActivity(@RequestParam("id") Long id) { - ActivityDO activity = activityService.getActivity(id); - return success(ActivityConvert.INSTANCE.convert(activity)); - } - - @GetMapping("/list") - @ApiOperation("获得促销活动列表") - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) - @PreAuthorize("@ss.hasPermission('market:activity:query')") - public CommonResult> getActivityList(@RequestParam("ids") Collection ids) { - List list = activityService.getActivityList(ids); - return success(ActivityConvert.INSTANCE.convertList(list)); - } - - @GetMapping("/page") - @ApiOperation("获得促销活动分页") - @PreAuthorize("@ss.hasPermission('market:activity:query')") - public CommonResult> getActivityPage(@Valid ActivityPageReqVO pageVO) { - PageResult pageResult = activityService.getActivityPage(pageVO); - return success(ActivityConvert.INSTANCE.convertPage(pageResult)); - } - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityBaseVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityBaseVO.java deleted file mode 100644 index f036da230..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityBaseVO.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.iocoder.yudao.module.market.controller.admin.activity.vo; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum; -import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum; -import lombok.*; -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 ActivityBaseVO { - - @ApiModelProperty(value = "活动标题", required = true) - @NotNull(message = "活动标题不能为空") - private String title; - - @ApiModelProperty(value = "活动类型", required = true) - @NotNull(message = "活动类型不能为空") - @InEnum(PromotionTypeEnum.class) - private Integer activityType; - - @ApiModelProperty(value = "活动状态", required = true) - @NotNull(message = "活动状态不能为空") - @InEnum(MarketActivityStatusEnum.class) - 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 = "失效时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private Date invalidTime; - - @ApiModelProperty(value = "删除时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private Date deleteTime; - - @ApiModelProperty(value = "限制折扣字符串,使用 JSON 序列化成字符串存储") - private String timeLimitedDiscount; - - @ApiModelProperty(value = "限制折扣字符串,使用 JSON 序列化成字符串存储") - private String fullPrivilege; - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java deleted file mode 100644 index 0ca112709..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityCreateReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.market.controller.admin.activity.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; - -/** - * @author xia - */ -@ApiModel("管理后台 - 促销活动创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ActivityCreateReqVO extends ActivityBaseVO { - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityPageReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityPageReqVO.java deleted file mode 100644 index 9eefc7c0d..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityPageReqVO.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.yudao.module.market.controller.admin.activity.vo; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum; -import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum; -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 ActivityPageReqVO extends PageParam { - - @ApiModelProperty(value = "活动标题") - private String title; - - @ApiModelProperty(value = "活动类型") - @InEnum(PromotionTypeEnum.class) - private Integer activityType; - - @ApiModelProperty(value = "活动状态") - @InEnum(MarketActivityStatusEnum.class) - private Integer status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "开始时间") - private Date[] startTime; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "结束时间") - private Date[] endTime; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "失效时间") - private Date[] invalidTime; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "删除时间") - private Date[] deleteTime; - - @ApiModelProperty(value = "限制折扣字符串,使用 JSON 序列化成字符串存储") - private String timeLimitedDiscount; - - @ApiModelProperty(value = "限制折扣字符串,使用 JSON 序列化成字符串存储") - private String fullPrivilege; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "创建时间") - private Date[] createTime; - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityRespVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityRespVO.java deleted file mode 100644 index de7ca3af2..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityRespVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.market.controller.admin.activity.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; - -@ApiModel("管理后台 - 促销活动 Response VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ActivityRespVO extends ActivityBaseVO { - - @ApiModelProperty(value = "活动编号", required = true) - private Long id; - - @ApiModelProperty(value = "创建时间", required = true) - private Date createTime; - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityUpdateReqVO.java deleted file mode 100644 index 1db24f259..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.market.controller.admin.activity.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 ActivityUpdateReqVO extends ActivityBaseVO { - - @ApiModelProperty(value = "活动编号", required = true) - @NotNull(message = "活动编号不能为空") - private Long id; - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/discount/package-info.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/discount/package-info.java new file mode 100644 index 000000000..a3f145f26 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/discount/package-info.java @@ -0,0 +1,4 @@ +/** + * TODO 占位 + */ +package cn.iocoder.yudao.module.market.controller.admin.discount; diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/activity/ActivityConvert.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/activity/ActivityConvert.java deleted file mode 100644 index 64ba73975..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/activity/ActivityConvert.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.module.market.convert.activity; - -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.market.controller.admin.activity.vo.*; -import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO; - -/** - * 促销活动 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface ActivityConvert { - - ActivityConvert INSTANCE = Mappers.getMapper(ActivityConvert.class); - - ActivityDO convert(ActivityCreateReqVO bean); - - ActivityDO convert(ActivityUpdateReqVO bean); - - ActivityRespVO convert(ActivityDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/discount/package-info.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/discount/package-info.java new file mode 100644 index 000000000..787492406 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/discount/package-info.java @@ -0,0 +1,4 @@ +/** + * TODO 占位 + */ +package cn.iocoder.yudao.module.market.convert.discount; diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/activity/ActivityDO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/activity/ActivityDO.java deleted file mode 100644 index 13dcbf67c..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/activity/ActivityDO.java +++ /dev/null @@ -1,64 +0,0 @@ -package cn.iocoder.yudao.module.market.dal.dataobject.activity; - -import lombok.*; -import java.util.*; -import com.baomidou.mybatisplus.annotation.*; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; - -/** - * 促销活动 DO - * - * @author 芋道源码 - */ -@TableName("market_activity") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class ActivityDO extends BaseDO { - - /** - * 活动编号 - */ - @TableId - private Long id; - /** - * 活动标题 - */ - private String title; - /** - * 活动类型MarketActivityTypeEnum - */ - private Integer activityType; - /** - * 活动状态MarketActivityStatusEnum - */ - private Integer status; - /** - * 开始时间 - */ - private Date startTime; - /** - * 结束时间 - */ - private Date endTime; - /** - * 失效时间 - */ - private Date invalidTime; - /** - * 删除时间 - */ - private Date deleteTime; - /** - * 限制折扣字符串,使用 JSON 序列化成字符串存储 - */ - private String timeLimitedDiscount; - /** - * 限制折扣字符串,使用 JSON 序列化成字符串存储 - */ - private String fullPrivilege; - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountActivityDO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountActivityDO.java new file mode 100644 index 000000000..8780546f6 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountActivityDO.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.market.dal.dataobject.discount; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.market.enums.common.PromotionActivityStatusEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 限时折扣活动 DO + * + * 一个活动下,可以有 {@link DiscountProductDO} 商品; + * 一个商品,在指定时间段内,只能属于一个活动; + * + * @author 芋道源码 + */ +@TableName(value = "promotion_discount_activity", autoResultMap = true) +@KeySequence("promotion_discount_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +public class DiscountActivityDO extends BaseDO { + + /** + * 活动编号,主键自增 + */ + @TableId + private Long id; + /** + * 活动标题 + */ + private String name; + /** + * 状态 + * + * 枚举 {@link PromotionActivityStatusEnum} + */ + private Integer status; + /** + * 开始时间 + */ + private Date startTime; + /** + * 结束时间 + */ + private Date endTime; + /** + * 备注 + */ + private String remark; + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountProductDO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountProductDO.java new file mode 100644 index 000000000..cd73a19a5 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/discount/DiscountProductDO.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.market.dal.dataobject.discount; + +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.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 限时折扣商品 DO + * + * @author 芋道源码 + */ +@TableName(value = "promotion_discount_product", autoResultMap = true) +@KeySequence("promotion_discount_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +public class DiscountProductDO extends BaseDO { + + /** + * 编号,主键自增 + */ + @TableId + private Long id; + /** + * 限时折扣活动的编号 + * + * 关联 {@link DiscountActivityDO#getId()} + */ + private Long activityId; + /** + * 商品 SPU 编号 + * + * 关联 ProductSpuDO 的 id 编号 + */ + private Long spuId; + /** + * 商品 SKU 编号 + * + * 关联 ProductSkuDO 的 id 编号 + */ + private Long skuId; + /** + * 开始时间 + */ + private Date startTime; + /** + * 结束时间 + */ + private Date endTime; + /** + * 销售价格,单位:分 + * + * 冗余 ProductSkuDO 的 price 字段 + */ + private Integer originalPrice; + /** + * 优惠价格,单位:分 + */ + private Integer promotionPrice; + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/reward/RewardActivityDO.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/reward/RewardActivityDO.java new file mode 100644 index 000000000..85cd8c955 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/dataobject/reward/RewardActivityDO.java @@ -0,0 +1,116 @@ +package cn.iocoder.yudao.module.market.dal.dataobject.reward; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.market.enums.common.PromotionActivityStatusEnum; +import cn.iocoder.yudao.module.market.enums.common.PromotionConditionTypeEnum; +import cn.iocoder.yudao.module.market.enums.common.PromotionProductScopeEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; +import java.util.List; + +/** + * 满减送活动 DO + * + * @author 芋道源码 + */ +@TableName(value = "promotion_reward_activity", autoResultMap = true) +@KeySequence("promotion_reward_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +public class RewardActivityDO extends BaseDO { + + /** + * 活动编号,主键自增 + */ + @TableId + private Long id; + /** + * 活动标题 + */ + private String name; + /** + * 状态 + * + * 枚举 {@link PromotionActivityStatusEnum} + */ + private Integer status; + /** + * 开始时间 + */ + private Date startTime; + /** + * 结束时间 + */ + private Date endTime; + /** + * 备注 + */ + private String remark; + /** + * 条件类型 + * + * 枚举 {@link PromotionConditionTypeEnum} + */ + private Integer conditionType; + /** + * 商品范围 + * + * 枚举 {@link PromotionProductScopeEnum} + */ + private Integer productScope; + /** + * 商品 SPU 编号的数组 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List spuIds; + /** + * 优惠规则的数组 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List rules; + + /** + * 优惠规则 + */ + @Data + public static class Rule { + + /** + * 优惠门槛 + * + * 1. 满 N 元,单位:分 + * 2. 满 N 件 + */ + private Integer limit; + /** + * 优惠价格,单位:分 + */ + private Integer promotionPrice; + /** + * 是否包邮 + */ + private Boolean freeDelivery; + /** + * 赠送的积分 + */ + private Integer integral; + /** + * 赠送的优惠劵编号的数组 + */ + private List couponIds; + /** + * 赠送的优惠卷数量的数组 + */ + private List couponCounts; + + } + + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/activity/ActivityMapper.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/activity/ActivityMapper.java deleted file mode 100644 index feb3fb122..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/activity/ActivityMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.market.dal.mysql.activity; - -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.market.dal.dataobject.activity.ActivityDO; -import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.market.controller.admin.activity.vo.*; - -/** - * 促销活动 Mapper - * - * @author 芋道源码 - */ -@Mapper -public interface ActivityMapper extends BaseMapperX { - - default PageResult selectPage(ActivityPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(ActivityDO::getTitle, reqVO.getTitle()) - .eqIfPresent(ActivityDO::getActivityType, reqVO.getActivityType()) - .eqIfPresent(ActivityDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(ActivityDO::getStartTime, reqVO.getStartTime()) - .betweenIfPresent(ActivityDO::getEndTime, reqVO.getEndTime()) - .betweenIfPresent(ActivityDO::getInvalidTime, reqVO.getInvalidTime()) - .betweenIfPresent(ActivityDO::getDeleteTime, reqVO.getDeleteTime()) - .eqIfPresent(ActivityDO::getTimeLimitedDiscount, reqVO.getTimeLimitedDiscount()) - .eqIfPresent(ActivityDO::getFullPrivilege, reqVO.getFullPrivilege()) - .betweenIfPresent(ActivityDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(ActivityDO::getId)); - } - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/discount/package-info.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/discount/package-info.java new file mode 100644 index 000000000..f8de42cd9 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/dal/mysql/discount/package-info.java @@ -0,0 +1,4 @@ +/** + * TODO 占位 + */ +package cn.iocoder.yudao.module.market.dal.mysql.discount; diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/package-info.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/package-info.java index 2efde4ec7..92b9c698d 100644 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/package-info.java +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/package-info.java @@ -1,8 +1,8 @@ /** - * market 模块,我们放营销业务。 + * promotion 模块,我们放营销业务。 * 例如说:营销活动、banner、优惠券等等 * - * 1. Controller URL:以 /market/ 开头,避免和其它 Module 冲突 - * 2. DataObject 表名:以 market_ 开头,方便在数据库中区分 + * 1. Controller URL:以 /promotion/ 开头,避免和其它 Module 冲突 + * 2. DataObject 表名:以 promotion_ 开头,方便在数据库中区分 */ package cn.iocoder.yudao.module.market; diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityService.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityService.java deleted file mode 100644 index 1d5e27857..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityService.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.iocoder.yudao.module.market.service.activity; - -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.market.controller.admin.activity.vo.*; -import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -/** - * 促销活动 Service 接口 - * - * @author 芋道源码 - */ -public interface ActivityService { - - /** - * 创建促销活动 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createActivity(@Valid ActivityCreateReqVO createReqVO); - - /** - * 更新促销活动 - * - * @param updateReqVO 更新信息 - */ - void updateActivity(@Valid ActivityUpdateReqVO updateReqVO); - - /** - * 删除促销活动 - * - * @param id 编号 - */ - void deleteActivity(Long id); - - /** - * 获得促销活动 - * - * @param id 编号 - * @return 促销活动 - */ - ActivityDO getActivity(Long id); - - /** - * 获得促销活动列表 - * - * @param ids 编号 - * @return 促销活动列表 - */ - List getActivityList(Collection ids); - - /** - * 获得促销活动分页 - * - * @param pageReqVO 分页查询 - * @return 促销活动分页 - */ - PageResult getActivityPage(ActivityPageReqVO pageReqVO); - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImpl.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImpl.java deleted file mode 100644 index 57bb9af53..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.yudao.module.market.service.activity; - -import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; - -import java.util.*; -import cn.iocoder.yudao.module.market.controller.admin.activity.vo.*; -import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import cn.iocoder.yudao.module.market.convert.activity.ActivityConvert; -import cn.iocoder.yudao.module.market.dal.mysql.activity.ActivityMapper; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.market.enums.ErrorCodeConstants.*; - -/** - * 促销活动 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -public class ActivityServiceImpl implements ActivityService { - - @Resource - private ActivityMapper activityMapper; - - @Override - public Long createActivity(ActivityCreateReqVO createReqVO) { - // 插入 - ActivityDO activity = ActivityConvert.INSTANCE.convert(createReqVO); - activityMapper.insert(activity); - // 返回 - return activity.getId(); - } - - @Override - public void updateActivity(ActivityUpdateReqVO updateReqVO) { - // 校验存在 - this.validateActivityExists(updateReqVO.getId()); - // 更新 - ActivityDO updateObj = ActivityConvert.INSTANCE.convert(updateReqVO); - activityMapper.updateById(updateObj); - } - - @Override - public void deleteActivity(Long id) { - // 校验存在 - this.validateActivityExists(id); - // 删除 - activityMapper.deleteById(id); - } - - private void validateActivityExists(Long id) { - if (activityMapper.selectById(id) == null) { - throw exception(ACTIVITY_NOT_EXISTS); - } - } - - @Override - public ActivityDO getActivity(Long id) { - return activityMapper.selectById(id); - } - - @Override - public List getActivityList(Collection ids) { - return activityMapper.selectBatchIds(ids); - } - - @Override - public PageResult getActivityPage(ActivityPageReqVO pageReqVO) { - return activityMapper.selectPage(pageReqVO); - } - -} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/discount/package-info.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/discount/package-info.java new file mode 100644 index 000000000..f52febd44 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/discount/package-info.java @@ -0,0 +1,4 @@ +/** + * TODO 占位 + */ +package cn.iocoder.yudao.module.market.service.discount; diff --git a/yudao-module-mall/yudao-module-market-biz/src/test/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImplTest.java b/yudao-module-mall/yudao-module-market-biz/src/test/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImplTest.java deleted file mode 100644 index b292251a4..000000000 --- a/yudao-module-mall/yudao-module-market-biz/src/test/java/cn/iocoder/yudao/module/market/service/activity/ActivityServiceImplTest.java +++ /dev/null @@ -1,197 +0,0 @@ -package cn.iocoder.yudao.module.market.service.activity; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import javax.annotation.Resource; - -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; - -import cn.iocoder.yudao.module.market.controller.admin.activity.vo.*; -import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO; -import cn.iocoder.yudao.module.market.dal.mysql.activity.ActivityMapper; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.springframework.context.annotation.Import; - -import static cn.iocoder.yudao.module.market.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 org.junit.jupiter.api.Assertions.*; - -/** -* {@link ActivityServiceImpl} 的单元测试类 -* -* @author 芋道源码 -*/ -@Import(ActivityServiceImpl.class) -public class ActivityServiceImplTest extends BaseDbUnitTest { - - @Resource - private ActivityServiceImpl activityService; - - @Resource - private ActivityMapper activityMapper; - - @Test - public void testCreateActivity_success() { - // 准备参数 - ActivityCreateReqVO reqVO = randomPojo(ActivityCreateReqVO.class); - - // 调用 - Long activityId = activityService.createActivity(reqVO); - // 断言 - assertNotNull(activityId); - // 校验记录的属性是否正确 - ActivityDO activity = activityMapper.selectById(activityId); - assertPojoEquals(reqVO, activity); - } - - @Test - public void testUpdateActivity_success() { - // mock 数据 - ActivityDO dbActivity = randomPojo(ActivityDO.class); - activityMapper.insert(dbActivity);// @Sql: 先插入出一条存在的数据 - // 准备参数 - ActivityUpdateReqVO reqVO = randomPojo(ActivityUpdateReqVO.class, o -> { - o.setId(dbActivity.getId()); // 设置更新的 ID - }); - - // 调用 - activityService.updateActivity(reqVO); - // 校验是否更新正确 - ActivityDO activity = activityMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, activity); - } - - @Test - public void testUpdateActivity_notExists() { - // 准备参数 - ActivityUpdateReqVO reqVO = randomPojo(ActivityUpdateReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> activityService.updateActivity(reqVO), ACTIVITY_NOT_EXISTS); - } - - @Test - public void testDeleteActivity_success() { - // mock 数据 - ActivityDO dbActivity = randomPojo(ActivityDO.class); - activityMapper.insert(dbActivity);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbActivity.getId(); - - // 调用 - activityService.deleteActivity(id); - // 校验数据不存在了 - assertNull(activityMapper.selectById(id)); - } - - @Test - public void testDeleteActivity_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> activityService.deleteActivity(id), ACTIVITY_NOT_EXISTS); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetActivityPage() { - // mock 数据 - ActivityDO dbActivity = randomPojo(ActivityDO.class, o -> { // 等会查询到 - o.setTitle(null); - o.setActivityType(null); - o.setStatus(null); - o.setStartTime(null); - o.setEndTime(null); - o.setInvalidTime(null); - o.setDeleteTime(null); - o.setTimeLimitedDiscount(null); - o.setFullPrivilege(null); - o.setCreateTime(null); - }); - activityMapper.insert(dbActivity); - // 测试 title 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setTitle(null))); - // 测试 activityType 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setActivityType(null))); - // 测试 status 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setStatus(null))); - // 测试 startTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setStartTime(null))); - // 测试 endTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setEndTime(null))); - // 测试 invalidTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setInvalidTime(null))); - // 测试 deleteTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setDeleteTime(null))); - // 测试 timeLimitedDiscount 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setTimeLimitedDiscount(null))); - // 测试 fullPrivilege 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setFullPrivilege(null))); - // 测试 createTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setCreateTime(null))); - // 准备参数 - ActivityPageReqVO reqVO = new ActivityPageReqVO(); - reqVO.setTitle(null); - reqVO.setActivityType(null); - reqVO.setStatus(null); - reqVO.setStartTime(null); - reqVO.setEndTime(null); - reqVO.setInvalidTime(null); - reqVO.setDeleteTime(null); - reqVO.setTimeLimitedDiscount(null); - reqVO.setFullPrivilege(null); - reqVO.setCreateTime(null); - - // 调用 - PageResult pageResult = activityService.getActivityPage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbActivity, pageResult.getList().get(0)); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetActivityList() { - // mock 数据 - ActivityDO dbActivity = randomPojo(ActivityDO.class, o -> { // 等会查询到 - o.setTitle(null); - o.setActivityType(null); - o.setStatus(null); - o.setStartTime(null); - o.setEndTime(null); - o.setInvalidTime(null); - o.setDeleteTime(null); - o.setTimeLimitedDiscount(null); - o.setFullPrivilege(null); - o.setCreateTime(null); - }); - activityMapper.insert(dbActivity); - // 测试 title 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setTitle(null))); - // 测试 activityType 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setActivityType(null))); - // 测试 status 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setStatus(null))); - // 测试 startTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setStartTime(null))); - // 测试 endTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setEndTime(null))); - // 测试 invalidTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setInvalidTime(null))); - // 测试 deleteTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setDeleteTime(null))); - // 测试 timeLimitedDiscount 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setTimeLimitedDiscount(null))); - // 测试 fullPrivilege 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setFullPrivilege(null))); - // 测试 createTime 不匹配 - activityMapper.insert(cloneIgnoreId(dbActivity, o -> o.setCreateTime(null))); - } - -}