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
fb3c0f0e
Commit
fb3c0f0e
authored
Nov 05, 2026
by
wujipeng
Browse files
教务管理-班级管理-班级详情-学员名单-优化
parent
29ed92a5
Changes
25
Hide whitespace changes
Inline
Side-by-side
practical-business/src/main/resources/sql/class_management.sql
View file @
fb3c0f0e
...
...
@@ -148,3 +148,39 @@ where occupation is null
or
training_year
is
null
or
start_date
is
null
or
end_date
is
null
;
-- 学员移除/转班后,class_student只保留当前有效关系;本表保存不可变的历史轨迹。
-- 不设置外键,保持与项目现有业务表一致,由班级学员服务在同一事务内保证引用有效。
create
table
if
not
exists
class_student_change_log
(
id
bigint
not
null
auto_increment
comment
'主键'
,
user_id
varchar
(
64
)
not
null
comment
'学员用户ID'
,
source_class_id
int
not
null
comment
'原班级ID'
,
target_class_id
int
null
comment
'目标班级ID,移除操作为空'
,
operation_type
varchar
(
16
)
not
null
comment
'操作类型:REMOVE/TRANSFER'
,
operator_id
varchar
(
64
)
null
comment
'管理员用户ID'
,
operation_time
datetime
not
null
comment
'操作时间'
,
primary
key
(
id
),
index
idx_class_student_change_user
(
user_id
,
operation_time
),
index
idx_class_student_change_source
(
source_class_id
,
operation_time
),
index
idx_class_student_change_target
(
target_class_id
,
operation_time
)
)
comment
=
'班级学员关系变更记录'
;
-- 班级维度的结业记录用于保留批次、说明和电子证书,不复用职业资格证书字段。
-- 唯一键阻止同一学员在同一班级因重复点击产生两条结业记录。
create
table
if
not
exists
student_graduation_record
(
id
bigint
not
null
auto_increment
comment
'主键'
,
class_id
int
not
null
comment
'结业班级ID'
,
user_id
varchar
(
64
)
not
null
comment
'学员用户ID'
,
graduation_date
date
not
null
comment
'结业日期'
,
batch_no
varchar
(
100
)
null
comment
'结业批次'
,
remark
varchar
(
1000
)
null
comment
'结业说明'
,
certificate_issued
tinyint
(
1
)
not
null
default
0
comment
'是否发放电子结业证书'
,
certificate_no
varchar
(
64
)
null
comment
'电子结业证书编号'
,
notification_requested
tinyint
(
1
)
not
null
default
0
comment
'是否请求发送站内通知'
,
operator_id
varchar
(
64
)
null
comment
'管理员用户ID'
,
create_time
datetime
not
null
comment
'创建时间'
,
primary
key
(
id
),
unique
key
uk_student_graduation_class_user
(
class_id
,
user_id
),
unique
key
uk_student_graduation_certificate
(
certificate_no
),
index
idx_student_graduation_user
(
user_id
,
graduation_date
)
)
comment
=
'学员结业办理记录'
;
practical-business/src/test/java/com/platform/business/mapper/ClassMapperXmlTest.java
View file @
fb3c0f0e
...
...
@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
...
...
@@ -47,6 +48,31 @@ class ClassMapperXmlTest {
"order by min(subject.date) asc, min(subject.time_frame) asc, min(subject.id) asc"
));
}
@Test
void
adminStudentSqlShouldSupportDetailLockAndSafePendingExamCleanup
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
Map
<
String
,
Object
>
detail
=
new
HashMap
<>();
detail
.
put
(
"classId"
,
1
);
detail
.
put
(
"userId"
,
"u1"
);
String
detailSql
=
compactSql
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ClassMapper.selectAdminStudent"
)
.
getBoundSql
(
detail
).
getSql
());
assertTrue
(
detailSql
.
contains
(
"theory_exam.type = '理论考试'"
));
assertTrue
(
detailSql
.
contains
(
"practice_exam.type = '实训考试'"
));
assertTrue
(
detailSql
.
contains
(
"cs_member.user_id = ?"
));
Map
<
String
,
Object
>
batch
=
new
HashMap
<>();
batch
.
put
(
"classId"
,
1
);
batch
.
put
(
"userIds"
,
Collections
.
singletonList
(
"u1"
));
batch
.
put
(
"now"
,
new
java
.
util
.
Date
());
String
cleanupSql
=
compactSql
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ClassMapper.deletePendingExamStudents"
)
.
getBoundSql
(
batch
).
getSql
());
assertTrue
(
cleanupSql
.
contains
(
"e.exam_time > ?"
));
assertTrue
(
cleanupSql
.
contains
(
"student.score is null"
));
assertTrue
(
cleanupSql
.
contains
(
"student.answer_time is null"
));
}
private
static
Configuration
parseMapper
()
throws
Exception
{
String
resource
=
"com/platform/business/mapper/ClassMapper.xml"
;
Configuration
configuration
=
new
Configuration
();
...
...
practical-business/src/test/java/com/platform/business/service/impl/ClassAdminServiceImplTest.java
View file @
fb3c0f0e
...
...
@@ -141,7 +141,7 @@ class ClassAdminServiceImplTest {
@Test
void
updateShouldRejectCapacityBelowActualStudents
()
{
when
(
classMapper
.
selectById
(
7
)).
thenReturn
(
new
ClassEntity
());
when
(
classMapper
.
selectById
(
7
)).
thenReturn
(
upcomingClass
());
when
(
classMapper
.
countAdminStudents
(
7
)).
thenReturn
(
35
);
mockValidLevel
();
ClassAdminSaveDTO
request
=
validRequest
();
...
...
@@ -153,7 +153,7 @@ class ClassAdminServiceImplTest {
@Test
void
updateShouldExplicitlyClearOptionalFields
()
{
when
(
classMapper
.
selectById
(
7
)).
thenReturn
(
new
ClassEntity
());
when
(
classMapper
.
selectById
(
7
)).
thenReturn
(
upcomingClass
());
when
(
classMapper
.
countAdminStudents
(
7
)).
thenReturn
(
10
);
mockValidLevel
();
when
(
classMapper
.
countAdminDuplicateName
(
2026
,
"污水处理一级三班"
,
7
)).
thenReturn
(
0
);
...
...
@@ -296,4 +296,12 @@ class ClassAdminServiceImplTest {
detail
.
setEndDate
(
end
);
return
detail
;
}
/** 编辑接口只允许待开课班级,测试数据必须显式提供未来日期,避免依赖执行当天。 */
private
ClassEntity
upcomingClass
()
{
ClassEntity
entity
=
new
ClassEntity
();
entity
.
setStartDate
(
Date
.
valueOf
(
LocalDate
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
).
plusDays
(
1
)));
entity
.
setEndDate
(
Date
.
valueOf
(
LocalDate
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
).
plusDays
(
30
)));
return
entity
;
}
}
practical-business/src/test/java/com/platform/business/service/impl/ClassAdminStudentServiceImplTest.java
0 → 100644
View file @
fb3c0f0e
package
com.platform.business.service.impl
;
import
com.platform.business.mapper.ClassMapper
;
import
com.platform.business.mapper.ClassStudentChangeLogMapper
;
import
com.platform.business.mapper.StudentGraduationRecordMapper
;
import
com.platform.business.model.dto.ClassStudentExportDTO
;
import
com.platform.business.model.dto.ClassStudentGraduationDTO
;
import
com.platform.business.model.dto.ClassStudentIdsDTO
;
import
com.platform.business.model.dto.ClassStudentTransferDTO
;
import
com.platform.business.model.entity.ClassEntity
;
import
com.platform.business.model.entity.ClassStudentChangeLogEntity
;
import
com.platform.business.model.entity.StudentGraduationRecordEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.ClassAdminStudentVO
;
import
com.platform.business.model.vo.ClassStudentExportFileVO
;
import
com.platform.business.model.vo.ClassStudentGraduationResultVO
;
import
com.platform.business.service.BusinessNotificationPublisher
;
import
com.platform.business.service.SysLevelService
;
import
com.platform.business.service.SysPhoneRoleService
;
import
com.platform.business.service.UserService
;
import
com.platform.exception.BusinessException
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
java.nio.charset.StandardCharsets
;
import
java.sql.Date
;
import
java.time.LocalDate
;
import
java.util.Arrays
;
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
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** 班级详情学员名单写操作、结业判定和CSV导出的核心回归测试。 */
@ExtendWith
(
MockitoExtension
.
class
)
class
ClassAdminStudentServiceImplTest
{
@Mock
private
ClassMapper
classMapper
;
@Mock
private
SysLevelService
sysLevelService
;
@Mock
private
UserService
userService
;
@Mock
private
SysPhoneRoleService
phoneRoleService
;
@Mock
private
ClassStudentChangeLogMapper
changeLogMapper
;
@Mock
private
StudentGraduationRecordMapper
graduationRecordMapper
;
@Mock
private
BusinessNotificationPublisher
notificationPublisher
;
@InjectMocks
private
ClassAdminServiceImpl
service
;
@Test
void
removeShouldAuditCleanPendingExamsAndDeleteCurrentRelations
()
{
ClassEntity
source
=
activeClass
(
1
,
"原班级"
);
when
(
classMapper
.
selectById
(
1
)).
thenReturn
(
source
);
when
(
classMapper
.
lockAdminStudentIds
(
1
,
Arrays
.
asList
(
"u1"
,
"u2"
)))
.
thenReturn
(
Arrays
.
asList
(
"u1"
,
"u2"
));
when
(
changeLogMapper
.
insert
(
any
(
ClassStudentChangeLogEntity
.
class
))).
thenReturn
(
1
);
when
(
classMapper
.
deleteAdminStudentRelations
(
1
,
Arrays
.
asList
(
"u1"
,
"u2"
))).
thenReturn
(
2
);
ClassStudentIdsDTO
request
=
new
ClassStudentIdsDTO
();
request
.
setStudentIds
(
Arrays
.
asList
(
"u1"
,
"u2"
,
"u1"
));
assertEquals
(
2
,
service
.
removeStudents
(
1
,
request
,
operator
()).
getAffectedCount
());
verify
(
classMapper
).
deletePendingExamStudents
(
eq
(
1
),
eq
(
Arrays
.
asList
(
"u1"
,
"u2"
)),
any
());
verify
(
classMapper
).
deleteAdminStudentRelations
(
1
,
Arrays
.
asList
(
"u1"
,
"u2"
));
}
@Test
void
transferShouldRejectEndedTargetBeforeChangingRelations
()
{
when
(
classMapper
.
selectById
(
1
)).
thenReturn
(
activeClass
(
1
,
"原班级"
));
ClassEntity
ended
=
new
ClassEntity
();
ended
.
setId
(
2
);
ended
.
setName
(
"已结课班级"
);
ended
.
setStartDate
(
Date
.
valueOf
(
LocalDate
.
now
().
minusMonths
(
2
)));
ended
.
setEndDate
(
Date
.
valueOf
(
LocalDate
.
now
().
minusDays
(
1
)));
when
(
classMapper
.
selectById
(
2
)).
thenReturn
(
ended
);
ClassStudentTransferDTO
request
=
new
ClassStudentTransferDTO
();
request
.
setTargetClassId
(
2
);
request
.
setStudentIds
(
Collections
.
singletonList
(
"u1"
));
assertThrows
(
BusinessException
.
class
,
()
->
service
.
transferStudents
(
1
,
request
,
operator
()));
verify
(
classMapper
,
never
()).
deleteAdminStudentRelations
(
any
(),
any
());
}
@Test
void
passedOnlyGraduationShouldSkipStudentMissingPracticeScore
()
{
when
(
classMapper
.
selectById
(
1
)).
thenReturn
(
activeClass
(
1
,
"测试班"
));
when
(
classMapper
.
lockAdminStudentIds
(
1
,
Collections
.
singletonList
(
"u1"
)))
.
thenReturn
(
Collections
.
singletonList
(
"u1"
));
ClassAdminStudentVO
student
=
student
(
"u1"
,
"张三"
);
student
.
setTheoryScore
(
80
D
);
student
.
setPracticalScore
(
null
);
student
.
setAccountStatus
(
"STUDYING"
);
when
(
classMapper
.
selectAdminStudent
(
1
,
"u1"
)).
thenReturn
(
student
);
ClassStudentGraduationDTO
request
=
graduationRequest
(
"PASSED_ONLY"
);
ClassStudentGraduationResultVO
result
=
service
.
graduateStudents
(
1
,
request
,
operator
());
assertEquals
(
0
,
result
.
getGraduatedCount
());
assertEquals
(
1
,
result
.
getSkippedCount
());
assertFalse
(
Boolean
.
TRUE
.
equals
(
student
.
getGraduationEligible
()));
verify
(
classMapper
,
never
()).
graduateAdminStudent
(
any
(),
any
(),
any
());
}
@Test
void
exportShouldWriteBomEscapeCsvAndUseSelectedSuffix
()
{
ClassEntity
clazz
=
activeClass
(
1
,
"污水/一班"
);
clazz
.
setOccupation
(
"污水"
);
clazz
.
setTrainingYear
(
2026
);
when
(
classMapper
.
selectById
(
1
)).
thenReturn
(
clazz
);
ClassAdminStudentVO
student
=
student
(
"u1"
,
"张\"三,同学"
);
student
.
setLegacyPersonType1
(
"在职"
);
student
.
setWorkUnit
(
"测试,单位"
);
student
.
setHighestEducation
(
"本科"
);
student
.
setAccountStatus
(
"STUDYING"
);
when
(
classMapper
.
selectAdminStudents
(
1
,
null
)).
thenReturn
(
Collections
.
singletonList
(
student
));
ClassStudentExportDTO
request
=
new
ClassStudentExportDTO
();
request
.
setScope
(
"SELECTED"
);
request
.
setStudentIds
(
Collections
.
singletonList
(
"u1"
));
ClassStudentExportFileVO
file
=
service
.
exportStudents
(
1
,
request
);
String
csv
=
new
String
(
file
.
getContent
(),
StandardCharsets
.
UTF_8
);
assertTrue
(
csv
.
startsWith
(
"\uFEFF"
));
assertTrue
(
csv
.
contains
(
"\"张\"\"三,同学\""
));
assertTrue
(
csv
.
contains
(
"\"测试,单位\""
));
assertTrue
(
file
.
getFileName
().
contains
(
"_选中1名_"
));
assertFalse
(
file
.
getFileName
().
contains
(
"/"
));
}
private
ClassStudentGraduationDTO
graduationRequest
(
String
mode
)
{
ClassStudentGraduationDTO
request
=
new
ClassStudentGraduationDTO
();
request
.
setStudentIds
(
Collections
.
singletonList
(
"u1"
));
request
.
setGraduationDate
(
Date
.
valueOf
(
LocalDate
.
now
()));
request
.
setMode
(
mode
);
request
.
setIssueCertificate
(
true
);
request
.
setNotifyStudent
(
false
);
return
request
;
}
private
ClassAdminStudentVO
student
(
String
id
,
String
name
)
{
ClassAdminStudentVO
student
=
new
ClassAdminStudentVO
();
student
.
setUserId
(
id
);
student
.
setName
(
name
);
student
.
setPhone
(
"13800000000"
);
return
student
;
}
private
ClassEntity
activeClass
(
int
id
,
String
name
)
{
ClassEntity
clazz
=
new
ClassEntity
();
clazz
.
setId
(
id
);
clazz
.
setName
(
name
);
clazz
.
setStartDate
(
Date
.
valueOf
(
LocalDate
.
now
().
minusDays
(
1
)));
clazz
.
setEndDate
(
Date
.
valueOf
(
LocalDate
.
now
().
plusDays
(
1
)));
return
clazz
;
}
private
UserEntity
operator
()
{
UserEntity
user
=
new
UserEntity
();
user
.
setId
(
"admin"
);
user
.
setNickName
(
"管理员"
);
return
user
;
}
}
practical-business/src/test/java/com/platform/business/sql/ClassStudentManagementSqlTest.java
0 → 100644
View file @
fb3c0f0e
package
com.platform.business.sql
;
import
org.junit.jupiter.api.Test
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 验证班级学员操作所需表结构随制品发布,且DDL遵守不指定字符集的交付要求。 */
class
ClassStudentManagementSqlTest
{
@Test
void
migrationShouldContainHistoryGraduationAndNoCharsetClause
()
throws
Exception
{
String
sql
=
resource
(
"sql/class_management.sql"
).
toLowerCase
();
assertTrue
(
sql
.
contains
(
"create table if not exists class_student_change_log"
));
assertTrue
(
sql
.
contains
(
"create table if not exists student_graduation_record"
));
assertTrue
(
sql
.
contains
(
"uk_student_graduation_class_user"
));
assertFalse
(
sql
.
contains
(
"charset="
));
assertFalse
(
sql
.
contains
(
"character set"
));
assertFalse
(
sql
.
contains
(
"collate="
));
}
private
static
String
resource
(
String
path
)
throws
Exception
{
try
(
InputStream
input
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
path
))
{
assertTrue
(
input
!=
null
,
"迁移SQL资源必须存在:"
+
path
);
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
4096
];
int
length
;
while
((
length
=
input
.
read
(
buffer
))
>=
0
)
{
output
.
write
(
buffer
,
0
,
length
);
}
return
new
String
(
output
.
toByteArray
(),
StandardCharsets
.
UTF_8
);
}
}
}
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