Commit aa5525d1f58aa2e39731cbd6461a1e18c9c57b81
1 parent
1da14a3f
code review:营销活动 & 交易订单的对接
Showing
11 changed files
with
45 additions
and
28 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java
| @@ -11,7 +11,7 @@ public interface BargainActivityApi { | @@ -11,7 +11,7 @@ public interface BargainActivityApi { | ||
| 11 | * 更新砍价活动库存 | 11 | * 更新砍价活动库存 |
| 12 | * | 12 | * |
| 13 | * @param id 砍价活动编号 | 13 | * @param id 砍价活动编号 |
| 14 | - * @param count 购买数量 | 14 | + * @param count 购买数量 |
| 15 | */ | 15 | */ |
| 16 | void updateBargainActivityStock(Long id, Integer count); | 16 | void updateBargainActivityStock(Long id, Integer count); |
| 17 | 17 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java
| @@ -38,7 +38,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { | @@ -38,7 +38,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { | ||
| 38 | * @param count 扣减的库存数量 | 38 | * @param count 扣减的库存数量 |
| 39 | * @return 影响的行数 | 39 | * @return 影响的行数 |
| 40 | */ | 40 | */ |
| 41 | - default int updateActivityStock(Long id, int count) { | 41 | + default int updateStock(Long id, int count) { |
| 42 | return update(null, new LambdaUpdateWrapper<BargainActivityDO>() | 42 | return update(null, new LambdaUpdateWrapper<BargainActivityDO>() |
| 43 | .eq(BargainActivityDO::getId, id) | 43 | .eq(BargainActivityDO::getId, id) |
| 44 | .ge(BargainActivityDO::getStock, count) | 44 | .ge(BargainActivityDO::getStock, count) |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java
| @@ -41,7 +41,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> { | @@ -41,7 +41,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> { | ||
| 41 | * @param count 扣减的库存数量 | 41 | * @param count 扣减的库存数量 |
| 42 | * @return 影响的行数 | 42 | * @return 影响的行数 |
| 43 | */ | 43 | */ |
| 44 | - default int updateActivityStock(Long id, int count) { | 44 | + default int updateStock(Long id, int count) { |
| 45 | return update(null, new LambdaUpdateWrapper<SeckillActivityDO>() | 45 | return update(null, new LambdaUpdateWrapper<SeckillActivityDO>() |
| 46 | .eq(SeckillActivityDO::getId, id) | 46 | .eq(SeckillActivityDO::getId, id) |
| 47 | .gt(SeckillActivityDO::getTotalStock, 0) | 47 | .gt(SeckillActivityDO::getTotalStock, 0) |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java
| @@ -16,8 +16,13 @@ import java.util.List; | @@ -16,8 +16,13 @@ import java.util.List; | ||
| 16 | @Mapper | 16 | @Mapper |
| 17 | public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> { | 17 | public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> { |
| 18 | 18 | ||
| 19 | - default List<SeckillProductDO> selectListByActivityId(Long id) { | ||
| 20 | - return selectList(SeckillProductDO::getActivityId, id); | 19 | + default List<SeckillProductDO> selectListByActivityId(Long activityId) { |
| 20 | + return selectList(SeckillProductDO::getActivityId, activityId); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + default SeckillProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId) { | ||
| 24 | + return selectOne(SeckillProductDO::getActivityId, activityId, | ||
| 25 | + SeckillProductDO::getSkuId, skuId); | ||
| 21 | } | 26 | } |
| 22 | 27 | ||
| 23 | default List<SeckillProductDO> selectListByActivityId(Collection<Long> ids) { | 28 | default List<SeckillProductDO> selectListByActivityId(Collection<Long> ids) { |
| @@ -31,7 +36,7 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> { | @@ -31,7 +36,7 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> { | ||
| 31 | * @param count 扣减的库存数量 | 36 | * @param count 扣减的库存数量 |
| 32 | * @return 影响的行数 | 37 | * @return 影响的行数 |
| 33 | */ | 38 | */ |
| 34 | - default int updateActivityStock(Long id, int count) { | 39 | + default int updateStock(Long id, int count) { |
| 35 | return update(null, new LambdaUpdateWrapper<SeckillProductDO>() | 40 | return update(null, new LambdaUpdateWrapper<SeckillProductDO>() |
| 36 | .eq(SeckillProductDO::getId, id) | 41 | .eq(SeckillProductDO::getId, id) |
| 37 | .gt(SeckillProductDO::getStock, count) | 42 | .gt(SeckillProductDO::getStock, count) |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java
| @@ -75,16 +75,18 @@ public class BargainActivityServiceImpl implements BargainActivityService { | @@ -75,16 +75,18 @@ public class BargainActivityServiceImpl implements BargainActivityService { | ||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | @Override | 77 | @Override |
| 78 | - @Transactional(rollbackFor = Exception.class) | ||
| 79 | public void updateBargainActivityStock(Long id, Integer count) { | 78 | public void updateBargainActivityStock(Long id, Integer count) { |
| 80 | // 查询砍价活动 | 79 | // 查询砍价活动 |
| 81 | BargainActivityDO activity = getBargainActivity(id); | 80 | BargainActivityDO activity = getBargainActivity(id); |
| 82 | if (activity == null) { | 81 | if (activity == null) { |
| 83 | throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); | 82 | throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); |
| 84 | } | 83 | } |
| 84 | + if (count > activity.getStock()) { | ||
| 85 | + throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); | ||
| 86 | + } | ||
| 85 | 87 | ||
| 86 | // 更新砍价库存 | 88 | // 更新砍价库存 |
| 87 | - int updateCount = bargainActivityMapper.updateActivityStock(id, count); | 89 | + int updateCount = bargainActivityMapper.updateStock(id, count); |
| 88 | if (updateCount == 0) { | 90 | if (updateCount == 0) { |
| 89 | throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); | 91 | throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); |
| 90 | } | 92 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| @@ -96,12 +96,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -96,12 +96,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 96 | return recordDO; | 96 | return recordDO; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | + // TODO @puhui999:有一个应该在创建那要做下;就是当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先; | ||
| 100 | + | ||
| 99 | @Override | 101 | @Override |
| 100 | @Transactional(rollbackFor = Exception.class) | 102 | @Transactional(rollbackFor = Exception.class) |
| 101 | public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { | 103 | public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { |
| 102 | // 1.1 校验拼团活动 | 104 | // 1.1 校验拼团活动 |
| 103 | CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(reqDTO.getActivityId()); | 105 | CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(reqDTO.getActivityId()); |
| 104 | // 1.2 需要校验下,他当前是不是已经参加了该拼团; | 106 | // 1.2 需要校验下,他当前是不是已经参加了该拼团; |
| 107 | + // TODO @puhui999:拼团应该可以重复参加;应该去校验总共的上限哈,就是 activity.totalLimitCount | ||
| 105 | CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(reqDTO.getUserId(), reqDTO.getOrderId()); | 108 | CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(reqDTO.getUserId(), reqDTO.getOrderId()); |
| 106 | if (recordDO != null) { | 109 | if (recordDO != null) { |
| 107 | throw exception(COMBINATION_RECORD_EXISTS); | 110 | throw exception(COMBINATION_RECORD_EXISTS); |
| @@ -111,6 +114,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -111,6 +114,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 111 | if (CollUtil.isNotEmpty(recordDOList)) { | 114 | if (CollUtil.isNotEmpty(recordDOList)) { |
| 112 | throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); | 115 | throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); |
| 113 | } | 116 | } |
| 117 | + // TODO @puhui999:有个开始时间未校验 | ||
| 114 | // 1.4 校验当前活动是否过期 | 118 | // 1.4 校验当前活动是否过期 |
| 115 | if (LocalDateTime.now().isAfter(activity.getEndTime())) { | 119 | if (LocalDateTime.now().isAfter(activity.getEndTime())) { |
| 116 | throw exception(COMBINATION_RECORD_FAILED_TIME_END); | 120 | throw exception(COMBINATION_RECORD_FAILED_TIME_END); |
| @@ -128,6 +132,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -128,6 +132,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 128 | } | 132 | } |
| 129 | } | 133 | } |
| 130 | 134 | ||
| 135 | + // TODO @puhui999:单次限购 | ||
| 136 | + | ||
| 131 | // 2. 创建拼团记录 | 137 | // 2. 创建拼团记录 |
| 132 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); | 138 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); |
| 133 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); | 139 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java
| @@ -149,31 +149,25 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -149,31 +149,25 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 149 | @Override | 149 | @Override |
| 150 | @Transactional(rollbackFor = Exception.class) | 150 | @Transactional(rollbackFor = Exception.class) |
| 151 | public void updateSeckillStock(Long id, Long skuId, Integer count) { | 151 | public void updateSeckillStock(Long id, Long skuId, Integer count) { |
| 152 | - // 1、校验秒杀活动是否存在 | 152 | + // 1.1 校验活动库存是否充足 |
| 153 | SeckillActivityDO seckillActivity = getSeckillActivity(id); | 153 | SeckillActivityDO seckillActivity = getSeckillActivity(id); |
| 154 | - // 1.1、校验库存是否充足 | ||
| 155 | - if (seckillActivity.getTotalStock() < count) { | 154 | + if (count > seckillActivity.getTotalStock()) { |
| 156 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); | 155 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); |
| 157 | } | 156 | } |
| 158 | - | ||
| 159 | - // 2、获取活动商品 | ||
| 160 | - List<SeckillProductDO> products = getSeckillProductListByActivityId(id); | ||
| 161 | - // 2.1、过滤出购买的商品 | ||
| 162 | - SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(skuId, item.getSkuId())); | ||
| 163 | - // 2.2、检查活动商品库存是否充足 | ||
| 164 | - boolean isSufficient = product == null || (product.getStock() == 0 || (product.getStock() < count) || (product.getStock() - count) < 0); | ||
| 165 | - if (isSufficient) { | 157 | + // 1.2 校验商品库存是否充足 |
| 158 | + SeckillProductDO product = seckillProductMapper.selectByActivityIdAndSkuId(id, skuId); | ||
| 159 | + if (product == null || count > product.getStock()) { | ||
| 166 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); | 160 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); |
| 167 | } | 161 | } |
| 168 | 162 | ||
| 169 | - // 3、更新活动商品库存 | ||
| 170 | - int updateCount = seckillProductMapper.updateActivityStock(product.getId(), count); | 163 | + // 2.1 更新活动商品库存 |
| 164 | + int updateCount = seckillProductMapper.updateStock(product.getId(), count); | ||
| 171 | if (updateCount == 0) { | 165 | if (updateCount == 0) { |
| 172 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); | 166 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); |
| 173 | } | 167 | } |
| 174 | 168 | ||
| 175 | - // 4、更新活动库存 | ||
| 176 | - updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), count); | 169 | + // 2.2 更新活动库存 |
| 170 | + updateCount = seckillActivityMapper.updateStock(seckillActivity.getId(), count); | ||
| 177 | if (updateCount == 0) { | 171 | if (updateCount == 0) { |
| 178 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); | 172 | throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); |
| 179 | } | 173 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java
| @@ -106,7 +106,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | @@ -106,7 +106,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | ||
| 106 | if (order == null) { | 106 | if (order == null) { |
| 107 | throw exception(ORDER_NOT_FOUND); | 107 | throw exception(ORDER_NOT_FOUND); |
| 108 | } | 108 | } |
| 109 | - | 109 | + // 查询物流 |
| 110 | return getExpressTrackList(order); | 110 | return getExpressTrackList(order); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| @@ -117,7 +117,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | @@ -117,7 +117,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | ||
| 117 | if (order == null) { | 117 | if (order == null) { |
| 118 | throw exception(ORDER_NOT_FOUND); | 118 | throw exception(ORDER_NOT_FOUND); |
| 119 | } | 119 | } |
| 120 | - | 120 | + // 查询物流 |
| 121 | return getExpressTrackList(order); | 121 | return getExpressTrackList(order); |
| 122 | } | 122 | } |
| 123 | 123 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java
| @@ -20,14 +20,17 @@ public class TradeBargainHandler implements TradeOrderHandler { | @@ -20,14 +20,17 @@ public class TradeBargainHandler implements TradeOrderHandler { | ||
| 20 | @Resource | 20 | @Resource |
| 21 | private BargainActivityApi bargainActivityApi; | 21 | private BargainActivityApi bargainActivityApi; |
| 22 | 22 | ||
| 23 | + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件: | ||
| 24 | + // 1. 商品存在、库存充足、单次限购; | ||
| 25 | + // 2. 活动进行中、时间段符合 | ||
| 26 | + | ||
| 23 | @Override | 27 | @Override |
| 24 | public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { | 28 | public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { |
| 25 | // 如果是砍价订单 | 29 | // 如果是砍价订单 |
| 26 | if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), reqBO.getOrderType())) { | 30 | if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), reqBO.getOrderType())) { |
| 27 | return; | 31 | return; |
| 28 | } | 32 | } |
| 29 | - | ||
| 30 | - // 额外扣减砍价的库存 | 33 | + // 扣减砍价活动的库存 |
| 31 | bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount()); | 34 | bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount()); |
| 32 | } | 35 | } |
| 33 | 36 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java
| @@ -24,9 +24,12 @@ public interface TradeOrderHandler { | @@ -24,9 +24,12 @@ public interface TradeOrderHandler { | ||
| 24 | */ | 24 | */ |
| 25 | void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO); | 25 | void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO); |
| 26 | 26 | ||
| 27 | + // TODO @puhui999:这个搞成订单取消 | ||
| 27 | /** | 28 | /** |
| 28 | * 回滚 | 29 | * 回滚 |
| 29 | */ | 30 | */ |
| 30 | void rollback(); | 31 | void rollback(); |
| 31 | 32 | ||
| 33 | + // TODO @puhui999:再搞个订单项取消哈 | ||
| 34 | + | ||
| 32 | } | 35 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java
| @@ -20,13 +20,17 @@ public class TradeSeckillHandler implements TradeOrderHandler { | @@ -20,13 +20,17 @@ public class TradeSeckillHandler implements TradeOrderHandler { | ||
| 20 | @Resource | 20 | @Resource |
| 21 | private SeckillActivityApi seckillActivityApi; | 21 | private SeckillActivityApi seckillActivityApi; |
| 22 | 22 | ||
| 23 | + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件: | ||
| 24 | + // 1. 商品存在、库存充足、单次限购; | ||
| 25 | + // 2. 活动进行中、时间段符合 | ||
| 26 | + | ||
| 23 | @Override | 27 | @Override |
| 24 | public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { | 28 | public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { |
| 25 | // 如果是秒杀订单:额外扣减秒杀的库存; | 29 | // 如果是秒杀订单:额外扣减秒杀的库存; |
| 26 | if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), reqBO.getOrderType())) { | 30 | if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), reqBO.getOrderType())) { |
| 27 | return; | 31 | return; |
| 28 | } | 32 | } |
| 29 | - | 33 | + // 扣减秒杀活动的库存 |
| 30 | seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount()); | 34 | seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount()); |
| 31 | } | 35 | } |
| 32 | 36 |