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
4f087901
Commit
4f087901
authored
Sep 21, 2026
by
wujipeng
Browse files
优化
parent
f11e9683
Changes
13
Show whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/entity/FzGradesEntity.java
View file @
4f087901
...
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
...
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -78,4 +79,10 @@ public class FzGradesEntity {
...
@@ -78,4 +79,10 @@ public class FzGradesEntity {
@ApiModelProperty
(
"基础分数"
)
@ApiModelProperty
(
"基础分数"
)
@TableField
(
"basic_score"
)
@TableField
(
"basic_score"
)
private
Double
basicScore
;
private
Double
basicScore
;
@ApiModelProperty
(
"错误:false,正确:true"
)
@TableField
(
"right_or_wrong"
)
// 该字段允许第三方成绩上报时写入,但不扩大已有管理端/教师端实体响应协议。
@JsonProperty
(
access
=
JsonProperty
.
Access
.
WRITE_ONLY
)
private
Boolean
rightOrWrong
;
}
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/StudentScoreVO.java
View file @
4f087901
package
com.platform.business.model.vo
;
package
com.platform.business.model.vo
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -113,17 +114,25 @@ public final class StudentScoreVO {
...
@@ -113,17 +114,25 @@ public final class StudentScoreVO {
private
String
options
;
private
String
options
;
private
String
text
;
private
String
text
;
private
String
result
;
private
String
result
;
/**
* fz_grades中的结构化正误标记,仅供Mapper映射和服务层聚合使用。
*
* <p>该字段是新协议提供的权威判定依据,但并非学生端逐题响应协议的一部分,
* 因此必须从JSON中隐藏;历史记录为空时由服务层继续兼容result文本。</p>
*/
@JsonIgnore
private
Boolean
rightOrWrong
;
private
String
file
;
private
String
file
;
private
Double
score
;
private
Double
score
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
startTime
;
private
Date
startTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
submissionTime
;
private
Date
submissionTime
;
/** PASS、PARTIAL或FAIL,
由现有
result文本
归一化得到
。 */
/** PASS、PARTIAL或FAIL,
优先依据结构化正误标记,历史数据再回退
result文本。 */
private
String
normalizedStatus
;
private
String
normalizedStatus
;
}
}
/** 基于
现有实训结果文本
计算的
步骤
数量汇总。 */
/** 基于
实训步骤统一判定结果
计算的数量汇总。 */
@Data
@Data
public
static
class
PracticeSummary
{
public
static
class
PracticeSummary
{
private
Integer
totalCount
;
private
Integer
totalCount
;
...
...
practical-business/src/main/java/com/platform/business/service/impl/FzGradesServiceImpl.java
View file @
4f087901
...
@@ -16,14 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -16,14 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
/**
/**
* @Author: wujipeng
* @Author: wujipeng
...
@@ -109,7 +102,9 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
...
@@ -109,7 +102,9 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
return
true
;
return
true
;
}
}
/** 校验List确实只表示同一考试、同一学员的一份完整且可确定顺序的成绩快照。 */
/**
* 校验List确实只表示同一考试、同一学员的一份完整且可确定顺序的成绩快照。
*/
private
List
<
FzGradesEntity
>
normalizeAndValidateBatch
(
List
<
FzGradesDTO
>
values
)
{
private
List
<
FzGradesEntity
>
normalizeAndValidateBatch
(
List
<
FzGradesDTO
>
values
)
{
if
(
values
==
null
||
values
.
isEmpty
())
{
if
(
values
==
null
||
values
.
isEmpty
())
{
throw
new
BusinessException
(
"仿真实训成绩明细不能为空"
);
throw
new
BusinessException
(
"仿真实训成绩明细不能为空"
);
...
@@ -151,7 +146,7 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
...
@@ -151,7 +146,7 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
//主观题 -> 主观题
//主观题 -> 主观题
//绘图题 -> 绘图题
//绘图题 -> 绘图题
//实操题 -> 实操题
//实操题 -> 实操题
if
(
StrUtil
.
isNotEmpty
(
value
.
getType
())){
if
(
StrUtil
.
isNotEmpty
(
value
.
getType
()))
{
switch
(
value
.
getType
())
{
switch
(
value
.
getType
())
{
case
"单选题"
:
case
"单选题"
:
case
"多选题"
:
case
"多选题"
:
...
@@ -170,13 +165,16 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
...
@@ -170,13 +165,16 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
default
:
default
:
}
}
}
}
// rightOrWrong只保留上游显式上报值;未上报时继续为NULL,由读取端回退解析result。
}
}
List
<
FzGradesEntity
>
result
=
new
ArrayList
<>(
byCode
.
values
());
List
<
FzGradesEntity
>
result
=
new
ArrayList
<>(
byCode
.
values
());
result
.
sort
(
Comparator
.
comparing
(
FzGradesEntity:
:
getCode
));
result
.
sort
(
Comparator
.
comparing
(
FzGradesEntity:
:
getCode
));
return
result
;
return
result
;
}
}
/** 比较业务字段而非服务端主键,数组顺序变化不影响第三方幂等重试。 */
/**
* 比较业务字段而非服务端主键,数组顺序变化不影响第三方幂等重试。
*/
private
boolean
sameSnapshot
(
List
<
FzGradesEntity
>
incoming
,
List
<
FzGradesEntity
>
persisted
)
{
private
boolean
sameSnapshot
(
List
<
FzGradesEntity
>
incoming
,
List
<
FzGradesEntity
>
persisted
)
{
if
(
incoming
.
size
()
!=
persisted
.
size
())
{
if
(
incoming
.
size
()
!=
persisted
.
size
())
{
return
false
;
return
false
;
...
@@ -211,7 +209,9 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
...
@@ -211,7 +209,9 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
&&
Objects
.
equals
(
left
.
getFileFormat
(),
right
.
getFileFormat
())
&&
Objects
.
equals
(
left
.
getFileFormat
(),
right
.
getFileFormat
())
&&
Double
.
compare
(
left
.
getScore
(),
right
.
getScore
())
==
0
&&
Double
.
compare
(
left
.
getScore
(),
right
.
getScore
())
==
0
// basicScore决定阅卷页面展示的单题分值,变化时不能误判为相同快照。
// basicScore决定阅卷页面展示的单题分值,变化时不能误判为相同快照。
&&
Objects
.
equals
(
left
.
getBasicScore
(),
right
.
getBasicScore
());
&&
Objects
.
equals
(
left
.
getBasicScore
(),
right
.
getBasicScore
())
// rightOrWrong是权威判题结果;NULL与布尔值也必须视为不同快照。
&&
Objects
.
equals
(
left
.
getRightOrWrong
(),
right
.
getRightOrWrong
());
}
}
private
String
requireText
(
String
value
,
String
field
,
int
maxLength
)
{
private
String
requireText
(
String
value
,
String
field
,
int
maxLength
)
{
...
...
practical-business/src/main/java/com/platform/business/service/impl/StudentScoreServiceImpl.java
View file @
4f087901
...
@@ -182,7 +182,9 @@ public class StudentScoreServiceImpl implements StudentScoreService {
...
@@ -182,7 +182,9 @@ public class StudentScoreServiceImpl implements StudentScoreService {
int
partial
=
0
;
int
partial
=
0
;
int
failed
=
0
;
int
failed
=
0
;
for
(
StudentScoreVO
.
PracticeItem
item
:
items
)
{
for
(
StudentScoreVO
.
PracticeItem
item
:
items
)
{
String
status
=
normalizePracticeStatus
(
item
.
getResult
());
// 新协议明确提供正误布尔值时必须以它为准,即使result文本与其冲突也不能覆盖;
// 只有历史记录未保存right_or_wrong时,才继续使用原有文本规则识别部分通过等状态。
String
status
=
normalizePracticeStatus
(
item
.
getRightOrWrong
(),
item
.
getResult
());
item
.
setNormalizedStatus
(
status
);
item
.
setNormalizedStatus
(
status
);
if
(
"PASS"
.
equals
(
status
))
{
if
(
"PASS"
.
equals
(
status
))
{
passed
++;
passed
++;
...
@@ -192,13 +194,22 @@ public class StudentScoreServiceImpl implements StudentScoreService {
...
@@ -192,13 +194,22 @@ public class StudentScoreServiceImpl implements StudentScoreService {
failed
++;
failed
++;
}
}
}
}
// 顶部正确率卡片与practiceSummary必须共享同一次统计结果,避免两处口径漂移。
// 部分通过按0.5题计入正确率;空明细显式返回0,防止前端收到null后展示为“—”。
double
weightedPassRate
=
items
.
isEmpty
()
?
0
D
:
round
(
100
D
*
(
passed
+
partial
*
0.5
D
)
/
items
.
size
());
detail
.
setTotalQuestionCount
(
items
.
size
());
detail
.
setRightCount
(
passed
);
detail
.
setWrongCount
(
failed
);
detail
.
setPartiallyRightCount
(
partial
);
detail
.
setCorrectRate
(
weightedPassRate
);
StudentScoreVO
.
PracticeSummary
summary
=
new
StudentScoreVO
.
PracticeSummary
();
StudentScoreVO
.
PracticeSummary
summary
=
new
StudentScoreVO
.
PracticeSummary
();
summary
.
setTotalCount
(
items
.
size
());
summary
.
setTotalCount
(
items
.
size
());
summary
.
setPassedCount
(
passed
);
summary
.
setPassedCount
(
passed
);
summary
.
setPartiallyPassedCount
(
partial
);
summary
.
setPartiallyPassedCount
(
partial
);
summary
.
setFailedCount
(
failed
);
summary
.
setFailedCount
(
failed
);
summary
.
setWeightedPassRate
(
items
.
isEmpty
()
?
0
D
summary
.
setWeightedPassRate
(
weightedPassRate
);
:
round
(
100
D
*
(
passed
+
partial
*
0.5
D
)
/
items
.
size
()));
detail
.
setPracticeItems
(
items
);
detail
.
setPracticeItems
(
items
);
detail
.
setPracticeSummary
(
summary
);
detail
.
setPracticeSummary
(
summary
);
}
}
...
@@ -241,7 +252,12 @@ public class StudentScoreServiceImpl implements StudentScoreService {
...
@@ -241,7 +252,12 @@ public class StudentScoreServiceImpl implements StudentScoreService {
return
"不合格"
;
return
"不合格"
;
}
}
private
String
normalizePracticeStatus
(
String
result
)
{
private
String
normalizePracticeStatus
(
Boolean
rightOrWrong
,
String
result
)
{
// Boolean非空表示新协议已经给出确定结论,优先级高于任何展示文本。
if
(
rightOrWrong
!=
null
)
{
return
rightOrWrong
?
"PASS"
:
"FAIL"
;
}
// 历史数据没有结构化标记,保留原有文本兼容规则,包含部分通过的半权重语义。
if
(
result
==
null
||
result
.
trim
().
isEmpty
())
{
if
(
result
==
null
||
result
.
trim
().
isEmpty
())
{
return
"FAIL"
;
return
"FAIL"
;
}
}
...
...
practical-business/src/main/resources/com/platform/business/mapper/FzGradesMapper.xml
View file @
4f087901
...
@@ -23,7 +23,8 @@
...
@@ -23,7 +23,8 @@
g.id, g.exam_id AS examId, g.user_id AS userId, g.code, g.lev,
g.id, g.exam_id AS examId, g.user_id AS userId, g.code, g.lev,
g.start_time AS startTime, g.submission_time AS submissionTime,
g.start_time AS startTime, g.submission_time AS submissionTime,
g.title, g.type, g.options, g.mark, g.text, g.result, g.file,
g.title, g.type, g.options, g.mark, g.text, g.result, g.file,
g.file_format AS fileFormat, g.score
g.file_format AS fileFormat, g.score,
g.basic_score AS basicScore, g.right_or_wrong AS rightOrWrong
FROM fz_grades g
FROM fz_grades g
INNER JOIN (
INNER JOIN (
SELECT MAX(id) AS id
SELECT MAX(id) AS id
...
...
practical-business/src/main/resources/com/platform/business/mapper/StudentScoreMapper.xml
View file @
4f087901
...
@@ -266,6 +266,11 @@
...
@@ -266,6 +266,11 @@
grade.options,
grade.options,
grade.text,
grade.text,
grade.result,
grade.result,
<!--
新协议的结构化正误标记优先于result文本。使用显式别名保证MyBatis稳定映射到
PracticeItem.rightOrWrong;该内部字段已通过JsonIgnore从学生端响应中隐藏。
-->
grade.right_or_wrong AS rightOrWrong,
grade.file,
grade.file,
grade.score,
grade.score,
grade.start_time AS startTime,
grade.start_time AS startTime,
...
...
practical-business/src/main/resources/sql/student_score_management.sql
View file @
4f087901
...
@@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS fz_grades (
...
@@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS fz_grades (
file
TEXT
NULL
COMMENT
'附件地址或标识'
,
file
TEXT
NULL
COMMENT
'附件地址或标识'
,
score
DECIMAL
(
10
,
2
)
NOT
NULL
DEFAULT
0
COMMENT
'本题实际得分'
,
score
DECIMAL
(
10
,
2
)
NOT
NULL
DEFAULT
0
COMMENT
'本题实际得分'
,
basic_score
DECIMAL
(
10
,
2
)
NULL
COMMENT
'第三方提供的本题基础分值,仅用于展示和汇总'
,
basic_score
DECIMAL
(
10
,
2
)
NULL
COMMENT
'第三方提供的本题基础分值,仅用于展示和汇总'
,
right_or_wrong
TINYINT
(
1
)
NULL
COMMENT
'结构化判题结果:0错误、1正确;历史数据为空时由应用兼容解析'
,
PRIMARY
KEY
(
id
)
PRIMARY
KEY
(
id
)
)
ENGINE
=
InnoDB
)
ENGINE
=
InnoDB
COMMENT
=
'仿真实训逐题成绩明细'
;
COMMENT
=
'仿真实训逐题成绩明细'
;
...
@@ -65,6 +66,18 @@ begin
...
@@ -65,6 +66,18 @@ begin
after
score
;
after
score
;
end
if
;
end
if
;
-- 旧数据保持NULL,由应用回退解析result,避免迁移时猜测并污染历史结果。
if
not
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
and
table_name
=
'fz_grades'
and
column_name
=
'right_or_wrong'
)
then
alter
table
fz_grades
add
column
right_or_wrong
tinyint
(
1
)
null
comment
'结构化判题结果:0错误、1正确;历史数据为空时由应用兼容解析'
after
basic_score
;
end
if
;
-- 完整成绩上报和单个学员详情均先按考试、学员、题号缩小范围。
-- 完整成绩上报和单个学员详情均先按考试、学员、题号缩小范围。
if
not
exists
(
if
not
exists
(
select
1
from
information_schema
.
statistics
select
1
from
information_schema
.
statistics
...
...
practical-business/src/main/resources/student-score-api.md
View file @
4f087901
...
@@ -22,6 +22,9 @@
...
@@ -22,6 +22,9 @@
-
实训考试只读取
`fz_grades`
,同一
`exam_id + user_id + code`
按最大雪花ID取最新记录。
-
实训考试只读取
`fz_grades`
,同一
`exam_id + user_id + code`
按最大雪花ID取最新记录。
-
详情分支同时识别
`理论/理论考试/THEORY`
和
`实训/实训考试/PRACTICE`
,用于兼容历史数据,
-
详情分支同时识别
`理论/理论考试/THEORY`
和
`实训/实训考试/PRACTICE`
,用于兼容历史数据,
不对已有考试记录执行类型迁移。
不对已有考试记录执行类型迁移。
-
实训现有协议没有步骤满分、扣分维度和教师评语,因此接口不会构造这些字段;仅根据
`result`
-
实训现有协议没有步骤满分、扣分维度和教师评语,因此接口不会构造这些字段。步骤判定优先使用
文本归一化
`PASS/PARTIAL/FAIL`
并计算步骤数量及加权通过率。
`right_or_wrong`
(
`true`
为通过、
`false`
为失败),历史空值才回退
`result`
文本归一化
`PASS/PARTIAL/FAIL`
;
`right_or_wrong`
仅用于服务端聚合,不出现在逐题JSON中。
-
实训详情顶部与
`practiceSummary`
共享同一组统计:部分通过按半题计算正确率,空明细的题数、
正确数、错误数、部分正确数和正确率均返回
`0`
,正确率按两位小数四舍五入。
-
详情和导出均使用
`examStudentId + JWT学员ID`
查询,不能访问其他学员成绩。
-
详情和导出均使用
`examStudentId + JWT学员ID`
查询,不能访问其他学员成绩。
practical-business/src/test/java/com/platform/business/mapper/ScoreAdminMapperXmlTest.java
View file @
4f087901
...
@@ -170,6 +170,22 @@ class ScoreAdminMapperXmlTest {
...
@@ -170,6 +170,22 @@ class ScoreAdminMapperXmlTest {
"com.platform.business.mapper.FzGradesMapper.submitPracticeStudent"
));
"com.platform.business.mapper.FzGradesMapper.submitPracticeStudent"
));
}
}
@Test
void
latestPracticeItemsShouldReadAllIdempotencyFields
()
throws
Exception
{
Configuration
configuration
=
parse
(
"com/platform/business/mapper/FzGradesMapper.xml"
);
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"examId"
,
1
);
parameters
.
put
(
"studentId"
,
"student-1"
);
String
sql
=
normalizeSql
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.FzGradesMapper.selectLatestItems"
)
.
getBoundSql
(
parameters
).
getSql
());
// 最新快照必须读回所有参与幂等比较的新增字段,否则相同请求会被误判为内容变化。
assertTrue
(
sql
.
contains
(
"g.basic_score as basicscore"
));
assertTrue
(
sql
.
contains
(
"g.right_or_wrong as rightorwrong"
));
}
@Test
@Test
void
examReviewMapperShouldRegisterPracticeReviewStatements
()
throws
Exception
{
void
examReviewMapperShouldRegisterPracticeReviewStatements
()
throws
Exception
{
Configuration
configuration
=
parse
(
"com/platform/business/mapper/ExamReviewMapper.xml"
);
Configuration
configuration
=
parse
(
"com/platform/business/mapper/ExamReviewMapper.xml"
);
...
...
practical-business/src/test/java/com/platform/business/mapper/StudentLearningMapperXmlTest.java
View file @
4f087901
...
@@ -123,6 +123,15 @@ class StudentLearningMapperXmlTest {
...
@@ -123,6 +123,15 @@ class StudentLearningMapperXmlTest {
"com.platform.business.mapper.StudentScoreMapper.selectPage"
)
"com.platform.business.mapper.StudentScoreMapper.selectPage"
)
.
getBoundSql
(
parameters
).
getSql
());
.
getBoundSql
(
parameters
).
getSql
());
assertTrue
(
practiceSql
.
contains
(
"upper(trim(e.type)) in ('实训考试', '实训', 'practice')"
));
assertTrue
(
practiceSql
.
contains
(
"upper(trim(e.type)) in ('实训考试', '实训', 'practice')"
));
Map
<
String
,
Object
>
practiceDetailParameters
=
new
HashMap
<>();
practiceDetailParameters
.
put
(
"examId"
,
10
);
practiceDetailParameters
.
put
(
"studentId"
,
"student-1"
);
String
practiceDetailSql
=
compact
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.StudentScoreMapper.selectPracticeItems"
)
.
getBoundSql
(
practiceDetailParameters
).
getSql
());
// 必须显式读取并映射结构化正误字段,服务层才能在文本冲突时使用权威布尔值。
assertTrue
(
practiceDetailSql
.
contains
(
"grade.right_or_wrong as rightorwrong"
));
}
}
private
Configuration
parse
(
String
resource
)
throws
Exception
{
private
Configuration
parse
(
String
resource
)
throws
Exception
{
...
...
practical-business/src/test/java/com/platform/business/service/impl/FzGradesServiceImplTest.java
View file @
4f087901
package
com.platform.business.service.impl
;
package
com.platform.business.service.impl
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.platform.business.constant.ExamAdminConstants
;
import
com.platform.business.constant.ExamAdminConstants
;
import
com.platform.business.mapper.FzGradesMapper
;
import
com.platform.business.mapper.FzGradesMapper
;
import
com.platform.business.model.dto.FzGradesDTO
;
import
com.platform.business.model.dto.FzGradesDTO
;
...
@@ -20,6 +21,7 @@ import java.util.Arrays;
...
@@ -20,6 +21,7 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
@@ -62,14 +64,108 @@ class FzGradesServiceImplTest {
...
@@ -62,14 +64,108 @@ class FzGradesServiceImplTest {
verify
(
mapper
).
submitPracticeStudent
(
eq
(
9
),
eq
(
75
D
),
any
(),
any
(),
any
(),
any
());
verify
(
mapper
).
submitPracticeStudent
(
eq
(
9
),
eq
(
75
D
),
any
(),
any
(),
any
(),
any
());
}
}
@Test
void
explicitRightOrWrongShouldBePreservedForObjectiveQuestion
()
{
mockWritableCandidate
();
when
(
mapper
.
selectLatestItems
(
1
,
"student-1"
)).
thenReturn
(
Collections
.
emptyList
());
when
(
mapper
.
insert
(
any
(
FzGradesEntity
.
class
))).
thenReturn
(
1
);
when
(
mapper
.
submitPracticeStudent
(
eq
(
9
),
eq
(
10
D
),
any
(),
any
(),
any
(),
any
()))
.
thenReturn
(
1
);
FzGradesDTO
incoming
=
item
(
"Q-1"
,
10
D
);
incoming
.
setType
(
"单选题"
);
incoming
.
setRightOrWrong
(
false
);
assertTrue
(
service
.
receive
(
Collections
.
singletonList
(
incoming
)));
ArgumentCaptor
<
FzGradesEntity
>
captor
=
ArgumentCaptor
.
forClass
(
FzGradesEntity
.
class
);
verify
(
mapper
).
insert
(
captor
.
capture
());
// 即使客观题得分大于0,也必须原样保留上游明确给出的错误标记。
assertFalse
(
captor
.
getValue
().
getRightOrWrong
());
}
@Test
void
rightOrWrongShouldBeAcceptedFromJsonButHiddenFromEntityResponses
()
throws
Exception
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
FzGradesEntity
incoming
=
objectMapper
.
readValue
(
"{\"rightOrWrong\":true}"
,
FzGradesEntity
.
class
);
String
responseJson
=
objectMapper
.
writeValueAsString
(
incoming
);
// 保持成绩上报入参能力,同时不让实体被复用时意外改变管理端/教师端JSON。
assertTrue
(
incoming
.
getRightOrWrong
());
assertFalse
(
responseJson
.
contains
(
"rightOrWrong"
));
}
@Test
@Test
void
identicalReplayShouldBeIdempotentWithoutWriting
()
{
void
identicalReplayShouldBeIdempotentWithoutWriting
()
{
mockWritableCandidate
();
mockWritableCandidate
();
FzGradesDTO
incoming
=
item
(
"Q-1"
,
50
D
);
incoming
.
setRightOrWrong
(
true
);
FzGradesEntity
existing
=
persisted
(
"Q-1"
,
50
D
);
existing
.
setRightOrWrong
(
true
);
when
(
mapper
.
selectLatestItems
(
1
,
"student-1"
))
.
thenReturn
(
Collections
.
singletonList
(
existing
));
assertTrue
(
service
.
receive
(
Collections
.
singletonList
(
incoming
)));
verify
(
mapper
,
never
()).
insert
(
any
(
FzGradesEntity
.
class
));
verify
(
mapper
,
never
()).
submitPracticeStudent
(
any
(),
any
(),
any
(),
any
(),
any
(),
any
());
}
@Test
void
legacyObjectiveReplayWithoutStoredRightOrWrongShouldRemainIdempotent
()
{
mockWritableCandidate
();
FzGradesDTO
incoming
=
item
(
"Q-1"
,
50
D
);
incoming
.
setType
(
"单选题"
);
FzGradesEntity
existing
=
persisted
(
"Q-1"
,
50
D
);
existing
.
setType
(
"客观题"
);
existing
.
setRightOrWrong
(
null
);
when
(
mapper
.
selectLatestItems
(
1
,
"student-1"
))
.
thenReturn
(
Collections
.
singletonList
(
existing
));
assertTrue
(
service
.
receive
(
Collections
.
singletonList
(
incoming
)));
// 旧库的NULL不应让相同客观题快照在升级后被误判为变更。
verify
(
mapper
,
never
()).
insert
(
any
(
FzGradesEntity
.
class
));
verify
(
mapper
,
never
()).
submitPracticeStudent
(
any
(),
any
(),
any
(),
any
(),
any
(),
any
());
}
@Test
void
changedRightOrWrongShouldNotBeTreatedAsIdenticalReplay
()
{
mockWritableCandidate
();
FzGradesDTO
incoming
=
item
(
"Q-1"
,
50
D
);
incoming
.
setRightOrWrong
(
false
);
FzGradesEntity
existing
=
persisted
(
"Q-1"
,
50
D
);
existing
.
setRightOrWrong
(
true
);
when
(
mapper
.
selectLatestItems
(
1
,
"student-1"
))
when
(
mapper
.
selectLatestItems
(
1
,
"student-1"
))
.
thenReturn
(
Collections
.
singletonList
(
persisted
(
"Q-1"
,
50
D
)
));
.
thenReturn
(
Collections
.
singletonList
(
existing
));
assertTrue
(
service
.
receive
(
Collections
.
singletonList
(
item
(
"Q-1"
,
50
D
))));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
receive
(
Collections
.
singletonList
(
incoming
)));
// 分值等其他业务字段完全一致时,判题标记变化仍代表不同快照,不能绕过首次接收锁定。
assertEquals
(
"仿真实训成绩已经接收,后续只能由教师复核调整"
,
error
.
getMessage
());
verify
(
mapper
,
never
()).
insert
(
any
(
FzGradesEntity
.
class
));
verify
(
mapper
,
never
()).
submitPracticeStudent
(
any
(),
any
(),
any
(),
any
(),
any
(),
any
());
}
@Test
void
addingRightOrWrongToLegacySnapshotShouldBeTreatedAsChange
()
{
mockWritableCandidate
();
FzGradesDTO
incoming
=
item
(
"Q-1"
,
50
D
);
incoming
.
setType
(
"单选题"
);
incoming
.
setRightOrWrong
(
true
);
FzGradesEntity
existing
=
persisted
(
"Q-1"
,
50
D
);
existing
.
setType
(
"客观题"
);
existing
.
setRightOrWrong
(
null
);
when
(
mapper
.
selectLatestItems
(
1
,
"student-1"
))
.
thenReturn
(
Collections
.
singletonList
(
existing
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
receive
(
Collections
.
singletonList
(
incoming
)));
// 历史NULL与本次显式上报的布尔值不同,不能被当作相同快照。
assertEquals
(
"仿真实训成绩已经接收,后续只能由教师复核调整"
,
error
.
getMessage
());
verify
(
mapper
,
never
()).
insert
(
any
(
FzGradesEntity
.
class
));
verify
(
mapper
,
never
()).
insert
(
any
(
FzGradesEntity
.
class
));
verify
(
mapper
,
never
()).
submitPracticeStudent
(
any
(),
any
(),
any
(),
any
(),
any
(),
any
());
verify
(
mapper
,
never
()).
submitPracticeStudent
(
any
(),
any
(),
any
(),
any
(),
any
(),
any
());
}
}
...
...
practical-business/src/test/java/com/platform/business/service/impl/StudentScoreServiceImplTest.java
View file @
4f087901
package
com.platform.business.service.impl
;
package
com.platform.business.service.impl
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.platform.business.mapper.StudentScoreMapper
;
import
com.platform.business.mapper.StudentScoreMapper
;
import
com.platform.business.model.dto.StudentScoreQueryDTO
;
import
com.platform.business.model.dto.StudentScoreQueryDTO
;
import
com.platform.business.model.vo.StudentScoreVO
;
import
com.platform.business.model.vo.StudentScoreVO
;
...
@@ -19,6 +20,7 @@ import java.util.Arrays;
...
@@ -19,6 +20,7 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
...
@@ -113,15 +115,13 @@ class StudentScoreServiceImplTest {
...
@@ -113,15 +115,13 @@ class StudentScoreServiceImplTest {
@ParameterizedTest
@ParameterizedTest
@ValueSource
(
strings
=
{
"实训"
,
"实训考试"
,
"PRACTICE"
})
@ValueSource
(
strings
=
{
"实训"
,
"实训考试"
,
"PRACTICE"
})
void
practiceAliasesShould
LoadItemsWithoutInventingMaxScore
s
(
String
examType
)
{
void
practiceAliasesShould
PreferBooleanAndSynchronizeAllStatistic
s
(
String
examType
)
{
StudentScoreVO
.
Detail
detail
=
detail
(
examType
);
StudentScoreVO
.
Detail
detail
=
detail
(
examType
);
when
(
mapper
.
selectDetail
(
1
,
"student-1"
)).
thenReturn
(
detail
);
when
(
mapper
.
selectDetail
(
1
,
"student-1"
)).
thenReturn
(
detail
);
StudentScoreVO
.
PracticeItem
pass
=
new
StudentScoreVO
.
PracticeItem
();
// 布尔值与文本故意冲突,用于验证新字段非空时具有最高优先级。
pass
.
setResult
(
"通过"
);
StudentScoreVO
.
PracticeItem
pass
=
practiceItem
(
true
,
"未通过"
);
StudentScoreVO
.
PracticeItem
partial
=
new
StudentScoreVO
.
PracticeItem
();
StudentScoreVO
.
PracticeItem
partial
=
practiceItem
(
null
,
"部分通过"
);
partial
.
setResult
(
"部分通过"
);
StudentScoreVO
.
PracticeItem
fail
=
practiceItem
(
false
,
"通过"
);
StudentScoreVO
.
PracticeItem
fail
=
new
StudentScoreVO
.
PracticeItem
();
fail
.
setResult
(
"未通过"
);
when
(
mapper
.
selectPracticeItems
(
10
,
"student-1"
))
when
(
mapper
.
selectPracticeItems
(
10
,
"student-1"
))
.
thenReturn
(
Arrays
.
asList
(
pass
,
partial
,
fail
));
.
thenReturn
(
Arrays
.
asList
(
pass
,
partial
,
fail
));
...
@@ -130,9 +130,94 @@ class StudentScoreServiceImplTest {
...
@@ -130,9 +130,94 @@ class StudentScoreServiceImplTest {
assertEquals
(
"PASS"
,
pass
.
getNormalizedStatus
());
assertEquals
(
"PASS"
,
pass
.
getNormalizedStatus
());
assertEquals
(
"PARTIAL"
,
partial
.
getNormalizedStatus
());
assertEquals
(
"PARTIAL"
,
partial
.
getNormalizedStatus
());
assertEquals
(
"FAIL"
,
fail
.
getNormalizedStatus
());
assertEquals
(
"FAIL"
,
fail
.
getNormalizedStatus
());
// 顶部统计与实训摘要必须来自同一份计数,避免前端卡片和明细摘要不一致。
assertEquals
(
3
,
result
.
getTotalQuestionCount
());
assertEquals
(
1
,
result
.
getRightCount
());
assertEquals
(
1
,
result
.
getWrongCount
());
assertEquals
(
1
,
result
.
getPartiallyRightCount
());
assertEquals
(
50
D
,
result
.
getCorrectRate
());
assertEquals
(
3
,
result
.
getPracticeSummary
().
getTotalCount
());
assertEquals
(
1
,
result
.
getPracticeSummary
().
getPassedCount
());
assertEquals
(
1
,
result
.
getPracticeSummary
().
getFailedCount
());
assertEquals
(
1
,
result
.
getPracticeSummary
().
getPartiallyPassedCount
());
assertEquals
(
50
D
,
result
.
getPracticeSummary
().
getWeightedPassRate
());
assertEquals
(
50
D
,
result
.
getPracticeSummary
().
getWeightedPassRate
());
}
}
@Test
void
practiceCorrectRateShouldRoundHalfUpToTwoDecimals
()
{
StudentScoreVO
.
Detail
detail
=
detail
(
"实训"
);
when
(
mapper
.
selectDetail
(
1
,
"student-1"
)).
thenReturn
(
detail
);
when
(
mapper
.
selectPracticeItems
(
10
,
"student-1"
)).
thenReturn
(
Arrays
.
asList
(
practiceItem
(
true
,
null
),
practiceItem
(
false
,
null
),
practiceItem
(
false
,
null
)));
StudentScoreVO
.
Detail
result
=
service
.
detail
(
1
,
"student-1"
);
// 一题正确、三题总数必须按HALF_UP保留两位,不能返回无限小数或整数截断值。
assertEquals
(
33.33
D
,
result
.
getCorrectRate
());
assertEquals
(
33.33
D
,
result
.
getPracticeSummary
().
getWeightedPassRate
());
}
@Test
void
allPracticeItemsCorrectShouldReturnOneHundredPercent
()
{
StudentScoreVO
.
Detail
detail
=
detail
(
"实训"
);
when
(
mapper
.
selectDetail
(
1
,
"student-1"
)).
thenReturn
(
detail
);
when
(
mapper
.
selectPracticeItems
(
10
,
"student-1"
)).
thenReturn
(
Arrays
.
asList
(
practiceItem
(
true
,
null
),
practiceItem
(
true
,
null
)));
StudentScoreVO
.
Detail
result
=
service
.
detail
(
1
,
"student-1"
);
assertEquals
(
2
,
result
.
getRightCount
());
assertEquals
(
0
,
result
.
getWrongCount
());
assertEquals
(
100
D
,
result
.
getCorrectRate
());
}
@Test
void
nonEmptyAllWrongPracticeItemsShouldReturnZeroPercent
()
{
StudentScoreVO
.
Detail
detail
=
detail
(
"实训"
);
when
(
mapper
.
selectDetail
(
1
,
"student-1"
)).
thenReturn
(
detail
);
when
(
mapper
.
selectPracticeItems
(
10
,
"student-1"
)).
thenReturn
(
Arrays
.
asList
(
practiceItem
(
false
,
null
),
practiceItem
(
false
,
null
)));
StudentScoreVO
.
Detail
result
=
service
.
detail
(
1
,
"student-1"
);
assertEquals
(
0
,
result
.
getRightCount
());
assertEquals
(
2
,
result
.
getWrongCount
());
assertEquals
(
0
D
,
result
.
getCorrectRate
());
}
@Test
void
emptyPracticeItemsShouldReturnZeroStatisticsInsteadOfNull
()
{
StudentScoreVO
.
Detail
detail
=
detail
(
"实训考试"
);
when
(
mapper
.
selectDetail
(
1
,
"student-1"
)).
thenReturn
(
detail
);
when
(
mapper
.
selectPracticeItems
(
10
,
"student-1"
)).
thenReturn
(
Collections
.
emptyList
());
StudentScoreVO
.
Detail
result
=
service
.
detail
(
1
,
"student-1"
);
assertEquals
(
0
,
result
.
getTotalQuestionCount
());
assertEquals
(
0
,
result
.
getRightCount
());
assertEquals
(
0
,
result
.
getWrongCount
());
assertEquals
(
0
,
result
.
getPartiallyRightCount
());
assertEquals
(
0
D
,
result
.
getCorrectRate
());
assertEquals
(
0
,
result
.
getPracticeSummary
().
getTotalCount
());
assertEquals
(
0
,
result
.
getPracticeSummary
().
getPassedCount
());
assertEquals
(
0
,
result
.
getPracticeSummary
().
getFailedCount
());
assertEquals
(
0
,
result
.
getPracticeSummary
().
getPartiallyPassedCount
());
assertEquals
(
0
D
,
result
.
getPracticeSummary
().
getWeightedPassRate
());
}
@Test
void
rightOrWrongShouldRemainInternalWhenPracticeItemIsSerialized
()
throws
Exception
{
StudentScoreVO
.
PracticeItem
item
=
practiceItem
(
true
,
"通过"
);
String
json
=
new
ObjectMapper
().
writeValueAsString
(
item
);
// rightOrWrong只用于Mapper和服务层计算,不得扩大学生端逐题JSON协议。
assertFalse
(
json
.
contains
(
"rightOrWrong"
));
assertTrue
(
json
.
contains
(
"result"
));
}
@Test
@Test
void
exportShouldReturnUtf8CsvForOwnedPublishedScore
()
throws
Exception
{
void
exportShouldReturnUtf8CsvForOwnedPublishedScore
()
throws
Exception
{
StudentScoreVO
.
Detail
detail
=
detail
(
"实训"
);
StudentScoreVO
.
Detail
detail
=
detail
(
"实训"
);
...
@@ -169,4 +254,11 @@ class StudentScoreServiceImplTest {
...
@@ -169,4 +254,11 @@ class StudentScoreServiceImplTest {
question
.
setPartiallyRight
(
partial
);
question
.
setPartiallyRight
(
partial
);
return
question
;
return
question
;
}
}
private
StudentScoreVO
.
PracticeItem
practiceItem
(
Boolean
rightOrWrong
,
String
result
)
{
StudentScoreVO
.
PracticeItem
item
=
new
StudentScoreVO
.
PracticeItem
();
item
.
setRightOrWrong
(
rightOrWrong
);
item
.
setResult
(
result
);
return
item
;
}
}
}
practical-business/src/test/java/com/platform/business/sql/PracticeScoreMigrationSqlTest.java
View file @
4f087901
...
@@ -25,6 +25,11 @@ class PracticeScoreMigrationSqlTest {
...
@@ -25,6 +25,11 @@ class PracticeScoreMigrationSqlTest {
assertTrue
(
sql
.
contains
(
"basic_score decimal(10,2) null"
));
assertTrue
(
sql
.
contains
(
"basic_score decimal(10,2) null"
));
assertTrue
(
sql
.
contains
(
"column_name = 'basic_score'"
));
assertTrue
(
sql
.
contains
(
"column_name = 'basic_score'"
));
assertTrue
(
sql
.
contains
(
"add column basic_score"
));
assertTrue
(
sql
.
contains
(
"add column basic_score"
));
// right_or_wrong在新建和存量表迁移路径中都必须可空;历史值保持NULL,由应用兼容result文本。
assertTrue
(
sql
.
contains
(
"right_or_wrong tinyint(1) null"
));
assertTrue
(
sql
.
contains
(
"column_name = 'right_or_wrong'"
));
assertTrue
(
sql
.
contains
(
"add column right_or_wrong"
));
assertFalse
(
sql
.
contains
(
"update fz_grades"
));
assertFalse
(
sql
.
contains
(
"delete from fz_grades"
));
assertFalse
(
sql
.
contains
(
"delete from fz_grades"
));
}
}
...
...
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