mall:新增 discount 限时折扣、reward 满减送

pull/2/head
YunaiV 2022-08-17 01:10:13 +08:00
parent 96fc252348
commit 405bf497ef
26 changed files with 371 additions and 795 deletions

View File

@ -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. WAITRUNEND 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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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<String> get() {
return success("true");
}
}

View File

@ -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<Long> createActivity(@Valid @RequestBody ActivityCreateReqVO createReqVO) {
return success(activityService.createActivity(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新促销活动")
@PreAuthorize("@ss.hasPermission('market:activity:update')")
public CommonResult<Boolean> 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<Boolean> 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<ActivityRespVO> 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<List<ActivityRespVO>> getActivityList(@RequestParam("ids") Collection<Long> ids) {
List<ActivityDO> list = activityService.getActivityList(ids);
return success(ActivityConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得促销活动分页")
@PreAuthorize("@ss.hasPermission('market:activity:query')")
public CommonResult<PageResult<ActivityRespVO>> getActivityPage(@Valid ActivityPageReqVO pageVO) {
PageResult<ActivityDO> pageResult = activityService.getActivityPage(pageVO);
return success(ActivityConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,4 @@
/**
* TODO
*/
package cn.iocoder.yudao.module.market.controller.admin.discount;

View File

@ -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<ActivityRespVO> convertList(List<ActivityDO> list);
PageResult<ActivityRespVO> convertPage(PageResult<ActivityDO> page);
}

View File

@ -0,0 +1,4 @@
/**
* TODO
*/
package cn.iocoder.yudao.module.market.convert.discount;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<Long> spuIds;
/**
*
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<Rule> rules;
/**
*
*/
@Data
public static class Rule {
/**
*
*
* 1. N
* 2. N
*/
private Integer limit;
/**
*
*/
private Integer promotionPrice;
/**
*
*/
private Boolean freeDelivery;
/**
*
*/
private Integer integral;
/**
*
*/
private List<Long> couponIds;
/**
*
*/
private List<Integer> couponCounts;
}
}

View File

@ -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<ActivityDO> {
default PageResult<ActivityDO> selectPage(ActivityPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ActivityDO>()
.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));
}
}

View File

@ -0,0 +1,4 @@
/**
* TODO
*/
package cn.iocoder.yudao.module.market.dal.mysql.discount;

View File

@ -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;

View File

@ -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<ActivityDO> getActivityList(Collection<Long> ids);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<ActivityDO> getActivityPage(ActivityPageReqVO pageReqVO);
}

View File

@ -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<ActivityDO> getActivityList(Collection<Long> ids) {
return activityMapper.selectBatchIds(ids);
}
@Override
public PageResult<ActivityDO> getActivityPage(ActivityPageReqVO pageReqVO) {
return activityMapper.selectPage(pageReqVO);
}
}

View File

@ -0,0 +1,4 @@
/**
* TODO
*/
package cn.iocoder.yudao.module.market.service.discount;

View File

@ -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<ActivityDO> 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)));
}
}