|
@@ -15,6 +15,8 @@ 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.constant.ProjectClassification;
|
|
|
+import org.dromara.system.domain.constant.SortType;
|
|
|
import org.dromara.system.domain.vo.GameAthleteVo;
|
|
|
import org.dromara.system.domain.vo.GameEventProjectVo;
|
|
|
import org.dromara.system.domain.vo.GameTeamVo;
|
|
@@ -32,6 +34,17 @@ import java.math.BigDecimal;
|
|
|
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.vo.GameScoreSummaryExportVo;
|
|
|
+import org.dromara.system.domain.bo.GameEventProjectBo;
|
|
|
+import org.dromara.system.domain.bo.GameTeamBo;
|
|
|
+
|
|
|
+import java.net.URLEncoder;
|
|
|
+
|
|
|
+// Apache POI imports for dynamic Excel export
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
/**
|
|
|
* 成绩Service业务层处理
|
|
@@ -330,7 +343,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
log.info("处理运动员: athleteId={}, name={}, teamId={}", athlete.getAthleteId(), athlete.getName(), athlete.getTeamId());
|
|
|
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
- data.put("id", athlete.getAthleteId());
|
|
|
+// data.put("id", athlete.getAthleteId());
|
|
|
data.put("athleteId", athlete.getAthleteId());
|
|
|
data.put("userId", athlete.getUserId());
|
|
|
data.put("eventId", eventId);
|
|
@@ -404,7 +417,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
}
|
|
|
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
- data.put("id", team.getTeamId());
|
|
|
+// data.put("id", team.getTeamId());
|
|
|
data.put("teamId", team.getTeamId());
|
|
|
data.put("teamName", team.getTeamName());
|
|
|
data.put("teamCode", team.getTeamCode());
|
|
@@ -581,7 +594,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
queryBo.setProjectId(projectId);
|
|
|
List<GameScoreVo> allScores = queryList(queryBo);
|
|
|
|
|
|
- if ("0".equals(classification)) {
|
|
|
+ if (ProjectClassification.SINGLE.getValue().equals(classification)) {
|
|
|
// 个人项目:按个人成绩排序
|
|
|
return handleIndividualProjectRanking(allScores, scoreValue, eventId, projectId);
|
|
|
} else {
|
|
@@ -614,8 +627,8 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
.sorted((a, b) -> {
|
|
|
BigDecimal aIndividualPerformance = a.getIndividualPerformance() != null ? a.getIndividualPerformance() : BigDecimal.ZERO;
|
|
|
BigDecimal bIndividualPerformance = b.getIndividualPerformance() != null ? b.getIndividualPerformance() : BigDecimal.ZERO;
|
|
|
-
|
|
|
- if ("0".equals(orderType)) {
|
|
|
+
|
|
|
+ if (orderType.equals(SortType.ASC.getValue())) {
|
|
|
// 升序:成绩越小越好
|
|
|
return aIndividualPerformance.compareTo(bIndividualPerformance);
|
|
|
} else {
|
|
@@ -632,7 +645,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
.toList();
|
|
|
|
|
|
// 根据orderType决定积分分配方式
|
|
|
- if ("0".equals(orderType)) {
|
|
|
+ if (orderType.equals(SortType.ASC.getValue())) {
|
|
|
// 升序项目:成绩越小,积分分配越多
|
|
|
for (int i = 0; i < sortedScores.size(); i++) {
|
|
|
GameScoreVo score = sortedScores.get(i);
|
|
@@ -711,50 +724,33 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
String orderType = project.getOrderType();
|
|
|
log.info("团体项目排名计算,projectId: {}, orderType: {}", projectId, orderType);
|
|
|
|
|
|
- // 按队伍ID分组,汇总每个队伍的积分
|
|
|
- Map<Long, Integer> teamTotalPoints = new HashMap<>();
|
|
|
+ // 按队伍ID分组,获取每个队伍的最佳成绩
|
|
|
Map<Long, BigDecimal> teamBestPerformance = new HashMap<>();
|
|
|
- Map<Long, String> teamNames = new HashMap<>();
|
|
|
-// Map<Long, String> teamCodes = new HashMap<>();
|
|
|
|
|
|
for (GameScoreVo score : allScores) {
|
|
|
Long teamId = score.getTeamId();
|
|
|
if (teamId != null) {
|
|
|
- // 累计队伍积分,处理null值
|
|
|
- Integer currentPoints = score.getScorePoint() != null ? score.getScorePoint() : 0;
|
|
|
- teamTotalPoints.merge(teamId, currentPoints, Integer::sum);
|
|
|
-
|
|
|
- // 记录队伍最佳成绩
|
|
|
+ // 记录队伍最佳成绩(团体成绩)
|
|
|
if (score.getTeamPerformance() != null && score.getTeamPerformance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
BigDecimal currentBest = teamBestPerformance.get(teamId);
|
|
|
- if (currentBest == null || score.getTeamPerformance().compareTo(currentBest) > 0) {
|
|
|
+ if (currentBest == null ||
|
|
|
+ (orderType.equals(SortType.ASC.getValue()) && score.getTeamPerformance().compareTo(currentBest) < 0) || // 升序:成绩越小越好
|
|
|
+ (!orderType.equals(SortType.ASC.getValue()) && score.getTeamPerformance().compareTo(currentBest) > 0)) { // 降序:成绩越大越好
|
|
|
teamBestPerformance.put(teamId, score.getTeamPerformance());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 记录队伍信息
|
|
|
- if (score.getTeamName() != null) {
|
|
|
- teamNames.put(teamId, score.getTeamName());
|
|
|
- }
|
|
|
-// if (score.getTeamCode() != null) {
|
|
|
-// teamCodes.put(teamId, score.getTeamCode());
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 根据orderType决定队伍总积分排序方式
|
|
|
- // orderType: 0-升序(积分越高排名越靠前),1-降序(积分越高排名越靠前)
|
|
|
- List<Map.Entry<Long, Integer>> sortedTeams;
|
|
|
- if ("0".equals(orderType)) {
|
|
|
- // 升序:积分越高排名越靠前
|
|
|
- sortedTeams = teamTotalPoints.entrySet().stream()
|
|
|
- .sorted(Map.Entry.comparingByValue())
|
|
|
- .collect(Collectors.toList());
|
|
|
+ // 根据队伍成绩进行排序
|
|
|
+ List<Map.Entry<Long, BigDecimal>> sortedTeamsByPerformance = new ArrayList<>(teamBestPerformance.entrySet());
|
|
|
+
|
|
|
+ if (orderType.equals(SortType.ASC.getValue())) {
|
|
|
+ // 升序:成绩越小排名越靠前
|
|
|
+ sortedTeamsByPerformance.sort(Map.Entry.comparingByValue());
|
|
|
} else {
|
|
|
- // 降序:积分越高排名越靠前(默认)
|
|
|
- sortedTeams = teamTotalPoints.entrySet().stream()
|
|
|
- .sorted(Map.Entry.<Long, Integer>comparingByValue().reversed())
|
|
|
- .collect(Collectors.toList());
|
|
|
+ // 降序:成绩越大排名越靠前
|
|
|
+ sortedTeamsByPerformance.sort(Map.Entry.<Long, BigDecimal>comparingByValue().reversed());
|
|
|
}
|
|
|
|
|
|
// 解析积分分值
|
|
@@ -763,53 +759,339 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
.map(Integer::parseInt)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 根据orderType决定积分分配方式
|
|
|
- if ("0".equals(orderType)) {
|
|
|
- // 升序项目:成绩越小,积分分配越多
|
|
|
- for (int i = 0; i < sortedTeams.size(); i++) {
|
|
|
- Map.Entry<Long, Integer> teamEntry = sortedTeams.get(i);
|
|
|
- Long teamId = teamEntry.getKey();
|
|
|
- int rank = i + 1;
|
|
|
- int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+ // 根据成绩排序结果分配积分和排名
|
|
|
+ Map<Long, Integer> teamPoints = new HashMap<>();
|
|
|
+ Map<Long, Integer> teamRanks = new HashMap<>();
|
|
|
|
|
|
- // 更新该队伍所有运动员的成绩记录
|
|
|
- for (GameScoreVo score : allScores) {
|
|
|
- if (teamId.equals(score.getTeamId())) {
|
|
|
- GameScoreBo updateBo = new GameScoreBo();
|
|
|
- updateBo.setScoreId(score.getScoreId());
|
|
|
- updateBo.setScoreRank(rank);
|
|
|
- updateBo.setScorePoint(points); // 使用队伍排名对应的积分
|
|
|
- updateBo.setEventId(eventId);
|
|
|
- updateBo.setProjectId(projectId);
|
|
|
-
|
|
|
- updateByBo(updateBo);
|
|
|
- }
|
|
|
+ for (int i = 0; i < sortedTeamsByPerformance.size(); i++) {
|
|
|
+ Map.Entry<Long, BigDecimal> teamEntry = sortedTeamsByPerformance.get(i);
|
|
|
+ Long teamId = teamEntry.getKey();
|
|
|
+ int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+ int rank = i + 1;
|
|
|
+
|
|
|
+ teamPoints.put(teamId, points);
|
|
|
+ teamRanks.put(teamId, rank);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新每个队伍中所有运动员的成绩记录
|
|
|
+ for (GameScoreVo score : allScores) {
|
|
|
+ Long teamId = score.getTeamId();
|
|
|
+ if (teamId != null && teamPoints.containsKey(teamId)) {
|
|
|
+ GameScoreBo updateBo = new GameScoreBo();
|
|
|
+ updateBo.setScoreId(score.getScoreId());
|
|
|
+ updateBo.setScoreRank(teamRanks.get(teamId));
|
|
|
+ updateBo.setScorePoint(teamPoints.get(teamId));
|
|
|
+ updateBo.setEventId(eventId);
|
|
|
+ updateBo.setProjectId(projectId);
|
|
|
+
|
|
|
+ updateByBo(updateBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出成绩汇总表
|
|
|
+ * @param eventId 赛事ID
|
|
|
+ * @param response HTTP响应对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void exportScoresSummary(Long eventId, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ // 获取所有项目
|
|
|
+ GameEventProjectBo projectQuery = new GameEventProjectBo();
|
|
|
+ projectQuery.setEventId(eventId);
|
|
|
+ List<GameEventProjectVo> projects = gameEventProjectService.queryList(projectQuery);
|
|
|
+
|
|
|
+ if (projects.isEmpty()) {
|
|
|
+ throw new RuntimeException("未找到赛事项目");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取所有队伍
|
|
|
+ GameTeamBo teamQuery = new GameTeamBo();
|
|
|
+ teamQuery.setEventId(eventId);
|
|
|
+ List<GameTeamVo> teams = gameTeamService.queryList(teamQuery);
|
|
|
+
|
|
|
+ if (teams.isEmpty()) {
|
|
|
+ throw new RuntimeException("未找到参赛队伍");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量查询所有队伍在所有项目中的成绩
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- // 降序项目:成绩越大,积分分配越多
|
|
|
- for (int i = 0; i < sortedTeams.size(); i++) {
|
|
|
- Map.Entry<Long, Integer> teamEntry = sortedTeams.get(i);
|
|
|
- Long teamId = teamEntry.getKey();
|
|
|
- int rank = i + 1;
|
|
|
- int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
|
|
|
- // 更新该队伍所有运动员的成绩记录
|
|
|
- for (GameScoreVo score : allScores) {
|
|
|
- if (teamId.equals(score.getTeamId())) {
|
|
|
- GameScoreBo updateBo = new GameScoreBo();
|
|
|
- updateBo.setScoreId(score.getScoreId());
|
|
|
- updateBo.setScoreRank(rank);
|
|
|
- updateBo.setScorePoint(points); // 使用队伍排名对应的积分
|
|
|
- updateBo.setEventId(eventId);
|
|
|
- updateBo.setProjectId(projectId);
|
|
|
-
|
|
|
- updateByBo(updateBo);
|
|
|
+ // 构建导出数据
|
|
|
+ List<GameScoreSummaryExportVo> exportData = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < teams.size(); i++) {
|
|
|
+ GameTeamVo team = teams.get(i);
|
|
|
+ GameScoreSummaryExportVo exportVo = new GameScoreSummaryExportVo();
|
|
|
+
|
|
|
+ // 设置基本信息
|
|
|
+ exportVo.setSerialNumber(i + 1);
|
|
|
+ exportVo.setTeamName(team.getTeamName());
|
|
|
+
|
|
|
+ // 计算该队伍在各项目中的积分
|
|
|
+ int totalScore = 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;
|
|
|
}
|
|
|
+
|
|
|
+ // 使用项目名称设置积分
|
|
|
+ exportVo.setProjectScore(project.getProjectName(), projectScore);
|
|
|
}
|
|
|
+
|
|
|
+ // 设置总分
|
|
|
+ exportVo.setTotalScore(totalScore);
|
|
|
+
|
|
|
+ // 设置加分(暂时设为0,后续可根据业务需求调整)
|
|
|
+ exportVo.setExtraScore(0);
|
|
|
+
|
|
|
+ exportData.add(exportVo);
|
|
|
}
|
|
|
+
|
|
|
+ // 按总分排序,生成排名
|
|
|
+ exportData.sort((a, b) -> Integer.compare(b.getTotalScore(), a.getTotalScore()));
|
|
|
+ for (int i = 0; i < exportData.size(); i++) {
|
|
|
+ exportData.get(i).setRank(i + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用动态列导出Excel
|
|
|
+ exportExcelWithDynamicColumns(exportData, projects, response);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出成绩汇总表失败", e);
|
|
|
+ throw new RuntimeException("导出失败:" + e.getMessage());
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
+ /**
|
|
|
+ * 动态列导出Excel
|
|
|
+ */
|
|
|
+ private void exportExcelWithDynamicColumns(List<GameScoreSummaryExportVo> exportData,
|
|
|
+ List<GameEventProjectVo> projects,
|
|
|
+ HttpServletResponse response) throws Exception {
|
|
|
+ // 创建动态列的数据结构
|
|
|
+ List<Map<String, Object>> dynamicData = new ArrayList<>();
|
|
|
+
|
|
|
+ for (GameScoreSummaryExportVo exportVo : exportData) {
|
|
|
+ Map<String, Object> rowData = new HashMap<>();
|
|
|
+
|
|
|
+ // 基础列
|
|
|
+ rowData.put("序号", exportVo.getSerialNumber());
|
|
|
+ rowData.put("代表队名称", exportVo.getTeamName());
|
|
|
+ rowData.put("排名", exportVo.getRank());
|
|
|
+ rowData.put("总分", exportVo.getTotalScore());
|
|
|
+
|
|
|
+ // 动态项目列
|
|
|
+ for (GameEventProjectVo project : projects) {
|
|
|
+ String projectName = project.getProjectName();
|
|
|
+ Integer score = exportVo.getProjectScore(projectName);
|
|
|
+ rowData.put(projectName, score != null ? score : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加分列
|
|
|
+ rowData.put("加分", exportVo.getExtraScore());
|
|
|
+
|
|
|
+ dynamicData.add(rowData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用Apache POI直接操作Excel
|
|
|
+ exportExcelWithPOI(dynamicData, projects, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用Apache POI导出动态列Excel
|
|
|
+ */
|
|
|
+ private void exportExcelWithPOI(List<Map<String, Object>> dynamicData,
|
|
|
+ List<GameEventProjectVo> projects,
|
|
|
+ HttpServletResponse response) throws Exception {
|
|
|
+ try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
+ Sheet sheet = workbook.createSheet("成绩汇总表");
|
|
|
+
|
|
|
+ // 创建标题行样式
|
|
|
+ CellStyle headerStyle = createHeaderStyle(workbook);
|
|
|
+
|
|
|
+ // 创建数据行样式 - 奇数行(浅色背景)
|
|
|
+ CellStyle dataStyleOdd = createDataStyle(workbook, IndexedColors.WHITE);
|
|
|
+
|
|
|
+ // 创建数据行样式 - 偶数行(深色背景)
|
|
|
+ CellStyle dataStyleEven = createDataStyle(workbook, IndexedColors.GREY_25_PERCENT);
|
|
|
+
|
|
|
+ // 创建标题行
|
|
|
+ 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 (GameEventProjectVo project : projects) {
|
|
|
+ Cell cell = headerRow.createCell(colIndex++);
|
|
|
+ cell.setCellValue(project.getProjectName());
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加分列标题
|
|
|
+ Cell extraCell = headerRow.createCell(colIndex++);
|
|
|
+ extraCell.setCellValue("加分");
|
|
|
+ extraCell.setCellStyle(headerStyle);
|
|
|
+
|
|
|
+ // 填充数据行
|
|
|
+ int rowIndex = 1;
|
|
|
+ for (Map<String, Object> rowData : dynamicData) {
|
|
|
+ Row dataRow = sheet.createRow(rowIndex++);
|
|
|
+ colIndex = 0;
|
|
|
+
|
|
|
+ // 选择行样式(奇数行或偶数行)
|
|
|
+ CellStyle currentRowStyle = (rowIndex % 2 == 0) ? dataStyleEven : dataStyleOdd;
|
|
|
+
|
|
|
+ // 基础列数据
|
|
|
+ createCellWithStyle(dataRow, colIndex++, (Integer) rowData.get("序号"), currentRowStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, (String) rowData.get("代表队名称"), currentRowStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, (Integer) rowData.get("排名"), currentRowStyle);
|
|
|
+ createCellWithStyle(dataRow, colIndex++, (Integer) rowData.get("总分"), currentRowStyle);
|
|
|
+
|
|
|
+ // 动态项目列数据
|
|
|
+ for (GameEventProjectVo project : projects) {
|
|
|
+ String projectName = project.getProjectName();
|
|
|
+ Object scoreObj = rowData.get(projectName);
|
|
|
+ int score = scoreObj != null ? (Integer) scoreObj : 0;
|
|
|
+ createCellWithStyle(dataRow, colIndex++, score, currentRowStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加分列数据
|
|
|
+ createCellWithStyle(dataRow, colIndex++, (Integer) rowData.get("加分"), currentRowStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动调整列宽
|
|
|
+ for (int i = 0; i < colIndex; i++) {
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ // 设置最小列宽,确保内容不会太挤
|
|
|
+ if (sheet.getColumnWidth(i) < 3000) {
|
|
|
+ sheet.setColumnWidth(i, 3000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入响应流
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = URLEncoder.encode("成绩汇总表", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
+
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建标题行样式
|
|
|
+ */
|
|
|
+ private CellStyle createHeaderStyle(Workbook workbook) {
|
|
|
+ CellStyle headerStyle = workbook.createCellStyle();
|
|
|
+
|
|
|
+ // 字体样式
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
+ headerFont.setBold(true);
|
|
|
+ headerFont.setFontHeightInPoints((short) 12);
|
|
|
+ headerFont.setColor(IndexedColors.WHITE.getIndex());
|
|
|
+ headerStyle.setFont(headerFont);
|
|
|
+
|
|
|
+ // 对齐方式
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+
|
|
|
+ // 背景色
|
|
|
+ headerStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
|
|
|
+ headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+
|
|
|
+ // 边框样式
|
|
|
+ headerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ headerStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ headerStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ headerStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ headerStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+
|
|
|
+ return headerStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建数据行样式
|
|
|
+ */
|
|
|
+ private CellStyle createDataStyle(Workbook workbook, IndexedColors backgroundColor) {
|
|
|
+ CellStyle dataStyle = workbook.createCellStyle();
|
|
|
+
|
|
|
+ // 字体样式
|
|
|
+ Font dataFont = workbook.createFont();
|
|
|
+ dataFont.setFontHeightInPoints((short) 11);
|
|
|
+ dataStyle.setFont(dataFont);
|
|
|
+
|
|
|
+ // 对齐方式
|
|
|
+ dataStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+
|
|
|
+ // 背景色
|
|
|
+ dataStyle.setFillForegroundColor(backgroundColor.getIndex());
|
|
|
+ dataStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+
|
|
|
+ // 边框样式
|
|
|
+ dataStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ dataStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ dataStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ dataStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ dataStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+
|
|
|
+ return dataStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建单元格并设置样式
|
|
|
+ */
|
|
|
+ private void createCellWithStyle(Row row, int colIndex, Object value, CellStyle style) {
|
|
|
+ Cell cell = row.createCell(colIndex);
|
|
|
+
|
|
|
+ if (value instanceof Integer) {
|
|
|
+ cell.setCellValue((Integer) value);
|
|
|
+ } else if (value instanceof String) {
|
|
|
+ cell.setCellValue((String) value);
|
|
|
+ } else if (value instanceof Double) {
|
|
|
+ cell.setCellValue((Double) value);
|
|
|
+ } else if (value != null) {
|
|
|
+ cell.setCellValue(value.toString());
|
|
|
+ } else {
|
|
|
+ cell.setCellValue("");
|
|
|
+ }
|
|
|
+
|
|
|
+ cell.setCellStyle(style);
|
|
|
}
|
|
|
}
|