Commit a530d209 authored by wujipeng's avatar wujipeng
Browse files

个人信息添加考试类型

parent 67ead0bb
......@@ -81,6 +81,10 @@ public class User {
@TableField("exam_flag")
private Boolean examFlag;
@ApiModelProperty("考试类型")
@TableField("exam_type")
private String examType;
@ApiModelProperty("考生个人考试id")
@TableField("exam_oneself_id")
private Integer examOneselfId;
......
......@@ -205,6 +205,10 @@ public class UserEntity {
@TableField("exam_flag")
private Boolean examFlag;
@ApiModelProperty("考试类型")
@TableField("exam_type")
private String examType;
@ApiModelProperty("考生个人考试id")
@TableField("exam_oneself_id")
private Integer examOneselfId;
......
......@@ -137,7 +137,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
attempt.getExamId(), studentId);
if (attempt.getStartTime() != null && generated > 0) {
// 已经开考时返回原应考记录ID,前端可直接恢复,不再把重复点击当作异常。
markUserExamState(studentId, attempt.getId());
markUserExamState(studentId, attempt);
return attempt.getId();
}
......@@ -152,7 +152,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
throw new BusinessException("考试状态已变化,请刷新后重试");
}
}
markUserExamState(studentId, attempt.getId());
markUserExamState(studentId, attempt);
return attempt.getId();
}
......@@ -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();
update.setId(studentId);
update.setExamFlag(true);
update.setExamOneselfId(examStudentId);
update.setExamOneselfId(attempt.getId());
/*
* examFlag、examOneselfId和examType共同描述同一场进行中的考试,必须从同一个
* Attempt一次性写入,避免重复开考恢复时只修复考试ID而遗留空或错误的考试类型。
*/
update.setExamType(attempt.getExamType());
if (!userService.updateById(update)) {
throw new BusinessException("学员考试状态更新失败");
}
......
......@@ -54,6 +54,7 @@
role.id as roleId,
role.name as roleName,
user.exam_flag,
user.exam_type as examType,
user.exam_oneself_id,
user.level,
user.simulation_flag,
......@@ -73,6 +74,7 @@
<update id="closeExam">
update user
set exam_flag = false,
exam_type = null,
exam_oneself_id = null
where id = #{id}
</update>
......@@ -103,10 +105,20 @@
and coalesce(candidate.submit, 0) = 0
group by candidate.student_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,
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
or target_user.exam_oneself_id is null
or target_user.exam_oneself_id &lt;&gt; active_exam.exam_student_id
or coalesce(target_user.exam_type, '') &lt;&gt; coalesce(selected_exam.type, '')
</update>
</mapper>
......@@ -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.assertTrue;
/** 验证用户查询条件和考试标记批量更新SQL。 */
/** 验证用户查询条件以及考试标记、考试类型的查询和批量更新SQL。 */
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
void keywordAndRoleShouldBeCombinedAsTwoCompleteConditions() throws Exception {
Configuration configuration = parseMapper();
......@@ -52,11 +65,30 @@ class UserMapperXmlTest {
assertTrue(sql.contains("greatest(coalesce(exam_plan.duration, 0), 0)"));
assertTrue(sql.contains(") > ?"));
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_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());
}
@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。 */
private Configuration parseMapper() throws Exception {
String resource = "com/platform/business/mapper/UserMapper.xml";
......
......@@ -7,6 +7,7 @@ import com.platform.business.model.dto.StudentExamCenterQueryDTO;
import com.platform.business.model.entity.TheoreticalPaperDetailEntity;
import com.platform.business.model.entity.TheoreticalPaperEntity;
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.service.TheoreticalPaperDetailService;
import com.platform.business.service.TheoreticalPaperService;
......@@ -108,6 +109,15 @@ class StudentExamCenterServiceImplTest {
assertEquals(1, service.start(1, "student-1"));
verify(studentDetailService, never()).saveBatch(anyCollection());
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment