|
|
@@ -308,7 +308,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
|
|
|
// 获取当前页的数据
|
|
|
List<Map<String, Object>> pageData = new ArrayList<>();
|
|
|
- if (startIndex < total) {
|
|
|
+ if (startIndex <= total) {
|
|
|
pageData = allDataList.subList(startIndex, endIndex);
|
|
|
log.info("当前页数据量: {}", pageData.size());
|
|
|
} else {
|
|
|
@@ -1503,33 +1503,33 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
public void exportScoresDetail(Long eventId, HttpServletResponse response) {
|
|
|
try {
|
|
|
log.info("开始导出成绩详情,eventId: {}", eventId);
|
|
|
-
|
|
|
+
|
|
|
// 1. 获取所有项目
|
|
|
List<GameEventProjectVo> projects = gameEventProjectService.queryListByEventId(eventId);
|
|
|
if (projects.isEmpty()) {
|
|
|
throw new RuntimeException("未找到赛事项目");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 2. 创建Excel工作簿
|
|
|
try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
-
|
|
|
+
|
|
|
// 3. 创建样式
|
|
|
CellStyle headerStyle = createHeaderStyle(workbook);
|
|
|
CellStyle dataStyleOdd = createDataStyle(workbook, IndexedColors.WHITE);
|
|
|
CellStyle dataStyleEven = createDataStyle(workbook, IndexedColors.GREY_25_PERCENT);
|
|
|
-
|
|
|
+
|
|
|
// 4. 为每个项目创建Sheet页
|
|
|
for (GameEventProjectVo project : projects) {
|
|
|
createProjectSheet(workbook, project, eventId, headerStyle, dataStyleOdd, dataStyleEven);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 5. 设置响应头并输出
|
|
|
setResponseHeaders(response, "成绩详情表");
|
|
|
workbook.write(response.getOutputStream());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
log.info("成绩详情导出完成");
|
|
|
-
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("导出成绩详情失败", e);
|
|
|
throw new RuntimeException("导出失败:" + e.getMessage());
|
|
|
@@ -1539,7 +1539,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
/**
|
|
|
* 为单个项目创建Sheet页
|
|
|
*/
|
|
|
- private void createProjectSheet(Workbook workbook, GameEventProjectVo project, Long eventId,
|
|
|
+ private void createProjectSheet(Workbook workbook, GameEventProjectVo project, Long eventId,
|
|
|
CellStyle headerStyle, CellStyle dataStyleOdd, CellStyle dataStyleEven) {
|
|
|
|
|
|
// 1. 创建Sheet页,名称限制在31个字符内
|
|
|
@@ -1548,8 +1548,8 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
|
|
|
// 2. 获取项目详细数据
|
|
|
List<Map<String, Object>> projectData = getProjectScoreDataAll(
|
|
|
- eventId,
|
|
|
- project.getProjectId(),
|
|
|
+ eventId,
|
|
|
+ project.getProjectId(),
|
|
|
project.getClassification()
|
|
|
);
|
|
|
|
|
|
@@ -1568,7 +1568,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
*/
|
|
|
private List<Map<String, Object>> getProjectScoreDataAll(Long eventId, Long projectId, String classification) {
|
|
|
log.info("获取项目全部数据: eventId={}, projectId={}, classification={}", eventId, projectId, classification);
|
|
|
-
|
|
|
+
|
|
|
if ("0".equals(classification)) {
|
|
|
// 个人项目:获取所有运动员数据
|
|
|
return getIndividualProjectDataAll(eventId, projectId);
|
|
|
@@ -1583,13 +1583,13 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
*/
|
|
|
private List<Map<String, Object>> getIndividualProjectDataAll(Long eventId, Long projectId) {
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
-
|
|
|
+
|
|
|
// 查询参与该项目的所有运动员(不分页)
|
|
|
List<GameAthleteVo> athletes = gameAthleteService.queryListByEventIdAndProjectId(eventId, projectId, null);
|
|
|
-
|
|
|
+
|
|
|
for (GameAthleteVo athlete : athletes) {
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
// 基础信息
|
|
|
data.put("athleteId", athlete.getAthleteId());
|
|
|
data.put("userId", athlete.getUserId());
|
|
|
@@ -1600,7 +1600,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
data.put("name", athlete.getName());
|
|
|
data.put("unit", athlete.getUnit());
|
|
|
data.put("groupType", athlete.getGroupType());
|
|
|
-
|
|
|
+
|
|
|
// 队伍信息
|
|
|
if (athlete.getTeamId() != null) {
|
|
|
GameTeamVo team = gameTeamService.queryById(athlete.getTeamId());
|
|
|
@@ -1609,7 +1609,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
data.put("teamCode", team.getTeamCode());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 成绩信息
|
|
|
GameScoreVo score = getScoreByAthleteIdAndProjectId(athlete.getAthleteId(), projectId);
|
|
|
if (score != null) {
|
|
|
@@ -1628,10 +1628,10 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
data.put("scoreRank", 0);
|
|
|
data.put("updateTime", "");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
resultList.add(data);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
@@ -1641,30 +1641,30 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
private List<Map<String, Object>> getTeamProjectDataAll(Long eventId, Long projectId) {
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
Set<Long> processedTeamIds = new HashSet<>();
|
|
|
-
|
|
|
+
|
|
|
// 查询参与该项目的所有运动员
|
|
|
List<GameAthleteVo> athletes = gameAthleteService.queryListByEventIdAndProjectId(eventId, projectId, null);
|
|
|
-
|
|
|
+
|
|
|
for (GameAthleteVo athlete : athletes) {
|
|
|
if (athlete.getTeamId() == null || processedTeamIds.contains(athlete.getTeamId())) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
processedTeamIds.add(athlete.getTeamId());
|
|
|
-
|
|
|
+
|
|
|
// 查询队伍信息
|
|
|
GameTeamVo team = gameTeamService.queryById(athlete.getTeamId());
|
|
|
if (team == null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
data.put("teamId", team.getTeamId());
|
|
|
data.put("teamName", team.getTeamName());
|
|
|
data.put("teamCode", team.getTeamCode());
|
|
|
data.put("eventId", eventId);
|
|
|
data.put("projectId", projectId);
|
|
|
-
|
|
|
+
|
|
|
// 查询成绩信息
|
|
|
GameScoreVo score = getScoreByAthleteIdAndProjectId(athlete.getAthleteId(), projectId);
|
|
|
if (score != null) {
|
|
|
@@ -1682,10 +1682,10 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
data.put("scoreRank", 0);
|
|
|
data.put("updateTime", "");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
resultList.add(data);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
@@ -1695,15 +1695,15 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
private void createProjectHeaderRow(Sheet sheet, GameEventProjectVo project, CellStyle headerStyle) {
|
|
|
Row headerRow = sheet.createRow(0);
|
|
|
int colIndex = 0;
|
|
|
-
|
|
|
+
|
|
|
// 根据项目类型确定列标题
|
|
|
if ("0".equals(project.getClassification())) {
|
|
|
// 个人项目列标题
|
|
|
String[] headers = {
|
|
|
- "序号", "队伍编号", "队伍名称", "姓名", "号码",
|
|
|
+ "序号", "队伍编号", "队伍名称", "姓名", "号码",
|
|
|
"个人成绩", "积分", "排名", "更新时间"
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
for (String header : headers) {
|
|
|
Cell cell = headerRow.createCell(colIndex++);
|
|
|
cell.setCellValue(header);
|
|
|
@@ -1712,10 +1712,10 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
} else {
|
|
|
// 团体项目列标题
|
|
|
String[] headers = {
|
|
|
- "序号", "队伍编号", "队伍名称", "团队成绩",
|
|
|
+ "序号", "队伍编号", "队伍名称", "团队成绩",
|
|
|
"积分", "排名", "更新时间"
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
for (String header : headers) {
|
|
|
Cell cell = headerRow.createCell(colIndex++);
|
|
|
cell.setCellValue(header);
|
|
|
@@ -1727,7 +1727,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
/**
|
|
|
* 填充项目数据行
|
|
|
*/
|
|
|
- private void fillProjectDataRows(Sheet sheet, List<Map<String, Object>> projectData,
|
|
|
+ private void fillProjectDataRows(Sheet sheet, List<Map<String, Object>> projectData,
|
|
|
GameEventProjectVo project, CellStyle dataStyleOdd, CellStyle dataStyleEven) {
|
|
|
|
|
|
int rowIndex = 1;
|
|
|
@@ -1771,7 +1771,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
if (projectName == null) {
|
|
|
return "项目";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 替换Excel不允许的特殊字符
|
|
|
String cleanName = projectName
|
|
|
.replace("*", "×") // 星号替换为乘号
|
|
|
@@ -1782,22 +1782,22 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
.replace("]", ")") // 右方括号替换为右括号
|
|
|
.replace(":", ":") // 英文冒号替换为中文冒号
|
|
|
.trim(); // 去除首尾空格
|
|
|
-
|
|
|
+
|
|
|
// 处理单引号问题
|
|
|
if (cleanName.startsWith("'") || cleanName.endsWith("'")) {
|
|
|
cleanName = cleanName.replace("'", "_");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 如果处理后为空,使用默认名称
|
|
|
if (cleanName.isEmpty()) {
|
|
|
cleanName = "项目";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 限制长度在31个字符内
|
|
|
if (cleanName.length() > 31) {
|
|
|
cleanName = cleanName.substring(0, 31);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return cleanName;
|
|
|
}
|
|
|
|