|
|
@@ -19,6 +19,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.dromara.system.domain.bo.GameEventGroupBo;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
import org.dromara.system.domain.constant.ProjectClassification;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.idev.excel.FastExcel;
|
|
|
+import cn.idev.excel.write.metadata.style.WriteCellStyle;
|
|
|
+import cn.idev.excel.write.style.HorizontalCellStyleStrategy;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
+import org.dromara.common.core.utils.file.FileUtils;
|
|
|
import org.dromara.system.domain.GameEventGroup;
|
|
|
import org.dromara.system.mapper.GameEventGroupMapper;
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
@@ -635,4 +643,96 @@ public class GameEventGroupServiceImpl implements IGameEventGroupService {
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出分组详情矩阵 Excel
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param response 响应体
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void exportDetail(GameEventGroupBo bo, HttpServletResponse response) {
|
|
|
+ if (bo.getGroupId() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Object> groupData = getGroupResultFromDB(bo.getGroupId());
|
|
|
+ if (groupData == null || !groupData.containsKey("groupResult")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取分组原始信息,以取得正确的道次数和显示模式
|
|
|
+ GameEventGroupVo groupInfo = queryById(bo.getGroupId());
|
|
|
+ if (groupInfo == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> groupResult = (Map<String, Object>) groupData.get("groupResult");
|
|
|
+ int trackNumTotal = Convert.toInt(groupInfo.getTrackNum(), 0);
|
|
|
+ String displayMode = groupInfo.getTrackDisplayMode(); // 0=第N道 1=序号N
|
|
|
+
|
|
|
+ // 1. 构造表头: List<List<String>>
|
|
|
+ List<List<String>> head = new ArrayList<>();
|
|
|
+ head.add(Collections.singletonList("组别"));
|
|
|
+ for (int i = 1; i <= trackNumTotal; i++) {
|
|
|
+ String trackName = "1".equals(displayMode) ? String.valueOf(i) : "第" + i + "道";
|
|
|
+ head.add(Collections.singletonList(trackName));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 构造数据行: List<List<Object>>
|
|
|
+ // 先按组号组织数据: Map<组号, Map<道次, 运动员信息>>
|
|
|
+ Map<Integer, Map<Integer, String>> matrixData = new TreeMap<>();
|
|
|
+ for (Map.Entry<String, Object> entry : groupResult.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ if (!key.contains("-")) continue;
|
|
|
+
|
|
|
+ String[] split = key.split("-");
|
|
|
+ try {
|
|
|
+ Integer groupIndex = Integer.valueOf(split[0]);
|
|
|
+ Integer trackIndex = Integer.valueOf(split[1]);
|
|
|
+
|
|
|
+ GameAthleteVo athleteVo = JSONUtil.toBean(JSONUtil.toJsonStr(entry.getValue()), GameAthleteVo.class);
|
|
|
+ String cellContent = String.format("%s\n%s\n%s",
|
|
|
+ athleteVo.getAthleteCode(),
|
|
|
+ athleteVo.getName(),
|
|
|
+ athleteVo.getTeamName());
|
|
|
+
|
|
|
+ matrixData.computeIfAbsent(groupIndex, k -> new HashMap<>()).put(trackIndex, cellContent);
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<List<Object>> dataList = new ArrayList<>();
|
|
|
+ for (Map.Entry<Integer, Map<Integer, String>> rowEntry : matrixData.entrySet()) {
|
|
|
+ List<Object> row = new ArrayList<>();
|
|
|
+ row.add("第" + rowEntry.getKey() + "组"); // 第一列是组别
|
|
|
+
|
|
|
+ Map<Integer, String> tracks = rowEntry.getValue();
|
|
|
+ for (int i = 1; i <= trackNumTotal; i++) {
|
|
|
+ row.add(tracks.getOrDefault(i, "")); // 填充各道次数据
|
|
|
+ }
|
|
|
+ dataList.add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String fileName = "分组详情_" + System.currentTimeMillis() + ".xlsx";
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, fileName);
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
|
|
|
+
|
|
|
+ // 内容样式:自动换行 + 居中
|
|
|
+ WriteCellStyle contentStyle = new WriteCellStyle();
|
|
|
+ contentStyle.setWrapped(true);
|
|
|
+ contentStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
|
|
+ HorizontalCellStyleStrategy styleStrategy = new HorizontalCellStyleStrategy(null, contentStyle);
|
|
|
+
|
|
|
+ FastExcel.write(response.getOutputStream())
|
|
|
+ .head(head)
|
|
|
+ .registerWriteHandler(styleStrategy)
|
|
|
+ .sheet("分组详情")
|
|
|
+ .doWrite(dataList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出分组详情矩阵失败", e);
|
|
|
+ throw new RuntimeException("导出分组详情失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|