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

实训成绩导出字段切换

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