code review:拼团逻辑
This commit is contained in:
parent
7bc3b7b2ff
commit
4359c584bb
@ -28,7 +28,7 @@ public interface CombinationRecordApi {
|
||||
* 创建开团记录
|
||||
*
|
||||
* @param reqDTO 请求 DTO
|
||||
* @return 团信息
|
||||
* @return 拼团信息
|
||||
*/
|
||||
CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
|
||||
|
||||
|
@ -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')")
|
||||
|
@ -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(
|
||||
|
@ -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));
|
||||
|
@ -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 @puhui999:1)方法名,直接 selectUserCount;2)COUNT(DISTINCT(user_id)) 就可以啦,不用 group by 哈
|
||||
default Long selectUserDistinctCount() {
|
||||
return selectCount(new QueryWrapper<CombinationRecordDO>()
|
||||
.select("DISTINCT (user_id)")
|
||||
|
@ -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:这里可以改成“每个团”,处理一次哈;这样 handleExpireRecord、handleVirtualGroupRecord 都改成按团处理,每个是一个小事务;
|
||||
// 3. 校验是否虚拟成团
|
||||
List<CombinationRecordDO> virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团
|
||||
for (Iterator<CombinationRecordDO> iterator = headExpireRecords.iterator(); iterator.hasNext(); ) {
|
||||
CombinationRecordDO record = iterator.next();
|
||||
|
@ -93,6 +93,7 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
|
||||
return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode);
|
||||
}
|
||||
|
||||
// TODO @puhui999:selectByUserIdAndCombinationActivityIdAndStatus,这样更容易理解哈。
|
||||
/**
|
||||
* 只针对 combinationActivityId 的查询
|
||||
*
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user