mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-15 02:31:53 +08:00
code review:拼团逻辑
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user