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
a530d209
"...java/com/git@gitlab.ruzhoukj.com:wujipeng/relation.git" did not exist on "f1ae0d4d0415686f34352f10245467c233ddefc4"
Commit
a530d209
authored
Sep 14, 2026
by
wujipeng
Browse files
个人信息添加考试类型
parent
67ead0bb
Changes
6
Hide whitespace changes
Inline
Side-by-side
practical-api/practical-auth-api/src/main/java/com/platform/auth/model/entity/User.java
View file @
a530d209
...
@@ -81,6 +81,10 @@ public class User {
...
@@ -81,6 +81,10 @@ public class User {
@TableField
(
"exam_flag"
)
@TableField
(
"exam_flag"
)
private
Boolean
examFlag
;
private
Boolean
examFlag
;
@ApiModelProperty
(
"考试类型"
)
@TableField
(
"exam_type"
)
private
String
examType
;
@ApiModelProperty
(
"考生个人考试id"
)
@ApiModelProperty
(
"考生个人考试id"
)
@TableField
(
"exam_oneself_id"
)
@TableField
(
"exam_oneself_id"
)
private
Integer
examOneselfId
;
private
Integer
examOneselfId
;
...
...
practical-api/practical-business-api/src/main/java/com/platform/business/model/entity/UserEntity.java
View file @
a530d209
...
@@ -205,6 +205,10 @@ public class UserEntity {
...
@@ -205,6 +205,10 @@ public class UserEntity {
@TableField
(
"exam_flag"
)
@TableField
(
"exam_flag"
)
private
Boolean
examFlag
;
private
Boolean
examFlag
;
@ApiModelProperty
(
"考试类型"
)
@TableField
(
"exam_type"
)
private
String
examType
;
@ApiModelProperty
(
"考生个人考试id"
)
@ApiModelProperty
(
"考生个人考试id"
)
@TableField
(
"exam_oneself_id"
)
@TableField
(
"exam_oneself_id"
)
private
Integer
examOneselfId
;
private
Integer
examOneselfId
;
...
...
practical-business/src/main/java/com/platform/business/service/impl/StudentExamCenterServiceImpl.java
View file @
a530d209
...
@@ -137,7 +137,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
...
@@ -137,7 +137,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
attempt
.
getExamId
(),
studentId
);
attempt
.
getExamId
(),
studentId
);
if
(
attempt
.
getStartTime
()
!=
null
&&
generated
>
0
)
{
if
(
attempt
.
getStartTime
()
!=
null
&&
generated
>
0
)
{
// 已经开考时返回原应考记录ID,前端可直接恢复,不再把重复点击当作异常。
// 已经开考时返回原应考记录ID,前端可直接恢复,不再把重复点击当作异常。
markUserExamState
(
studentId
,
attempt
.
getId
()
);
markUserExamState
(
studentId
,
attempt
);
return
attempt
.
getId
();
return
attempt
.
getId
();
}
}
...
@@ -152,7 +152,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
...
@@ -152,7 +152,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
throw
new
BusinessException
(
"考试状态已变化,请刷新后重试"
);
throw
new
BusinessException
(
"考试状态已变化,请刷新后重试"
);
}
}
}
}
markUserExamState
(
studentId
,
attempt
.
getId
()
);
markUserExamState
(
studentId
,
attempt
);
return
attempt
.
getId
();
return
attempt
.
getId
();
}
}
...
@@ -405,11 +405,16 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
...
@@ -405,11 +405,16 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
}
}
}
}
private
void
markUserExamState
(
String
studentId
,
Integer
examStudentId
)
{
private
void
markUserExamState
(
String
studentId
,
StudentExamCenterVO
.
Attempt
attempt
)
{
UserEntity
update
=
new
UserEntity
();
UserEntity
update
=
new
UserEntity
();
update
.
setId
(
studentId
);
update
.
setId
(
studentId
);
update
.
setExamFlag
(
true
);
update
.
setExamFlag
(
true
);
update
.
setExamOneselfId
(
examStudentId
);
update
.
setExamOneselfId
(
attempt
.
getId
());
/*
* examFlag、examOneselfId和examType共同描述同一场进行中的考试,必须从同一个
* Attempt一次性写入,避免重复开考恢复时只修复考试ID而遗留空或错误的考试类型。
*/
update
.
setExamType
(
attempt
.
getExamType
());
if
(!
userService
.
updateById
(
update
))
{
if
(!
userService
.
updateById
(
update
))
{
throw
new
BusinessException
(
"学员考试状态更新失败"
);
throw
new
BusinessException
(
"学员考试状态更新失败"
);
}
}
...
...
practical-business/src/main/resources/com/platform/business/mapper/UserMapper.xml
View file @
a530d209
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
role.id as roleId,
role.id as roleId,
role.name as roleName,
role.name as roleName,
user.exam_flag,
user.exam_flag,
user.exam_type as examType,
user.exam_oneself_id,
user.exam_oneself_id,
user.level,
user.level,
user.simulation_flag,
user.simulation_flag,
...
@@ -73,6 +74,7 @@
...
@@ -73,6 +74,7 @@
<update
id=
"closeExam"
>
<update
id=
"closeExam"
>
update user
update user
set exam_flag = false,
set exam_flag = false,
exam_type = null,
exam_oneself_id = null
exam_oneself_id = null
where id = #{id}
where id = #{id}
</update>
</update>
...
@@ -103,10 +105,20 @@
...
@@ -103,10 +105,20 @@
and coalesce(candidate.submit, 0) = 0
and coalesce(candidate.submit, 0) = 0
group by candidate.student_id
group by candidate.student_id
) active_exam on active_exam.student_id = target_user.id
) active_exam on active_exam.student_id = target_user.id
inner join exam_student selected_candidate
on selected_candidate.id = active_exam.exam_student_id
inner join exam selected_exam
on selected_exam.id = selected_candidate.exam_id
<!--
exam_type必须取自min(candidate.id)最终选中的同一条应考记录,不能直接在聚合子查询中
随意选择exam_plan.type,否则同一学员存在多条候选记录时,考试ID和类型可能不对应。
-->
set target_user.exam_flag = true,
set target_user.exam_flag = true,
target_user.exam_oneself_id = active_exam.exam_student_id
target_user.exam_oneself_id = active_exam.exam_student_id,
target_user.exam_type = selected_exam.type
where coalesce(target_user.exam_flag, 0) = 0
where coalesce(target_user.exam_flag, 0) = 0
or target_user.exam_oneself_id is null
or target_user.exam_oneself_id is null
or target_user.exam_oneself_id
<>
active_exam.exam_student_id
or target_user.exam_oneself_id
<>
active_exam.exam_student_id
or coalesce(target_user.exam_type, '')
<>
coalesce(selected_exam.type, '')
</update>
</update>
</mapper>
</mapper>
practical-business/src/test/java/com/platform/business/mapper/UserMapperXmlTest.java
View file @
a530d209
...
@@ -15,9 +15,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
...
@@ -15,9 +15,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 验证用户查询条件
和
考试标记批量更新SQL。 */
/** 验证用户查询条件
以及
考试标记
、考试类型的查询和
批量更新SQL。 */
class
UserMapperXmlTest
{
class
UserMapperXmlTest
{
@Test
void
queryByUserNameShouldReturnCurrentExamType
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.UserMapper.queryByUserName"
)
.
getBoundSql
(
Collections
.
singletonMap
(
"userName"
,
"13800000000"
));
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
(
Locale
.
ROOT
);
// 使用显式别名保证不依赖不同环境的MyBatis下划线转换配置,接口始终返回examType。
assertTrue
(
sql
.
contains
(
"user.exam_type as examtype"
));
}
@Test
@Test
void
keywordAndRoleShouldBeCombinedAsTwoCompleteConditions
()
throws
Exception
{
void
keywordAndRoleShouldBeCombinedAsTwoCompleteConditions
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
Configuration
configuration
=
parseMapper
();
...
@@ -52,11 +65,30 @@ class UserMapperXmlTest {
...
@@ -52,11 +65,30 @@ class UserMapperXmlTest {
assertTrue
(
sql
.
contains
(
"greatest(coalesce(exam_plan.duration, 0), 0)"
));
assertTrue
(
sql
.
contains
(
"greatest(coalesce(exam_plan.duration, 0), 0)"
));
assertTrue
(
sql
.
contains
(
") > ?"
));
assertTrue
(
sql
.
contains
(
") > ?"
));
assertTrue
(
sql
.
contains
(
"coalesce(candidate.submit, 0) = 0"
));
assertTrue
(
sql
.
contains
(
"coalesce(candidate.submit, 0) = 0"
));
assertTrue
(
sql
.
contains
(
"selected_candidate.id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"selected_exam.id = selected_candidate.exam_id"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_flag = true"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_flag = true"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_oneself_id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_oneself_id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_type = selected_exam.type"
));
assertTrue
(
sql
.
contains
(
"coalesce(target_user.exam_type, '') "
+
"<> coalesce(selected_exam.type, '')"
));
assertEquals
(
2
,
boundSql
.
getParameterMappings
().
size
());
assertEquals
(
2
,
boundSql
.
getParameterMappings
().
size
());
}
}
@Test
void
closeExamShouldClearFlagAttemptIdAndExamTypeTogether
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.UserMapper.closeExam"
)
.
getBoundSql
(
Collections
.
singletonMap
(
"id"
,
"student-1"
));
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
(
Locale
.
ROOT
);
// 三个字段描述同一场当前考试,关闭时必须原子清理,避免接口返回已结束考试的类型。
assertTrue
(
sql
.
contains
(
"set exam_flag = false, exam_type = null, "
+
"exam_oneself_id = null"
));
}
/** 解析真实Mapper XML,使测试覆盖MyBatis动态标签最终生成的SQL。 */
/** 解析真实Mapper XML,使测试覆盖MyBatis动态标签最终生成的SQL。 */
private
Configuration
parseMapper
()
throws
Exception
{
private
Configuration
parseMapper
()
throws
Exception
{
String
resource
=
"com/platform/business/mapper/UserMapper.xml"
;
String
resource
=
"com/platform/business/mapper/UserMapper.xml"
;
...
...
practical-business/src/test/java/com/platform/business/service/impl/StudentExamCenterServiceImplTest.java
View file @
a530d209
...
@@ -7,6 +7,7 @@ import com.platform.business.model.dto.StudentExamCenterQueryDTO;
...
@@ -7,6 +7,7 @@ import com.platform.business.model.dto.StudentExamCenterQueryDTO;
import
com.platform.business.model.entity.TheoreticalPaperDetailEntity
;
import
com.platform.business.model.entity.TheoreticalPaperDetailEntity
;
import
com.platform.business.model.entity.TheoreticalPaperEntity
;
import
com.platform.business.model.entity.TheoreticalPaperEntity
;
import
com.platform.business.model.entity.TheoreticalPaperStudentDetailEntity
;
import
com.platform.business.model.entity.TheoreticalPaperStudentDetailEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.StudentExamCenterVO
;
import
com.platform.business.model.vo.StudentExamCenterVO
;
import
com.platform.business.service.TheoreticalPaperDetailService
;
import
com.platform.business.service.TheoreticalPaperDetailService
;
import
com.platform.business.service.TheoreticalPaperService
;
import
com.platform.business.service.TheoreticalPaperService
;
...
@@ -108,6 +109,15 @@ class StudentExamCenterServiceImplTest {
...
@@ -108,6 +109,15 @@ class StudentExamCenterServiceImplTest {
assertEquals
(
1
,
service
.
start
(
1
,
"student-1"
));
assertEquals
(
1
,
service
.
start
(
1
,
"student-1"
));
verify
(
studentDetailService
,
never
()).
saveBatch
(
anyCollection
());
verify
(
studentDetailService
,
never
()).
saveBatch
(
anyCollection
());
verify
(
mapper
,
never
()).
updateAttemptStarted
(
any
(),
any
(),
any
(),
any
());
verify
(
mapper
,
never
()).
updateAttemptStarted
(
any
(),
any
(),
any
(),
any
());
ArgumentCaptor
<
UserEntity
>
userCaptor
=
ArgumentCaptor
.
forClass
(
UserEntity
.
class
);
verify
(
userService
).
updateById
(
userCaptor
.
capture
());
UserEntity
updatedUser
=
userCaptor
.
getValue
();
// 重复开考同样要修复完整的当前考试状态,不能只恢复examFlag和应考记录ID。
assertEquals
(
"student-1"
,
updatedUser
.
getId
());
assertEquals
(
Boolean
.
TRUE
,
updatedUser
.
getExamFlag
());
assertEquals
(
Integer
.
valueOf
(
1
),
updatedUser
.
getExamOneselfId
());
assertEquals
(
ExamAdminConstants
.
TYPE_THEORY
,
updatedUser
.
getExamType
());
}
}
@Test
@Test
...
...
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