Commit 331be53b8ba547469482bb99363e11e29c2e8cbf
1 parent
49d72601
fix:完善时段配置管理
Showing
10 changed files
with
105 additions
and
115 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| @@ -56,5 +56,7 @@ public interface ErrorCodeConstants { | @@ -56,5 +56,7 @@ public interface ErrorCodeConstants { | ||
| 56 | // ========== 秒杀时段 1013009000 ========== | 56 | // ========== 秒杀时段 1013009000 ========== |
| 57 | ErrorCode SECKILL_TIME_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在"); | 57 | ErrorCode SECKILL_TIME_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在"); |
| 58 | ErrorCode SECKILL_TIME_CONFLICTS = new ErrorCode(1013009001, "秒杀时段冲突"); | 58 | ErrorCode SECKILL_TIME_CONFLICTS = new ErrorCode(1013009001, "秒杀时段冲突"); |
| 59 | + ErrorCode SECKILL_TIME_EQUAL = new ErrorCode(1013009002, "秒杀时段开始时间和结束时间不能相等"); | ||
| 60 | + ErrorCode SECKILL_START_TIME_BEFORE_END_TIME = new ErrorCode(1013009003, "秒杀时段开始时间不能在结束时间之后"); | ||
| 59 | 61 | ||
| 60 | } | 62 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillConfigController.java
| @@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill; | @@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigRespVO; | ||
| 8 | -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO; | 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.*; |
| 9 | import cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig.SeckillConfigConvert; | 6 | import cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig.SeckillConfigConvert; |
| 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; |
| 11 | import cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig.SeckillConfigService; | 8 | import cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig.SeckillConfigService; |
| @@ -77,6 +74,13 @@ public class SeckillConfigController { | @@ -77,6 +74,13 @@ public class SeckillConfigController { | ||
| 77 | return success(SeckillConfigConvert.INSTANCE.convertList(list)); | 74 | return success(SeckillConfigConvert.INSTANCE.convertList(list)); |
| 78 | } | 75 | } |
| 79 | 76 | ||
| 77 | + @GetMapping("/list-all-simple") | ||
| 78 | + @Operation(summary = "获得所有开启状态的秒杀时段精简列表", description = "主要用于前端的下拉选项") | ||
| 79 | + public CommonResult<List<SeckillConfigSimpleRespVO>> getListAllSimple() { | ||
| 80 | + List<SeckillConfigDO> list = seckillConfigService.getListAllSimple(); | ||
| 81 | + return success(SeckillConfigConvert.INSTANCE.convertList1(list)); | ||
| 82 | + } | ||
| 83 | + | ||
| 80 | @GetMapping("/page") | 84 | @GetMapping("/page") |
| 81 | @Operation(summary = "获得秒杀活动分页") | 85 | @Operation(summary = "获得秒杀活动分页") |
| 82 | @PreAuthorize("@ss.hasPermission('promotion:seckill-config:query')") | 86 | @PreAuthorize("@ss.hasPermission('promotion:seckill-config:query')") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigSimpleRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.NoArgsConstructor; | ||
| 7 | + | ||
| 8 | +import javax.validation.constraints.NotNull; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 管理后台 - 秒杀时段配置精简信息 Response VO | ||
| 12 | + * | ||
| 13 | + * @author HUIHUI | ||
| 14 | + */ | ||
| 15 | +@Schema(description = "管理后台 - 秒杀时段配置精简信息 Response VO") | ||
| 16 | +@Data | ||
| 17 | +@NoArgsConstructor | ||
| 18 | +@AllArgsConstructor | ||
| 19 | +public class SeckillConfigSimpleRespVO { | ||
| 20 | + | ||
| 21 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 22 | + @NotNull(message = "编号不能为空") | ||
| 23 | + private Long id; | ||
| 24 | + | ||
| 25 | + @Schema(description = "秒杀时段名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "早上场") | ||
| 26 | + @NotNull(message = "秒杀时段名称不能为空") | ||
| 27 | + private String name; | ||
| 28 | + | ||
| 29 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillconfig/SeckillConfigConvert.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; | 4 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigRespVO; | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigRespVO; |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigSimpleRespVO; | ||
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; |
| 8 | import org.mapstruct.Mapper; | 9 | import org.mapstruct.Mapper; |
| @@ -28,6 +29,8 @@ public interface SeckillConfigConvert { | @@ -28,6 +29,8 @@ public interface SeckillConfigConvert { | ||
| 28 | 29 | ||
| 29 | List<SeckillConfigRespVO> convertList(List<SeckillConfigDO> list); | 30 | List<SeckillConfigRespVO> convertList(List<SeckillConfigDO> list); |
| 30 | 31 | ||
| 32 | + List<SeckillConfigSimpleRespVO> convertList1(List<SeckillConfigDO> list); | ||
| 33 | + | ||
| 31 | PageResult<SeckillConfigRespVO> convertPage(PageResult<SeckillConfigDO> page); | 34 | PageResult<SeckillConfigRespVO> convertPage(PageResult<SeckillConfigDO> page); |
| 32 | 35 | ||
| 33 | } | 36 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java
| @@ -41,7 +41,7 @@ public class SeckillActivityDO extends BaseDO { | @@ -41,7 +41,7 @@ public class SeckillActivityDO extends BaseDO { | ||
| 41 | private String name; | 41 | private String name; |
| 42 | /** | 42 | /** |
| 43 | * 活动状态 | 43 | * 活动状态 |
| 44 | - * <p> | 44 | + * |
| 45 | * 枚举 {@link PromotionActivityStatusEnum 对应的类} | 45 | * 枚举 {@link PromotionActivityStatusEnum 对应的类} |
| 46 | */ | 46 | */ |
| 47 | private Integer status; | 47 | private Integer status; |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillconfig/SeckillConfigMapper.java
| @@ -5,34 +5,11 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | @@ -5,34 +5,11 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; |
| 8 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 9 | -import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; | ||
| 10 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 9 | ||
| 12 | -import java.time.LocalTime; | ||
| 13 | -import java.util.Collection; | ||
| 14 | -import java.util.List; | ||
| 15 | - | ||
| 16 | @Mapper | 10 | @Mapper |
| 17 | public interface SeckillConfigMapper extends BaseMapperX<SeckillConfigDO> { | 11 | public interface SeckillConfigMapper extends BaseMapperX<SeckillConfigDO> { |
| 18 | 12 | ||
| 19 | - default List<SeckillConfigDO> selectListByTime(LocalTime time) { | ||
| 20 | - return selectList(SeckillConfigDO::getStartTime, SeckillConfigDO::getEndTime, time); | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | - default List<SeckillConfigDO> selectListByTime(LocalTime startTime, LocalTime endTime) { | ||
| 24 | - return selectList(new LambdaQueryWrapper<SeckillConfigDO>() | ||
| 25 | - .ge(SeckillConfigDO::getStartTime, startTime) | ||
| 26 | - .le(SeckillConfigDO::getEndTime, endTime)); | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - default void updateActivityCount(Collection<Long> ids, String type, Integer count) { | ||
| 30 | - new LambdaUpdateChainWrapper<>(this) | ||
| 31 | - .in(SeckillConfigDO::getId, ids) | ||
| 32 | - .setSql("`seckill_activity_count` = `seckill_activity_count` " + type + count) | ||
| 33 | - .update(); | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | default PageResult<SeckillConfigDO> selectPage(SeckillConfigPageReqVO reqVO) { | 13 | default PageResult<SeckillConfigDO> selectPage(SeckillConfigPageReqVO reqVO) { |
| 37 | return selectPage(reqVO, new LambdaQueryWrapperX<SeckillConfigDO>() | 14 | return selectPage(reqVO, new LambdaQueryWrapperX<SeckillConfigDO>() |
| 38 | .likeIfPresent(SeckillConfigDO::getName, reqVO.getName()) | 15 | .likeIfPresent(SeckillConfigDO::getName, reqVO.getName()) |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java
| @@ -56,8 +56,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -56,8 +56,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 56 | // 插入商品 | 56 | // 插入商品 |
| 57 | List<SeckillProductDO> productDOs = SeckillActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), seckillActivity); | 57 | List<SeckillProductDO> productDOs = SeckillActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), seckillActivity); |
| 58 | seckillProductMapper.insertBatch(productDOs); | 58 | seckillProductMapper.insertBatch(productDOs); |
| 59 | - // 更新秒杀时段的秒杀活动数量 | ||
| 60 | - seckillConfigService.seckillActivityCountIncr(createReqVO.getConfigIds()); | ||
| 61 | return seckillActivity.getId(); | 59 | return seckillActivity.getId(); |
| 62 | } | 60 | } |
| 63 | 61 | ||
| @@ -77,31 +75,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -77,31 +75,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 77 | seckillActivityMapper.updateById(updateObj); | 75 | seckillActivityMapper.updateById(updateObj); |
| 78 | // 更新商品 | 76 | // 更新商品 |
| 79 | updateSeckillProduct(updateReqVO); | 77 | updateSeckillProduct(updateReqVO); |
| 80 | - // 更新秒杀时段的秒杀活动数量 | ||
| 81 | - updateSeckillConfigActivityCount(seckillActivity, updateReqVO.getConfigIds()); | ||
| 82 | } | 78 | } |
| 83 | 79 | ||
| 84 | - /** | ||
| 85 | - * 更新秒杀时段的秒杀活动数量 | ||
| 86 | - * | ||
| 87 | - * @param seckillActivity 查询出的秒杀活动 | ||
| 88 | - * @param updateTimeIds 更新后的秒杀时段id列表 | ||
| 89 | - */ | ||
| 90 | - private void updateSeckillConfigActivityCount(SeckillActivityDO seckillActivity, List<Long> updateTimeIds) { | ||
| 91 | - // 查询出 timeIds | ||
| 92 | - List<Long> existsTimeIds = seckillActivity.getConfigIds(); | ||
| 93 | - // 需要减少的时间段 | ||
| 94 | - Collection<Long> reduceIds = CollUtil.filterNew(existsTimeIds, existsTimeId -> !updateTimeIds.contains(existsTimeId)); | ||
| 95 | - // 需要添加的时间段 | ||
| 96 | - updateTimeIds.removeIf(existsTimeIds::contains); | ||
| 97 | - // 更新减少时间段和增加时间段 | ||
| 98 | - if (CollUtil.isNotEmpty(updateTimeIds)) { | ||
| 99 | - seckillConfigService.seckillActivityCountIncr(updateTimeIds); | ||
| 100 | - } | ||
| 101 | - if (CollUtil.isNotEmpty(reduceIds)) { | ||
| 102 | - seckillConfigService.seckillActivityCountDecr(reduceIds); | ||
| 103 | - } | ||
| 104 | - } | ||
| 105 | 80 | ||
| 106 | /** | 81 | /** |
| 107 | * 更新秒杀商品 | 82 | * 更新秒杀商品 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigService.java
| @@ -61,20 +61,6 @@ public interface SeckillConfigService { | @@ -61,20 +61,6 @@ public interface SeckillConfigService { | ||
| 61 | */ | 61 | */ |
| 62 | void validateSeckillConfigExists(Collection<Long> timeIds); | 62 | void validateSeckillConfigExists(Collection<Long> timeIds); |
| 63 | 63 | ||
| 64 | - /** | ||
| 65 | - * 秒杀时段列表的秒杀活动数量加 1 | ||
| 66 | - * | ||
| 67 | - * @param ids 秒杀时段id列表 | ||
| 68 | - */ | ||
| 69 | - void seckillActivityCountIncr(Collection<Long> ids); | ||
| 70 | - | ||
| 71 | - | ||
| 72 | - /** | ||
| 73 | - * 秒杀时段列表的秒杀活动数量减 1 | ||
| 74 | - * | ||
| 75 | - * @param ids 秒杀时段id列表 | ||
| 76 | - */ | ||
| 77 | - void seckillActivityCountDecr(Collection<Long> ids); | ||
| 78 | 64 | ||
| 79 | /** | 65 | /** |
| 80 | * 获得秒杀时间段配置分页数据 | 66 | * 获得秒杀时间段配置分页数据 |
| @@ -84,4 +70,10 @@ public interface SeckillConfigService { | @@ -84,4 +70,10 @@ public interface SeckillConfigService { | ||
| 84 | */ | 70 | */ |
| 85 | PageResult<SeckillConfigDO> getSeckillConfigPage(SeckillConfigPageReqVO pageVO); | 71 | PageResult<SeckillConfigDO> getSeckillConfigPage(SeckillConfigPageReqVO pageVO); |
| 86 | 72 | ||
| 73 | + /** | ||
| 74 | + * 获得所有正常状态的时段配置列表 | ||
| 75 | + * | ||
| 76 | + * @return 秒杀时段列表 | ||
| 77 | + */ | ||
| 78 | + List<SeckillConfigDO> getListAllSimple(); | ||
| 87 | } | 79 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java
| 1 | package cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig; | 1 | package cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; |
| @@ -15,11 +16,11 @@ import javax.annotation.Resource; | @@ -15,11 +16,11 @@ import javax.annotation.Resource; | ||
| 15 | import java.time.LocalTime; | 16 | import java.time.LocalTime; |
| 16 | import java.util.Collection; | 17 | import java.util.Collection; |
| 17 | import java.util.List; | 18 | import java.util.List; |
| 18 | -import java.util.Objects; | 19 | +import java.util.Set; |
| 20 | +import java.util.stream.Collectors; | ||
| 19 | 21 | ||
| 20 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 21 | -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_TIME_CONFLICTS; | ||
| 22 | -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_TIME_NOT_EXISTS; | 23 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | * 秒杀时段 Service 实现类 | 26 | * 秒杀时段 Service 实现类 |
| @@ -36,7 +37,7 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | @@ -36,7 +37,7 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | ||
| 36 | @Override | 37 | @Override |
| 37 | public Long createSeckillConfig(SeckillConfigCreateReqVO createReqVO) { | 38 | public Long createSeckillConfig(SeckillConfigCreateReqVO createReqVO) { |
| 38 | // 校验时间段是否冲突 | 39 | // 校验时间段是否冲突 |
| 39 | - //validateSeckillConfigConflict(null, createReqVO.getStartTime(), createReqVO.getEndTime()); | 40 | + validateSeckillConfigConflict(createReqVO.getStartTime(), createReqVO.getEndTime()); |
| 40 | 41 | ||
| 41 | // 插入 | 42 | // 插入 |
| 42 | SeckillConfigDO seckillConfig = SeckillConfigConvert.INSTANCE.convert(createReqVO); | 43 | SeckillConfigDO seckillConfig = SeckillConfigConvert.INSTANCE.convert(createReqVO); |
| @@ -48,9 +49,9 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | @@ -48,9 +49,9 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | ||
| 48 | @Override | 49 | @Override |
| 49 | public void updateSeckillConfig(SeckillConfigUpdateReqVO updateReqVO) { | 50 | public void updateSeckillConfig(SeckillConfigUpdateReqVO updateReqVO) { |
| 50 | // 校验存在 | 51 | // 校验存在 |
| 51 | - this.validateSeckillConfigExists(updateReqVO.getId()); | 52 | + validateSeckillConfigExists(updateReqVO.getId()); |
| 52 | // 校验时间段是否冲突 | 53 | // 校验时间段是否冲突 |
| 53 | - //validateSeckillConfigConflict(updateReqVO.getId(), updateReqVO.getStartTime(), updateReqVO.getEndTime()); | 54 | + validateSeckillConfigConflict(updateReqVO.getStartTime(), updateReqVO.getEndTime()); |
| 54 | 55 | ||
| 55 | // 更新 | 56 | // 更新 |
| 56 | SeckillConfigDO updateObj = SeckillConfigConvert.INSTANCE.convert(updateReqVO); | 57 | SeckillConfigDO updateObj = SeckillConfigConvert.INSTANCE.convert(updateReqVO); |
| @@ -60,7 +61,8 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | @@ -60,7 +61,8 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | ||
| 60 | @Override | 61 | @Override |
| 61 | public void deleteSeckillConfig(Long id) { | 62 | public void deleteSeckillConfig(Long id) { |
| 62 | // 校验存在 | 63 | // 校验存在 |
| 63 | - this.validateSeckillConfigExists(id); | 64 | + validateSeckillConfigExists(id); |
| 65 | + | ||
| 64 | // 删除 | 66 | // 删除 |
| 65 | seckillConfigMapper.deleteById(id); | 67 | seckillConfigMapper.deleteById(id); |
| 66 | } | 68 | } |
| @@ -77,21 +79,32 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | @@ -77,21 +79,32 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | ||
| 77 | * @param startTime 开始时间 | 79 | * @param startTime 开始时间 |
| 78 | * @param endTime 结束时间 | 80 | * @param endTime 结束时间 |
| 79 | */ | 81 | */ |
| 80 | - private void validateSeckillConfigConflict(Long id, LocalTime startTime, LocalTime endTime) { | ||
| 81 | - //查询开始时间,结束时间,是否在别人的时间段内 | ||
| 82 | - // TODO 为什么要检查这个时间段是否冲突 比如早上 09:00:00 - 10:00:00 我再添加一个 09:00:00 - 09:30:00 不可以这样吗? | ||
| 83 | - List<SeckillConfigDO> startTimeList = seckillConfigMapper.selectListByTime(startTime); | ||
| 84 | - List<SeckillConfigDO> endTimeList = seckillConfigMapper.selectListByTime(endTime); | ||
| 85 | - //查询自己时间段内是否有时间段 | ||
| 86 | - List<SeckillConfigDO> startEndTimeList = seckillConfigMapper.selectListByTime(startTime, endTime); | ||
| 87 | - if (id != null) { | ||
| 88 | - //移除自己 | ||
| 89 | - startTimeList.removeIf(seckillConfig -> Objects.equals(seckillConfig.getId(), id)); | ||
| 90 | - endTimeList.removeIf(seckillConfig -> Objects.equals(seckillConfig.getId(), id)); | ||
| 91 | - startEndTimeList.removeIf(seckillConfig -> Objects.equals(seckillConfig.getId(), id)); | 82 | + private void validateSeckillConfigConflict(String startTime, String endTime) { |
| 83 | + LocalTime startTime1 = LocalTime.parse(startTime); | ||
| 84 | + LocalTime endTime1 = LocalTime.parse(endTime); | ||
| 85 | + // 检查选择的时间是否相等 | ||
| 86 | + if (startTime1.equals(endTime1)) { | ||
| 87 | + throw exception(SECKILL_TIME_EQUAL); | ||
| 88 | + } | ||
| 89 | + // 检查开始时间是否在结束时间之前 | ||
| 90 | + if (startTime1.isAfter(endTime1)) { | ||
| 91 | + throw exception(SECKILL_START_TIME_BEFORE_END_TIME); | ||
| 92 | } | 92 | } |
| 93 | - if (CollUtil.isNotEmpty(startTimeList) || CollUtil.isNotEmpty(endTimeList) | ||
| 94 | - || CollUtil.isNotEmpty(startEndTimeList)) { | 93 | + // 查询出所有的时段配置 |
| 94 | + List<SeckillConfigDO> configDOs = seckillConfigMapper.selectList(); | ||
| 95 | + // 过滤出重叠的时段 ids | ||
| 96 | + Set<Long> ids = configDOs.stream().filter((config) -> { | ||
| 97 | + LocalTime startTime2 = LocalTime.parse(config.getStartTime()); | ||
| 98 | + LocalTime endTime2 = LocalTime.parse(config.getEndTime()); | ||
| 99 | + // 判断时间是否重叠 | ||
| 100 | + // 开始时间在已配置时段的结束时间之前 且 结束时间在已配置时段的开始时间之后 [] | ||
| 101 | + return startTime1.isBefore(endTime2) && endTime1.isAfter(startTime2) | ||
| 102 | + // 开始时间在已配置时段的开始时间之前 且 结束时间在已配置时段的开始时间之后 (] 或 () | ||
| 103 | + || startTime1.isBefore(startTime2) && endTime1.isAfter(startTime2) | ||
| 104 | + // 开始时间在已配置时段的结束时间之前 且 结束时间在已配值时段的结束时间之后 [) 或 () | ||
| 105 | + || startTime1.isBefore(endTime2) && endTime1.isAfter(endTime2); | ||
| 106 | + }).map(SeckillConfigDO::getId).collect(Collectors.toSet()); | ||
| 107 | + if (CollUtil.isNotEmpty(ids)) { | ||
| 95 | throw exception(SECKILL_TIME_CONFLICTS); | 108 | throw exception(SECKILL_TIME_CONFLICTS); |
| 96 | } | 109 | } |
| 97 | } | 110 | } |
| @@ -107,28 +120,23 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | @@ -107,28 +120,23 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { | ||
| 107 | } | 120 | } |
| 108 | 121 | ||
| 109 | @Override | 122 | @Override |
| 110 | - public void validateSeckillConfigExists(Collection<Long> timeIds) { | ||
| 111 | - if (CollUtil.isEmpty(timeIds)) { | 123 | + public void validateSeckillConfigExists(Collection<Long> configIds) { |
| 124 | + if (CollUtil.isEmpty(configIds)) { | ||
| 112 | throw exception(SECKILL_TIME_NOT_EXISTS); | 125 | throw exception(SECKILL_TIME_NOT_EXISTS); |
| 113 | } | 126 | } |
| 114 | - if (seckillConfigMapper.selectBatchIds(timeIds).size() != timeIds.size()) { | 127 | + if (seckillConfigMapper.selectBatchIds(configIds).size() != configIds.size()) { |
| 115 | throw exception(SECKILL_TIME_NOT_EXISTS); | 128 | throw exception(SECKILL_TIME_NOT_EXISTS); |
| 116 | } | 129 | } |
| 117 | } | 130 | } |
| 118 | 131 | ||
| 119 | @Override | 132 | @Override |
| 120 | - public void seckillActivityCountIncr(Collection<Long> ids) { | ||
| 121 | - seckillConfigMapper.updateActivityCount(ids, "+", 1); | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - @Override | ||
| 125 | - public void seckillActivityCountDecr(Collection<Long> ids) { | ||
| 126 | - seckillConfigMapper.updateActivityCount(ids, "-", 1); | 133 | + public PageResult<SeckillConfigDO> getSeckillConfigPage(SeckillConfigPageReqVO pageVO) { |
| 134 | + return seckillConfigMapper.selectPage(pageVO); | ||
| 127 | } | 135 | } |
| 128 | 136 | ||
| 129 | @Override | 137 | @Override |
| 130 | - public PageResult<SeckillConfigDO> getSeckillConfigPage(SeckillConfigPageReqVO pageVO) { | ||
| 131 | - return seckillConfigMapper.selectPage(pageVO); | 138 | + public List<SeckillConfigDO> getListAllSimple() { |
| 139 | + return seckillConfigMapper.selectList(SeckillConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus()); | ||
| 132 | } | 140 | } |
| 133 | 141 | ||
| 134 | } | 142 | } |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/seckillactivity/SeckillActivityServiceImplTest.java
| @@ -113,26 +113,26 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { | @@ -113,26 +113,26 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest { | ||
| 113 | }); | 113 | }); |
| 114 | seckillActivityMapper.insert(dbSeckillActivity); | 114 | seckillActivityMapper.insert(dbSeckillActivity); |
| 115 | // 测试 name 不匹配 | 115 | // 测试 name 不匹配 |
| 116 | - seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setName(null))); | ||
| 117 | - // 测试 status 不匹配 | ||
| 118 | - seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); | ||
| 119 | - // 测试 timeId 不匹配 | 116 | + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setName(null))); |
| 117 | + // 测试 status 不匹配 | ||
| 118 | + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); | ||
| 119 | + // 测试 timeId 不匹配 | ||
| 120 | seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setConfigIds(null))); | 120 | seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setConfigIds(null))); |
| 121 | - // 测试 createTime 不匹配 | ||
| 122 | - seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); | ||
| 123 | - // 准备参数 | ||
| 124 | - SeckillActivityPageReqVO reqVO = new SeckillActivityPageReqVO(); | ||
| 125 | - reqVO.setName(null); | 121 | + // 测试 createTime 不匹配 |
| 122 | + seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); | ||
| 123 | + // 准备参数 | ||
| 124 | + SeckillActivityPageReqVO reqVO = new SeckillActivityPageReqVO(); | ||
| 125 | + reqVO.setName(null); | ||
| 126 | reqVO.setStatus(null); | 126 | reqVO.setStatus(null); |
| 127 | reqVO.setConfigId(null); | 127 | reqVO.setConfigId(null); |
| 128 | reqVO.setCreateTime((new LocalDateTime[]{})); | 128 | reqVO.setCreateTime((new LocalDateTime[]{})); |
| 129 | 129 | ||
| 130 | - // 调用 | ||
| 131 | - PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(reqVO); | ||
| 132 | - // 断言 | ||
| 133 | - assertEquals(1, pageResult.getTotal()); | ||
| 134 | - assertEquals(1, pageResult.getList().size()); | ||
| 135 | - assertPojoEquals(dbSeckillActivity, pageResult.getList().get(0)); | 130 | + // 调用 |
| 131 | + PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(reqVO); | ||
| 132 | + // 断言 | ||
| 133 | + assertEquals(1, pageResult.getTotal()); | ||
| 134 | + assertEquals(1, pageResult.getList().size()); | ||
| 135 | + assertPojoEquals(dbSeckillActivity, pageResult.getList().get(0)); | ||
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | @Test | 138 | @Test |