Commit 2f15900c authored by wujipeng's avatar wujipeng
Browse files

实训成绩导出字段切换

parent a98260c1
......@@ -8,8 +8,20 @@ import java.math.BigDecimal;
@Data
public class ScoreAdminExportPracticeItemVO {
/** 学员ID,用于把逐项成绩归入汇总表中的对应学员。 */
private String studentId;
/** 实训项目编号,既作为动态列的唯一标识,也作为导出表头的前缀。 */
private String code;
private String title;
/**
* 二级题目类型,作为成绩汇总表中实训项目的展示名称。
*
* <p>该字段为空时导出层只展示项目编号,不回退使用题目标题,确保导出口径
* 始终与仿真平台上报的二级题目类型保持一致。</p>
*/
private String secondaryType;
/** 学员在该实训项目上的最终得分。 */
private BigDecimal score;
}
......@@ -439,12 +439,14 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
}
/**
* 项目定义来自实训上报的真实 code/title。相同编号出现不同非空标题说明源数据冲突;
* 项目数量不设业务上限,仅在超过旧版 .xls 的最大列数时拒绝导出。
* 项目定义来自实训上报的真实 code/secondaryType。相同编号出现不同的非空二级题目
* 类型说明源数据冲突;secondaryType 为空时保留空名称,使表头最终只展示 code,
* 严格避免回退到旧 title 字段。项目数量不设业务上限,仅在超过旧版 .xls 的最大
* 列数时拒绝导出。
*/
private PracticeExportData buildPracticeExportData(
List<ScoreAdminExportPracticeItemVO> items) {
Map<String, String> projectTitles = new LinkedHashMap<>();
Map<String, String> projectSecondaryTypes = new LinkedHashMap<>();
Map<String, Map<String, BigDecimal>> scores = new LinkedHashMap<>();
for (ScoreAdminExportPracticeItemVO item : items) {
String studentId = trimToNull(item.getStudentId());
......@@ -452,27 +454,28 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
if (studentId == null || code == null) {
throw new BusinessException("实训项目存在缺少学员ID或项目编号的数据,无法导出");
}
String title = valueOrBlank(item.getTitle());
if (!projectTitles.containsKey(code)) {
if (projectTitles.size() >= EXPORT_MAX_PROJECT_COUNT) {
String secondaryType = valueOrBlank(item.getSecondaryType());
if (!projectSecondaryTypes.containsKey(code)) {
if (projectSecondaryTypes.size() >= EXPORT_MAX_PROJECT_COUNT) {
throw new BusinessException("实训项目超过.xls格式最多"
+ EXPORT_MAX_PROJECT_COUNT + "项的限制,无法导出");
}
projectTitles.put(code, title);
projectSecondaryTypes.put(code, secondaryType);
} else {
String existingTitle = projectTitles.get(code);
if (hasText(existingTitle) && hasText(title)
&& !existingTitle.equals(title)) {
throw new BusinessException("实训项目编号" + code + "对应多个名称,无法导出");
String existingSecondaryType = projectSecondaryTypes.get(code);
if (hasText(existingSecondaryType) && hasText(secondaryType)
&& !existingSecondaryType.equals(secondaryType)) {
throw new BusinessException("实训项目编号" + code
+ "对应多个二级题目类型,无法导出");
}
if (!hasText(existingTitle) && hasText(title)) {
projectTitles.put(code, title);
if (!hasText(existingSecondaryType) && hasText(secondaryType)) {
projectSecondaryTypes.put(code, secondaryType);
}
}
scores.computeIfAbsent(studentId, key -> new LinkedHashMap<>())
.put(code, item.getScore());
}
return new PracticeExportData(projectTitles, scores);
return new PracticeExportData(projectSecondaryTypes, scores);
}
private HSSFWorkbook loadExportTemplate() throws IOException {
......@@ -519,7 +522,7 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
PracticeExportData practiceData,
int page) {
List<Map.Entry<String, String>> projects =
new ArrayList<>(practiceData.projectTitles.entrySet());
new ArrayList<>(practiceData.projectSecondaryTypes.entrySet());
int projectColumnCount = Math.max(EXPORT_TEMPLATE_PROJECT_COUNT, projects.size());
int remarkColumn = EXPORT_PROJECT_START_COLUMN + projectColumnCount;
expandSummaryTemplate(workbook, sheet, projectColumnCount, remarkColumn);
......@@ -1135,14 +1138,17 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
}
}
/** 动态项目顺序和按学员索引的逐项分数在构建后保持同一份导出快照。 */
/**
* 动态项目顺序、对应的二级题目类型和按学员索引的逐项分数,在构建后共同组成
* 同一份导出快照,确保表头与每位学员的成绩列始终按相同 code 对齐。
*/
private static final class PracticeExportData {
private final Map<String, String> projectTitles;
private final Map<String, String> projectSecondaryTypes;
private final Map<String, Map<String, BigDecimal>> scores;
private PracticeExportData(Map<String, String> projectTitles,
private PracticeExportData(Map<String, String> projectSecondaryTypes,
Map<String, Map<String, BigDecimal>> scores) {
this.projectTitles = projectTitles;
this.projectSecondaryTypes = projectSecondaryTypes;
this.scores = scores;
}
}
......
......@@ -536,7 +536,7 @@
SELECT
g.user_id AS studentId,
g.code,
g.title,
g.secondary_type AS secondaryType,
g.score
FROM fz_grades g
INNER JOIN (
......
......@@ -92,7 +92,8 @@ JWT解析当前用户并校验 `phone_role.role_name=管理员`。本模块只
单场汇总表响应类型为 `application/vnd.ms-excel`,文件名为“班级名称_成绩汇总表.xls”。名单
取两场应考学员并集,缺考或未列入另一场名单时对应成绩留空并写入备注;实训项目按实际
编号与标题动态填充,超过模板初始的5项时继续向右扩展,备注列同步顺延。受旧版 `.xls`
编号与二级题目类型动态填充,二级题目类型为空时仅展示编号,不回退使用题目标题。超过模板
初始的5项时继续向右扩展,备注列同步顺延。受旧版 `.xls`
最多256列的格式限制,单次导出最多支持251个实训项目。每27名学员生成一张同版式分表,
序号跨分表连续。
......
......@@ -66,6 +66,9 @@ class ScoreAdminMapperXmlTest {
.getBoundSql(1).getSql());
assertTrue(itemSql.contains("max(id) as id"));
assertTrue(itemSql.contains("ifnull(es.mark_flag, 0) = 1"));
// 汇总表项目名称必须明确读取二级题目类型,禁止继续从旧题目标题取值。
assertTrue(itemSql.contains("g.secondary_type as secondarytype"));
assertFalse(itemSql.contains("g.title"));
}
@Test
......
......@@ -544,6 +544,43 @@ class ScoreAdminServiceImplTest {
10, ExamAdminConstants.TYPE_THEORY);
}
@Test
void exportExamShouldKeepOnlyCodeWhenSecondaryTypeIsEmpty() throws Exception {
ScoreAdminExportExamVO practiceExam = endedExportExam(1, 10, "实训");
when(scoreAdminMapper.findExportExam(1)).thenReturn(practiceExam);
when(scoreAdminMapper.queryExportCandidates(1)).thenReturn(Collections.singletonList(
exportStudent("student-1", "张三", "90", true, true)));
// 导出专用对象没有 title 字段;secondaryType 为空时必须验证表头只剩项目编号。
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(Collections.singletonList(
practiceItem("student-1", "P1", null, "10")));
MockHttpServletResponse response = new MockHttpServletResponse();
service.exportExam(1, response);
try (HSSFWorkbook workbook = new HSSFWorkbook(
new ByteArrayInputStream(response.getContentAsByteArray()))) {
assertEquals("P1", text(workbook, 0, 5, 4));
}
}
@Test
void exportExamShouldRejectConflictingSecondaryTypesForSameCode() {
ScoreAdminExportExamVO practiceExam = endedExportExam(1, 10, "实训");
when(scoreAdminMapper.findExportExam(1)).thenReturn(practiceExam);
when(scoreAdminMapper.queryExportCandidates(1)).thenReturn(Arrays.asList(
exportStudent("student-1", "张三", "90", true, true),
exportStudent("student-2", "李四", "85", true, true)));
// 同一项目编号的二级题目类型应在全场保持一致,否则无法生成唯一、可信的表头。
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(Arrays.asList(
practiceItem("student-1", "P1", "日常运行管理", "10"),
practiceItem("student-2", "P1", "基础操作", "9")));
BusinessException error = assertThrows(BusinessException.class,
() -> service.exportExam(1, new MockHttpServletResponse()));
assertEquals("实训项目编号P1对应多个二级题目类型,无法导出", error.getMessage());
}
private ScoreAdminExamVO endedExam(boolean published) {
ScoreAdminExamVO exam = examAt(new Date(System.currentTimeMillis() - 3_600_000L), 30);
exam.setPublished(published);
......@@ -592,12 +629,13 @@ class ScoreAdminServiceImplTest {
return statistic;
}
/** 构造实训导出项目;导出专用对象仅携带 code、secondaryType 和最终得分。 */
private ScoreAdminExportPracticeItemVO practiceItem(
String studentId, String code, String title, String score) {
String studentId, String code, String secondaryType, String score) {
ScoreAdminExportPracticeItemVO item = new ScoreAdminExportPracticeItemVO();
item.setStudentId(studentId);
item.setCode(code);
item.setTitle(title);
item.setSecondaryType(secondaryType);
item.setScore(new BigDecimal(score));
return item;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment