code review:拼团逻辑

This commit is contained in:
YunaiV 2023-10-16 09:07:02 +08:00
parent 7bc3b7b2ff
commit 4359c584bb
8 changed files with 16 additions and 16 deletions

View File

@ -28,7 +28,7 @@ public interface CombinationRecordApi {
* 创建开团记录
*
* @param reqDTO 请求 DTO
* @return 团信息
* @return 团信息
*/
CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);

View File

@ -40,8 +40,6 @@ public class CombinationRecordController {
@Lazy
private CombinationRecordService combinationRecordService;
// 然后如果 headId 非空并且第一页单独多查询一条 head 放到第 0 个位置相当于说第一页特殊一点
@GetMapping("/page")
@Operation(summary = "获得拼团记录分页")
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")

View File

@ -47,13 +47,13 @@ public class AppCombinationRecordController {
public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() {
AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO();
// 1. 获得拼团参与用户数量
Long count = combinationRecordService.getCombinationUserCount();
if (count == 0) {
Long userCount = combinationRecordService.getCombinationUserCount();
if (userCount == 0) {
summary.setAvatars(Collections.emptyList());
summary.setUserCount(count);
summary.setUserCount(userCount);
return success(summary);
}
summary.setUserCount(count);
summary.setUserCount(userCount);
// 2. 获得拼团记录头像
List<CombinationRecordDO> records = combinationRecordService.getLatestCombinationRecordList(

View File

@ -192,7 +192,6 @@ public interface CombinationActivityConvert {
return result;
}
default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List<CombinationRecordDO> memberRecords) {
AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO()
.setHeadRecord(convert(headRecord)).setMemberRecords(convertList3(memberRecords));

View File

@ -99,10 +99,10 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
LambdaQueryWrapperX<CombinationRecordDO> queryWrapper = new LambdaQueryWrapperX<CombinationRecordDO>()
.eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus())
.betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime());
// 如果 headId 非空说明查询指定团的团长 + 团员的拼团记录
if (pageVO.getHeadId() != null) {
queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId())
.or()
.eq(CombinationRecordDO::getHeadId, pageVO.getHeadId());
queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId()) // 团长
.or().eq(CombinationRecordDO::getHeadId, pageVO.getHeadId()); // 团员
}
return selectPage(pageVO, queryWrapper);
}
@ -127,6 +127,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
*
* @return 参加过拼团的用户数
*/
// TODO @puhui9991方法名直接 selectUserCount2COUNT(DISTINCT(user_id)) 就可以啦不用 group by
default Long selectUserDistinctCount() {
return selectCount(new QueryWrapper<CombinationRecordDO>()
.select("DISTINCT (user_id)")

View File

@ -339,19 +339,20 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override
public KeyValue<Integer, Integer> expireCombinationRecord() {
// 1.获取所有正在进行中的过期的父拼团
// 1. 获取所有正在进行中的过期的父拼团
List<CombinationRecordDO> headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt(
CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now());
if (CollUtil.isEmpty(headExpireRecords)) {
return new KeyValue<>(0, 0);
}
// 2.获取拼团活动
// 2. 获取拼团活动
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(
convertSet(headExpireRecords, CombinationRecordDO::getActivityId));
Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId);
// 3.校验是否虚拟成团
// TODO @puhui999这里可以改成每个团处理一次哈这样 handleExpireRecordhandleVirtualGroupRecord 都改成按团处理每个是一个小事务
// 3. 校验是否虚拟成团
List<CombinationRecordDO> virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团
for (Iterator<CombinationRecordDO> iterator = headExpireRecords.iterator(); iterator.hasNext(); ) {
CombinationRecordDO record = iterator.next();

View File

@ -93,6 +93,7 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode);
}
// TODO @puhui999selectByUserIdAndCombinationActivityIdAndStatus这样更容易理解哈
/**
* 只针对 combinationActivityId 的查询
*

View File

@ -70,8 +70,8 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler {
TradeOrderConvert.INSTANCE.convert(order, item));
// 3. 更新拼团相关信息到订单
// TODO 芋艿只需要更新 record 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null
// 设置团长编号这个操作时在订单是否后创建拼团记录时才设置的所以支付完创建拼团记录后需要设置一下记录编号和团长编号
// 为什么几个字段都要更新原因是
// 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null 设置团长编号这个操作时在订单是否后创建拼团记录时才设置的
orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(),
combinationRecord.getCombinationRecordId(), combinationRecord.getCombinationHeadId());
}