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
0b4397af
Commit
0b4397af
authored
Sep 04, 2026
by
王蔡翾
Browse files
Merge remote-tracking branch 'origin/dev-v1.0' into dev-v1.0
parents
14515178
30a948eb
Changes
17
Show whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/dto/StudentLevelCertDTO.java
View file @
0b4397af
package
com.platform.business.model.dto
;
import
com.platform.business.model.entity.StudentLevelCertEntity
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
...
...
@@ -8,6 +9,16 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
StudentLevelCertDTO
extends
StudentLevelCertEntity
{
/**
* 证书列表的统一搜索关键字。
*
* <p>该字段不能复用父类的 {@code name}:{@code name} 对应证书表自身的名称列,
* 而管理端搜索框传递的是 {@code keyword}。显式声明后,Jackson 才会保留前端提交的
* 参数,MyBatis 也才能据此拼接姓名、身份证号和证书编号的模糊查询条件。</p>
*/
@ApiModelProperty
(
"姓名、身份证号或证书编号关键字,支持模糊查询"
)
private
String
keyword
;
private
int
pageNum
;
private
int
pageSize
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/ExamAdminClassVO.java
View file @
0b4397af
...
...
@@ -6,7 +6,7 @@ import lombok.Data;
import
java.util.Date
;
import
java.util.List
;
/** 考试管理页面右侧的班级摘要与
未结束
考试计划。 */
/** 考试管理页面右侧的班级摘要与
全部
考试计划。 */
@Data
public
class
ExamAdminClassVO
{
...
...
@@ -32,7 +32,9 @@ public class ExamAdminClassVO {
private
Integer
studentCount
;
/** 当前响应中的考试总数,包含未开始、进行中和已结束场次。 */
private
Integer
plannedCount
;
/** 按考试开始时间倒序返回的全部考试计划。 */
private
List
<
ExamAdminDetailVO
>
exams
;
}
practical-business/src/main/java/com/platform/business/mapper/ExamMapper.java
View file @
0b4397af
...
...
@@ -12,8 +12,8 @@ import com.platform.business.model.vo.ExamVO;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.Date
;
import
java.util.List
;
@Mapper
public
interface
ExamMapper
extends
BaseMapper
<
ExamEntity
>
{
...
...
@@ -43,9 +43,13 @@ public interface ExamMapper extends BaseMapper<ExamEntity> {
/** 查询考试管理页面所需的班级基础信息。 */
ExamAdminClassVO
selectAdminExamClass
(
@Param
(
"classId"
)
Integer
classId
);
/** 查询尚未结束的考试计划;历史考试由成绩管理模块负责。 */
List
<
ExamAdminDetailVO
>
selectAdminExamPlans
(
@Param
(
"classId"
)
Integer
classId
,
@Param
(
"now"
)
Date
now
);
/**
* 查询班级的全部考试计划,包括未开始、进行中和已结束场次。
*
* <p>已结束场次仍需留在考试管理页面供管理员追溯,因此这里不按当前时间过滤;
* 是否允许编辑或删除统一由服务层根据考试状态计算。</p>
*/
List
<
ExamAdminDetailVO
>
selectAdminExamPlans
(
@Param
(
"classId"
)
Integer
classId
);
ExamAdminDetailVO
selectAdminExamDetail
(
@Param
(
"examId"
)
Integer
examId
);
...
...
practical-business/src/main/java/com/platform/business/service/impl/AccountAdminServiceImpl.java
View file @
0b4397af
...
...
@@ -53,6 +53,7 @@ import java.math.BigDecimal;
import
java.net.URLEncoder
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Date
;
...
...
@@ -73,6 +74,12 @@ import java.util.regex.Pattern;
public
class
AccountAdminServiceImpl
implements
AccountAdminService
{
private
static
final
ZoneId
BUSINESS_ZONE
=
ZoneId
.
of
(
"Asia/Shanghai"
);
/**
* 账户清单中的时间固定按业务时区输出,避免Date.toString()受服务器默认时区、语言环境
* 影响而产生“Thu Sep ... CST ...”之类不便于阅读和筛选的文本。
*/
private
static
final
DateTimeFormatter
EXPORT_DATE_TIME_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
).
withZone
(
BUSINESS_ZONE
);
private
static
final
Pattern
PHONE_PATTERN
=
Pattern
.
compile
(
"^1[3-9]\\d{9}$"
);
private
static
final
Pattern
ACCOUNT_PATTERN
=
Pattern
.
compile
(
"^[A-Za-z0-9._-]{3,50}$"
);
private
static
final
Pattern
ID_CARD_PATTERN
=
Pattern
.
compile
(
"^(?:\\d{15}|\\d{17}[0-9Xx])$"
);
...
...
@@ -447,8 +454,8 @@ public class AccountAdminServiceImpl implements AccountAdminService {
for
(
AccountAdminListVO
item
:
rows
)
{
writeRow
(
sheet
.
createRow
(
rowIndex
++),
asList
(
item
.
getName
(),
item
.
getUsername
(),
item
.
getEmployeeNo
(),
item
.
getPhoneNumber
(),
item
.
getClassName
(),
item
.
getLevelName
(),
item
.
getRoleName
(),
item
.
getStatus
(),
item
.
getLastLoginTime
()
==
null
?
""
:
item
.
getLastLoginTime
()
.
toString
(
)));
item
.
getLevelName
(),
item
.
getRoleName
(),
exportStatusLabel
(
item
.
getStatus
()
)
,
formatExportDateTime
(
item
.
getLastLoginTime
())));
}
}
autoSize
(
sheet
,
headers
.
size
());
...
...
@@ -458,6 +465,31 @@ public class AccountAdminServiceImpl implements AccountAdminService {
}
}
/**
* 将数据库和接口使用的稳定英文状态码转换为面向业务人员的中文文案。
*
* <p>这里仅转换Excel展示值,分页查询及接口返回仍保留英文状态码,避免改变前端筛选、
* 状态流转和接口兼容性。遇到历史脏数据时保留原值,便于管理员识别和排查。</p>
*/
String
exportStatusLabel
(
String
status
)
{
if
(
status
==
null
)
return
""
;
if
(
AccountAdminConstants
.
STATUS_PENDING
.
equals
(
status
))
return
"待激活"
;
if
(
AccountAdminConstants
.
STATUS_STUDYING
.
equals
(
status
))
return
"在读"
;
if
(
AccountAdminConstants
.
STATUS_GRADUATED
.
equals
(
status
))
return
"已结业"
;
if
(
AccountAdminConstants
.
STATUS_ARCHIVED
.
equals
(
status
))
return
"已归档"
;
if
(
AccountAdminConstants
.
STATUS_ENABLED
.
equals
(
status
))
return
"启用"
;
if
(
AccountAdminConstants
.
STATUS_DISABLED
.
equals
(
status
))
return
"禁用"
;
return
status
;
}
/**
* 最后登录时间统一输出到秒;空值保持为空,表示该账户从未登录。
* 使用明确的Asia/Shanghai业务时区可保证开发机、测试机和生产服务器导出结果一致。
*/
String
formatExportDateTime
(
Date
date
)
{
return
date
==
null
?
""
:
EXPORT_DATE_TIME_FORMATTER
.
format
(
date
.
toInstant
());
}
/** 统一清理和校验查询参数,分页参数由控制器另外处理。 */
AccountAdminQueryDTO
normalizeQuery
(
AccountAdminQueryDTO
query
)
{
if
(
query
==
null
)
{
...
...
practical-business/src/main/java/com/platform/business/service/impl/ExamAdminServiceImpl.java
View file @
0b4397af
...
...
@@ -71,7 +71,9 @@ public class ExamAdminServiceImpl implements ExamAdminService {
result
.
setTermName
(
buildTermName
(
result
));
Date
now
=
businessNow
();
List
<
ExamAdminDetailVO
>
exams
=
examMapper
.
selectAdminExamPlans
(
classId
,
now
);
// Mapper返回该班级的完整考试历史;服务层再基于同一个业务时刻统一计算状态和操作权限,
// 避免同一次响应中的临界场次因多次取时而出现状态、按钮权限不一致。
List
<
ExamAdminDetailVO
>
exams
=
examMapper
.
selectAdminExamPlans
(
classId
);
if
(
exams
==
null
)
{
exams
=
Collections
.
emptyList
();
}
...
...
@@ -79,6 +81,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
applyStatus
(
exam
,
now
);
}
result
.
setExams
(
exams
);
// plannedCount现在表示页面实际返回的全部考试数量,包含已结束考试。
result
.
setPlannedCount
(
exams
.
size
());
return
result
;
}
...
...
practical-business/src/main/java/com/platform/business/service/impl/StudentLevelCertServiceImpl.java
View file @
0b4397af
...
...
@@ -39,9 +39,23 @@ public class StudentLevelCertServiceImpl extends ServiceImpl<StudentLevelCertMap
@Override
public
List
<
StudentLevelCertVO
>
queryList
(
StudentLevelCertDTO
studentLevelCertDTO
)
{
/*
* 去除搜索框输入首尾的无效空白,保证“ 王 ”与“王”生成相同的LIKE条件。
* 空白字符串转换为null后,Mapper不会附加搜索条件,行为与未输入关键字一致。
*/
if
(
studentLevelCertDTO
!=
null
)
{
String
keyword
=
studentLevelCertDTO
.
getKeyword
();
studentLevelCertDTO
.
setKeyword
(
StringUtils
.
isEmpty
(
keyword
)
?
null
:
trimToNull
(
keyword
));
}
return
baseMapper
.
queryList
(
studentLevelCertDTO
);
}
/** 将可选文本规范化;仅包含空白字符的输入按未填写处理。 */
private
String
trimToNull
(
String
value
)
{
String
trimmed
=
value
.
trim
();
return
trimmed
.
isEmpty
()
?
null
:
trimmed
;
}
@Override
@Transactional
public
Result
<
Boolean
>
importExcel
(
MultipartFile
file
)
{
...
...
practical-business/src/main/resources/account-management-api.md
View file @
0b4397af
...
...
@@ -95,6 +95,11 @@
-
身份证、手机号、组织机构代码和证书编号按文本编号处理,兼容Excel科学计数法显示。
-
花名册“等级”属于“所持前一等级证书信息”;当前培训等级仍由
`classId`
对应班级决定。
-
导出少于48人时保留完整空白表格,超过48人时自动扩展并下移签字、备注区。
教师和管理员账户清单中的状态使用中文业务文案(如“启用”“禁用”);最后登录时间固定按
上海业务时区输出为
`yyyy-MM-dd HH:mm:ss`
,从未登录的账户保持为空。状态转换同时覆盖学员
状态(“待激活”“在读”“已结业”“已归档”),供包含状态列的账户清单统一复用。
-
教师和管理员继续使用原有5列精简模板及账户清单格式。
## 数据库
...
...
practical-business/src/main/resources/com/platform/business/mapper/ExamMapper.xml
View file @
0b4397af
...
...
@@ -193,8 +193,11 @@
left join user invigilator on invigilator.id = e.invigilation_id
left join theoretical_paper paper on paper.id = e.paper_id
where e.class_id = #{classId}
and timestampadd(minute, coalesce(e.duration, 0), e.exam_time)
>
#{now}
order by e.exam_time asc, e.id asc
<!--
考试管理需要保留已结束场次供管理员追溯,不能再按“开始时间+时长”过滤历史数据。
相同开始时间使用主键倒序作为稳定次序,保证新创建的记录优先展示。
-->
order by e.exam_time desc, e.id desc
</select>
<select
id=
"selectAdminExamDetail"
resultType=
"com.platform.business.model.vo.ExamAdminDetailVO"
>
...
...
practical-business/src/main/resources/com/platform/business/mapper/StudentLevelCertMapper.xml
View file @
0b4397af
...
...
@@ -32,9 +32,23 @@
<if
test=
"factory != null and factory != ''"
>
and student_level_cert.factory = #{factory}
</if>
<if
test=
"name != null and name != ''"
>
and student_level_cert.user_name like concat('%',#{name},'%')
</if>
<!--
管理端搜索框统一提交keyword。姓名、身份证号和证书编号均属于页面可见的
人员身份信息,因此使用同一个关键字进行包含匹配;旧版客户端提交name时
仍保留原有姓名查询能力,避免接口升级后出现兼容性问题。
-->
<choose>
<when
test=
"keyword != null and keyword != ''"
>
and (
student_level_cert.user_name like concat('%', #{keyword}, '%')
or student_level_cert.id_card like concat('%', #{keyword}, '%')
or student_level_cert.cert_no like concat('%', #{keyword}, '%')
)
</when>
<when
test=
"name != null and name != ''"
>
and student_level_cert.user_name like concat('%', #{name}, '%')
</when>
</choose>
</where>
</select>
</mapper>
practical-business/src/main/resources/com/platform/business/mapper/UserMapper.xml
View file @
0b4397af
...
...
@@ -26,8 +26,13 @@
sys_user_and_role.role_id = role.id
<where>
<if
test=
"nickName != null and nickName != ''"
>
user.username like concat('%',#{nickName},'%')
or user.nick_name like concat('%',#{nickName},'%')
<!--
账号和姓名属于同一个关键词筛选条件,必须整体加括号后再与角色条件拼接。
如果省略括号,MySQL 会优先计算 AND,最终条件将变成
“账号匹配 OR(姓名匹配 AND 角色匹配)”,导致账号命中的学生绕过教师角色限制。
-->
(user.username like concat('%',#{nickName},'%')
or user.nick_name like concat('%',#{nickName},'%'))
</if>
<if
test=
"idType != null and idType != ''"
>
and id_type = #{idType}
...
...
practical-business/src/main/resources/exam-management-api.md
View file @
0b4397af
...
...
@@ -9,7 +9,7 @@
2.
`src/main/resources/sql/exam_management.sql`
考试状态不写入数据库:开始前为
`UPCOMING`
,开始后至“开始时间+时长”为
`ONGOING`
,
之后为
`ENDED`
。考试计划页
只返回尚未
结束
的
场次
,
历史成绩
继续
由成绩管理模块查询。
之后为
`ENDED`
。考试计划页
保留全部场次供管理员追溯,已
结束场次
只读;
历史成绩
仍
由成绩管理模块查询。
## 1. 班级导航树
...
...
@@ -22,9 +22,10 @@
`GET /exam/admin/classes/{classId}`
返回班级名称、工种、年度、等级、培训日期、学期、学员人数和未结束考试数组。每场考试包括
返回班级名称、工种、年度、等级、培训日期、学期、学员人数和全部考试数组,考试按开始时间倒序排列,
`plannedCount`
为本次返回的考试总数(包含已结束场次)。每场考试包括
开始时间、时长、总分/合格分、考评员、监考教师、试卷、考场、状态以及服务端计算的
`editable/deletable`
,
页面不能仅按本地时间决定是否允许操作。
`editable/deletable`
。已结束考试返回
`ENDED / 已结束`
,且不可编辑、不可删除;
页面不能仅按本地时间决定是否允许操作。
## 3. 表单选项
...
...
practical-business/src/test/java/com/platform/business/mapper/ExamMapperXmlTest.java
View file @
0b4397af
...
...
@@ -8,6 +8,8 @@ import org.junit.jupiter.api.Test;
import
java.io.InputStream
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 确保管理员考试新增的动态SQL在应用启动前即可被MyBatis完整解析。 */
...
...
@@ -30,6 +32,21 @@ class ExamMapperXmlTest {
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.ExamMapper.updateAdminExam"
));
/*
* 考试管理必须返回完整历史,不能再用当前时间过滤已结束考试;同时固定按考试时间和
* 主键倒序,确保最新创建、最新开考的记录稳定地展示在列表前方。
*/
org
.
apache
.
ibatis
.
mapping
.
BoundSql
examPlansBoundSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ExamMapper.selectAdminExamPlans"
)
.
getBoundSql
(
Collections
.
singletonMap
(
"classId"
,
1
));
String
examPlansSql
=
examPlansBoundSql
.
getSql
()
.
replaceAll
(
"\\s+"
,
" "
)
.
toLowerCase
();
assertFalse
(
examPlansSql
.
contains
(
"timestampadd"
));
assertEquals
(
1
,
examPlansBoundSql
.
getParameterMappings
().
size
());
assertEquals
(
"classId"
,
examPlansBoundSql
.
getParameterMappings
().
get
(
0
).
getProperty
());
assertTrue
(
examPlansSql
.
contains
(
"order by e.exam_time desc, e.id desc"
));
/*
* 学员详情使用新版 company_name1/company_name2 保存单位,旧数据则仍可能只保存
* factory。这里直接检查 MyBatis 最终生成的 SQL,防止后续改动又退回只查询旧字段,
...
...
practical-business/src/test/java/com/platform/business/mapper/StudentLevelCertMapperXmlTest.java
0 → 100644
View file @
0b4397af
package
com.platform.business.mapper
;
import
com.platform.business.model.dto.StudentLevelCertDTO
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.session.Configuration
;
import
org.junit.jupiter.api.Test
;
import
java.io.InputStream
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 证书管理查询的动态SQL回归测试,防止管理端keyword参数再次被漏接。 */
class
StudentLevelCertMapperXmlTest
{
private
static
final
String
RESOURCE
=
"com/platform/business/mapper/StudentLevelCertMapper.xml"
;
private
static
final
String
STATEMENT
=
"com.platform.business.mapper.StudentLevelCertMapper.queryList"
;
@Test
void
keywordShouldFuzzyMatchVisibleIdentityFields
()
throws
Exception
{
StudentLevelCertDTO
query
=
new
StudentLevelCertDTO
();
query
.
setKeyword
(
"王"
);
String
sql
=
compactSql
(
boundSql
(
query
).
getSql
());
assertTrue
(
sql
.
contains
(
"student_level_cert.user_name like concat('%', ?, '%')"
));
assertTrue
(
sql
.
contains
(
"student_level_cert.id_card like concat('%', ?, '%')"
));
assertTrue
(
sql
.
contains
(
"student_level_cert.cert_no like concat('%', ?, '%')"
));
}
@Test
void
emptyKeywordShouldNotAddFuzzyCondition
()
throws
Exception
{
StudentLevelCertDTO
query
=
new
StudentLevelCertDTO
();
String
sql
=
compactSql
(
boundSql
(
query
).
getSql
());
assertFalse
(
sql
.
contains
(
" like concat("
));
}
/** 解析真实Mapper XML并生成动态SQL,覆盖OGNL字段名和XML语法是否正确。 */
private
BoundSql
boundSql
(
StudentLevelCertDTO
query
)
throws
Exception
{
Configuration
configuration
=
new
Configuration
();
try
(
InputStream
input
=
Resources
.
getResourceAsStream
(
RESOURCE
))
{
XMLMapperBuilder
builder
=
new
XMLMapperBuilder
(
input
,
configuration
,
RESOURCE
,
configuration
.
getSqlFragments
());
builder
.
parse
();
}
return
configuration
.
getMappedStatement
(
STATEMENT
).
getBoundSql
(
query
);
}
/** 压缩SQL空白,避免格式化差异干扰对关键查询片段的断言。 */
private
String
compactSql
(
String
sql
)
{
return
sql
.
replaceAll
(
"\\s+"
,
" "
).
trim
();
}
}
practical-business/src/test/java/com/platform/business/mapper/UserMapperXmlTest.java
0 → 100644
View file @
0b4397af
package
com.platform.business.mapper
;
import
com.platform.business.model.dto.UserDTO
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.session.Configuration
;
import
org.junit.jupiter.api.Test
;
import
java.io.InputStream
;
import
java.util.Locale
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 验证历史用户列表的关键词条件不会绕过教师或其他角色筛选。 */
class
UserMapperXmlTest
{
@Test
void
keywordAndRoleShouldBeCombinedAsTwoCompleteConditions
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
UserDTO
query
=
new
UserDTO
();
query
.
setNickName
(
"2"
);
query
.
setRoleId
(
2
);
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.UserMapper.queryList"
).
getBoundSql
(
query
);
// 压缩空白后验证完整条件顺序:关键词的两个 OR 分支先在括号内完成,
// 教师 roleId 再通过 AND 作用于整个关键词条件,防止账号匹配的学生混入结果。
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
trim
()
.
toLowerCase
(
Locale
.
ROOT
);
assertTrue
(
sql
.
contains
(
"where (user.username like concat('%',?,'%') "
+
"or user.nick_name like concat('%',?,'%')) and role.id = ?"
),
()
->
"关键词与角色条件的分组不正确,实际SQL:"
+
sql
);
}
/** 解析真实 Mapper XML,使测试覆盖 MyBatis 动态标签最终生成的 SQL。 */
private
Configuration
parseMapper
()
throws
Exception
{
Configuration
configuration
=
new
Configuration
();
try
(
InputStream
input
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"com/platform/business/mapper/UserMapper.xml"
))
{
assertNotNull
(
input
);
new
XMLMapperBuilder
(
input
,
configuration
,
"com/platform/business/mapper/UserMapper.xml"
,
configuration
.
getSqlFragments
()).
parse
();
}
return
configuration
;
}
}
practical-business/src/test/java/com/platform/business/service/impl/AccountAdminRosterExcelServiceTest.java
View file @
0b4397af
...
...
@@ -8,6 +8,7 @@ import com.platform.business.model.entity.ClassStudentEntity;
import
com.platform.business.model.entity.SysPhoneRoleEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.AccountAdminDetailVO
;
import
com.platform.business.model.vo.AccountAdminListVO
;
import
com.platform.business.model.vo.AccountImportResultVO
;
import
com.platform.business.model.vo.AccountStudentRosterVO
;
import
com.platform.business.service.ClassStudentService
;
...
...
@@ -36,6 +37,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.time.Instant
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Date
;
...
...
@@ -276,6 +278,32 @@ class AccountAdminRosterExcelServiceTest {
}
}
/**
* 从服务导出的真实工作簿回读状态和最后登录时间,确保格式化方法已经接入教师、
* 管理员共用的账户清单导出链路,而不只是独立工具方法测试通过。
*/
@Test
void
staffExportShouldWriteChineseStatusAndStandardLoginTime
()
throws
Exception
{
AccountAdminListVO
row
=
new
AccountAdminListVO
();
row
.
setName
(
"王老师"
);
row
.
setStatus
(
"ENABLED"
);
row
.
setLastLoginTime
(
Date
.
from
(
Instant
.
parse
(
"2026-09-03T08:15:20Z"
)));
when
(
accountAdminMapper
.
selectAccounts
(
any
(
AccountAdminQueryDTO
.
class
),
anyString
(),
any
(
Date
.
class
))).
thenReturn
(
Collections
.
singletonList
(
row
));
AccountAdminQueryDTO
query
=
new
AccountAdminQueryDTO
();
query
.
setAccountType
(
"TEACHER"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
service
.
export
(
query
,
response
);
try
(
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
new
ByteArrayInputStream
(
response
.
getContentAsByteArray
())))
{
Row
exported
=
workbook
.
getSheet
(
"账户清单"
).
getRow
(
1
);
assertEquals
(
"启用"
,
exported
.
getCell
(
7
).
getStringCellValue
());
assertEquals
(
"2026-09-03 16:15:20"
,
exported
.
getCell
(
8
).
getStringCellValue
());
}
}
private
byte
[]
downloadTemplate
(
String
type
)
{
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
service
.
downloadTemplate
(
type
,
response
);
...
...
practical-business/src/test/java/com/platform/business/service/impl/AccountAdminServiceImplTest.java
View file @
0b4397af
...
...
@@ -5,6 +5,7 @@ import com.platform.exception.BusinessException;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
java.time.Instant
;
import
java.util.Date
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
...
...
@@ -65,4 +66,26 @@ class AccountAdminServiceImplTest {
reversed
.
setEndDate
(
new
Date
(
1_000L
));
assertThrows
(
BusinessException
.
class
,
()
->
service
.
normalizeQuery
(
reversed
));
}
/** 覆盖学员和教职工的全部合法状态,防止导出再次泄露英文枚举值。 */
@Test
void
exportStatusLabelShouldUseReadableChineseText
()
{
assertEquals
(
"待激活"
,
service
.
exportStatusLabel
(
"PENDING"
));
assertEquals
(
"在读"
,
service
.
exportStatusLabel
(
"STUDYING"
));
assertEquals
(
"已结业"
,
service
.
exportStatusLabel
(
"GRADUATED"
));
assertEquals
(
"已归档"
,
service
.
exportStatusLabel
(
"ARCHIVED"
));
assertEquals
(
"启用"
,
service
.
exportStatusLabel
(
"ENABLED"
));
assertEquals
(
"禁用"
,
service
.
exportStatusLabel
(
"DISABLED"
));
assertEquals
(
""
,
service
.
exportStatusLabel
(
null
));
assertEquals
(
"UNKNOWN"
,
service
.
exportStatusLabel
(
"UNKNOWN"
));
}
/** 验证导出时间不依赖运行测试的机器时区,并且未登录账户输出空单元格。 */
@Test
void
formatExportDateTimeShouldUseShanghaiTimeAndSecondPrecision
()
{
Date
loginTime
=
Date
.
from
(
Instant
.
parse
(
"2026-09-03T08:15:20Z"
));
assertEquals
(
"2026-09-03 16:15:20"
,
service
.
formatExportDateTime
(
loginTime
));
assertEquals
(
""
,
service
.
formatExportDateTime
(
null
));
}
}
practical-business/src/test/java/com/platform/business/service/impl/ExamAdminServiceImplTest.java
View file @
0b4397af
...
...
@@ -57,6 +57,31 @@ class ExamAdminServiceImplTest {
@InjectMocks
private
ExamAdminServiceImpl
service
;
@Test
void
classPlansShouldKeepEndedExamsAndCountAllStatuses
()
{
long
now
=
System
.
currentTimeMillis
();
ExamAdminClassVO
managedClass
=
managedClass
();
ExamAdminDetailVO
upcoming
=
examAt
(
new
Date
(
now
+
3_600_000L
),
60
);
ExamAdminDetailVO
ongoing
=
examAt
(
new
Date
(
now
-
30
*
60_000L
),
60
);
ExamAdminDetailVO
ended
=
examAt
(
new
Date
(
now
-
2
*
3_600_000L
),
60
);
when
(
examMapper
.
selectAdminExamClass
(
1
)).
thenReturn
(
managedClass
);
// Mapper的返回顺序即页面顺序;这里同时放入三种状态,验证服务不会再次丢弃历史考试。
when
(
examMapper
.
selectAdminExamPlans
(
1
)).
thenReturn
(
Arrays
.
asList
(
upcoming
,
ongoing
,
ended
));
ExamAdminClassVO
result
=
service
.
classPlans
(
1
);
assertEquals
(
3
,
result
.
getPlannedCount
());
assertEquals
(
3
,
result
.
getExams
().
size
());
assertEquals
(
ExamAdminConstants
.
STATUS_UPCOMING
,
upcoming
.
getStatus
());
assertEquals
(
ExamAdminConstants
.
STATUS_ONGOING
,
ongoing
.
getStatus
());
assertEquals
(
ExamAdminConstants
.
STATUS_ENDED
,
ended
.
getStatus
());
assertEquals
(
"已结束"
,
ended
.
getStatusName
());
assertFalse
(
ended
.
getEditable
());
assertFalse
(
ended
.
getDeletable
());
verify
(
examMapper
).
selectAdminExamPlans
(
1
);
}
@Test
void
createShouldSnapshotPaperScoreAndSaveAllCandidates
()
{
ExamAdminSaveDTO
request
=
validCreateRequest
();
...
...
@@ -372,6 +397,15 @@ class ExamAdminServiceImplTest {
when
(
examMapper
.
selectAdminExamClass
(
1
)).
thenReturn
(
managedClass
());
}
/** 构造只包含状态计算必需字段的考试记录,避免测试被无关展示字段干扰。 */
private
ExamAdminDetailVO
examAt
(
Date
examTime
,
int
duration
)
{
ExamAdminDetailVO
exam
=
new
ExamAdminDetailVO
();
exam
.
setExamTime
(
examTime
);
exam
.
setDuration
(
duration
);
exam
.
setAttemptCount
(
0
);
return
exam
;
}
private
void
mockValidPaper
()
{
TheoreticalPaperEntity
paper
=
new
TheoreticalPaperEntity
();
paper
.
setId
(
"paper-1"
);
...
...
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