ExamRoomStudentRelationServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. package com.keao.edu.user.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.keao.edu.auth.api.client.SysUserFeignService;
  4. import com.keao.edu.auth.api.entity.SysUser;
  5. import com.keao.edu.common.dal.BaseDAO;
  6. import com.keao.edu.common.exception.BizException;
  7. import com.keao.edu.common.page.PageInfo;
  8. import com.keao.edu.common.service.IdGeneratorService;
  9. import com.keao.edu.common.service.impl.BaseServiceImpl;
  10. import com.keao.edu.common.tenant.TenantContextHolder;
  11. import com.keao.edu.im.api.client.ImFeignService;
  12. import com.keao.edu.im.api.entity.MemberChangedMessage;
  13. import com.keao.edu.im.api.entity.PublishMessageDto;
  14. import com.keao.edu.im.api.entity.ReqUserData;
  15. import com.keao.edu.user.api.entity.ExamRoom;
  16. import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
  17. import com.keao.edu.user.api.enums.ExamModeEnum;
  18. import com.keao.edu.user.dao.*;
  19. import com.keao.edu.user.dto.ExamRoomStudentRelationDto;
  20. import com.keao.edu.user.dto.NeedCheckingDetailDto;
  21. import com.keao.edu.user.dto.RoomStudentListDto;
  22. import com.keao.edu.user.dto.StuRecordDetailDto;
  23. import com.keao.edu.user.entity.*;
  24. import com.keao.edu.user.page.ExamRoomStudentRelationQueryInfo;
  25. import com.keao.edu.user.service.*;
  26. import com.keao.edu.util.collection.MapUtil;
  27. import com.keao.edu.util.date.DateUtil;
  28. import org.apache.commons.lang.StringEscapeUtils;
  29. import org.apache.commons.lang3.StringUtils;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.stereotype.Service;
  32. import org.springframework.transaction.annotation.Isolation;
  33. import org.springframework.transaction.annotation.Transactional;
  34. import org.springframework.util.CollectionUtils;
  35. import java.util.*;
  36. import java.util.stream.Collectors;
  37. @Service
  38. public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, ExamRoomStudentRelation> implements ExamRoomStudentRelationService {
  39. @Autowired
  40. private ExamRoomStudentRelationDao examRoomStudentRelationDao;
  41. @Autowired
  42. private ExamRoomDao examRoomDao;
  43. @Autowired
  44. private OrganizationService organizationService;
  45. @Autowired
  46. private StudentExamResultDao studentExamResultDao;
  47. @Autowired
  48. private ExamCertificationService examCertificationService;
  49. @Autowired
  50. private ExamLocationDao examLocationDao;
  51. @Autowired
  52. private IdGeneratorService idGeneratorService;
  53. @Autowired
  54. private ExamRegistrationDao examRegistrationDao;
  55. @Autowired
  56. private ExamTeacherSalaryService examTeacherSalaryService;
  57. @Autowired
  58. private ImFeignService imFeignService;
  59. @Autowired
  60. private SysUserFeignService sysUserFeignService;
  61. @Autowired
  62. private SysConfigService sysConfigService;
  63. @Autowired
  64. private ExamOrganizationRelationDao examOrganizationRelationDao;
  65. @Override
  66. public BaseDAO<Long, ExamRoomStudentRelation> getDAO() {
  67. return examRoomStudentRelationDao;
  68. }
  69. @Override
  70. public void switchClassRoom(Integer openFlag, Integer examinationBasicId, Integer studentId) {
  71. examRoomStudentRelationDao.switchClassRoom(openFlag,examinationBasicId,studentId);
  72. }
  73. @Override
  74. @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
  75. public void addStudentForRoom(Long examRoomId, String registIdsStr, Integer organId) {
  76. if(Objects.isNull(examRoomId)){
  77. throw new BizException("请指定教室");
  78. }
  79. if(StringUtils.isBlank(registIdsStr)){
  80. throw new BizException("请指定学员报名编号");
  81. }
  82. ExamRoom examRoom = examRoomDao.lockRoom(examRoomId);
  83. if(Objects.isNull(examRoom)){
  84. throw new BizException("教室不存在");
  85. }
  86. if(examRoom.getExamPlanPushFlag()==1){
  87. throw new BizException("无法添加学员");
  88. }
  89. ExamOrganizationRelation examOrganizationRelation = examOrganizationRelationDao.getExamOrganizationRelation(examRoom.getExaminationBasicId(), organId);
  90. if(Objects.isNull(examOrganizationRelation)||examOrganizationRelation.getIsAllowArrangeExam()==0){
  91. throw new BizException("无权操作");
  92. }
  93. ExamLocation examLocation = null;
  94. if(ExamModeEnum.OFFLINE.equals(examRoom.getExamMode())){
  95. examLocation = examLocationDao.get(examRoom.getExamLocationId());
  96. if(Objects.isNull(examLocation)){
  97. throw new BizException("考点信息错误");
  98. }
  99. }
  100. List<ExamRoomStudentRelation> studentsWithExamRoom = examRoomStudentRelationDao.findStudentsWithExamRoom(examRoomId);
  101. Set<Long> existRegistIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getExamRegistrationId).collect(Collectors.toSet());
  102. Set<Integer> existStudentIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
  103. String[] registIds = registIdsStr.split(",");
  104. List<ExamRegistration> examRegistrations = examRegistrationDao.getRegists(Arrays.asList(registIds).stream().map(e -> Long.valueOf(e)).collect(Collectors.toList()));
  105. Map<Integer, ExamRegistration> studentRegistMap = examRegistrations.stream().collect(Collectors.toMap(ExamRegistration::getId, e -> e));
  106. Set<Integer> studentIds = examRegistrations.stream().map(ExamRegistration::getStudentId).collect(Collectors.toSet());
  107. if(studentIds.size()!=registIds.length){
  108. throw new BizException("学员重复");
  109. }
  110. List<ExamRoomStudentRelation> examRoomStudentRelations=new ArrayList<>();
  111. for (String registId : registIds) {
  112. if(existRegistIds.contains(Long.valueOf(registId))){
  113. continue;
  114. }
  115. ExamRegistration examRegistration = studentRegistMap.get(Integer.valueOf(registId));
  116. if(Objects.isNull(examRegistration)){
  117. throw new BizException("学员信息错误");
  118. }
  119. if(existStudentIds.contains(examRegistration.getStudentId())){
  120. throw new BizException("学员重复");
  121. }
  122. ExamRoomStudentRelation e=new ExamRoomStudentRelation();
  123. e.setExamRegistrationId(Long.valueOf(registId));
  124. e.setExaminationBasicId(examRoom.getExaminationBasicId());
  125. e.setExamRoomId(examRoom.getId());
  126. e.setStudentId(examRegistration.getStudentId());
  127. e.setTenantId(TenantContextHolder.getTenantId());
  128. examRoomStudentRelations.add(e);
  129. }
  130. if(!CollectionUtils.isEmpty(examRoomStudentRelations)){
  131. examRoomStudentRelationDao.batchInsert(examRoomStudentRelations);
  132. examTeacherSalaryService.teacherSalarySettlementWithExam(examRoom.getExaminationBasicId());
  133. examRoom.setExamRoomStudentNum(examRoomStudentRelationDao.countStudentsWithRoom(examRoom.getId()));
  134. examRoomDao.update(examRoom);
  135. }
  136. }
  137. @Override
  138. @Transactional(rollbackFor = Exception.class)
  139. public void changeStudentExamRoom(Long registId, Long examRoomId, Integer organId) {
  140. if(Objects.isNull(registId)){
  141. throw new BizException("请指定报名信息");
  142. }
  143. if(Objects.isNull(examRoomId)){
  144. throw new BizException("请指定新考场");
  145. }
  146. ExamRegistration examRegistration = examRegistrationDao.get(registId);
  147. if(Objects.isNull(examRegistration)){
  148. throw new BizException("学员报名信息不存在");
  149. }
  150. ExamRoom examRoom = examRoomDao.get(examRoomId);
  151. if(Objects.isNull(examRoom)){
  152. throw new BizException("考场信息不存在");
  153. }
  154. List<ExamRoomStudentRelation> studentsWithExamRoom = examRoomStudentRelationDao.findStudentsWithExamRoom(examRoomId);
  155. Set<Long> existRegistIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getExamRegistrationId).collect(Collectors.toSet());
  156. Set<Integer> existStudentIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
  157. if(existRegistIds.contains(Long.valueOf(registId))){
  158. throw new BizException("学员重复");
  159. }
  160. if(existStudentIds.contains(examRegistration.getStudentId())){
  161. throw new BizException("学员重复");
  162. }
  163. ExamOrganizationRelation examOrganizationRelation = examOrganizationRelationDao.getExamOrganizationRelation(examRoom.getExaminationBasicId(), organId);
  164. if(Objects.isNull(examOrganizationRelation)||examOrganizationRelation.getIsAllowArrangeExam()==0){
  165. throw new BizException("无权操作");
  166. }
  167. ExamRoomStudentRelation studentExamRoom = examRoomStudentRelationDao.getStudentExamRoom(registId);
  168. if(Objects.isNull(studentExamRoom)){
  169. studentExamRoom=new ExamRoomStudentRelation();
  170. studentExamRoom.setExaminationBasicId(examRegistration.getExaminationBasicId());
  171. studentExamRoom.setExamRoomId(examRoomId);
  172. studentExamRoom.setExamRegistrationId(examRegistration.getId().longValue());
  173. studentExamRoom.setStudentId(examRegistration.getStudentId());
  174. studentExamRoom.setClassroomSwitch(0);
  175. examRoomStudentRelationDao.insert(studentExamRoom);
  176. return;
  177. }
  178. studentExamRoom.setExamRoomId(examRoomId);
  179. examRoomStudentRelationDao.update(studentExamRoom);
  180. examRoom.setExamRoomStudentNum(examRoomStudentRelationDao.countStudentsWithRoom(examRoom.getId()));
  181. examRoomDao.update(examRoom);
  182. }
  183. @Override
  184. public PageInfo<ExamRoomStudentRelationDto> findExamRoomStudents(ExamRoomStudentRelationQueryInfo queryInfo) {
  185. if(Objects.nonNull(queryInfo.getInRoom())&&Objects.isNull(queryInfo.getExamRoomId())){
  186. throw new BizException("请指定考场");
  187. }
  188. PageInfo<ExamRoomStudentRelationDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
  189. Map<String, Object> params = new HashMap<String, Object>();
  190. MapUtil.populateMap(params, queryInfo);
  191. if(Objects.nonNull(queryInfo.getExamRoomId())){
  192. ExamRoom examRoom = examRoomDao.get(queryInfo.getExamRoomId());
  193. if(Objects.isNull(examRoom)){
  194. throw new BizException("考场不存在");
  195. }
  196. if(!examRoom.getExaminationBasicId().equals(queryInfo.getExamId())){
  197. throw new BizException("考场信息异常");
  198. }
  199. params.put("subjectIds", examRoom.getSubjectIdList());
  200. }
  201. List<Integer> nextLevelOrganIds = organizationService.getChildOrganIds(queryInfo.getOrganId(), true);
  202. params.put("organIds", nextLevelOrganIds);
  203. List<ExamRoomStudentRelationDto> dataList = new ArrayList<>();
  204. int count = examRoomStudentRelationDao.countExamRoomStudents(params);
  205. if (count > 0) {
  206. pageInfo.setTotal(count);
  207. params.put("offset", pageInfo.getOffset());
  208. dataList = examRoomStudentRelationDao.findExamRoomStudents(params);
  209. List<Integer> studentIds = dataList.stream().map(e->e.getExamRegistration().getStudentId()).collect(Collectors.toList());
  210. List<Integer> subjectIds = dataList.stream().map(e->e.getExamRegistration().getSubjectId()).collect(Collectors.toList());
  211. Map<Integer, String> studentIdNameMap = this.getMap("sys_user", "id_", "real_name_", studentIds, Integer.class, String.class);
  212. Map<Integer, String> subjectIdNameMap = this.getMap("subject", "id_", "name_", subjectIds, Integer.class, String.class);
  213. for (ExamRoomStudentRelationDto e : dataList) {
  214. e.setStudentInfo(new SysUser(e.getStudentId(),studentIdNameMap.get(e.getExamRegistration().getStudentId())));
  215. e.setSubject(new Subject(e.getExamRegistration().getSubjectId(), subjectIdNameMap.get(e.getExamRegistration().getSubjectId())));
  216. }
  217. }
  218. pageInfo.setRows(dataList);
  219. return pageInfo;
  220. }
  221. @Override
  222. @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
  223. public void deleteStudentFromRoom(Long examRoomId, String registIdsStr, Integer organId) {
  224. if(Objects.isNull(examRoomId)){
  225. throw new BizException("请指定教室");
  226. }
  227. ExamRoom examRoom = examRoomDao.lockRoom(examRoomId);
  228. if(Objects.isNull(examRoom)){
  229. throw new BizException("教室不存在");
  230. }
  231. if(examRoom.getExamPlanPushFlag()==1){
  232. throw new BizException("无法删除学员");
  233. }
  234. ExamOrganizationRelation examOrganizationRelation = examOrganizationRelationDao.getExamOrganizationRelation(examRoom.getExaminationBasicId(), organId);
  235. if(Objects.isNull(examOrganizationRelation)||examOrganizationRelation.getIsAllowArrangeExam()==0){
  236. throw new BizException("无权操作");
  237. }
  238. if(StringUtils.isBlank(registIdsStr)){
  239. return;
  240. }
  241. examRoom.setExamRoomStudentNum(examRoomStudentRelationDao.countStudentsWithRoom(examRoom.getId()));
  242. examRoomDao.update(examRoom);
  243. examTeacherSalaryService.teacherSalarySettlementWithExam(examRoom.getExaminationBasicId());
  244. }
  245. @Override
  246. public ExamRoomStudentRelation getExamRoomStudentRelation(Long registrationId) {
  247. return examRoomStudentRelationDao.getStudentExamRoom(registrationId);
  248. }
  249. @Override
  250. @Transactional(rollbackFor = Exception.class)
  251. public void recorded(Long roomId) {
  252. List<RoomStudentListDto> roomStudentListDtos = examRoomStudentRelationDao.queryStudentList(roomId);
  253. if(roomStudentListDtos != null && roomStudentListDtos.size() > 0){
  254. SysUser sysUser = sysUserFeignService.queryUserInfo();
  255. RoomStudentListDto roomStudentListDto = roomStudentListDtos.get(0);
  256. if(roomStudentListDto.getFinishedExam() != 0){
  257. throw new BizException("操作失败:当前学员状态不支持录播");
  258. }
  259. ExamRoomStudentRelation examRoomStudentRelation = examRoomStudentRelationDao.get(roomStudentListDto.getExamRoomStudentRelationId());
  260. //修改学员考试状态
  261. StudentExamResult studentExamResult = studentExamResultDao.findByRegistrationId(examRoomStudentRelation.getExamRegistrationId());
  262. studentExamResult.setRecordFlag(1);
  263. studentExamResult.setIsFinishedExam(4);
  264. studentExamResultDao.update(studentExamResult);
  265. //关闭学员房间入口
  266. examRoomStudentRelation.setClassroomSwitch(0);
  267. examRoomStudentRelationDao.update(examRoomStudentRelation);
  268. publishMessage(examRoomStudentRelation,MemberChangedMessage.Action_Recorded,true,sysUser.getId());
  269. if(roomStudentListDtos.size() > 1){
  270. RoomStudentListDto roomStudentListDto1 = roomStudentListDtos.get(1);
  271. if(roomStudentListDto1.getFinishedExam() == 2){
  272. nextStudent(roomStudentListDto1.getExamRoomStudentRelationId(),false,sysUser.getId());
  273. }
  274. }
  275. //将当前学员退踢出教室
  276. // imFeignService.kickRoom(new ReqUserData(examRoomStudentRelation.getExamRegistrationId(),roomStudentListDto.getStudentId().toString()));
  277. }
  278. }
  279. @Override
  280. @Transactional(rollbackFor = Exception.class)
  281. public NeedCheckingDetailDto stuRecorded(Long examRegistrationId) {
  282. //修改考试状态为录播
  283. /*StudentExamResult studentExamResult = studentExamResultDao.findByRegistrationId(examRegistrationId);
  284. studentExamResult.setRecordFlag(1);
  285. studentExamResult.setRecordStartTime(new Date());
  286. studentExamResultDao.update(studentExamResult);*/
  287. //返回详情数据
  288. return examCertificationService.needCheckingDetail(examRegistrationId);
  289. }
  290. @Override
  291. @Transactional(rollbackFor = Exception.class)
  292. public NeedCheckingDetailDto againQueue(Long examRegistrationId) {
  293. //清除排队状态
  294. examRoomStudentRelationDao.cleanSignInTime(examRegistrationId);
  295. //返回详情数据
  296. return examCertificationService.needCheckingDetail(examRegistrationId);
  297. }
  298. @Override
  299. public List<ExamRoomStudentRelation> findStudentsWithExamRooms(List<Long> examRoomIds) {
  300. return examRoomStudentRelationDao.findStudentsWithExamRooms(examRoomIds);
  301. }
  302. @Override
  303. public void deleteWithExamRooms(List<Long> examRoomIds) {
  304. examRoomStudentRelationDao.deleteWithExamRooms(examRoomIds);
  305. }
  306. @Override
  307. public String getStudentIds(Long examRoomId) {
  308. return examRoomStudentRelationDao.getStudentIds(examRoomId);
  309. }
  310. @Override
  311. public List<Map<Integer, String>> getStuRegistrationMap(Long examRoomId) {
  312. return examRoomStudentRelationDao.getStuRegistrationMap(examRoomId);
  313. }
  314. @Override
  315. @Transactional(rollbackFor = Exception.class)
  316. public StuRecordDetailDto stuRecordDetail(Long examRegistrationId) {
  317. StudentExamResult studentExamResult = studentExamResultDao.findByRegistrationId(examRegistrationId);
  318. //当前学员是否完成考试
  319. if(studentExamResult.getIsFinishedExam() != 4){
  320. throw new BizException("操作失败:当前状态不允许录播");
  321. }
  322. //是否允许录播
  323. if(studentExamResult.getRecordStartTime() == null){
  324. if(studentExamResult.getRecordFlag() == 0){
  325. studentExamResult.setRecordFlag(1);
  326. studentExamResult.setRecordStartTime(new Date());
  327. studentExamResultDao.update(studentExamResult);
  328. }else {
  329. studentExamResult.setRecordStartTime(new Date());
  330. studentExamResultDao.update(studentExamResult);
  331. }
  332. }
  333. StuRecordDetailDto stuRecordDetailDto = examRegistrationDao.getStuRecordDetail(examRegistrationId);
  334. int recordMinutes = Integer.parseInt(sysConfigService.findByParamName("record_minutes").getParanValue());
  335. Date date = DateUtil.addMinutes(stuRecordDetailDto.getRecordStartTime(),recordMinutes);
  336. stuRecordDetailDto.setExamEndTime(date);
  337. int secondsBetween = DateUtil.secondsBetween(new Date(),date);
  338. if(secondsBetween <= 0){
  339. throw new BizException("操作失败:录制超时");
  340. }
  341. stuRecordDetailDto.setSubTime(secondsBetween);
  342. stuRecordDetailDto.setRecordTime(recordMinutes);
  343. stuRecordDetailDto.setExamRegistrationId(examRegistrationId);
  344. stuRecordDetailDto.setSongJson(StringEscapeUtils.unescapeJavaScript(stuRecordDetailDto.getSongJson()));
  345. stuRecordDetailDto.setSingleSongRecordMinutes(Integer.parseInt(sysConfigService.findByParamName("single_song_record_minutes").getParanValue()));
  346. return stuRecordDetailDto;
  347. }
  348. @Override
  349. @Transactional(rollbackFor = Exception.class)
  350. public void stuEndRecord(Long examRegistrationId, String videoUrl) {
  351. StudentExamResult studentExamResult = studentExamResultDao.findByRegistrationId(examRegistrationId);
  352. //当前学员是否完成考试
  353. if(studentExamResult.getIsFinishedExam() != 4){
  354. throw new BizException("提交失败:当前考试状态不允许录播");
  355. }
  356. studentExamResult.setVideoUrl(videoUrl);
  357. studentExamResult.setIsFinishedExam(5);
  358. studentExamResultDao.update(studentExamResult);
  359. ExamRoomStudentRelation roomStudentRelation = examRoomStudentRelationDao.getStudentExamRoom(examRegistrationId);
  360. publishMessage(roomStudentRelation,MemberChangedMessage.Student_Queue,true,studentExamResult.getStudentId());
  361. }
  362. @Override
  363. @Transactional(rollbackFor = Exception.class)
  364. public void actionExam(Long roomId) {
  365. ExamRoom examRoom = examRoomDao.get(roomId);
  366. if(examRoom.getExamFlag() == 1){
  367. throw new BizException("考试已开启,请勿重复操作");
  368. }
  369. examRoom.setExamFlag(1);
  370. examRoomDao.update(examRoom);
  371. nextBit(null,roomId);
  372. }
  373. @Override
  374. public Integer countSignInNum(Long examRoomId) {
  375. return examRoomStudentRelationDao.countSignInNum(examRoomId);
  376. }
  377. @Override
  378. public ExamRoomStudentRelation getStudentExamRoom(Long examRegistrationId) {
  379. return examRoomStudentRelationDao.getStudentExamRoom(examRegistrationId);
  380. }
  381. @Override
  382. @Transactional(rollbackFor = Exception.class)
  383. public void nextBit(Integer examStatus,Long examRoomId) {
  384. List<RoomStudentListDto> roomStudentListDtos = examRoomStudentRelationDao.queryStudentList(examRoomId);
  385. if(roomStudentListDtos != null && roomStudentListDtos.size() > 0){
  386. RoomStudentListDto roomStudentListDto = roomStudentListDtos.get(0);
  387. SysUser sysUser = sysUserFeignService.queryUserInfo();
  388. if(roomStudentListDto.getFinishedExam() == 0 || roomStudentListDto.getFinishedExam() == 1){
  389. //考试中
  390. currentStudent(roomStudentListDto.getExamRoomStudentRelationId(),true,examStatus,sysUser.getId());
  391. if(roomStudentListDtos.size() > 1){
  392. RoomStudentListDto roomStudentListDto1 = roomStudentListDtos.get(1);
  393. if(roomStudentListDto1.getFinishedExam() == 2){
  394. nextStudent(roomStudentListDto1.getExamRoomStudentRelationId(),false,sysUser.getId());
  395. }
  396. }
  397. }else if(roomStudentListDto.getFinishedExam() == 2){
  398. //未开始
  399. nextStudent(roomStudentListDto.getExamRoomStudentRelationId(),true,sysUser.getId());
  400. }else {
  401. throw new BizException("操作失败:没有待考学员");
  402. }
  403. }
  404. }
  405. private void currentStudent(Long examRoomStudentRelationId,Boolean isPush,Integer examStatus,Integer operator){
  406. ExamRoomStudentRelation examRoomStudentRelation = examRoomStudentRelationDao.get(examRoomStudentRelationId);
  407. //将当前学员退出教室并添加参考状态,如果考试未完成,清除签到时间,重新签到
  408. imFeignService.kickRoom(new ReqUserData(examRoomStudentRelation.getExamRegistrationId(),examRoomStudentRelation.getStudentId().toString()));
  409. if(examStatus != null && examStatus == 0){
  410. //未完成
  411. examRoomStudentRelationDao.cleanSignInTime(examRoomStudentRelation.getExamRegistrationId());
  412. studentExamResultDao.updateFinishedExam(examRoomStudentRelation.getExamRegistrationId(),3);
  413. }else {
  414. //结束考试
  415. studentExamResultDao.updateFinishedExam(examRoomStudentRelation.getExamRegistrationId(),5);
  416. }
  417. //关闭学员房间入口
  418. examRoomStudentRelation.setClassroomSwitch(0);
  419. examRoomStudentRelationDao.update(examRoomStudentRelation);
  420. publishMessage(examRoomStudentRelation,MemberChangedMessage.Student_Queue,isPush,operator);
  421. }
  422. private void nextStudent(Long nextExamRoomStudentRelationId,Boolean isPush,Integer operator){
  423. ExamRoomStudentRelation examRoomStudentRelation = examRoomStudentRelationDao.get(nextExamRoomStudentRelationId);
  424. //开启学员房间入口
  425. examRoomStudentRelation.setClassroomSwitch(1);
  426. examRoomStudentRelationDao.update(examRoomStudentRelation);
  427. //状态变更为呼叫中
  428. studentExamResultDao.updateFinishedExam(examRoomStudentRelation.getExamRegistrationId(),1);
  429. publishMessage(examRoomStudentRelation,MemberChangedMessage.Student_Queue,isPush,operator);
  430. }
  431. @Override
  432. public void publishMessage(ExamRoomStudentRelation examRoomStudentRelation,Integer action,Boolean isPush,Integer operator){
  433. if (!isPush){
  434. return;
  435. }
  436. PublishMessageDto publishMessageDto = new PublishMessageDto();
  437. publishMessageDto.setUserId(operator.toString());
  438. publishMessageDto.setRoomId(examRoomStudentRelation.getExamRoomId().toString());
  439. MemberChangedMessage msg = new MemberChangedMessage(action, examRoomStudentRelation.getStudentId().toString(),3);
  440. /*if(action == 3 || action == 4){
  441. msg = new MemberChangedMessage(action, examRoomStudentRelation.getStudentId().toString(),3);
  442. }else {
  443. msg = new MemberChangedMessage(action, examRoomStudentRelation.getStudentId(),3);
  444. }*/
  445. // String jsonString = JSONObject.toJSONString(examCertificationService.needCheckingDetail(examRoomStudentRelation.getExamRegistrationId()));
  446. NeedCheckingDetailDto needCheckingDetailDto = examCertificationService.needCheckingDetail(examRoomStudentRelation.getExamRegistrationId());
  447. msg.setWaitNum(needCheckingDetailDto.getWaitNum());
  448. msg.setClassroomSwitch(needCheckingDetailDto.getClassroomSwitch());
  449. msg.setOpenFlag(needCheckingDetailDto.getOpenFlag());
  450. // msg.setAppParamJson(jsonString);
  451. Map<String,Object> paramMap = new HashMap<>(2);
  452. paramMap.put("studentQueue",this.queryNeedCheckingList(examRoomStudentRelation.getExamRoomId()));
  453. paramMap.put("examCertification",examCertificationService.findDetailByStudentId(examRoomStudentRelation.getExamRegistrationId()));
  454. msg.setWebParamJson(JSONObject.toJSONString(paramMap));
  455. publishMessageDto.setMemberChangedMessage(msg);
  456. imFeignService.publishMessage(publishMessageDto);
  457. }
  458. public PublishMessageDto getPublishMessage(Long examRegistrationId){
  459. SysUser sysUser = sysUserFeignService.queryUserInfo();
  460. ExamRoomStudentRelation examRoomStudentRelation = examRoomStudentRelationDao.getStudentExamRoom(examRegistrationId);
  461. PublishMessageDto publishMessageDto = new PublishMessageDto();
  462. String userId = sysUser.getId().toString();
  463. publishMessageDto.setUserId(userId);
  464. publishMessageDto.setRoomId(examRoomStudentRelation.getExamRoomId().toString());
  465. MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Student_Queue, examRoomStudentRelation.getStudentId().toString(),3);
  466. // String jsonString = JSONObject.toJSONString(examCertificationService.needCheckingDetail(examRoomStudentRelation.getExamRegistrationId()));
  467. // msg.setAppParamJson(jsonString);
  468. NeedCheckingDetailDto needCheckingDetailDto = examCertificationService.needCheckingDetail(examRoomStudentRelation.getExamRegistrationId());
  469. msg.setWaitNum(needCheckingDetailDto.getWaitNum());
  470. msg.setClassroomSwitch(needCheckingDetailDto.getClassroomSwitch());
  471. msg.setOpenFlag(needCheckingDetailDto.getOpenFlag());
  472. Map<String,Object> paramMap = new HashMap<>(2);
  473. this.queryNeedCheckingList(examRoomStudentRelation.getExamRoomId());
  474. paramMap.put("studentQueue",this.queryNeedCheckingList(examRoomStudentRelation.getExamRoomId()));
  475. paramMap.put("examCertification",examCertificationService.findDetailByStudentId(examRoomStudentRelation.getExamRegistrationId()));
  476. msg.setWebParamJson(JSONObject.toJSONString(paramMap));
  477. publishMessageDto.setMemberChangedMessage(msg);
  478. return publishMessageDto;
  479. }
  480. @Override
  481. public List<RoomStudentListDto> queryStudentList(Long roomId) {
  482. return examRoomStudentRelationDao.queryStudentList(roomId);
  483. }
  484. @Override
  485. public Map<String, Object> queryNeedCheckingList(Long roomId) {
  486. List<RoomStudentListDto> roomStudentListDtos = examRoomStudentRelationDao.queryStudentList(roomId);
  487. Map<String,Object> resultMap = new HashMap<>(4);
  488. resultMap.put("studentList",roomStudentListDtos);
  489. resultMap.put("signTotalNum",examRoomStudentRelationDao.querySignTotalNum(roomId));
  490. resultMap.put("noSignTotalNum",examRoomStudentRelationDao.queryNoSignTotalNum(roomId));
  491. resultMap.put("surplusNum",examRoomStudentRelationDao.querySurplusNum(roomId));
  492. return resultMap;
  493. }
  494. @Override
  495. @Transactional(rollbackFor = Exception.class)
  496. public synchronized void signIn(Long examRegistrationId) {
  497. ExamRoomStudentRelation studentExamRoom = examRoomStudentRelationDao.getStudentExamRoom(examRegistrationId);
  498. if(studentExamRoom.getSignInTime() != null){
  499. throw new BizException("您已签到,请勿重复操作!");
  500. }
  501. studentExamRoom.setSignInTime(new Date());
  502. examRoomStudentRelationDao.update(studentExamRoom);
  503. SysUser sysUser = sysUserFeignService.queryUserInfo();
  504. PublishMessageDto publishMessageDto = new PublishMessageDto();
  505. String userId = sysUser.getId().toString();
  506. publishMessageDto.setUserId(userId);
  507. publishMessageDto.setRoomId(studentExamRoom.getExamRoomId().toString());
  508. MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Student_Queue, userId,3);
  509. // String jsonString = JSONObject.toJSONString(examCertificationService.needCheckingDetail(examRegistrationId));
  510. NeedCheckingDetailDto needCheckingDetailDto = examCertificationService.needCheckingDetail(examRegistrationId);
  511. // msg.setAppParamJson(needCheckingDetailDto.getWaitNum());
  512. msg.setWaitNum(needCheckingDetailDto.getWaitNum());
  513. msg.setClassroomSwitch(0);
  514. msg.setOpenFlag(needCheckingDetailDto.getOpenFlag());
  515. publishMessageDto.setMemberChangedMessage(msg);
  516. //修改签到状态
  517. studentExamResultDao.updateFinishedExam(examRegistrationId,2);
  518. imFeignService.publishMessage(publishMessageDto);
  519. }
  520. }