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
74d345cb
Commit
74d345cb
authored
Sep 07, 2026
by
wujipeng
Browse files
bug修复
parent
b18b0873
Changes
23
Show whitespace changes
Inline
Side-by-side
practical-business/src/test/java/com/platform/business/mapper/ScoreAdminMapperXmlTest.java
View file @
74d345cb
...
@@ -89,6 +89,36 @@ class ScoreAdminMapperXmlTest {
...
@@ -89,6 +89,36 @@ class ScoreAdminMapperXmlTest {
assertTrue
(
exportSql
.
contains
(
"date_add(e.exam_time"
));
assertTrue
(
exportSql
.
contains
(
"date_add(e.exam_time"
));
}
}
@Test
void
studentDetailShouldEscapeMysqlRankAlias
()
throws
Exception
{
Configuration
configuration
=
parse
(
"com/platform/business/mapper/ScoreAdminMapper.xml"
);
String
detailSql
=
normalizeSql
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ScoreAdminMapper.findStudent"
)
.
getBoundSql
(
1052
).
getSql
());
// RANK从MySQL 8.0.2开始是保留字:详情查询必须转义别名,否则“查看试卷”会返回500。
assertTrue
(
detailSql
.
contains
(
"as `rank`"
));
// 同时显式排除旧写法,防止后续整理SQL时误删反引号而令线上问题回归。
assertFalse
(
detailSql
.
matches
(
".*\\bas\\s+rank\\b.*"
));
}
@Test
void
theoryStatisticsShouldUseNumericSequenceAndStableLegacyFallbackOrder
()
throws
Exception
{
Configuration
configuration
=
parse
(
"com/platform/business/mapper/ScoreAdminMapper.xml"
);
String
statisticsSql
=
normalizeSql
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ScoreAdminMapper.queryTheoryStatistics"
)
.
getBoundSql
(
1
).
getSql
());
// 数字序号必须按数值而非字符串排序,否则第10题会错排在第2题之前。
assertTrue
(
statisticsSql
.
contains
(
"regexp '^[0-9]+$'"
));
assertTrue
(
statisticsSql
.
contains
(
"cast(trim(d.sequence) as unsigned)"
));
// 历史空序号以最早明细ID托底,保证服务层每次生成的1..N题号稳定。
assertTrue
(
statisticsSql
.
contains
(
"nullif(trim(d.sequence), '')"
));
assertTrue
(
statisticsSql
.
contains
(
"min(d.id)"
));
}
@Test
@Test
void
fzGradesMapperShouldRegisterIdempotentReceiveStatements
()
throws
Exception
{
void
fzGradesMapperShouldRegisterIdempotentReceiveStatements
()
throws
Exception
{
Configuration
configuration
=
parse
(
"com/platform/business/mapper/FzGradesMapper.xml"
);
Configuration
configuration
=
parse
(
"com/platform/business/mapper/FzGradesMapper.xml"
);
...
...
practical-business/src/test/java/com/platform/business/service/impl/ExamServiceImplTest.java
0 → 100644
View file @
74d345cb
package
com.platform.business.service.impl
;
import
com.platform.business.mapper.ExamMapper
;
import
com.platform.business.model.dto.ExamDTO
;
import
com.platform.business.model.vo.ExamSummaryVO
;
import
com.platform.business.model.vo.ExamVO
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
java.sql.Timestamp
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** 通用考试分页的中文三态和顶部全局汇总测试。 */
@ExtendWith
(
MockitoExtension
.
class
)
class
ExamServiceImplTest
{
private
static
final
Date
NOW
=
Timestamp
.
valueOf
(
"2026-09-18 09:00:00"
);
@Mock
private
ExamMapper
examMapper
;
private
ExamServiceImpl
service
;
@BeforeEach
void
setUp
()
{
/*
* 固定业务时间,避免测试恰好跨越真实考试边界而偶发失败;baseMapper声明在
* MyBatis-Plus父类中,因此通过测试工具注入同一个Mapper替身。
*/
service
=
new
ExamServiceImpl
()
{
@Override
Date
businessNow
()
{
return
NOW
;
}
};
ReflectionTestUtils
.
setField
(
service
,
"baseMapper"
,
examMapper
);
}
@Test
void
queryListShouldCalculateAllStatusBoundariesFromOneTimeSnapshot
()
{
ExamVO
future
=
examAt
(
"2026-09-18 10:00:00"
,
60
);
ExamVO
exactStart
=
examAt
(
"2026-09-18 09:00:00"
,
60
);
ExamVO
ongoing
=
examAt
(
"2026-09-18 08:30:00"
,
60
);
ExamVO
exactEnd
=
examAt
(
"2026-09-18 08:00:00"
,
60
);
ExamVO
missingTime
=
examAt
(
null
,
60
);
ExamVO
missingDuration
=
examAt
(
"2026-09-18 09:00:00"
,
null
);
ExamVO
negativeDuration
=
examAt
(
"2026-09-18 08:00:00"
,
-
30
);
List
<
ExamVO
>
rows
=
Arrays
.
asList
(
future
,
exactStart
,
ongoing
,
exactEnd
,
missingTime
,
missingDuration
,
negativeDuration
);
ExamDTO
query
=
new
ExamDTO
();
when
(
examMapper
.
queryList
(
query
)).
thenReturn
(
rows
);
List
<
ExamVO
>
result
=
service
.
queryList
(
query
);
assertEquals
(
"未开始"
,
result
.
get
(
0
).
getStatus
());
assertEquals
(
"进行中"
,
result
.
get
(
1
).
getStatus
());
assertEquals
(
"进行中"
,
result
.
get
(
2
).
getStatus
());
assertEquals
(
"已结束"
,
result
.
get
(
3
).
getStatus
());
assertEquals
(
"已结束"
,
result
.
get
(
4
).
getStatus
());
assertEquals
(
"已结束"
,
result
.
get
(
5
).
getStatus
());
assertEquals
(
"已结束"
,
result
.
get
(
6
).
getStatus
());
}
@Test
void
queryListShouldConvertNullMapperResultToEmptyList
()
{
ExamDTO
query
=
new
ExamDTO
();
when
(
examMapper
.
queryList
(
query
)).
thenReturn
(
null
);
assertEquals
(
Collections
.
emptyList
(),
service
.
queryList
(
query
));
}
@Test
void
summaryShouldKeepGlobalCountsAndUseTheSameBusinessTime
()
{
ExamSummaryVO
mapped
=
new
ExamSummaryVO
();
mapped
.
setTotalCount
(
15L
);
mapped
.
setNotStartedCount
(
5L
);
mapped
.
setOngoingCount
(
3L
);
mapped
.
setEndedCount
(
7L
);
when
(
examMapper
.
summary
(
eq
(
NOW
))).
thenReturn
(
mapped
);
ExamSummaryVO
result
=
service
.
summary
();
assertEquals
(
15L
,
result
.
getTotalCount
());
assertEquals
(
5L
,
result
.
getNotStartedCount
());
assertEquals
(
3L
,
result
.
getOngoingCount
());
assertEquals
(
7L
,
result
.
getEndedCount
());
assertEquals
(
result
.
getTotalCount
().
longValue
(),
result
.
getNotStartedCount
()
+
result
.
getOngoingCount
()
+
result
.
getEndedCount
());
verify
(
examMapper
).
summary
(
NOW
);
}
@Test
void
summaryShouldReturnFourZerosWhenMapperHasNoResult
()
{
when
(
examMapper
.
summary
(
eq
(
NOW
))).
thenReturn
(
null
);
ExamSummaryVO
result
=
service
.
summary
();
assertEquals
(
0L
,
result
.
getTotalCount
());
assertEquals
(
0L
,
result
.
getNotStartedCount
());
assertEquals
(
0L
,
result
.
getOngoingCount
());
assertEquals
(
0L
,
result
.
getEndedCount
());
}
/** 创建仅含状态计算必需字段的考试记录,使每个断言只关注时间边界。 */
private
ExamVO
examAt
(
String
examTime
,
Integer
duration
)
{
ExamVO
exam
=
new
ExamVO
();
exam
.
setExamTime
(
examTime
==
null
?
null
:
Timestamp
.
valueOf
(
examTime
));
exam
.
setDuration
(
duration
);
return
exam
;
}
}
practical-business/src/test/java/com/platform/business/service/impl/ScoreAdminServiceImplTest.java
View file @
74d345cb
...
@@ -7,6 +7,7 @@ import com.platform.business.model.dto.ScoreAdminStudentQueryDTO;
...
@@ -7,6 +7,7 @@ import com.platform.business.model.dto.ScoreAdminStudentQueryDTO;
import
com.platform.business.model.vo.ScoreAdminExportExamVO
;
import
com.platform.business.model.vo.ScoreAdminExportExamVO
;
import
com.platform.business.model.vo.ScoreAdminExportPracticeItemVO
;
import
com.platform.business.model.vo.ScoreAdminExportPracticeItemVO
;
import
com.platform.business.model.vo.ScoreAdminExamVO
;
import
com.platform.business.model.vo.ScoreAdminExamVO
;
import
com.platform.business.model.vo.ScoreAdminQuestionStatisticsVO
;
import
com.platform.business.model.vo.ScoreAdminStudentDetailVO
;
import
com.platform.business.model.vo.ScoreAdminStudentDetailVO
;
import
com.platform.business.model.vo.ScoreAdminStudentVO
;
import
com.platform.business.model.vo.ScoreAdminStudentVO
;
import
com.platform.business.service.ExamAdminService
;
import
com.platform.business.service.ExamAdminService
;
...
@@ -29,6 +30,7 @@ import java.util.Date;
...
@@ -29,6 +30,7 @@ import java.util.Date;
import
java.util.List
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
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
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
never
;
...
@@ -155,6 +157,47 @@ class ScoreAdminServiceImplTest {
...
@@ -155,6 +157,47 @@ class ScoreAdminServiceImplTest {
verify
(
scoreAdminMapper
,
never
()).
queryTheoryStatistics
(
1
);
verify
(
scoreAdminMapper
,
never
()).
queryTheoryStatistics
(
1
);
}
}
@Test
void
theoryStatisticsShouldReturnContinuousQuestionNumbersForLegacySequences
()
{
ScoreAdminExamVO
exam
=
endedExam
(
true
);
exam
.
setExamType
(
ExamAdminConstants
.
TYPE_THEORY
);
when
(
scoreAdminMapper
.
findExam
(
1
)).
thenReturn
(
exam
);
// 覆盖历史明细中实际存在的null、空字符串和非数字序号。
ScoreAdminQuestionStatisticsVO
first
=
theoryStatistic
(
null
,
"判断题1"
);
ScoreAdminQuestionStatisticsVO
second
=
theoryStatistic
(
""
,
"判断题2"
);
ScoreAdminQuestionStatisticsVO
third
=
theoryStatistic
(
"legacy"
,
"判断题3"
);
when
(
scoreAdminMapper
.
queryTheoryStatistics
(
1
))
.
thenReturn
(
Arrays
.
asList
(
first
,
second
,
third
));
List
<
ScoreAdminQuestionStatisticsVO
>
result
=
service
.
questionStatistics
(
1
);
assertEquals
(
Arrays
.
asList
(
"1"
,
"2"
,
"3"
),
Arrays
.
asList
(
result
.
get
(
0
).
getSequence
(),
result
.
get
(
1
).
getSequence
(),
result
.
get
(
2
).
getSequence
()));
verify
(
scoreAdminMapper
).
queryTheoryStatistics
(
1
);
verify
(
scoreAdminMapper
,
never
()).
queryPracticeStatistics
(
1
);
}
@Test
void
practiceStatisticsShouldKeepQuestionCodeAndNotGenerateTheorySequence
()
{
ScoreAdminExamVO
exam
=
endedExam
(
true
);
exam
.
setExamType
(
ExamAdminConstants
.
TYPE_PRACTICE
);
when
(
scoreAdminMapper
.
findExam
(
1
)).
thenReturn
(
exam
);
ScoreAdminQuestionStatisticsVO
practiceItem
=
new
ScoreAdminQuestionStatisticsVO
();
practiceItem
.
setQuestionCode
(
"1.1"
);
when
(
scoreAdminMapper
.
queryPracticeStatistics
(
1
))
.
thenReturn
(
Collections
.
singletonList
(
practiceItem
));
List
<
ScoreAdminQuestionStatisticsVO
>
result
=
service
.
questionStatistics
(
1
);
assertEquals
(
"1.1"
,
result
.
get
(
0
).
getQuestionCode
());
assertNull
(
result
.
get
(
0
).
getSequence
());
verify
(
scoreAdminMapper
).
queryPracticeStatistics
(
1
);
verify
(
scoreAdminMapper
,
never
()).
queryTheoryStatistics
(
1
);
}
@Test
@Test
void
studentDetailShouldRejectDraftScore
()
{
void
studentDetailShouldRejectDraftScore
()
{
ScoreAdminStudentDetailVO
detail
=
new
ScoreAdminStudentDetailVO
();
ScoreAdminStudentDetailVO
detail
=
new
ScoreAdminStudentDetailVO
();
...
@@ -365,6 +408,14 @@ class ScoreAdminServiceImplTest {
...
@@ -365,6 +408,14 @@ class ScoreAdminServiceImplTest {
return
student
;
return
student
;
}
}
/** 构造理论题统计行,用于校验服务层对历史序号的返回兼容。 */
private
ScoreAdminQuestionStatisticsVO
theoryStatistic
(
String
sequence
,
String
title
)
{
ScoreAdminQuestionStatisticsVO
statistic
=
new
ScoreAdminQuestionStatisticsVO
();
statistic
.
setSequence
(
sequence
);
statistic
.
setTitle
(
title
);
return
statistic
;
}
private
ScoreAdminExportPracticeItemVO
practiceItem
(
private
ScoreAdminExportPracticeItemVO
practiceItem
(
String
studentId
,
String
code
,
String
title
,
String
score
)
{
String
studentId
,
String
code
,
String
title
,
String
score
)
{
ScoreAdminExportPracticeItemVO
item
=
new
ScoreAdminExportPracticeItemVO
();
ScoreAdminExportPracticeItemVO
item
=
new
ScoreAdminExportPracticeItemVO
();
...
...
Prev
1
2
Next
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