Commit 4359c584bb2b970f33df78fd0a5f5f9f24567e1f
1 parent
7bc3b7b2
code review:拼团逻辑
Showing
8 changed files
with
16 additions
and
16 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
| @@ -28,7 +28,7 @@ public interface CombinationRecordApi { | @@ -28,7 +28,7 @@ public interface CombinationRecordApi { | ||
| 28 | * 创建开团记录 | 28 | * 创建开团记录 |
| 29 | * | 29 | * |
| 30 | * @param reqDTO 请求 DTO | 30 | * @param reqDTO 请求 DTO |
| 31 | - * @return 团信息 | 31 | + * @return 拼团信息 |
| 32 | */ | 32 | */ |
| 33 | CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); | 33 | CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); |
| 34 | 34 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java
| @@ -40,8 +40,6 @@ public class CombinationRecordController { | @@ -40,8 +40,6 @@ public class CombinationRecordController { | ||
| 40 | @Lazy | 40 | @Lazy |
| 41 | private CombinationRecordService combinationRecordService; | 41 | private CombinationRecordService combinationRecordService; |
| 42 | 42 | ||
| 43 | - // 然后如果 headId 非空,并且第一页,单独多查询一条 head ;放到第 0 个位置;相当于说,第一页特殊一点; | ||
| 44 | - | ||
| 45 | @GetMapping("/page") | 43 | @GetMapping("/page") |
| 46 | @Operation(summary = "获得拼团记录分页") | 44 | @Operation(summary = "获得拼团记录分页") |
| 47 | @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") | 45 | @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java
| @@ -47,13 +47,13 @@ public class AppCombinationRecordController { | @@ -47,13 +47,13 @@ public class AppCombinationRecordController { | ||
| 47 | public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() { | 47 | public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() { |
| 48 | AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); | 48 | AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); |
| 49 | // 1. 获得拼团参与用户数量 | 49 | // 1. 获得拼团参与用户数量 |
| 50 | - Long count = combinationRecordService.getCombinationUserCount(); | ||
| 51 | - if (count == 0) { | 50 | + Long userCount = combinationRecordService.getCombinationUserCount(); |
| 51 | + if (userCount == 0) { | ||
| 52 | summary.setAvatars(Collections.emptyList()); | 52 | summary.setAvatars(Collections.emptyList()); |
| 53 | - summary.setUserCount(count); | 53 | + summary.setUserCount(userCount); |
| 54 | return success(summary); | 54 | return success(summary); |
| 55 | } | 55 | } |
| 56 | - summary.setUserCount(count); | 56 | + summary.setUserCount(userCount); |
| 57 | 57 | ||
| 58 | // 2. 获得拼团记录头像 | 58 | // 2. 获得拼团记录头像 |
| 59 | List<CombinationRecordDO> records = combinationRecordService.getLatestCombinationRecordList( | 59 | List<CombinationRecordDO> records = combinationRecordService.getLatestCombinationRecordList( |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| @@ -192,7 +192,6 @@ public interface CombinationActivityConvert { | @@ -192,7 +192,6 @@ public interface CombinationActivityConvert { | ||
| 192 | return result; | 192 | return result; |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | - | ||
| 196 | default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List<CombinationRecordDO> memberRecords) { | 195 | default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List<CombinationRecordDO> memberRecords) { |
| 197 | AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO() | 196 | AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO() |
| 198 | .setHeadRecord(convert(headRecord)).setMemberRecords(convertList3(memberRecords)); | 197 | .setHeadRecord(convert(headRecord)).setMemberRecords(convertList3(memberRecords)); |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
| @@ -99,10 +99,10 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | @@ -99,10 +99,10 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | ||
| 99 | LambdaQueryWrapperX<CombinationRecordDO> queryWrapper = new LambdaQueryWrapperX<CombinationRecordDO>() | 99 | LambdaQueryWrapperX<CombinationRecordDO> queryWrapper = new LambdaQueryWrapperX<CombinationRecordDO>() |
| 100 | .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus()) | 100 | .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus()) |
| 101 | .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()); | 101 | .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()); |
| 102 | + // 如果 headId 非空,说明查询指定团的团长 + 团员的拼团记录 | ||
| 102 | if (pageVO.getHeadId() != null) { | 103 | if (pageVO.getHeadId() != null) { |
| 103 | - queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId()) | ||
| 104 | - .or() | ||
| 105 | - .eq(CombinationRecordDO::getHeadId, pageVO.getHeadId()); | 104 | + queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId()) // 团长 |
| 105 | + .or().eq(CombinationRecordDO::getHeadId, pageVO.getHeadId()); // 团员 | ||
| 106 | } | 106 | } |
| 107 | return selectPage(pageVO, queryWrapper); | 107 | return selectPage(pageVO, queryWrapper); |
| 108 | } | 108 | } |
| @@ -127,6 +127,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | @@ -127,6 +127,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | ||
| 127 | * | 127 | * |
| 128 | * @return 参加过拼团的用户数 | 128 | * @return 参加过拼团的用户数 |
| 129 | */ | 129 | */ |
| 130 | + // TODO @puhui999:1)方法名,直接 selectUserCount;2)COUNT(DISTINCT(user_id)) 就可以啦,不用 group by 哈 | ||
| 130 | default Long selectUserDistinctCount() { | 131 | default Long selectUserDistinctCount() { |
| 131 | return selectCount(new QueryWrapper<CombinationRecordDO>() | 132 | return selectCount(new QueryWrapper<CombinationRecordDO>() |
| 132 | .select("DISTINCT (user_id)") | 133 | .select("DISTINCT (user_id)") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| @@ -339,19 +339,20 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -339,19 +339,20 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 339 | 339 | ||
| 340 | @Override | 340 | @Override |
| 341 | public KeyValue<Integer, Integer> expireCombinationRecord() { | 341 | public KeyValue<Integer, Integer> expireCombinationRecord() { |
| 342 | - // 1.获取所有正在进行中的过期的父拼团 | 342 | + // 1. 获取所有正在进行中的过期的父拼团 |
| 343 | List<CombinationRecordDO> headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt( | 343 | List<CombinationRecordDO> headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt( |
| 344 | CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now()); | 344 | CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now()); |
| 345 | if (CollUtil.isEmpty(headExpireRecords)) { | 345 | if (CollUtil.isEmpty(headExpireRecords)) { |
| 346 | return new KeyValue<>(0, 0); | 346 | return new KeyValue<>(0, 0); |
| 347 | } | 347 | } |
| 348 | 348 | ||
| 349 | - // 2.获取拼团活动 | 349 | + // 2. 获取拼团活动 |
| 350 | List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds( | 350 | List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds( |
| 351 | convertSet(headExpireRecords, CombinationRecordDO::getActivityId)); | 351 | convertSet(headExpireRecords, CombinationRecordDO::getActivityId)); |
| 352 | Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId); | 352 | Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId); |
| 353 | 353 | ||
| 354 | - // 3.校验是否虚拟成团 | 354 | + // TODO @puhui999:这里可以改成“每个团”,处理一次哈;这样 handleExpireRecord、handleVirtualGroupRecord 都改成按团处理,每个是一个小事务; |
| 355 | + // 3. 校验是否虚拟成团 | ||
| 355 | List<CombinationRecordDO> virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团 | 356 | List<CombinationRecordDO> virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团 |
| 356 | for (Iterator<CombinationRecordDO> iterator = headExpireRecords.iterator(); iterator.hasNext(); ) { | 357 | for (Iterator<CombinationRecordDO> iterator = headExpireRecords.iterator(); iterator.hasNext(); ) { |
| 357 | CombinationRecordDO record = iterator.next(); | 358 | CombinationRecordDO record = iterator.next(); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java
| @@ -93,6 +93,7 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> { | @@ -93,6 +93,7 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> { | ||
| 93 | return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode); | 93 | return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | + // TODO @puhui999:selectByUserIdAndCombinationActivityIdAndStatus,这样更容易理解哈。 | ||
| 96 | /** | 97 | /** |
| 97 | * 只针对 combinationActivityId 的查询 | 98 | * 只针对 combinationActivityId 的查询 |
| 98 | * | 99 | * |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java
| @@ -70,8 +70,8 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler { | @@ -70,8 +70,8 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler { | ||
| 70 | TradeOrderConvert.INSTANCE.convert(order, item)); | 70 | TradeOrderConvert.INSTANCE.convert(order, item)); |
| 71 | 71 | ||
| 72 | // 3. 更新拼团相关信息到订单 | 72 | // 3. 更新拼团相关信息到订单 |
| 73 | - // TODO 芋艿,只需要更新 record。 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null 的, | ||
| 74 | - // 设置团长编号这个操作时在订单是否后创建拼团记录时才设置的,所以支付完创建拼团记录后需要设置一下记录编号和团长编号 | 73 | + // 为什么几个字段都要更新?原因是: |
| 74 | + // 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null 的,设置团长编号这个操作时在订单是否后创建拼团记录时才设置的。 | ||
| 75 | orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(), | 75 | orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(), |
| 76 | combinationRecord.getCombinationRecordId(), combinationRecord.getCombinationHeadId()); | 76 | combinationRecord.getCombinationRecordId(), combinationRecord.getCombinationHeadId()); |
| 77 | } | 77 | } |