diff --git a/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/LoginUser.java b/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/LoginUser.java index 0e170fa7..9a2fdd70 100644 --- a/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/LoginUser.java +++ b/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/LoginUser.java @@ -17,6 +17,7 @@ import java.util.Map; */ @Data public class LoginUser { + public static final String INFO_KEY_SEX = "sex"; public static final String INFO_KEY_SFZ = "sfz"; public static final String INFO_KEY_USERNAME = "username"; public static final String INFO_KEY_NICKNAME = "nickname"; diff --git a/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/util/SecurityFrameworkUtils.java b/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/util/SecurityFrameworkUtils.java index 1756de24..9069ccb1 100644 --- a/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/util/SecurityFrameworkUtils.java +++ b/exam-framework/exam-spring-boot-starter-security/src/main/java/pc/exam/pp/framework/security/core/util/SecurityFrameworkUtils.java @@ -109,6 +109,16 @@ public class SecurityFrameworkUtils { LoginUser loginUser = getLoginUser(); return loginUser != null ? MapUtil.getStr(loginUser.getInfo(), LoginUser.INFO_KEY_SFZ) : null; } + /** + * 获得当前用户的性别,从上下文中 + * + * @return 用户编号 + */ + @Nullable + public static String getLoginUserSEX() { + LoginUser loginUser = getLoginUser(); + return loginUser != null ? MapUtil.getStr(loginUser.getInfo(), LoginUser.INFO_KEY_SEX) : null; + } /** * 获得当前用户的租户ID,从上下文中 * diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/monitor/MonitorController.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/monitor/MonitorController.java index e275d132..91c8f5a5 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/monitor/MonitorController.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/monitor/MonitorController.java @@ -87,13 +87,15 @@ public void exportMonitorExcel(@Valid MonitorPageReqVO pageReqVO, HttpServletRes @PostMapping("/stuMonitor") @Operation(summary = "学生端进入考试返回值") - public CommonResult getStuMonitor(@Valid @RequestBody StuMonitorPaperVo stuMonitorPaperVo) { - Boolean stuMonitor = monitorService.getStuMonitor(stuMonitorPaperVo); - if (stuMonitor) + public CommonResult getStuMonitor(@Valid @RequestBody StuMonitorPaperVo stuMonitorPaperVo) { + long stuMonitor = monitorService.getStuMonitor(stuMonitorPaperVo); + if (stuMonitor>0) { - return success("进入考试成功"); + return success(stuMonitor); + }else { + return error(DEMO03_MONITOR_TIME_EXISTS); + } - return error(DEMO03_MONITOR_TIME_EXISTS); } @PostMapping("/stuMonitorQu") diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/paper/vo/StuInfoPaper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/paper/vo/StuInfoPaper.java index 6542296e..2d4c095f 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/paper/vo/StuInfoPaper.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/paper/vo/StuInfoPaper.java @@ -25,4 +25,6 @@ public class StuInfoPaper { private Time answerTime; + private String sex; + } diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/specialty/ExamSpecialtyController.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/specialty/ExamSpecialtyController.java index ee3fc1fb..d7a0aa07 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/specialty/ExamSpecialtyController.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/specialty/ExamSpecialtyController.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import pc.exam.pp.framework.common.pojo.CommonResult; import pc.exam.pp.framework.common.util.object.BeanUtils; +import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils; import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialRolesVo; import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtListReqVo; import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtyQueryVo; diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorService.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorService.java index b2d3ed24..8d6bc15b 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorService.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorService.java @@ -53,7 +53,7 @@ import java.util.List; */ PageResult getMonitorPage(MonitorPageReqVO pageReqVO); - Boolean getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo); + long getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo); Boolean updateStuMonitor(StuMonitorQuVo stuMonitorQuVo); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorServiceImpl.java index 3cbdecee..f9add552 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorServiceImpl.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/monitor/MonitorServiceImpl.java @@ -13,6 +13,7 @@ import org.springframework.validation.annotation.Validated; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.sql.Time; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -111,11 +112,9 @@ public class MonitorServiceImpl implements MonitorService { return monitorMapper.selectPage(pageReqVO); } @Override - public Boolean getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo) { + public long getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo) { String key = "userCache:"+stuMonitorPaperVo.getTaskId()+":" + stuMonitorPaperVo.getStuId(); MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class); -// MonitorDO info=new MonitorDO(); - if (StringUtils.isNotBlank(stuMonitorPaperVo.getPaperId())){ EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(stuMonitorPaperVo.getPaperId()); String counts = educationPaper.getCounts(); @@ -140,52 +139,72 @@ public class MonitorServiceImpl implements MonitorService { if (info.getRemainingTime()==null){ stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info)); monitorMapper.updateById(info); - return true; + return 24 * 60 * 60L; // (1天) }else { - EducationPaperPerson educationPaperPerson = educationPaperPersonMapper.selectByTaskIdAndPersonId(stuMonitorPaperVo.getTaskId(), stuMonitorPaperVo.getStuId()); - EducationPaperSession educationPaperSession = educationPaperSessionMapper.selectEducationPaperSessionBySessionId(educationPaperPerson.getSessionId()); + EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(stuMonitorPaperVo.getTaskId()); + //测评时长 + Time examTime = educationPaperParam.getExamTime(); + + //判断是否开启测评时长限制 + //开启测评时长限制 开启场次 判断场次时间 ,,,,没开启测评时长限制 开启场次 -判断场次时间 + if ("0".equals(educationPaperParam.getIsSession())){ + //获得场次开始时间, 结束时间 判断是否在 时间范围内 + + EducationPaperPerson educationPaperPerson = educationPaperPersonMapper.selectByTaskIdAndPersonId(stuMonitorPaperVo.getTaskId(), stuMonitorPaperVo.getStuId()); + EducationPaperSession educationPaperSession = educationPaperSessionMapper.selectEducationPaperSessionBySessionId(educationPaperPerson.getSessionId()); - //结束时间 - Date endTime = educationPaperSession.getEndTime(); - //开始时间 - Date startTime = educationPaperSession.getStartTime(); - //开始考试前分钟,允许入场 - String allowEntry = educationPaperSession.getAllowEntry(); - //开始考试后分钟,禁止入场 - String endAllowEntry = educationPaperSession.getEndAllowEntry(); + //结束时间 + Date endTime = educationPaperSession.getEndTime(); + //开始时间 + Date startTime = educationPaperSession.getStartTime(); + //开始考试前分钟,允许入场 + String allowEntry = educationPaperSession.getAllowEntry(); + //开始考试后分钟,禁止入场 + String endAllowEntry = educationPaperSession.getEndAllowEntry(); - LocalDateTime now = LocalDateTime.now(); - LocalDateTime start = DateUtil.toLocalDateTime(startTime); - LocalDateTime end = DateUtil.toLocalDateTime(endTime); + LocalDateTime now = LocalDateTime.now(); + LocalDateTime start = DateUtil.toLocalDateTime(startTime); + LocalDateTime end = DateUtil.toLocalDateTime(endTime); - // 考试开始前允许入场时间(分钟) - int allowEntryMin = Integer.parseInt(allowEntry); + // 考试开始前允许入场时间(分钟) + int allowEntryMin = Integer.parseInt(allowEntry); - // 考试开始后允许入场时间(分钟) - int endAllowEntryMin = Integer.parseInt(endAllowEntry); + // 考试开始后允许入场时间(分钟) + int endAllowEntryMin = Integer.parseInt(endAllowEntry); - // 入场允许范围: [start , end + endAllowEntryMin] - LocalDateTime entryEnd = end.plusMinutes(endAllowEntryMin); + // 入场允许范围: [start-allowEntryMin , end + endAllowEntryMin] + LocalDateTime entryStart = start.minusMinutes(allowEntryMin); + LocalDateTime entryEnd = end.plusMinutes(endAllowEntryMin); + //包含边界值 + boolean isWithinEntryTime = !now.isBefore(entryStart) && !now.isAfter(entryEnd); + System.out.println("是否在允许入场时间段内:" + isWithinEntryTime); - boolean isWithinEntryTime = now.isAfter(start) && now.isBefore(entryEnd); - System.out.println("是否在允许入场时间段内:" + isWithinEntryTime); + if (isWithinEntryTime){ + long remainingSeconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), + DateUtil.toLocalDateTime(endTime)); + info.setRemainingTime(remainingSeconds > 0 ? remainingSeconds : 0); - if (isWithinEntryTime){ - long remainingSeconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), - DateUtil.toLocalDateTime(endTime)); - info.setRemainingTime(remainingSeconds > 0 ? remainingSeconds : 0); - - - //判分后删除 -// stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info), remainingSeconds, TimeUnit.SECONDS); - stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info)); - - monitorMapper.updateById(info); - return true; - }else { - return false; + //判分后删除 + stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info)); + monitorMapper.updateById(info); + return remainingSeconds > 0 ? remainingSeconds : 0; + }else { + return 0; + } } + + //开启测评时长限制 没开启场次 -直接返回测评时长 + + if ("1".equals(educationPaperParam.getIsSession())&&"0".equals(educationPaperParam.getIsTime())){ + + info.setRemainingTime((long) examTime.toLocalTime().toSecondOfDay()); + + + return (long) examTime.toLocalTime().toSecondOfDay(); + } + + return 0L; } } @@ -301,6 +320,12 @@ public class MonitorServiceImpl implements MonitorService { monitorDO1.setStuId(stuId); monitorDO1.setUsername(personRepDto.getUsername()); monitorDO1.setNickname(personRepDto.getNickname()); + EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId); + Time examTime = educationPaperParam.getExamTime(); + //如果开启了 时长限制 或者考场 + if ("0".equals(educationPaperParam.getIsTime())||"0".equals(educationPaperParam.getIsSession())){ + monitorDO1.setRemainingTime((long) examTime.toLocalTime().toSecondOfDay()); + } stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(monitorDO1)); }else { info.setExamStatus(status); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperPersonServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperPersonServiceImpl.java index 70a5b39e..8f4a151f 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperPersonServiceImpl.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperPersonServiceImpl.java @@ -173,12 +173,13 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer for (String studentId : studentIds) { // 查询是否存在该 taskId + studentId 的记录,且 sessionId 为 null EducationPaperPerson existing = educationPaperPersonMapper.selectByTaskIdAndPersonId(taskId, studentId); + //学生已在试卷任务里,给学生设置考场 if (existing != null && (existing.getSessionId() == null || existing.getSessionId().isEmpty())) { // 更新已有记录的 sessionId 和 batch existing.setSessionId(sessionId); existing.setBatch(batch); educationPaperPersonMapper.updateByTaskIdAndStuId(existing); - //todo 本来没有设置考场的,这里要更新缓存的 剩余时间 + // 本来没有设置考场的,这里要更新缓存的 剩余时间 EducationPaperSession educationPaperSession = educationPaperSessionMapper.selectEducationPaperSessionBySessionId(sessionId); String key = "userCache:" + taskId+":"+studentId; MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class); @@ -206,6 +207,7 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer } + //把学生加到试卷任务里 if (existing == null) { EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskId); String name= educationPaperTaskMapper.selectEducationPaperTaskNameByid(taskId); @@ -222,10 +224,12 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer info.setUsername(personRepDto.getUsername()); info.setNickname(personRepDto.getNickname()); //判断是否开启测评时长限制 + Time examTime = educationPaperParam.getExamTime(); + //开启测评时长限制 if ("0".equals(educationPaperParam.getIsTime())){ - Time examTime = educationPaperParam.getExamTime(); info.setRemainingTime((long) examTime.toLocalTime().toSecondOfDay()); } + //设置学生班级 if (StringUtils.isNotBlank(personRepDto.getClassId().toString())){ String className=educationPaperTaskMapper.selectStuClassNameByClassId(personRepDto.getClassId()); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperQuServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperQuServiceImpl.java index 3d3fb579..ac469299 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperQuServiceImpl.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperQuServiceImpl.java @@ -154,6 +154,7 @@ public class EducationPaperQuServiceImpl implements IEducationPaperQuService stuInfoPaper.setTaskName(educationPaperTask.getTaskName()); stuInfoPaper.setUserName(SecurityFrameworkUtils.getLoginUserName()); stuInfoPaper.setSfz(SecurityFrameworkUtils.getLoginUserSFZ()); + stuInfoPaper.setSex(SecurityFrameworkUtils.getLoginUserSEX()); ExamPaperVo examPaperVo=new ExamPaperVo(); examPaperVo.setPaperId(paperId); examPaperVo.setExamQuestionList(examQuestionList); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperServiceImpl.java index ad96c8c0..6a4279da 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperServiceImpl.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperServiceImpl.java @@ -444,7 +444,7 @@ public class EducationPaperServiceImpl implements IEducationPaperService Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId(); String schoolName= examQuestionMapper.selectSchoolnameBytId(loginTenantId); stuInfoPaper.setSchoolName(schoolName); - + stuInfoPaper.setSex(SecurityFrameworkUtils.getLoginUserSEX()); ExamPaperVo examPaperVo=new ExamPaperVo(); examPaperVo.setExamQuestionList(examQuestionList); examPaperVo.setEducationPaperSchemeList(educationPaperSchemeList); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperTaskServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperTaskServiceImpl.java index dde860bd..b8e2059e 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperTaskServiceImpl.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/paper/EducationPaperTaskServiceImpl.java @@ -437,6 +437,7 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService stuInfoPaper.setUserName(SecurityFrameworkUtils.getLoginUserName()); stuInfoPaper.setSfz(SecurityFrameworkUtils.getLoginUserSFZ()); stuInfoPaper.setSchoolName(schoolName); + stuInfoPaper.setSex(SecurityFrameworkUtils.getLoginUserSEX()); ExamPaperVo examPaperVo=new ExamPaperVo(); examPaperVo.setExamQuestionList(examQuestionList); examPaperVo.setEducationPaperSchemeList(educationPaperSchemeList); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/EducationPaperTaskMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/EducationPaperTaskMapper.xml index c61ed92b..d11939c8 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/EducationPaperTaskMapper.xml +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/EducationPaperTaskMapper.xml @@ -65,6 +65,7 @@ FROM exam_knowledge_points WHERE FIND_IN_SET(#{id}, ancestors) and deleted='0' + and status='0' ORDER BY order_num; diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/knowledge/ExamKnowledgePointsMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/knowledge/ExamKnowledgePointsMapper.xml index 43395578..3a7899fb 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/knowledge/ExamKnowledgePointsMapper.xml +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/knowledge/ExamKnowledgePointsMapper.xml @@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" --- delete from knowledge_points + delete from knowledge_points update exam_knowledge_points deleted = 1 diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/oauth2/OAuth2TokenServiceImpl.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/oauth2/OAuth2TokenServiceImpl.java index a08b4c0e..00bdca3f 100644 --- a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/oauth2/OAuth2TokenServiceImpl.java +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/oauth2/OAuth2TokenServiceImpl.java @@ -204,6 +204,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { .put(LoginUser.INFO_KEY_QUEUE, StrUtil.toStringOrNull(user.getQueueName())) .put(LoginUser.INFO_KEY_USERNAME,StrUtil.toStringOrNull(user.getUsername())) .put(LoginUser.INFO_KEY_SFZ,StrUtil.toStringOrNull(user.getSfz())) + .put(LoginUser.INFO_KEY_SEX,StrUtil.toStringOrNull(user.getSex())) .build(); } else if (userType.equals(UserTypeEnum.MEMBER.getValue())) { // 注意:目前 Member 暂时不读取,可以按需实现