Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
practical_train
Commits
2f15900c
Commit
2f15900c
authored
Oct 28, 2026
by
wujipeng
Browse files
实训成绩导出字段切换
parent
a98260c1
Changes
6
Show whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/ScoreAdminExportPracticeItemVO.java
View file @
2f15900c
...
...
@@ -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
;
}
practical-business/src/main/java/com/platform/business/service/impl/ScoreAdminServiceImpl.java
View file @
2f15900c
...
...
@@ -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
>
project
Titl
es
=
new
LinkedHashMap
<>();
Map
<
String
,
String
>
project
SecondaryTyp
es
=
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
titl
e
=
valueOrBlank
(
item
.
get
Titl
e
());
if
(!
project
Titl
es
.
containsKey
(
code
))
{
if
(
project
Titl
es
.
size
()
>=
EXPORT_MAX_PROJECT_COUNT
)
{
String
secondaryTyp
e
=
valueOrBlank
(
item
.
get
SecondaryTyp
e
());
if
(!
project
SecondaryTyp
es
.
containsKey
(
code
))
{
if
(
project
SecondaryTyp
es
.
size
()
>=
EXPORT_MAX_PROJECT_COUNT
)
{
throw
new
BusinessException
(
"实训项目超过.xls格式最多"
+
EXPORT_MAX_PROJECT_COUNT
+
"项的限制,无法导出"
);
}
project
Titl
es
.
put
(
code
,
titl
e
);
project
SecondaryTyp
es
.
put
(
code
,
secondaryTyp
e
);
}
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
(
existing
Titl
e
)
&&
hasText
(
titl
e
))
{
project
Titl
es
.
put
(
code
,
titl
e
);
if
(!
hasText
(
existing
SecondaryTyp
e
)
&&
hasText
(
secondaryTyp
e
))
{
project
SecondaryTyp
es
.
put
(
code
,
secondaryTyp
e
);
}
}
scores
.
computeIfAbsent
(
studentId
,
key
->
new
LinkedHashMap
<>())
.
put
(
code
,
item
.
getScore
());
}
return
new
PracticeExportData
(
project
Titl
es
,
scores
);
return
new
PracticeExportData
(
project
SecondaryTyp
es
,
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
.
project
Titl
es
.
entrySet
());
new
ArrayList
<>(
practiceData
.
project
SecondaryTyp
es
.
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
>
project
Titl
es
;
private
final
Map
<
String
,
String
>
project
SecondaryTyp
es
;
private
final
Map
<
String
,
Map
<
String
,
BigDecimal
>>
scores
;
private
PracticeExportData
(
Map
<
String
,
String
>
project
Titl
es
,
private
PracticeExportData
(
Map
<
String
,
String
>
project
SecondaryTyp
es
,
Map
<
String
,
Map
<
String
,
BigDecimal
>>
scores
)
{
this
.
project
Titles
=
projectTitl
es
;
this
.
project
SecondaryTypes
=
projectSecondaryTyp
es
;
this
.
scores
=
scores
;
}
}
...
...
practical-business/src/main/resources/com/platform/business/mapper/ScoreAdminMapper.xml
View file @
2f15900c
...
...
@@ -536,7 +536,7 @@
SELECT
g.user_id AS studentId,
g.code,
g.
titl
e,
g.
secondary_type AS secondaryTyp
e,
g.score
FROM fz_grades g
INNER JOIN (
...
...
practical-business/src/main/resources/student-score-management-api.md
View file @
2f15900c
...
...
@@ -92,7 +92,8 @@ JWT解析当前用户并校验 `phone_role.role_name=管理员`。本模块只
单场汇总表响应类型为
`application/vnd.ms-excel`
,文件名为“班级名称_成绩汇总表.xls”。名单
取两场应考学员并集,缺考或未列入另一场名单时对应成绩留空并写入备注;实训项目按实际
编号与标题动态填充,超过模板初始的5项时继续向右扩展,备注列同步顺延。受旧版
`.xls`
编号与二级题目类型动态填充,二级题目类型为空时仅展示编号,不回退使用题目标题。超过模板
初始的5项时继续向右扩展,备注列同步顺延。受旧版
`.xls`
最多256列的格式限制,单次导出最多支持251个实训项目。每27名学员生成一张同版式分表,
序号跨分表连续。
...
...
practical-business/src/test/java/com/platform/business/mapper/ScoreAdminMapperXmlTest.java
View file @
2f15900c
...
...
@@ -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
...
...
practical-business/src/test/java/com/platform/business/service/impl/ScoreAdminServiceImplTest.java
View file @
2f15900c
...
...
@@ -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
titl
e
,
String
score
)
{
String
studentId
,
String
code
,
String
secondaryTyp
e
,
String
score
)
{
ScoreAdminExportPracticeItemVO
item
=
new
ScoreAdminExportPracticeItemVO
();
item
.
setStudentId
(
studentId
);
item
.
setCode
(
code
);
item
.
set
Title
(
titl
e
);
item
.
set
SecondaryType
(
secondaryTyp
e
);
item
.
setScore
(
new
BigDecimal
(
score
));
return
item
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment