Commit 0b9ddddd1830029cce2c3d1043ccd88a44de3f7b
1 parent
aee5f39a
promotion:code review 秒杀的代码
Showing
9 changed files
with
71 additions
and
44 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckillactivity/vo/SeckillActivityCreateReqVO.java
| @@ -12,6 +12,7 @@ import javax.validation.constraints.NotEmpty; | @@ -12,6 +12,7 @@ import javax.validation.constraints.NotEmpty; | ||
| 12 | import javax.validation.constraints.NotNull; | 12 | import javax.validation.constraints.NotNull; |
| 13 | import java.util.List; | 13 | import java.util.List; |
| 14 | 14 | ||
| 15 | +// TODO halfninety:检查下所有的 VO,需要保证 example 都写了哈。 | ||
| 15 | @ApiModel("管理后台 - 秒杀活动创建 Request VO") | 16 | @ApiModel("管理后台 - 秒杀活动创建 Request VO") |
| 16 | @Data | 17 | @Data |
| 17 | @EqualsAndHashCode(callSuper = true) | 18 | @EqualsAndHashCode(callSuper = true) |
| @@ -25,6 +26,7 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO { | @@ -25,6 +26,7 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO { | ||
| 25 | @NotNull(message = "排序不能为空") | 26 | @NotNull(message = "排序不能为空") |
| 26 | private Integer sort; | 27 | private Integer sort; |
| 27 | 28 | ||
| 29 | + // TODO halfninety:直接使用数组接口。timeIds, | ||
| 28 | @ApiModelProperty(value = "秒杀时段id", required = true) | 30 | @ApiModelProperty(value = "秒杀时段id", required = true) |
| 29 | @NotBlank(message = "参与场次不能为空") | 31 | @NotBlank(message = "参与场次不能为空") |
| 30 | private String timeId; | 32 | private String timeId; |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/seckilltime/SeckillTimeController.java
| @@ -20,6 +20,7 @@ import java.util.List; | @@ -20,6 +20,7 @@ import java.util.List; | ||
| 20 | 20 | ||
| 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 22 | 22 | ||
| 23 | +// TODO @halfninety:controller 可以都放在 seckill 包下;vo 下分成 actvity 和 time | ||
| 23 | @Api(tags = "管理后台 - 秒杀时段") | 24 | @Api(tags = "管理后台 - 秒杀时段") |
| 24 | @RestController | 25 | @RestController |
| 25 | @RequestMapping("/promotion/seckill-time") | 26 | @RequestMapping("/promotion/seckill-time") |
| @@ -65,11 +66,13 @@ public class SeckillTimeController { | @@ -65,11 +66,13 @@ public class SeckillTimeController { | ||
| 65 | @GetMapping("/list") | 66 | @GetMapping("/list") |
| 66 | @ApiOperation("获得所有秒杀时段列表") | 67 | @ApiOperation("获得所有秒杀时段列表") |
| 67 | // @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") | 68 | // @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") |
| 69 | + // TODO @halfninety:权限为啥注释掉呀? | ||
| 68 | public CommonResult<List<SeckillTimeRespVO>> getSeckillTimeList() { | 70 | public CommonResult<List<SeckillTimeRespVO>> getSeckillTimeList() { |
| 69 | List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList(); | 71 | List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList(); |
| 70 | return success(SeckillTimeConvert.INSTANCE.convertList(list)); | 72 | return success(SeckillTimeConvert.INSTANCE.convertList(list)); |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 75 | + // TODO @halfninety:不用的,可以删除掉 | ||
| 73 | // @GetMapping("/page") | 76 | // @GetMapping("/page") |
| 74 | // @ApiOperation("获得秒杀时段分页") | 77 | // @ApiOperation("获得秒杀时段分页") |
| 75 | // @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") | 78 | // @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java
| @@ -57,8 +57,9 @@ public class SeckillActivityDO extends BaseDO { | @@ -57,8 +57,9 @@ public class SeckillActivityDO extends BaseDO { | ||
| 57 | */ | 57 | */ |
| 58 | private Integer sort; | 58 | private Integer sort; |
| 59 | /** | 59 | /** |
| 60 | - * 秒杀时段id | 60 | + * 秒杀时段 id |
| 61 | */ | 61 | */ |
| 62 | + // TODO @halfninety 可以使用 List 存储;看下别的模块怎么做的哈 | ||
| 62 | private String timeId; | 63 | private String timeId; |
| 63 | /** | 64 | /** |
| 64 | * 付款订单数 | 65 | * 付款订单数 |
| @@ -68,6 +69,7 @@ public class SeckillActivityDO extends BaseDO { | @@ -68,6 +69,7 @@ public class SeckillActivityDO extends BaseDO { | ||
| 68 | * 付款人数 | 69 | * 付款人数 |
| 69 | */ | 70 | */ |
| 70 | private Integer userCount; | 71 | private Integer userCount; |
| 72 | + // TODO @halfninety 使用 Long 哈。单位是分 | ||
| 71 | /** | 73 | /** |
| 72 | * 订单实付金额,单位:分 | 74 | * 订单实付金额,单位:分 |
| 73 | */ | 75 | */ |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckilltime/SeckillTimeMapper.java
| 1 | package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime; | 1 | package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime; |
| 2 | 2 | ||
| 3 | -import java.time.LocalTime; | ||
| 4 | -import java.util.*; | ||
| 5 | - | ||
| 6 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; | 5 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; |
| @@ -10,6 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | @@ -10,6 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 10 | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; | 7 | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| 11 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 12 | 9 | ||
| 10 | +import java.time.LocalTime; | ||
| 11 | +import java.util.Collections; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 13 | /** | 14 | /** |
| 14 | * 秒杀时段 Mapper | 15 | * 秒杀时段 Mapper |
| 15 | * | 16 | * |
| @@ -17,16 +18,22 @@ import org.apache.ibatis.annotations.Mapper; | @@ -17,16 +18,22 @@ import org.apache.ibatis.annotations.Mapper; | ||
| 17 | */ | 18 | */ |
| 18 | @Mapper | 19 | @Mapper |
| 19 | public interface SeckillTimeMapper extends BaseMapperX<SeckillTimeDO> { | 20 | public interface SeckillTimeMapper extends BaseMapperX<SeckillTimeDO> { |
| 21 | + | ||
| 22 | + // @TODO halfninety:){ 之间要有空格哈 | ||
| 20 | default List<SeckillTimeDO> selectListWithTime(LocalTime time){ | 23 | default List<SeckillTimeDO> selectListWithTime(LocalTime time){ |
| 24 | + // TODO @halfninety:mapper 层,不做空判断,业务上面自己的保证 | ||
| 21 | if (time == null) { | 25 | if (time == null) { |
| 22 | return Collections.emptyList(); | 26 | return Collections.emptyList(); |
| 23 | } | 27 | } |
| 28 | + // TODO @halfninety:在 BaseMapperX 上,可以封装一个 2 个字段的检索哈 | ||
| 24 | return selectList(new LambdaQueryWrapper<SeckillTimeDO>() | 29 | return selectList(new LambdaQueryWrapper<SeckillTimeDO>() |
| 25 | .le(SeckillTimeDO::getStartTime,time) | 30 | .le(SeckillTimeDO::getStartTime,time) |
| 26 | .ge(SeckillTimeDO::getEndTime,time)); | 31 | .ge(SeckillTimeDO::getEndTime,time)); |
| 27 | } | 32 | } |
| 28 | - | 33 | + |
| 34 | + // TODO @halfninety:selectListByXXX,使用 By 作为查询条件。 | ||
| 29 | default List<SeckillTimeDO> selectListWithTime(LocalTime startTime, LocalTime endTime){ | 35 | default List<SeckillTimeDO> selectListWithTime(LocalTime startTime, LocalTime endTime){ |
| 36 | + // TODO @halfninety:mapper 层,不做空判断,业务上面自己的保证 | ||
| 30 | if (startTime == null && endTime == null) { | 37 | if (startTime == null && endTime == null) { |
| 31 | return Collections.emptyList(); | 38 | return Collections.emptyList(); |
| 32 | } | 39 | } |
| @@ -35,6 +42,7 @@ public interface SeckillTimeMapper extends BaseMapperX<SeckillTimeDO> { | @@ -35,6 +42,7 @@ public interface SeckillTimeMapper extends BaseMapperX<SeckillTimeDO> { | ||
| 35 | .le(SeckillTimeDO::getEndTime,endTime)); | 42 | .le(SeckillTimeDO::getEndTime,endTime)); |
| 36 | } | 43 | } |
| 37 | 44 | ||
| 45 | + // TODO @halfninety:updateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 | ||
| 38 | default void sekillActivityCountAdd(List<Long> ids){ | 46 | default void sekillActivityCountAdd(List<Long> ids){ |
| 39 | if (CollUtil.isEmpty(ids)){ | 47 | if (CollUtil.isEmpty(ids)){ |
| 40 | return; | 48 | return; |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java
| @@ -31,7 +31,7 @@ import static java.util.Arrays.asList; | @@ -31,7 +31,7 @@ import static java.util.Arrays.asList; | ||
| 31 | /** | 31 | /** |
| 32 | * 秒杀活动 Service 实现类 | 32 | * 秒杀活动 Service 实现类 |
| 33 | * | 33 | * |
| 34 | - * @author 芋道源码 | 34 | + * @author 芋道源码 // TODO @halfninety:作者改成你自己哈 |
| 35 | */ | 35 | */ |
| 36 | @Service | 36 | @Service |
| 37 | @Validated | 37 | @Validated |
| @@ -39,7 +39,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -39,7 +39,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 39 | 39 | ||
| 40 | @Resource | 40 | @Resource |
| 41 | private SeckillActivityMapper seckillActivityMapper; | 41 | private SeckillActivityMapper seckillActivityMapper; |
| 42 | - | ||
| 43 | @Resource | 42 | @Resource |
| 44 | private SeckillProductMapper seckillProductMapper; | 43 | private SeckillProductMapper seckillProductMapper; |
| 45 | 44 | ||
| @@ -48,32 +47,40 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -48,32 +47,40 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 48 | 47 | ||
| 49 | @Override | 48 | @Override |
| 50 | public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { | 49 | public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { |
| 50 | + // TODO @halfninety:多余的变量,需要删除 | ||
| 51 | List<Integer> statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); | 51 | List<Integer> statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); |
| 52 | // 校验商品是否冲突 | 52 | // 校验商品是否冲突 |
| 53 | validateSeckillActivityProductConflicts(null, createReqVO.getProducts()); | 53 | validateSeckillActivityProductConflicts(null, createReqVO.getProducts()); |
| 54 | - // 更新秒杀时段的秒杀活动数量 | ||
| 55 | - seckillTimeService.sekillActivityCountAdd(StrUtils.splitToLong(createReqVO.getTimeId(),",")); | 54 | + |
| 55 | + // TODO halfninety:要校验下,秒杀时间段存在 | ||
| 56 | // 插入秒杀活动 | 56 | // 插入秒杀活动 |
| 57 | SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO) | 57 | SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO) |
| 58 | .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime())); | 58 | .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime())); |
| 59 | seckillActivityMapper.insert(seckillActivity); | 59 | seckillActivityMapper.insert(seckillActivity); |
| 60 | // 插入商品 | 60 | // 插入商品 |
| 61 | + // TODO @halfninety:是不是写成一个 convertList,通过 default 来处理下;这样可读性更好哈 | ||
| 61 | List<SeckillProductDO> productDOS = CollectionUtils.convertList(createReqVO.getProducts(), | 62 | List<SeckillProductDO> productDOS = CollectionUtils.convertList(createReqVO.getProducts(), |
| 62 | product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(seckillActivity.getId())); | 63 | product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(seckillActivity.getId())); |
| 63 | seckillProductMapper.insertBatch(productDOS); | 64 | seckillProductMapper.insertBatch(productDOS); |
| 65 | + | ||
| 66 | + // TODO halfninety:最后在更新秒杀时间段的商品数量哈。【我已经改了】一般先做核心的逻辑,在做附件的逻辑。 | ||
| 67 | + // 更新秒杀时段的秒杀活动数量 | ||
| 68 | + seckillTimeService.sekillActivityCountAdd(StrUtils.splitToLong(createReqVO.getTimeId(),",")); | ||
| 64 | return seckillActivity.getId(); | 69 | return seckillActivity.getId(); |
| 65 | } | 70 | } |
| 66 | 71 | ||
| 67 | @Override | 72 | @Override |
| 68 | public void updateSeckillActivity(SeckillActivityUpdateReqVO updateReqVO) { | 73 | public void updateSeckillActivity(SeckillActivityUpdateReqVO updateReqVO) { |
| 69 | // 校验存在 | 74 | // 校验存在 |
| 70 | - SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(updateReqVO.getId()); | 75 | + SeckillActivityDO seckillActivity = validateSeckillActivityExists(updateReqVO.getId()); |
| 71 | if (PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { | 76 | if (PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { |
| 72 | throw exception(SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); | 77 | throw exception(SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); |
| 73 | } | 78 | } |
| 74 | // 校验商品是否冲突 | 79 | // 校验商品是否冲突 |
| 75 | validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); | 80 | validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); |
| 81 | + | ||
| 76 | // 更新秒杀时段的秒杀活动数量 | 82 | // 更新秒杀时段的秒杀活动数量 |
| 83 | + // TODO @halfninety:可以直接传递 seckillActivity 进去,不用重复查询; | ||
| 77 | updateSeckillTimeActivityCount(updateReqVO.getId(), updateReqVO.getTimeId()); | 84 | updateSeckillTimeActivityCount(updateReqVO.getId(), updateReqVO.getTimeId()); |
| 78 | // 更新活动 | 85 | // 更新活动 |
| 79 | SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) | 86 | SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) |
| @@ -83,6 +90,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -83,6 +90,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 83 | updateSeckillProduct(updateReqVO); | 90 | updateSeckillProduct(updateReqVO); |
| 84 | } | 91 | } |
| 85 | 92 | ||
| 93 | + // TODO @halfninety:注释写全哈; | ||
| 86 | /** | 94 | /** |
| 87 | * 更新秒杀时段的秒杀活动数量 | 95 | * 更新秒杀时段的秒杀活动数量 |
| 88 | * | 96 | * |
| @@ -91,16 +99,19 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -91,16 +99,19 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 91 | */ | 99 | */ |
| 92 | private void updateSeckillTimeActivityCount(Long id, String timeId) { | 100 | private void updateSeckillTimeActivityCount(Long id, String timeId) { |
| 93 | List<Long> updateTimeIds = StrUtils.splitToLong(timeId, ","); | 101 | List<Long> updateTimeIds = StrUtils.splitToLong(timeId, ","); |
| 94 | - // 查出自己的timeIds | 102 | + // 查出自己的 timeIds |
| 95 | SeckillActivityDO seckillActivityDO = seckillActivityMapper.selectById(id); | 103 | SeckillActivityDO seckillActivityDO = seckillActivityMapper.selectById(id); |
| 96 | List<Long> existsTimeIds = StrUtils.splitToLong(seckillActivityDO.getTimeId(), ","); | 104 | List<Long> existsTimeIds = StrUtils.splitToLong(seckillActivityDO.getTimeId(), ","); |
| 97 | - //需要减少的时间段 | 105 | + // 需要减少的时间段 |
| 106 | + // TODO @halfninety:可以使用 CollUtil.filterNew() | ||
| 98 | List<Long> reduceIds = existsTimeIds.stream() | 107 | List<Long> reduceIds = existsTimeIds.stream() |
| 99 | .filter(existsTimeId -> !updateTimeIds.contains(existsTimeId)) | 108 | .filter(existsTimeId -> !updateTimeIds.contains(existsTimeId)) |
| 100 | .collect(Collectors.toList()); | 109 | .collect(Collectors.toList()); |
| 101 | - //需要添加的时间段 | 110 | + // 需要添加的时间段 |
| 111 | + // TODO @halfninety:IDEA 一般会有告警提示,下面可以 lambada 表达式优化下;通过 command + 回车 | ||
| 102 | updateTimeIds.removeIf(updateTimeId -> existsTimeIds.contains(updateTimeId)); | 112 | updateTimeIds.removeIf(updateTimeId -> existsTimeIds.contains(updateTimeId)); |
| 103 | - //更新减少时间段和增加时间段 | 113 | + // 更新减少时间段和增加时间段 |
| 114 | + // TODO @halfninety:判断非空才操作 | ||
| 104 | seckillTimeService.sekillActivityCountAdd(updateTimeIds); | 115 | seckillTimeService.sekillActivityCountAdd(updateTimeIds); |
| 105 | seckillTimeService.sekillActivityCountReduce(reduceIds); | 116 | seckillTimeService.sekillActivityCountReduce(reduceIds); |
| 106 | } | 117 | } |
| @@ -111,17 +122,20 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -111,17 +122,20 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 111 | private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { | 122 | private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { |
| 112 | List<SeckillProductDO> seckillProductDOS = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); | 123 | List<SeckillProductDO> seckillProductDOS = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); |
| 113 | List<SeckillActivityBaseVO.Product> products = updateReqVO.getProducts(); | 124 | List<SeckillActivityBaseVO.Product> products = updateReqVO.getProducts(); |
| 114 | - //对后台查出的数据和前台查出的数据进行遍历, | ||
| 115 | - //1.对前台数据进行遍历:如果不存在于后台的sku中需要新增 | ||
| 116 | - //2.对后台数据进行遍历:如果不存在于前台的sku中需要删除 | ||
| 117 | - //计算需要删除的数据 | 125 | + // TODO halfninety:下面这段,其实可以放到注释哈 |
| 126 | + // 对后台查出的数据和前台查出的数据进行遍历, | ||
| 127 | + // 1. 对前台数据进行遍历:如果不存在于后台的 sku 中需要新增 | ||
| 128 | + // 2. 对后台数据进行遍历:如果不存在于前台的 sku 中需要删除 | ||
| 129 | + | ||
| 130 | + // 计算需要删除的数据 | ||
| 118 | List<Long> deleteIds = CollectionUtils.convertList(seckillProductDOS, SeckillProductDO::getId, | 131 | List<Long> deleteIds = CollectionUtils.convertList(seckillProductDOS, SeckillProductDO::getId, |
| 119 | seckillProductDO -> products.stream() | 132 | seckillProductDO -> products.stream() |
| 120 | .noneMatch(product -> SeckillActivityConvert.INSTANCE.isEquals(seckillProductDO, product))); | 133 | .noneMatch(product -> SeckillActivityConvert.INSTANCE.isEquals(seckillProductDO, product))); |
| 121 | if (CollUtil.isNotEmpty(deleteIds)) { | 134 | if (CollUtil.isNotEmpty(deleteIds)) { |
| 122 | seckillProductMapper.deleteBatchIds(deleteIds); | 135 | seckillProductMapper.deleteBatchIds(deleteIds); |
| 123 | } | 136 | } |
| 124 | - //计算需要新增的数据 | 137 | + |
| 138 | + // 计算需要新增的数据 | ||
| 125 | List<SeckillProductDO> newSeckillProductDOs = CollectionUtils.convertList(products, | 139 | List<SeckillProductDO> newSeckillProductDOs = CollectionUtils.convertList(products, |
| 126 | product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(updateReqVO.getId())); | 140 | product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(updateReqVO.getId())); |
| 127 | newSeckillProductDOs.removeIf(product -> seckillProductDOS.stream() | 141 | newSeckillProductDOs.removeIf(product -> seckillProductDOS.stream() |
| @@ -148,17 +162,16 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -148,17 +162,16 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 148 | } | 162 | } |
| 149 | List<SeckillActivityDO> seckillActivityDOS = seckillActivityMapper | 163 | List<SeckillActivityDO> seckillActivityDOS = seckillActivityMapper |
| 150 | .selectBatchIds(CollectionUtils.convertSet(seckillProductDOS, SeckillProductDO::getActivityId)); | 164 | .selectBatchIds(CollectionUtils.convertSet(seckillProductDOS, SeckillProductDO::getActivityId)); |
| 151 | - if (id != null) {// 排除自己这个活动 | 165 | + if (id != null) { // 排除自己这个活动 |
| 152 | seckillActivityDOS.removeIf(item -> id.equals(item.getId())); | 166 | seckillActivityDOS.removeIf(item -> id.equals(item.getId())); |
| 153 | } | 167 | } |
| 154 | - // 排除不满足status的活动 | 168 | + // 排除不满足 status 的活动 |
| 155 | List<Integer> statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); | 169 | List<Integer> statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus()); |
| 156 | seckillActivityDOS.removeIf(item -> !statuses.contains(item.getStatus())); | 170 | seckillActivityDOS.removeIf(item -> !statuses.contains(item.getStatus())); |
| 157 | - //如果非空,则说明冲突 | 171 | + // 如果非空,则说明冲突 |
| 158 | if (CollUtil.isNotEmpty(seckillActivityDOS)) { | 172 | if (CollUtil.isNotEmpty(seckillActivityDOS)) { |
| 159 | throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); | 173 | throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); |
| 160 | } | 174 | } |
| 161 | - | ||
| 162 | } | 175 | } |
| 163 | 176 | ||
| 164 | @Override | 177 | @Override |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckilltime/SeckillTimeServiceImpl.java
| @@ -3,33 +3,30 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime; | @@ -3,33 +3,30 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; | 4 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; |
| 6 | +import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime.SeckillTimeMapper; | ||
| 6 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 7 | - | ||
| 8 | -import javax.annotation.Resource; | ||
| 9 | - | ||
| 10 | import org.springframework.validation.annotation.Validated; | 10 | import org.springframework.validation.annotation.Validated; |
| 11 | 11 | ||
| 12 | +import javax.annotation.Resource; | ||
| 12 | import java.time.LocalTime; | 13 | import java.time.LocalTime; |
| 13 | -import java.util.*; | ||
| 14 | - | ||
| 15 | -import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; | ||
| 16 | - | ||
| 17 | -import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert; | ||
| 18 | -import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime.SeckillTimeMapper; | 14 | +import java.util.List; |
| 15 | +import java.util.Objects; | ||
| 19 | 16 | ||
| 20 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 21 | -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | 18 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_TIME_CONFLICTS; |
| 19 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_TIME_NOT_EXISTS; | ||
| 22 | 20 | ||
| 23 | /** | 21 | /** |
| 24 | * 秒杀时段 Service 实现类 | 22 | * 秒杀时段 Service 实现类 |
| 25 | * | 23 | * |
| 26 | - * @author 芋道源码 | 24 | + * @author 芋道源码 // TODO @halfninety:作者改成你自己哈 |
| 27 | */ | 25 | */ |
| 28 | @Service | 26 | @Service |
| 29 | @Validated | 27 | @Validated |
| 30 | public class SeckillTimeServiceImpl implements SeckillTimeService { | 28 | public class SeckillTimeServiceImpl implements SeckillTimeService { |
| 31 | 29 | ||
| 32 | - | ||
| 33 | @Resource | 30 | @Resource |
| 34 | private SeckillTimeMapper seckillTimeMapper; | 31 | private SeckillTimeMapper seckillTimeMapper; |
| 35 | 32 | ||
| @@ -93,7 +90,6 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { | @@ -93,7 +90,6 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { | ||
| 93 | } | 90 | } |
| 94 | } | 91 | } |
| 95 | 92 | ||
| 96 | - | ||
| 97 | @Override | 93 | @Override |
| 98 | public SeckillTimeDO getSeckillTime(Long id) { | 94 | public SeckillTimeDO getSeckillTime(Long id) { |
| 99 | return seckillTimeMapper.selectById(id); | 95 | return seckillTimeMapper.selectById(id); |
| @@ -104,6 +100,7 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { | @@ -104,6 +100,7 @@ public class SeckillTimeServiceImpl implements SeckillTimeService { | ||
| 104 | return seckillTimeMapper.selectList(); | 100 | return seckillTimeMapper.selectList(); |
| 105 | } | 101 | } |
| 106 | 102 | ||
| 103 | + // TODO @halfninety:updateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 | ||
| 107 | @Override | 104 | @Override |
| 108 | public void sekillActivityCountAdd(List<Long> ids) { | 105 | public void sekillActivityCountAdd(List<Long> ids) { |
| 109 | seckillTimeMapper.sekillActivityCountAdd(ids); | 106 | seckillTimeMapper.sekillActivityCountAdd(ids); |
yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckillactivity/SeckillActivityMapper.xml
| @@ -8,5 +8,6 @@ | @@ -8,5 +8,6 @@ | ||
| 8 | 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | 8 | 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 |
| 9 | 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | 9 | 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ |
| 10 | --> | 10 | --> |
| 11 | + <!-- TODO halfninety:不用的话,可以删除掉哈。 --> | ||
| 11 | 12 | ||
| 12 | </mapper> | 13 | </mapper> |
yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/seckilltime/SeckillTimeMapper.xml
| @@ -8,5 +8,6 @@ | @@ -8,5 +8,6 @@ | ||
| 8 | 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | 8 | 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 |
| 9 | 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | 9 | 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ |
| 10 | --> | 10 | --> |
| 11 | + <!-- TODO halfninety:不用的话,可以删除掉哈。 --> | ||
| 11 | 12 | ||
| 12 | </mapper> | 13 | </mapper> |
yudao-server/src/main/resources/application-local.yaml
| @@ -30,7 +30,7 @@ spring: | @@ -30,7 +30,7 @@ spring: | ||
| 30 | multi-statement-allow: true | 30 | multi-statement-allow: true |
| 31 | dynamic: # 多数据源配置 | 31 | dynamic: # 多数据源配置 |
| 32 | druid: # Druid 【连接池】相关的全局配置 | 32 | druid: # Druid 【连接池】相关的全局配置 |
| 33 | - initial-size: 1 # 初始连接数 | 33 | + initial-size: 5 # 初始连接数 |
| 34 | min-idle: 10 # 最小连接池数量 | 34 | min-idle: 10 # 最小连接池数量 |
| 35 | max-active: 20 # 最大连接池数量 | 35 | max-active: 20 # 最大连接池数量 |
| 36 | max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒 | 36 | max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒 |
| @@ -45,40 +45,40 @@ spring: | @@ -45,40 +45,40 @@ spring: | ||
| 45 | datasource: | 45 | datasource: |
| 46 | master: | 46 | master: |
| 47 | name: ruoyi-vue-pro | 47 | name: ruoyi-vue-pro |
| 48 | - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 | 48 | + url: jdbc:mysql://139.9.196.247:3307/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 |
| 49 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 | 49 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 |
| 50 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 | 50 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 |
| 51 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 | 51 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 |
| 52 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 | 52 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 |
| 53 | username: root | 53 | username: root |
| 54 | - password: 123456 | 54 | + password: ${RUOYI_VUE_PRO} |
| 55 | # username: sa | 55 | # username: sa |
| 56 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W | 56 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W |
| 57 | slave: # 模拟从库,可根据自己需要修改 | 57 | slave: # 模拟从库,可根据自己需要修改 |
| 58 | name: ruoyi-vue-pro | 58 | name: ruoyi-vue-pro |
| 59 | - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 | 59 | + url: jdbc:mysql://139.9.196.247:3307/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 |
| 60 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 | 60 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 |
| 61 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 | 61 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 |
| 62 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 | 62 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 |
| 63 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 | 63 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 |
| 64 | username: root | 64 | username: root |
| 65 | - password: 123456 | 65 | + password: ${RUOYI_VUE_PRO} |
| 66 | # username: sa | 66 | # username: sa |
| 67 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W | 67 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W |
| 68 | 68 | ||
| 69 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 | 69 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 |
| 70 | redis: | 70 | redis: |
| 71 | - host: 127.0.0.1 # 地址 | 71 | + host: 139.9.196.247 # 地址 |
| 72 | port: 6379 # 端口 | 72 | port: 6379 # 端口 |
| 73 | database: 0 # 数据库索引 | 73 | database: 0 # 数据库索引 |
| 74 | -# password: 123456 # 密码,建议生产环境开启 | 74 | + password: 123456 # 密码,建议生产环境开启 |
| 75 | 75 | ||
| 76 | --- #################### 定时任务相关配置 #################### | 76 | --- #################### 定时任务相关配置 #################### |
| 77 | 77 | ||
| 78 | # Quartz 配置项,对应 QuartzProperties 配置类 | 78 | # Quartz 配置项,对应 QuartzProperties 配置类 |
| 79 | spring: | 79 | spring: |
| 80 | quartz: | 80 | quartz: |
| 81 | - auto-startup: true # 本地开发环境,尽量不要开启 Job | 81 | + auto-startup: false # 本地开发环境,尽量不要开启 Job |
| 82 | scheduler-name: schedulerName # Scheduler 名字。默认为 schedulerName | 82 | scheduler-name: schedulerName # Scheduler 名字。默认为 schedulerName |
| 83 | job-store-type: jdbc # Job 存储器类型。默认为 memory 表示内存,可选 jdbc 使用数据库。 | 83 | job-store-type: jdbc # Job 存储器类型。默认为 memory 表示内存,可选 jdbc 使用数据库。 |
| 84 | wait-for-jobs-to-complete-on-shutdown: true # 应用关闭时,是否等待定时任务执行完成。默认为 false ,建议设置为 true | 84 | wait-for-jobs-to-complete-on-shutdown: true # 应用关闭时,是否等待定时任务执行完成。默认为 false ,建议设置为 true |