Commit 7b727d5ce2a7e53ec5d3b1765afcafdfae38265b
1 parent
781ec102
code review:拼团记录流程
Showing
12 changed files
with
38 additions
and
44 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java
| ... | ... | @@ -55,8 +55,8 @@ public class CombinationRecordController { |
| 55 | 55 | public CommonResult<CombinationRecordSummaryVO> getCombinationRecordSummary() { |
| 56 | 56 | CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO(); |
| 57 | 57 | summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null)); // 获取所有拼团记录 |
| 58 | - summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( | |
| 59 | - CombinationRecordStatusEnum.SUCCESS.getStatus(), null));// 获取成团记录 | |
| 58 | + summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( // 获取成团记录 | |
| 59 | + CombinationRecordStatusEnum.SUCCESS.getStatus(), null)); | |
| 60 | 60 | summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(null, Boolean.TRUE));// 获取虚拟成团记录 |
| 61 | 61 | return success(summaryVO); |
| 62 | 62 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java
| ... | ... | @@ -55,7 +55,6 @@ public class AppActivityController { |
| 55 | 55 | if (CollUtil.isEmpty(spuIds)) { |
| 56 | 56 | return success(MapUtil.empty()); |
| 57 | 57 | } |
| 58 | - | |
| 59 | 58 | // 每种活动,只返回一个;key 为 SPU 编号 |
| 60 | 59 | return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId)); |
| 61 | 60 | } |
| ... | ... | @@ -64,20 +63,15 @@ public class AppActivityController { |
| 64 | 63 | if (CollUtil.isEmpty(spuIds)) { |
| 65 | 64 | return new ArrayList<>(); |
| 66 | 65 | } |
| 67 | - | |
| 68 | 66 | List<AppActivityRespVO> activityList = new ArrayList<>(); |
| 69 | 67 | // 拼团活动 |
| 70 | 68 | List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatus( |
| 71 | 69 | spuIds, CommonStatusEnum.ENABLE.getStatus()); |
| 72 | 70 | if (CollUtil.isNotEmpty(combinationActivities)) { |
| 73 | 71 | combinationActivities.forEach(item -> { |
| 74 | - activityList.add(new AppActivityRespVO() | |
| 75 | - .setId(item.getId()) | |
| 76 | - .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) | |
| 77 | - .setName(item.getName()) | |
| 78 | - .setSpuId(item.getSpuId()) | |
| 79 | - .setStartTime(item.getStartTime()) | |
| 80 | - .setEndTime(item.getEndTime())); | |
| 72 | + activityList.add(new AppActivityRespVO().setId(item.getId()) | |
| 73 | + .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()).setName(item.getName()) | |
| 74 | + .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); | |
| 81 | 75 | }); |
| 82 | 76 | } |
| 83 | 77 | // 秒杀活动 |
| ... | ... | @@ -85,13 +79,9 @@ public class AppActivityController { |
| 85 | 79 | spuIds, CommonStatusEnum.ENABLE.getStatus()); |
| 86 | 80 | if (CollUtil.isNotEmpty(seckillActivities)) { |
| 87 | 81 | seckillActivities.forEach(item -> { |
| 88 | - activityList.add(new AppActivityRespVO() | |
| 89 | - .setId(item.getId()) | |
| 90 | - .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) | |
| 91 | - .setName(item.getName()) | |
| 92 | - .setSpuId(item.getSpuId()) | |
| 93 | - .setStartTime(item.getStartTime()) | |
| 94 | - .setEndTime(item.getEndTime())); | |
| 82 | + activityList.add(new AppActivityRespVO().setId(item.getId()) | |
| 83 | + .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()).setName(item.getName()) | |
| 84 | + .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); | |
| 95 | 85 | }); |
| 96 | 86 | } |
| 97 | 87 | // 砍价活动 |
| ... | ... | @@ -99,13 +89,9 @@ public class AppActivityController { |
| 99 | 89 | spuIds, CommonStatusEnum.ENABLE.getStatus()); |
| 100 | 90 | if (CollUtil.isNotEmpty(bargainActivities)) { |
| 101 | 91 | bargainActivities.forEach(item -> { |
| 102 | - activityList.add(new AppActivityRespVO() | |
| 103 | - .setId(item.getId()) | |
| 104 | - .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) | |
| 105 | - .setName(item.getName()) | |
| 106 | - .setSpuId(item.getSpuId()) | |
| 107 | - .setStartTime(item.getStartTime()) | |
| 108 | - .setEndTime(item.getEndTime())); | |
| 92 | + activityList.add(new AppActivityRespVO().setId(item.getId()) | |
| 93 | + .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()).setName(item.getName()) | |
| 94 | + .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); | |
| 109 | 95 | }); |
| 110 | 96 | } |
| 111 | 97 | return activityList; | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| ... | ... | @@ -109,22 +109,19 @@ public interface CombinationActivityConvert { |
| 109 | 109 | |
| 110 | 110 | CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); |
| 111 | 111 | |
| 112 | - // TODO @芋艿:在 convert 优化下; | |
| 113 | 112 | default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO, |
| 114 | 113 | CombinationActivityDO activity, MemberUserRespDTO user, |
| 115 | 114 | ProductSpuRespDTO spu, ProductSkuRespDTO sku) { |
| 116 | - return convert(reqDTO) | |
| 117 | - .setCount(reqDTO.getCount()) | |
| 118 | - .setVirtualGroup(false) // 默认 false 拼团过期都还没有成功,则按照 CombinationActivityDO#virtualGroup 来如果为 true 则执行虚拟成团的逻辑 | |
| 115 | + return convert(reqDTO).setVirtualGroup(false) | |
| 119 | 116 | .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 |
| 120 | - .setStartTime(LocalDateTime.now()) | |
| 117 | + .setStartTime(LocalDateTime.now()) // TODO @puhui999:想了下,这个 startTime 应该是团长的; | |
| 118 | + // TODO @puhui999:有团长的情况下,expireTime 应该是团长的; | |
| 121 | 119 | .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) |
| 122 | - .setUserSize(activity.getUserSize()) | |
| 123 | - .setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 | |
| 124 | - .setNickname(user.getNickname()) | |
| 125 | - .setAvatar(user.getAvatar()) | |
| 126 | - .setSpuName(spu.getName()) | |
| 127 | - .setPicUrl(sku.getPicUrl()); | |
| 120 | + .setUserSize(activity.getUserSize()).setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 | |
| 121 | + // 用户信息 | |
| 122 | + .setNickname(user.getNickname()).setAvatar(user.getAvatar()) | |
| 123 | + // 商品信息 | |
| 124 | + .setSpuName(spu.getName()).setPicUrl(sku.getPicUrl()); | |
| 128 | 125 | |
| 129 | 126 | } |
| 130 | 127 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java
| ... | ... | @@ -116,6 +116,9 @@ public class CombinationRecordDO extends BaseDO { |
| 116 | 116 | private Integer userCount; |
| 117 | 117 | /** |
| 118 | 118 | * 是否虚拟成团 |
| 119 | + * | |
| 120 | + * 默认为 false。 | |
| 121 | + * 拼团过期都还没有成功,如果 {@link CombinationActivityDO#getVirtualGroup()} 为 true,则执行虚拟成团的逻辑,才会更新该字段为 true | |
| 119 | 122 | */ |
| 120 | 123 | private Boolean virtualGroup; |
| 121 | 124 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java
| ... | ... | @@ -85,6 +85,8 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { |
| 85 | 85 | .last("LIMIT " + count)); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | + // TODO @puhui999:一个商品,在统一时间,不会参与多个活动;so 是不是不用 inner join 哈? | |
| 89 | + // PS:如果可以参与多个,其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC;通过 group 来过滤 | |
| 88 | 90 | /** |
| 89 | 91 | * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 |
| 90 | 92 | * | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
| ... | ... | @@ -100,7 +100,8 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO |
| 100 | 100 | .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime())); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - default Long selectRecordCount(Integer status, Boolean virtualGroup) { | |
| 103 | + // TODO @puhui999:这个最好把 headId 也作为一个参数;因为有个要求 userCount,它要 DISTINCT 下;整体可以参考 selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId | |
| 104 | + default Long selectCountByHeadAndStatusAndVirtualGroup(Integer status, Boolean virtualGroup) { | |
| 104 | 105 | return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>() |
| 105 | 106 | .eq(status != null || virtualGroup != null, |
| 106 | 107 | CombinationRecordDO::getHeadId, CombinationRecordDO.HEAD_ID_GROUP) // 统计团信息则指定团长 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java
| ... | ... | @@ -58,6 +58,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> { |
| 58 | 58 | .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | + // TODO @puhui999:类似 BargainActivityMapper | |
| 61 | 62 | /** |
| 62 | 63 | * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 |
| 63 | 64 | * | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| ... | ... | @@ -169,19 +169,22 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 169 | 169 | KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(), |
| 170 | 170 | reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); |
| 171 | 171 | |
| 172 | - // 2. 组合数据创建拼团记录 | |
| 172 | + // 2.1 组合数据创建拼团记录 | |
| 173 | 173 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); |
| 174 | 174 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); |
| 175 | 175 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); |
| 176 | 176 | CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); |
| 177 | - // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP | |
| 178 | - record.setHeadId(record.getHeadId() == null ? CombinationRecordDO.HEAD_ID_GROUP : record.getHeadId()); | |
| 177 | + // 2.2 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP | |
| 178 | + if (record.getHeadId() == null) { | |
| 179 | + record.setHeadId(CombinationRecordDO.HEAD_ID_GROUP); | |
| 180 | + } | |
| 179 | 181 | recordMapper.insert(record); |
| 180 | 182 | |
| 181 | 183 | if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { |
| 182 | 184 | return record.getId(); |
| 183 | 185 | } |
| 184 | 186 | |
| 187 | + // TODO @puhui:是不是这里的更新,放到 order 模块那;支付完成后; | |
| 185 | 188 | // 4、更新拼团相关信息到订单 |
| 186 | 189 | tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId()); |
| 187 | 190 | // 4、更新拼团记录 |
| ... | ... | @@ -239,7 +242,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 239 | 242 | |
| 240 | 243 | @Override |
| 241 | 244 | public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup) { |
| 242 | - return recordMapper.selectRecordCount(status, virtualGroup); | |
| 245 | + return recordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup); | |
| 243 | 246 | } |
| 244 | 247 | |
| 245 | 248 | @Override | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java
| ... | ... | @@ -153,15 +153,15 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { |
| 153 | 153 | * @return 物流轨迹 |
| 154 | 154 | */ |
| 155 | 155 | private List<ExpressTrackRespDTO> getExpressTrackList(TradeOrderDO order) { |
| 156 | - // 查询物流公司 | |
| 157 | 156 | if (order.getLogisticsId() == null) { |
| 158 | 157 | return Collections.emptyList(); |
| 159 | 158 | } |
| 159 | + // 查询物流公司 | |
| 160 | 160 | DeliveryExpressDO express = deliveryExpressService.getDeliveryExpress(order.getLogisticsId()); |
| 161 | 161 | if (express == null) { |
| 162 | 162 | throw exception(EXPRESS_NOT_EXISTS); |
| 163 | 163 | } |
| 164 | - | |
| 164 | + // 查询物流轨迹 | |
| 165 | 165 | return getSelf().getExpressTrackList(express.getCode(), order.getLogisticsNo(), order.getReceiverMobile()); |
| 166 | 166 | } |
| 167 | 167 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| ... | ... | @@ -743,6 +743,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 743 | 743 | // 校验交易订单 |
| 744 | 744 | TradeOrderDO order = validateOrderExists(reqVO.getId()); |
| 745 | 745 | // 发货后,不允许修改; |
| 746 | + // TODO @puhui999:只有待发货,可以执行 update | |
| 746 | 747 | if (TradeOrderStatusEnum.isDelivered(order.getStatus())) { |
| 747 | 748 | throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED); |
| 748 | 749 | } | ... | ... |