|
|
@@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.dromara.system.domain.bo.GameEventProjectBo;
|
|
|
import org.dromara.system.domain.bo.GameRefereeBo;
|
|
|
import org.dromara.system.domain.vo.GameEventProjectVo;
|
|
|
+import org.dromara.system.domain.vo.GameProjectStatsVo;
|
|
|
import org.dromara.system.service.IGameEventProjectService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -50,6 +51,7 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
private final GameTeamMapper gameTeamMapper;
|
|
|
private final GameAthleteMapper gameAthleteMapper;
|
|
|
private final GameEventGroupMapper gameEventGroupMapper;
|
|
|
+ private final GameScoreMapper gameScoreMapper;
|
|
|
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
@@ -61,13 +63,14 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
|
|
|
public GameEventProjectServiceImpl(GameEventProjectMapper baseMapper, GameEventMapper gameEventMapper,
|
|
|
ISysDictTypeService sysDictTypeService, GameTeamMapper gameTeamMapper, GameAthleteMapper gameAthleteMapper,
|
|
|
- GameEventGroupMapper gameEventGroupMapper) {
|
|
|
+ GameEventGroupMapper gameEventGroupMapper, GameScoreMapper gameScoreMapper) {
|
|
|
this.baseMapper = baseMapper;
|
|
|
this.gameEventMapper = gameEventMapper;
|
|
|
this.sysDictTypeService = sysDictTypeService;
|
|
|
this.gameTeamMapper = gameTeamMapper;
|
|
|
this.gameAthleteMapper = gameAthleteMapper;
|
|
|
this.gameEventGroupMapper = gameEventGroupMapper;
|
|
|
+ this.gameScoreMapper = gameScoreMapper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -82,7 +85,7 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
if (vo == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- if (vo.getRefereeGroup() != null && !"".equals(vo.getRefereeGroup())){
|
|
|
+ if (vo.getRefereeGroup() != null && !vo.getRefereeGroup().isEmpty()){
|
|
|
vo.setRefereeGroups(JSONUtil.toList(vo.getRefereeGroup(), Long.class));
|
|
|
}else{
|
|
|
vo.setRefereeGroups(new ArrayList<>());
|
|
|
@@ -110,14 +113,12 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
LambdaQueryWrapper<GameEventProject> lqw = buildQueryWrapper(bo);
|
|
|
// Page<GameEventProjectVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
Page<GameEventProjectVo> result = baseMapper.selectPageEventProjectList(pageQuery.build(), lqw);
|
|
|
-
|
|
|
- // 使用 forEach 直接修改原对象
|
|
|
+ GameEvent gameEvent = gameEventMapper.selectById(bo.getEventId());
|
|
|
result.getRecords()
|
|
|
.forEach(vo -> {
|
|
|
Optional.ofNullable(vo.getEventId())
|
|
|
.filter(ObjectUtil::isNotEmpty)
|
|
|
.ifPresent(eventId -> {
|
|
|
- GameEvent gameEvent = gameEventMapper.selectById(eventId);
|
|
|
if (gameEvent != null) {
|
|
|
vo.setEventName(gameEvent.getEventName());
|
|
|
}
|
|
|
@@ -131,9 +132,57 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ // 批量计算统计数据
|
|
|
+ calculateProjectStats(result.getRecords());
|
|
|
+
|
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量计算项目的统计数据(参赛总数、完赛数、未完赛数)
|
|
|
+ */
|
|
|
+ private void calculateProjectStats(List<GameEventProjectVo> projectList) {
|
|
|
+ if (CollectionUtils.isEmpty(projectList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> projectIds = projectList.stream()
|
|
|
+ .map(GameEventProjectVo::getProjectId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (projectIds.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据库聚合查询统计数据
|
|
|
+ List<GameProjectStatsVo> statsList = gameScoreMapper.selectStatsByProjectIds(projectIds);
|
|
|
+
|
|
|
+ // 转换为 Map 方便查找
|
|
|
+ Map<Long, GameProjectStatsVo> statsMap = statsList.stream()
|
|
|
+ .collect(Collectors.toMap(GameProjectStatsVo::getProjectId, s -> s));
|
|
|
+
|
|
|
+ // 回填统计数据
|
|
|
+ projectList.forEach(vo -> {
|
|
|
+ GameProjectStatsVo stats = statsMap.get(vo.getProjectId());
|
|
|
+ if (stats != null) {
|
|
|
+ // 根据归类决定总数
|
|
|
+ if ("0".equals(vo.getClassification())) {
|
|
|
+ // 个人项目
|
|
|
+ vo.setTotalParticipants(stats.getAthleteCount());
|
|
|
+ } else {
|
|
|
+ // 团体项目
|
|
|
+ vo.setTotalParticipants(stats.getTeamCount());
|
|
|
+ }
|
|
|
+ vo.setCompletedParticipants(stats.getCompletedCount());
|
|
|
+ } else {
|
|
|
+ vo.setTotalParticipants(0);
|
|
|
+ vo.setCompletedParticipants(0);
|
|
|
+ }
|
|
|
+ vo.setIncompleteParticipants(vo.getTotalParticipants() - vo.getCompletedParticipants());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public TableDataInfo<GameEventProjectVo> queryAllProjectList(GameEventProjectBo bo, PageQuery pageQuery) {
|
|
|
// 获取默认赛事ID
|