|
@@ -1,7 +1,10 @@
|
|
|
package org.dromara.system.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.reflect.GenericTypeUtils;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -10,7 +13,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
+import org.dromara.system.domain.GameEventProject;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
+import org.dromara.system.domain.vo.GameAthleteVo;
|
|
|
+import org.dromara.system.domain.vo.GameEventProjectVo;
|
|
|
+import org.dromara.system.domain.vo.GameTeamVo;
|
|
|
+import org.dromara.system.service.IGameAthleteService;
|
|
|
+import org.dromara.system.service.IGameEventProjectService;
|
|
|
+import org.dromara.system.service.IGameTeamService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.dromara.system.domain.bo.GameScoreBo;
|
|
|
import org.dromara.system.domain.vo.GameScoreVo;
|
|
@@ -18,9 +28,10 @@ import org.dromara.system.domain.GameScore;
|
|
|
import org.dromara.system.mapper.GameScoreMapper;
|
|
|
import org.dromara.system.service.IGameScoreService;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Collection;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 成绩Service业务层处理
|
|
@@ -34,6 +45,9 @@ import java.util.Collection;
|
|
|
public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
|
|
|
private final GameScoreMapper baseMapper;
|
|
|
+ private final IGameTeamService gameTeamService;
|
|
|
+ private final IGameAthleteService gameAthleteService;
|
|
|
+ private final IGameEventProjectService gameEventProjectService;
|
|
|
|
|
|
/**
|
|
|
* 查询成绩
|
|
@@ -42,7 +56,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
* @return 成绩
|
|
|
*/
|
|
|
@Override
|
|
|
- public GameScoreVo queryById(Long scoreId){
|
|
|
+ public GameScoreVo queryById(Long scoreId) {
|
|
|
return baseMapper.selectVoById(scoreId);
|
|
|
}
|
|
|
|
|
@@ -150,7 +164,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(GameScore entity){
|
|
|
+ private void validEntityBeforeSave(GameScore entity) {
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
@@ -163,9 +177,79 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
+ if (isValid) {
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户端获奖名单
|
|
|
+ *
|
|
|
+ * @param eventId
|
|
|
+ * @return 获奖名单 key:项目 list:获奖信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, List<GameScoreVo>> getAppScore(Long eventId) {
|
|
|
+ // 1.查询当前赛事下的每个项目下的分数最高的前三名
|
|
|
+ List<GameScore> scoreList = baseMapper.listAppScoreByEventIdGroupProjectId(eventId);
|
|
|
+
|
|
|
+ // 2.将分数最高的前三名按项目分组
|
|
|
+ Map<Long, List<GameScore>> gorupMap = scoreList.stream()
|
|
|
+ .collect(Collectors.groupingBy(GameScore::getProjectId));
|
|
|
+
|
|
|
+ // 3.查询当前赛事下所有的项目 并转为map对应 方便后续直接取值
|
|
|
+ List<GameEventProjectVo> projects = gameEventProjectService.queryListByEventId(eventId);
|
|
|
+ Map<Long, String> projectMap = projects.stream()
|
|
|
+ .collect(Collectors.toMap(GameEventProjectVo::getProjectId, GameEventProjectVo::getProjectName));
|
|
|
+
|
|
|
+ // 4. 提取所有需要的 athleteId 和 teamId
|
|
|
+ Set<Long> athleteIds = scoreList.stream()
|
|
|
+ .map(GameScore::getAthleteId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ Set<Long> teamIds = scoreList.stream()
|
|
|
+ .map(GameScore::getTeamId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 5. 批量查询运动员和队伍信息
|
|
|
+ Map<Long, String> athleteNameMap;
|
|
|
+ if (!athleteIds.isEmpty()) {
|
|
|
+ List<GameAthleteVo> athletes = gameAthleteService.listByIds(athleteIds);
|
|
|
+ athleteNameMap = athletes.stream()
|
|
|
+ .collect(Collectors.toMap(GameAthleteVo::getAthleteId, GameAthleteVo::getName));
|
|
|
+ } else {
|
|
|
+ athleteNameMap = new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, String> teamNameMap;
|
|
|
+ if (!teamIds.isEmpty()) {
|
|
|
+ List<GameTeamVo> teams = gameTeamService.listByIds(teamIds);
|
|
|
+ teamNameMap = teams.stream()
|
|
|
+ .collect(Collectors.toMap(GameTeamVo::getTeamId, GameTeamVo::getTeamName));
|
|
|
+ } else {
|
|
|
+ teamNameMap = new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 构建结果
|
|
|
+ Map<String, List<GameScoreVo>> result = new HashMap<>();
|
|
|
+ for (Map.Entry<Long, List<GameScore>> entry : gorupMap.entrySet()) {
|
|
|
+ String projectName = projectMap.get(entry.getKey());
|
|
|
+ List<GameScoreVo> voList = entry.getValue().stream().map(gameScore -> {
|
|
|
+ GameScoreVo vo = new GameScoreVo();
|
|
|
+ BeanUtil.copyProperties(gameScore, vo);
|
|
|
+ // 使用缓存 Map 获取,避免查库
|
|
|
+ vo.setAthleteName(athleteNameMap.get(vo.getAthleteId()));
|
|
|
+ vo.setTeamName(teamNameMap.get(vo.getTeamId()));
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ result.put(projectName, voList);
|
|
|
+ }
|
|
|
+ log.error("map:{}", gorupMap);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|