|
@@ -1,10 +1,8 @@
|
|
|
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;
|
|
@@ -13,12 +11,11 @@ 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.GameAthlete;
|
|
|
-import org.dromara.system.domain.GameEventProject;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
import org.dromara.system.domain.constant.ProjectClassification;
|
|
|
import org.dromara.system.domain.constant.SortType;
|
|
|
import org.dromara.system.domain.vo.*;
|
|
|
+import org.dromara.system.mapper.GameAthleteMapper;
|
|
|
import org.dromara.system.mapper.GameEventProjectMapper;
|
|
|
import org.dromara.system.service.IGameAthleteService;
|
|
|
import org.dromara.system.service.IGameEventProjectService;
|
|
@@ -34,7 +31,6 @@ import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
-import org.dromara.common.excel.utils.ExcelUtil;
|
|
|
import org.dromara.system.domain.bo.GameEventProjectBo;
|
|
|
import org.dromara.system.domain.bo.GameTeamBo;
|
|
|
|
|
@@ -58,10 +54,11 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
private final GameScoreMapper baseMapper;
|
|
|
private final IGameTeamService gameTeamService;
|
|
|
private final IGameAthleteService gameAthleteService;
|
|
|
-
|
|
|
+ private final GameAthleteMapper gameAthleteMapper;
|
|
|
private final GameEventProjectMapper projectMapper;
|
|
|
private final IGameEventProjectService gameEventProjectService;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 查询成绩
|
|
|
*
|
|
@@ -178,7 +175,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
private void validEntityBeforeSave(GameScore entity) {
|
|
|
- //TODO 做一些数据校验,如唯一约束
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -543,6 +540,8 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
athleteScoreBo.setTeamId(bo.getTeamId());
|
|
|
athleteScoreBo.setIndividualPerformance(BigDecimal.ZERO); // 团体项目个人成绩为0
|
|
|
athleteScoreBo.setTeamPerformance(bo.getTeamPerformance());
|
|
|
+// athleteScoreBo.setLeaderPoint(bo.getLeaderPoint());
|
|
|
+// athleteScoreBo.setExtraPoint(bo.getExtraPoint());
|
|
|
athleteScoreBo.setScoreType("team");
|
|
|
athleteScoreBo.setStatusFlag("0");
|
|
|
athleteScoreBo.setStatus("0");
|
|
@@ -649,12 +648,15 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
// 升序项目:成绩越小,积分分配越多
|
|
|
for (int i = 0; i < sortedScores.size(); i++) {
|
|
|
GameScoreVo score = sortedScores.get(i);
|
|
|
- int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+ int basePoints = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+// int leaderPoint = score.getLeaderPoint() != null ? score.getLeaderPoint() : 0;
|
|
|
+// int extraPoint = score.getExtraPoint() != null ? score.getExtraPoint() : 0;
|
|
|
+// int totalPoints = basePoints + leaderPoint + extraPoint;
|
|
|
|
|
|
// 更新成绩记录
|
|
|
GameScoreBo updateBo = new GameScoreBo();
|
|
|
updateBo.setScoreId(score.getScoreId());
|
|
|
- updateBo.setScorePoint(points);
|
|
|
+ updateBo.setScorePoint(basePoints);
|
|
|
updateBo.setEventId(eventId);
|
|
|
updateBo.setProjectId(projectId);
|
|
|
|
|
@@ -664,12 +666,15 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
// 降序项目:成绩越大,积分分配越多
|
|
|
for (int i = 0; i < sortedScores.size(); i++) {
|
|
|
GameScoreVo score = sortedScores.get(i);
|
|
|
- int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+ int basePoints = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+// int leaderPoint = score.getLeaderPoint() != null ? score.getLeaderPoint() : 0;
|
|
|
+// int extraPoint = score.getExtraPoint() != null ? score.getExtraPoint() : 0;
|
|
|
+// int totalPoints = basePoints + leaderPoint + extraPoint;
|
|
|
|
|
|
// 更新成绩记录
|
|
|
GameScoreBo updateBo = new GameScoreBo();
|
|
|
updateBo.setScoreId(score.getScoreId());
|
|
|
- updateBo.setScorePoint(points);
|
|
|
+ updateBo.setScorePoint(basePoints);
|
|
|
updateBo.setEventId(eventId);
|
|
|
updateBo.setProjectId(projectId);
|
|
|
|
|
@@ -697,10 +702,10 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
for (int i = 0; i < sortedByPoints.size(); i++) {
|
|
|
GameScoreVo score = sortedByPoints.get(i);
|
|
|
int currentPoints = score.getScorePoint() != null ? score.getScorePoint() : 0;
|
|
|
-
|
|
|
+
|
|
|
// 如果不是第一个,检查是否与前一个积分相同
|
|
|
if (i > 0) {
|
|
|
- int previousPoints = sortedByPoints.get(i - 1).getScorePoint() != null ?
|
|
|
+ int previousPoints = sortedByPoints.get(i - 1).getScorePoint() != null ?
|
|
|
sortedByPoints.get(i - 1).getScorePoint() : 0;
|
|
|
if (currentPoints != previousPoints) {
|
|
|
currentRank = i + 1;
|
|
@@ -778,8 +783,11 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
Map.Entry<Long, BigDecimal> teamEntry = sortedTeamsByPerformance.get(i);
|
|
|
Long teamId = teamEntry.getKey();
|
|
|
BigDecimal currentPerformance = teamEntry.getValue();
|
|
|
- int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
-
|
|
|
+ int basePoints = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+// int leaderPoint = score.getLeaderPoint() != null ? score.getLeaderPoint() : 0;
|
|
|
+// int extraPoint = score.getExtraPoint() != null ? score.getExtraPoint() : 0;
|
|
|
+// int totalPoints = basePoints + leaderPoint + extraPoint;
|
|
|
+
|
|
|
// 如果不是第一个,检查是否与前一个成绩相同
|
|
|
if (i > 0) {
|
|
|
BigDecimal previousPerformance = sortedTeamsByPerformance.get(i - 1).getValue();
|
|
@@ -788,7 +796,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- teamPoints.put(teamId, points);
|
|
|
+ teamPoints.put(teamId, basePoints);
|
|
|
teamRanks.put(teamId, currentRank);
|
|
|
}
|
|
|
|
|
@@ -800,6 +808,8 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
updateBo.setScoreId(score.getScoreId());
|
|
|
updateBo.setScoreRank(teamRanks.get(teamId));
|
|
|
updateBo.setScorePoint(teamPoints.get(teamId));
|
|
|
+// updateBo.setLeaderPoint(score.getLeaderPoint());
|
|
|
+// updateBo.setExtraPoint(score.getExtraPoint());
|
|
|
updateBo.setEventId(eventId);
|
|
|
updateBo.setProjectId(projectId);
|
|
|
|
|
@@ -870,21 +880,21 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
String key = team.getTeamId() + "_" + project.getProjectId();
|
|
|
GameScoreVo score = scoreMap.get(key);
|
|
|
|
|
|
- int projectScore = 0;
|
|
|
+ int projectPoint = 0;
|
|
|
if (score != null && score.getScorePoint() != null) {
|
|
|
- projectScore = score.getScorePoint();
|
|
|
- totalScore += projectScore;
|
|
|
+ projectPoint = score.getScorePoint();
|
|
|
+ totalScore += projectPoint;
|
|
|
}
|
|
|
|
|
|
// 使用项目名称设置积分
|
|
|
- exportVo.setProjectScore(project.getProjectName(), projectScore);
|
|
|
+ exportVo.setProjectScore(project.getProjectName(), projectPoint);
|
|
|
}
|
|
|
|
|
|
// 设置总分
|
|
|
exportVo.setTotalScore(totalScore);
|
|
|
|
|
|
// 设置加分(暂时设为0,后续可根据业务需求调整)
|
|
|
- exportVo.setExtraScore(0);
|
|
|
+ exportVo.setExtraPoint(0);
|
|
|
|
|
|
exportData.add(exportVo);
|
|
|
}
|
|
@@ -908,63 +918,96 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
* 用户端查询项目成绩信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<AppScoreVo> listAppScore(Long eventId, Long projectId) {
|
|
|
- // 获取项目详细信息
|
|
|
- GameEventProjectVo project = gameEventProjectService.queryById(projectId);
|
|
|
+ public List<AppScoreVo> listAppScore(Long eventId) {
|
|
|
+ try {
|
|
|
+ // 1. 获取所有相关成绩
|
|
|
+ List<GameScoreVo> allScores = baseMapper.selectVoList(
|
|
|
+ Wrappers.lambdaQuery(GameScore.class)
|
|
|
+ .eq(GameScore::getEventId, eventId)
|
|
|
+ );
|
|
|
|
|
|
- // 查询参与了该项目的运动员
|
|
|
- List<GameAthleteVo> athletes = gameAthleteService.queryListByEventIdAndProjectId(eventId, projectId, null);
|
|
|
-
|
|
|
- // 获取所有相关成绩
|
|
|
- GameScoreBo scoreBo = new GameScoreBo();
|
|
|
- scoreBo.setEventId(eventId);
|
|
|
- scoreBo.setProjectId(projectId);
|
|
|
- List<GameScoreVo> scores = queryList(scoreBo);
|
|
|
-
|
|
|
- // 创建成绩映射 athleteId -> GameScoreVo
|
|
|
- Map<Long, GameScoreVo> scoreMap = scores.stream()
|
|
|
- .collect(Collectors.toMap(GameScoreVo::getAthleteId, Function.identity(), (existing, replacement) -> existing));
|
|
|
-
|
|
|
- // 队伍id与名称的映射
|
|
|
- Set<Long> teamIds = athletes.stream().map(GameAthleteVo::getTeamId).collect(Collectors.toSet());
|
|
|
- Map<Long, String> teamMap = gameTeamService.queryTeamIdAndName(teamIds);
|
|
|
-
|
|
|
- List<AppScoreVo> result = result = athletes.stream().map(athlete -> {
|
|
|
- AppScoreVo vo = new AppScoreVo();
|
|
|
- vo.setProjectId(projectId);
|
|
|
- vo.setProjectName(project != null ? project.getProjectName() : "");
|
|
|
- vo.setClassification(project != null ? project.getClassification() : "");
|
|
|
- vo.setAthleteId(athlete.getAthleteId());
|
|
|
- vo.setAthleteName(athlete.getName());
|
|
|
- vo.setTeamId(athlete.getTeamId());
|
|
|
-
|
|
|
- // 获取队伍信息
|
|
|
- if (athlete.getTeamId() != null) {
|
|
|
- String teamName = teamMap.get(athlete.getTeamId());
|
|
|
- vo.setTeamName(teamName != null ? teamName : "");
|
|
|
+ if (allScores.isEmpty()) {
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
- // 获取成绩信息
|
|
|
- GameScoreVo score = scoreMap.get(athlete.getAthleteId());
|
|
|
- if (score != null) {
|
|
|
+ // 2. 获取所有运动员信息
|
|
|
+ List<GameAthleteVo> athletes = gameAthleteMapper.queryAthleteIdAndName(eventId);
|
|
|
+ Map<Long, GameAthleteVo> athleteMap = athletes.stream()
|
|
|
+ .collect(Collectors.toMap(GameAthleteVo::getAthleteId, Function.identity(), (existing, replacement) -> existing));
|
|
|
+
|
|
|
+ // 3. 获取所有队伍信息
|
|
|
+ Set<Long> teamIds = athletes.stream()
|
|
|
+ .map(GameAthleteVo::getTeamId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Map<Long, String> teamMap = gameTeamService.queryTeamIdAndName(teamIds);
|
|
|
+
|
|
|
+ // 4. 获取所有项目信息
|
|
|
+ GameEventProjectBo projectQuery = new GameEventProjectBo();
|
|
|
+ projectQuery.setEventId(eventId);
|
|
|
+ List<GameEventProjectVo> projects = gameEventProjectService.queryList(projectQuery);
|
|
|
+ Map<Long, GameEventProjectVo> projectMap = projects.stream()
|
|
|
+ .collect(Collectors.toMap(GameEventProjectVo::getProjectId, Function.identity(), (existing, replacement) -> existing));
|
|
|
+
|
|
|
+ // 5. 构建结果
|
|
|
+ List<AppScoreVo> result = new ArrayList<>();
|
|
|
+
|
|
|
+ for (GameScoreVo score : allScores) {
|
|
|
+ AppScoreVo vo = new AppScoreVo();
|
|
|
+
|
|
|
+ // 设置基本信息
|
|
|
+ vo.setAthleteId(score.getAthleteId());
|
|
|
+ vo.setTeamId(score.getTeamId());
|
|
|
+ vo.setProjectId(score.getProjectId());
|
|
|
+
|
|
|
+ // 设置运动员名称
|
|
|
+ GameAthleteVo athlete = athleteMap.get(score.getAthleteId());
|
|
|
+ if (athlete != null) {
|
|
|
+ vo.setAthleteName(athlete.getName());
|
|
|
+ } else {
|
|
|
+ vo.setAthleteName("");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置队伍名称
|
|
|
+ if (score.getTeamId() != null) {
|
|
|
+ String teamName = teamMap.get(score.getTeamId());
|
|
|
+ vo.setTeamName(teamName != null ? teamName : "");
|
|
|
+ } else {
|
|
|
+ vo.setTeamName("");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置项目信息
|
|
|
+ GameEventProjectVo project = projectMap.get(score.getProjectId());
|
|
|
+ if (project != null) {
|
|
|
+ vo.setProjectName(project.getProjectName());
|
|
|
+ vo.setClassification(project.getClassification());
|
|
|
+ } else {
|
|
|
+ vo.setProjectName("");
|
|
|
+ vo.setClassification("");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置成绩信息
|
|
|
vo.setIndividualPerformance(convertToBigDecimal(score.getIndividualPerformance()));
|
|
|
vo.setTeamPerformance(convertToBigDecimal(score.getTeamPerformance()));
|
|
|
- vo.setScorePoint(score.getScorePoint());
|
|
|
- vo.setScoreRank(score.getScoreRank());
|
|
|
- } else {
|
|
|
- vo.setIndividualPerformance(BigDecimal.ZERO);
|
|
|
- vo.setTeamPerformance(BigDecimal.ZERO);
|
|
|
- vo.setScorePoint(0);
|
|
|
- vo.setScoreRank(0);
|
|
|
+ vo.setScorePoint(score.getScorePoint() != null ? score.getScorePoint() : 0);
|
|
|
+ vo.setScoreRank(score.getScoreRank() != null ? score.getScoreRank() : 0);
|
|
|
+
|
|
|
+ result.add(vo);
|
|
|
}
|
|
|
|
|
|
- return vo;
|
|
|
- }).toList();
|
|
|
+ // 6. 按排名排序(排名为0或null的排在最后)
|
|
|
+ return result.stream()
|
|
|
+ .sorted((a, b) -> {
|
|
|
+ Integer rankA = a.getScoreRank() != null ? a.getScoreRank() : Integer.MAX_VALUE;
|
|
|
+ Integer rankB = b.getScoreRank() != null ? b.getScoreRank() : Integer.MAX_VALUE;
|
|
|
+ return Integer.compare(rankA, rankB);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- // 按排名排序
|
|
|
- return result.stream()
|
|
|
- .sorted(Comparator.comparing(AppScoreVo::getScoreRank))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询用户端成绩信息失败", e);
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1025,7 +1068,8 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
}
|
|
|
|
|
|
// 加分列
|
|
|
- rowData.put("加分", exportVo.getExtraScore());
|
|
|
+ rowData.put("领导加分", exportVo.getLeaderPoint());
|
|
|
+ rowData.put("额外加分", exportVo.getExtraPoint());
|
|
|
|
|
|
dynamicData.add(rowData);
|
|
|
}
|
|
@@ -1072,9 +1116,13 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
}
|
|
|
|
|
|
// 加分列标题
|
|
|
- Cell extraCell = headerRow.createCell(colIndex++);
|
|
|
- extraCell.setCellValue("加分");
|
|
|
- extraCell.setCellStyle(headerStyle);
|
|
|
+ Cell leaderBonusCell = headerRow.createCell(colIndex++);
|
|
|
+ leaderBonusCell.setCellValue("领导加分");
|
|
|
+ leaderBonusCell.setCellStyle(headerStyle);
|
|
|
+
|
|
|
+ Cell extraBonusCell = headerRow.createCell(colIndex++);
|
|
|
+ extraBonusCell.setCellValue("额外加分");
|
|
|
+ extraBonusCell.setCellStyle(headerStyle);
|
|
|
|
|
|
// 填充数据行
|
|
|
int rowIndex = 1;
|
|
@@ -1100,7 +1148,8 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
}
|
|
|
|
|
|
// 加分列数据
|
|
|
- createCellWithStyle(dataRow, colIndex++, (Integer) rowData.get("加分"), currentRowStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, (Integer) rowData.get("领导加分"), currentRowStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, (Integer) rowData.get("额外加分"), currentRowStyle);
|
|
|
}
|
|
|
|
|
|
// 自动调整列宽
|
|
@@ -1208,4 +1257,237 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
|
|
|
cell.setCellStyle(style);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取加分数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getBonusData(Long eventId) {
|
|
|
+ try {
|
|
|
+ // 获取所有项目
|
|
|
+ GameEventProjectBo projectQuery = new GameEventProjectBo();
|
|
|
+ projectQuery.setEventId(eventId);
|
|
|
+ List<GameEventProjectVo> projects = gameEventProjectService.queryList(projectQuery);
|
|
|
+
|
|
|
+ // 获取所有队伍
|
|
|
+ GameTeamBo teamQuery = new GameTeamBo();
|
|
|
+ teamQuery.setEventId(eventId);
|
|
|
+ List<GameTeamVo> teams = gameTeamService.queryList(teamQuery);
|
|
|
+
|
|
|
+ // 批量查询所有队伍在所有项目中的成绩
|
|
|
+ List<GameScoreVo> allScores = baseMapper.selectVoList(
|
|
|
+ Wrappers.lambdaQuery(GameScore.class)
|
|
|
+ .eq(GameScore::getEventId, eventId)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 按队伍ID和项目ID分组成绩数据
|
|
|
+ Map<String, GameScoreVo> scoreMap = new HashMap<>();
|
|
|
+ for (GameScoreVo score : allScores) {
|
|
|
+ if (score.getTeamId() != null && score.getProjectId() != null) {
|
|
|
+ String key = score.getTeamId() + "_" + score.getProjectId();
|
|
|
+ scoreMap.put(key, score);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建加分数据
|
|
|
+ List<Map<String, Object>> bonusData = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < teams.size(); i++) {
|
|
|
+ GameTeamVo team = teams.get(i);
|
|
|
+ Map<String, Object> teamData = new HashMap<>();
|
|
|
+
|
|
|
+ // 设置基本信息
|
|
|
+ teamData.put("teamId", team.getTeamId());
|
|
|
+ teamData.put("teamName", team.getTeamName());
|
|
|
+ teamData.put("rank", i + 1);
|
|
|
+
|
|
|
+ // 计算该队伍在各项目中的积分
|
|
|
+ int totalScore = 0;
|
|
|
+ Map<String, Integer> projectScores = new HashMap<>();
|
|
|
+ int leaderPoint = 0;
|
|
|
+ int extraPoint = 0;
|
|
|
+
|
|
|
+ // 设置各项目积分
|
|
|
+ for (GameEventProjectVo project : projects) {
|
|
|
+ String key = team.getTeamId() + "_" + project.getProjectId();
|
|
|
+ GameScoreVo score = scoreMap.get(key);
|
|
|
+
|
|
|
+ int projectScore = 0;
|
|
|
+ if (score != null && score.getScorePoint() != null) {
|
|
|
+ projectScore = score.getScorePoint();
|
|
|
+ totalScore += projectScore;
|
|
|
+
|
|
|
+ // 获取加分数据
|
|
|
+ if (score.getLeaderPoint() != null) {
|
|
|
+ leaderPoint = score.getLeaderPoint();
|
|
|
+ }
|
|
|
+ if (score.getExtraPoint() != null) {
|
|
|
+ extraPoint = score.getExtraPoint();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ projectScores.put(project.getProjectName(), projectScore);
|
|
|
+ }
|
|
|
+
|
|
|
+ teamData.put("projectScores", projectScores);
|
|
|
+ teamData.put("totalScore", totalScore);
|
|
|
+ teamData.put("leaderPoint", leaderPoint);
|
|
|
+ teamData.put("extraPoint", extraPoint);
|
|
|
+
|
|
|
+ bonusData.add(teamData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按总分排序,生成排名
|
|
|
+ bonusData.sort((a, b) -> Integer.compare((Integer) b.get("totalScore"), (Integer) a.get("totalScore")));
|
|
|
+ for (int i = 0; i < bonusData.size(); i++) {
|
|
|
+ bonusData.get(i).put("rank", i + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("rows", bonusData);
|
|
|
+ result.put("projects", projects);
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取加分数据失败", e);
|
|
|
+ throw new RuntimeException("获取加分数据失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新加分数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateBonusData(Map<String, Object> data) {
|
|
|
+ try {
|
|
|
+ Long eventId = Long.valueOf(data.get("eventId").toString());
|
|
|
+ List<Map<String, Object>> updateData = (List<Map<String, Object>>) data.get("data");
|
|
|
+
|
|
|
+ for (Map<String, Object> teamData : updateData) {
|
|
|
+ Long teamId = Long.valueOf(teamData.get("teamId").toString());
|
|
|
+ Integer leaderPoint = Integer.valueOf(teamData.get("leaderPoint").toString());
|
|
|
+ Integer extraPoint = Integer.valueOf(teamData.get("extraPoint").toString());
|
|
|
+
|
|
|
+ // 更新该队伍在所有项目中的加分数据
|
|
|
+ List<GameScoreVo> teamScores = baseMapper.selectVoList(
|
|
|
+ Wrappers.lambdaQuery(GameScore.class)
|
|
|
+ .eq(GameScore::getEventId, eventId)
|
|
|
+ .eq(GameScore::getTeamId, teamId)
|
|
|
+ );
|
|
|
+
|
|
|
+ for (GameScoreVo score : teamScores) {
|
|
|
+ GameScoreBo updateBo = new GameScoreBo();
|
|
|
+ updateBo.setScoreId(score.getScoreId());
|
|
|
+ updateBo.setLeaderPoint(leaderPoint);
|
|
|
+ updateBo.setExtraPoint(extraPoint);
|
|
|
+
|
|
|
+ // 重新计算积分
|
|
|
+ int basePoints = score.getScorePoint() != null ? score.getScorePoint() : 0;
|
|
|
+// int totalPoints = basePoints + leaderPoint + extraPoint;
|
|
|
+ updateBo.setScorePoint(basePoints);
|
|
|
+
|
|
|
+ updateByBo(updateBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新加分数据失败", e);
|
|
|
+ throw new RuntimeException("更新加分数据失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出加分Excel
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void exportBonusExcel(Map<String, Object> data, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ List<Map<String, Object>> bonusData = (List<Map<String, Object>>) data.get("data");
|
|
|
+ List<Map<String, Object>> projects = (List<Map<String, Object>>) data.get("projects");
|
|
|
+
|
|
|
+ // 使用Apache POI导出Excel
|
|
|
+ try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
+ Sheet sheet = workbook.createSheet("加分数据表");
|
|
|
+
|
|
|
+ // 创建标题行样式
|
|
|
+ CellStyle headerStyle = createHeaderStyle(workbook);
|
|
|
+ CellStyle dataStyle = createDataStyle(workbook, IndexedColors.WHITE);
|
|
|
+
|
|
|
+ // 创建标题行
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
+ int colIndex = 0;
|
|
|
+
|
|
|
+ // 基础列标题
|
|
|
+ String[] baseHeaders = {"序号", "代表队名称", "排名", "总分"};
|
|
|
+ for (String header : baseHeaders) {
|
|
|
+ Cell cell = headerRow.createCell(colIndex++);
|
|
|
+ cell.setCellValue(header);
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 动态项目列标题
|
|
|
+ for (Map<String, Object> project : projects) {
|
|
|
+ String projectName = (String) project.get("projectName");
|
|
|
+ Cell cell = headerRow.createCell(colIndex++);
|
|
|
+ cell.setCellValue(projectName);
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加分列标题
|
|
|
+ Cell leaderCell = headerRow.createCell(colIndex++);
|
|
|
+ leaderCell.setCellValue("领导加分");
|
|
|
+ leaderCell.setCellStyle(headerStyle);
|
|
|
+
|
|
|
+ Cell extraCell = headerRow.createCell(colIndex++);
|
|
|
+ extraCell.setCellValue("额外加分");
|
|
|
+ extraCell.setCellStyle(headerStyle);
|
|
|
+
|
|
|
+ // 填充数据行
|
|
|
+ int rowIndex = 1;
|
|
|
+ for (Map<String, Object> teamData : bonusData) {
|
|
|
+ Row dataRow = sheet.createRow(rowIndex++);
|
|
|
+ colIndex = 0;
|
|
|
+
|
|
|
+ // 基础列数据
|
|
|
+ createCellWithStyle(dataRow, colIndex++, rowIndex - 1, dataStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, teamData.get("teamName"), dataStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, teamData.get("rank"), dataStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, teamData.get("totalScore"), dataStyle);
|
|
|
+
|
|
|
+ // 动态项目列数据
|
|
|
+ Map<String, Integer> projectScores = (Map<String, Integer>) teamData.get("projectScores");
|
|
|
+ for (Map<String, Object> project : projects) {
|
|
|
+ String projectName = (String) project.get("projectName");
|
|
|
+ Integer score = projectScores != null ? projectScores.get(projectName) : 0;
|
|
|
+ createCellWithStyle(dataRow, colIndex++, score != null ? score : 0, dataStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加分列数据
|
|
|
+ createCellWithStyle(dataRow, colIndex++, teamData.get("leaderPoint"), dataStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, teamData.get("extraPoint"), dataStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动调整列宽
|
|
|
+ for (int i = 0; i < colIndex; i++) {
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = "加分数据表_" + System.currentTimeMillis() + ".xlsx";
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
|
|
+
|
|
|
+ // 写入响应
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出加分Excel失败", e);
|
|
|
+ throw new RuntimeException("导出失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|