| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- package com.keao.edu.user.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.keao.edu.auth.api.client.SysUserFeignService;
- import com.keao.edu.auth.api.entity.SysUser;
- import com.keao.edu.common.dal.BaseDAO;
- import com.keao.edu.common.enums.MessageTypeEnum;
- import com.keao.edu.common.exception.BizException;
- import com.keao.edu.common.page.PageInfo;
- import com.keao.edu.common.service.SysMessageService;
- import com.keao.edu.common.service.impl.BaseServiceImpl;
- import com.keao.edu.im.api.client.ImFeignService;
- import com.keao.edu.im.api.entity.MemberChangedMessage;
- import com.keao.edu.im.api.entity.PublishMessageDto;
- import com.keao.edu.thirdparty.message.provider.JiguangPushPlugin;
- import com.keao.edu.user.api.entity.ExamRoom;
- import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
- import com.keao.edu.user.api.entity.Student;
- import com.keao.edu.user.api.enums.StudentExamResultApiDto;
- import com.keao.edu.user.dao.ExaminationBasicDao;
- import com.keao.edu.user.dao.StudentExamResultDao;
- import com.keao.edu.user.dto.ExaminationBasicDto;
- import com.keao.edu.user.dto.RecordNotify;
- import com.keao.edu.user.dto.RoomStudentListDto;
- import com.keao.edu.user.dto.StudentExamResultStatisticsDto;
- import com.keao.edu.user.entity.ExaminationBasic;
- import com.keao.edu.user.entity.Organization;
- import com.keao.edu.user.entity.StudentExamResult;
- import com.keao.edu.user.entity.Subject;
- import com.keao.edu.user.enums.ExamStatusEnum;
- import com.keao.edu.user.enums.LevelEnum;
- import com.keao.edu.user.page.StudentExamResultQueryInfo;
- import com.keao.edu.user.service.ExamRoomService;
- import com.keao.edu.user.service.ExamRoomStudentRelationService;
- import com.keao.edu.user.service.OrganizationService;
- import com.keao.edu.user.service.StudentExamResultService;
- import com.keao.edu.util.collection.MapUtil;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service
- public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentExamResult> implements StudentExamResultService {
- @Autowired
- private ExaminationBasicDao examinationBasicDao;
- @Autowired
- private StudentExamResultDao studentExamResultDao;
- @Autowired
- private ExamRoomStudentRelationService examRoomStudentRelationService;
- @Autowired
- private OrganizationService organizationService;
- @Autowired
- private SysMessageService sysMessageService;
- @Autowired
- private SysUserFeignService sysUserFeignService;
- @Autowired
- private ImFeignService imFeignService;
- @Autowired
- private ExamRoomService examRoomService;
- private final static Logger logger = LoggerFactory.getLogger(StudentExamResultServiceImpl.class);
- @Override
- public BaseDAO<Long, StudentExamResult> getDAO() {
- return studentExamResultDao;
- }
- @Override
- public PageInfo<StudentExamResult> queryStudentExamResult(StudentExamResultQueryInfo queryInfo) {
- PageInfo<StudentExamResult> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
- Map<String, Object> params = new HashMap<String, Object>();
- MapUtil.populateMap(params, queryInfo);
- List<Integer> childOrganIds = organizationService.getChildOrganIds(queryInfo.getOrganId(), true);
- params.put("organIds", childOrganIds);
- List<StudentExamResult> dataList = new ArrayList<>();
- int count = studentExamResultDao.countStudentExamResult(params);
- if (count > 0) {
- pageInfo.setTotal(count);
- params.put("offset", pageInfo.getOffset());
- dataList = studentExamResultDao.queryStudentExamResult(params);
- List<Long> examIds = dataList.stream().map(StudentExamResult::getExaminationBasicId).collect(Collectors.toList());
- List<Integer> studentIds = dataList.stream().map(StudentExamResult::getStudentId).collect(Collectors.toList());
- List<Integer> subjectIds = dataList.stream().map(e -> e.getExamRegistration().getSubjectId()).collect(Collectors.toList());
- List<Integer> organIds = dataList.stream().map(e -> e.getExamRegistration().getOrganId()).collect(Collectors.toList());
- Map<Integer, String> studentIdNameMap = this.getMap("sys_user", "id_", "real_name_", studentIds, Integer.class, String.class);
- Map<Integer, String> subjectIdNameMap = this.getMap("subject", "id_", "name_", subjectIds, Integer.class, String.class);
- Map<Integer, String> organIdNameMap = this.getMap("organization", "id_", "name_", organIds, Integer.class, String.class);
- List<ExaminationBasicDto> exams = examinationBasicDao.getExams(examIds);
- Map<Long, ExaminationBasicDto> idExamMap = exams.stream().collect(Collectors.toMap(ExaminationBasic::getId, e -> e));
- for (StudentExamResult s : dataList) {
- Student student=new Student(s.getStudentId(), studentIdNameMap.get(s.getStudentId()));
- s.setExaminationBasic(idExamMap.get(s.getExaminationBasicId()));
- s.getExamRegistration().setSysUser(student);
- s.getExamRegistration().setSubject(new Subject(s.getExamRegistration().getSubjectId(), subjectIdNameMap.get(s.getExamRegistration().getSubjectId())));
- s.getExamRegistration().setOrganization(new Organization(s.getExamRegistration().getOrganId(), organIdNameMap.get(s.getExamRegistration().getOrganId())));
- }
- }
- pageInfo.setRows(dataList);
- return pageInfo;
- }
- @Override
- public void updateStudentExamResult(StudentExamResult studentExamResult) {
- if(Objects.isNull(studentExamResult.getId())){
- throw new BizException("请指定考试结果");
- }
- StudentExamResult oldStudentExamResult = studentExamResultDao.get(studentExamResult.getId());
- if(Objects.isNull(oldStudentExamResult)){
- throw new BizException("考试结果不存在");
- }
- ExaminationBasic examinationBasic = examinationBasicDao.get(studentExamResult.getExaminationBasicId().longValue());
- if(Objects.isNull(examinationBasic)){
- throw new BizException("考级项目不存在");
- }
- if(ExamStatusEnum.RESULT_CONFIRM.equals(examinationBasic.getStatus())||ExamStatusEnum.CLOSE.equals(examinationBasic.getStatus())){
- throw new BizException("考试结果不可编辑");
- }
- studentExamResultDao.update(studentExamResult);
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void examResultConfirmPush(Long examId) {
- if(Objects.isNull(examId)){
- return;
- }
- List<StudentExamResult> studentExamResults = studentExamResultDao.getWithExam(examId);
- Set<Long> examIds = studentExamResults.stream().map(StudentExamResult::getExaminationBasicId).collect(Collectors.toSet());
- Map<Long, String> examIdNameMap = this.getMap("examination_basic", "id_", "name_", new ArrayList(examIds), Long.class, String.class);
- Set<Subject> subjectIds = studentExamResults.stream().map(e -> e.getExamRegistration().getSubject()).collect(Collectors.toSet());
- Map<Integer, String> subjectIdNameMap = this.getMap("subject", "id_", "name_", new ArrayList(subjectIds), Integer.class, String.class);
- String baseUrl = "4?";
- for (StudentExamResult studentExamResult : studentExamResults) {
- String examName = examIdNameMap.get(studentExamResult.getExaminationBasicId());
- String subjectName = subjectIdNameMap.get(studentExamResult.getExamRegistration().getSubjectId());
- String level = LevelEnum.getMsg(studentExamResult.getExamRegistration().getLevel());
- Map<Integer, String> userPhoneMap = new HashMap<>();
- userPhoneMap.put(studentExamResult.getStudentId(), studentExamResult.getStudentId().toString());
- sysMessageService.batchSendMessage(MessageTypeEnum.EXAM_RESULT_CONFIRM_PUSH,
- userPhoneMap, null, 0, baseUrl, JiguangPushPlugin.PLUGIN_NAME,
- examName, subjectName, level, studentExamResult.getResult().getMsg());
- }
- }
- @Override
- public StudentExamResultStatisticsDto getStudentExamResultStatisticsInfo(Integer organId, Integer examId) {
- if(Objects.isNull(examId)){
- throw new BizException("请指定考级项目");
- }
- ExaminationBasic examinationBasic = examinationBasicDao.get(examId.longValue());
- if(Objects.isNull(examinationBasic)){
- throw new BizException("考级项目不存在");
- }
- if(!ExamStatusEnum.EXAM_END.equals(examinationBasic.getStatus())&&!ExamStatusEnum.RESULT_CONFIRM.equals(examinationBasic.getStatus())){
- return null;
- }
- List<Integer> childOrganIds = organizationService.getChildOrganIds(organId, true);
- StudentExamResultStatisticsDto studentExamResultStatisticsInfo = studentExamResultDao.getStudentExamResultStatisticsInfo(childOrganIds, examId);
- return studentExamResultStatisticsInfo;
- }
- @Override
- public StudentExamResultApiDto getStudentExamResultApiDto(Long id) {
- StudentExamResultApiDto resultApiDto = studentExamResultDao.getStudentExamResultApiDto(id);
- ExamRoomStudentRelation studentExamRoom = examRoomStudentRelationService.getStudentExamRoom(id);
- resultApiDto.setRoomId(studentExamRoom.getExamRoomId().toString());
- return resultApiDto;
- }
- @Override
- public void confirmStudent(Long examRegistrationId) {
- studentExamResultDao.confirmStudent(examRegistrationId);
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void updateFinishedExam(Long examRegistrationId, Integer finishedExam) {
- studentExamResultDao.updateFinishedExam(examRegistrationId,finishedExam);
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void recordSync(RecordNotify recordNotify) {
- logger.info("recordSync paramJson{}",recordNotify);
- if (recordNotify.getType() == 4){
- JSONObject jsonObject = JSONObject.parseObject(recordNotify.getOutput());
- if("10000".equals(jsonObject.get("fileState"))){
- StudentExamResult studentExamResult = studentExamResultDao.findByRoomIdAndUserId(recordNotify.getRoomId(), recordNotify.getUserId());
- String videoUrl = studentExamResult.getVideoUrl();
- if(StringUtils.isNotEmpty(videoUrl)){
- videoUrl += "," + jsonObject.get("fileUrl");
- }else {
- videoUrl = jsonObject.get("fileUrl").toString();
- }
- studentExamResult.setVideoUrl(videoUrl);
- studentExamResultDao.update(studentExamResult);
- }
- }
- }
- @Override
- public void updateSessionId(Long examRegistrationId, String sessionId) {
- studentExamResultDao.updateSessionId(examRegistrationId,sessionId);
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void shieldUserId(Long roomId,Integer shieldFlag) {
- ExamRoom examRoom = examRoomService.get(roomId);
- SysUser sysUser = sysUserFeignService.queryUserInfo();
- String userToString = sysUser.getId().toString();
- String shieldUserId = examRoom.getShieldUserId();
- //取消屏蔽
- if(shieldFlag == 0){
- if(StringUtils.isNotEmpty(shieldUserId)){
- if(shieldUserId.contains("," + userToString)){
- shieldUserId = shieldUserId.replace("," + userToString,"");
- }else if(shieldUserId.contains(userToString + ",")){
- shieldUserId = shieldUserId.replace(userToString + ",","");
- }else {
- shieldUserId = "";
- }
- }else {
- shieldUserId = "";
- }
- }else {
- if(StringUtils.isNotEmpty(shieldUserId)){
- if(!shieldUserId.contains(userToString)) {
- shieldUserId += "," + userToString;
- }
- }else {
- shieldUserId = userToString;
- }
- }
- examRoom.setShieldUserId(shieldUserId);
- examRoomService.update(examRoom);
- PublishMessageDto publishMessageDto = new PublishMessageDto();
- publishMessageDto.setUserId(userToString);
- publishMessageDto.setRoomId(roomId.toString());
- MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Shield_UserId, userToString,3);
- msg.setShieldUserId(shieldUserId);
- publishMessageDto.setMemberChangedMessage(msg);
- imFeignService.publishMessage(publishMessageDto);
- }
- }
|