wangliang 4 gadi atpakaļ
vecāks
revīzija
691d86d986

+ 22 - 52
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateCallMobileController.java

@@ -34,10 +34,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import java.io.File;
 import java.security.NoSuchAlgorithmException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * @Description: mobile监考监控通话信息 前端控制器
@@ -257,58 +254,31 @@ public class TIeInvigilateCallMobileController {
      */
     private String getSourceUserId(Long recordId) throws NoSuchAlgorithmException {
         String sourceUserId = null;
-        Long examId = ExamRecordCacheUtil.getExamId(recordId);
+        //Long examId = ExamRecordCacheUtil.getExamId(recordId);
         Long examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
-        if (Objects.isNull(examId)) {
+        if (Objects.isNull(examStudentId)) {
             TOeExamRecord tOeExamRecord = tOeExamRecordService.getById(recordId);
-            examId = tOeExamRecord.getExamId();
-            examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
+            //examId = tOeExamRecord.getExamId();
+            if (tOeExamRecord == null) {
+                throw new BusinessException(ExceptionResultEnum.NOT_FOUND_EXAM_RECORD);
+            }
+            examStudentId = tOeExamRecord.getExamStudentId();
         }
-        ExamCacheBean ec = teExamService.getExamCacheBean(examId);//考试缓存
+        //ExamCacheBean ec = teExamService.getExamCacheBean(examId);//考试缓存
         ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
-        if (Objects.nonNull(ec.getMonitorAudioEnable())) {
-            if (ec.getMonitorAudioEnable()) {
-                for (Source s : Source.values()) {
-                    String sessionId = SessionUtil.digest(examStudentCacheBean.getIdentity(),
-                            Math.abs(Sets.newHashSet(RoleEnum.STUDENT.name()).toString().hashCode()), s.name());
-                    TBSession tbSessionClient = (TBSession) redisUtil.getUserSession(sessionId);
-                    if (Objects.nonNull(tbSessionClient) && tbSessionClient.getExpireTime() > System.currentTimeMillis()
-                            && (Objects.equals(tbSessionClient.getSource(), Source.OE_CLIENT.name()) || Objects
-                            .equals(tbSessionClient.getSource(), Source.ADMIN_CLIENT.name())) && (
-                            Objects.equals(tbSessionClient.getPlatform(), Platform.WIN.name()) || Objects
-                                    .equals(tbSessionClient.getPlatform(), Platform.MAC.name()))) {
-                        if (Objects.nonNull(
-                                ExamRecordCacheUtil.getMonitorStatus(recordId, MonitorVideoSourceEnum.CLIENT_CAMERA))) {
-                            sourceUserId = "s_" + tbSessionClient.getId();
-                            break;
-                        } else if (Objects.nonNull(
-                                ExamRecordCacheUtil.getMonitorStatus(recordId, MonitorVideoSourceEnum.CLIENT_SCREEN))) {
-                            sourceUserId = "s_" + tbSessionClient.getId();
-                            break;
-                        }
-                    }
-                }
-            } else {
-                for (Source s : Source.values()) {
-                    String sessionId = SessionUtil.digest(examStudentCacheBean.getIdentity(),
-                            Math.abs(Sets.newHashSet(RoleEnum.STUDENT.name()).toString().hashCode()), s.name());
-                    TBSession tbSessionPhone = (TBSession) redisUtil.getUserSession(sessionId);
-                    if (Objects.nonNull(tbSessionPhone) && tbSessionPhone.getExpireTime() > System.currentTimeMillis()
-                            && (Objects.equals(tbSessionPhone.getSource(), Source.MOBILE_MONITOR_FIRST.name())
-                            || Objects.equals(tbSessionPhone.getSource(), Source.MOBILE_MONITOR_SECOND.name())) && (
-                            Objects.equals(tbSessionPhone.getPlatform(), Platform.ANDROID.name()) || Objects
-                                    .equals(tbSessionPhone.getPlatform(), Platform.IOS.name()))) {
-                        if (Objects.nonNull(
-                                ExamRecordCacheUtil.getMonitorStatus(recordId, MonitorVideoSourceEnum.MOBILE_FIRST))) {
-                            sourceUserId = "s_" + tbSessionPhone.getId();
-                            break;
-                        } else if (Objects.nonNull(
-                                ExamRecordCacheUtil.getMonitorStatus(recordId, MonitorVideoSourceEnum.MOBILE_SECOND))) {
-                            sourceUserId = "s_" + tbSessionPhone.getId();
-                            break;
-                        }
-                    }
-                }
+        //只针对客户端摄像头/屏幕、移动端主机位开启监考通话
+        List<MonitorVideoSourceEnum> sourceList = Arrays
+                .asList(MonitorVideoSourceEnum.CLIENT_CAMERA, MonitorVideoSourceEnum.CLIENT_SCREEN,
+                        MonitorVideoSourceEnum.MOBILE_FIRST);
+        for (MonitorVideoSourceEnum source : sourceList) {
+            Source sessionSource = source.getSessionSource();
+            String sessionId = SessionUtil.digest(examStudentCacheBean.getStudentId(),
+                    Math.abs(Sets.newHashSet(RoleEnum.STUDENT.name()).toString().hashCode()), sessionSource.name());
+            TBSession tbSession = (TBSession) redisUtil.getUserSession(sessionId);
+            if (Objects.nonNull(tbSession) && tbSession.getExpireTime() > System.currentTimeMillis() && Objects
+                    .nonNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
+                sourceUserId = "s_" + tbSession.getId();
+                break;
             }
         }
         return sourceUserId;

+ 26 - 0
themis-business/src/main/java/com/qmth/themis/business/enums/MonitorVideoSourceEnum.java

@@ -1,5 +1,7 @@
 package com.qmth.themis.business.enums;
 
+import com.qmth.themis.common.enums.Source;
+
 /**
  * @Description: 监控源 enum
  * @Param:
@@ -25,4 +27,28 @@ public enum MonitorVideoSourceEnum {
     public String getCode() {
         return code;
     }
+
+    public static MonitorVideoSourceEnum findByName(String name) {
+        for (MonitorVideoSourceEnum value : MonitorVideoSourceEnum.values()) {
+            if (value.toString().equalsIgnoreCase(name)) {
+                return value;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 根据监控视频源判断设备访问会话来源
+     *
+     * @return
+     */
+    public Source getSessionSource() {
+        if (this == MOBILE_FIRST) {
+            return Source.MOBILE_MONITOR_FIRST;
+        } else if (this == MOBILE_SECOND) {
+            return Source.MOBILE_MONITOR_SECOND;
+        } else {
+            return Source.OE_CLIENT;
+        }
+    }
 }

+ 3 - 18
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEMobileServiceImpl.java

@@ -121,7 +121,7 @@ public class TEMobileServiceImpl implements TEMobileService {
         ret.setMonitorKey(ExamRecordCacheUtil.getMonitorKey(recordId));
         ret.setMonitorVideoSource(monitorVideoSource);
         ret.setMonitorAudioEnable(getMonitorAudioEnable(recordId, monitorVideoSource));
-        Source sourceEnum = getSource(monitorVideoSource);
+        Source sourceEnum = monitorVideoSource.getSessionSource();
         ExamStudentCacheBean es = examStudentService
                 .getExamStudentCacheBean(ExamRecordCacheUtil.getExamStudentId(ret.getRecordId()));
         String userType = MobileAuthCacheUtil.getUserType(mode, code);
@@ -166,7 +166,7 @@ public class TEMobileServiceImpl implements TEMobileService {
 
     @Override
     public MobileAnswerSubmitReponseBean answerSubmit(Long studentId, Long recordId, Integer mainNumber,
-            Integer subNumber, Integer subIndex, String answer) {
+                                                      Integer subNumber, Integer subIndex, String answer) {
         // 校验当前登录用户和参数一致性
         if (ExamRecordCacheUtil.getId(recordId) == null) {
             throw new BusinessException(ExceptionResultEnum.NOT_FOUND_EXAM_RECORD);
@@ -208,25 +208,10 @@ public class TEMobileServiceImpl implements TEMobileService {
         String monitorVideoSource = exam.getMonitorVideoSource();
         if (!monitorVideoSource.toUpperCase().contains(MonitorVideoSourceEnum.CLIENT_SCREEN.name())
                 && !monitorVideoSource.toUpperCase().contains(MonitorVideoSourceEnum.CLIENT_CAMERA.name())
-                && Source.MOBILE_MONITOR_FIRST.equals(videoSource)) {
+                && MonitorVideoSourceEnum.MOBILE_FIRST.equals(videoSource)) {
             return true;
         } else {
             return false;
         }
     }
-
-    /**
-     * 根据监控视频源判断设备访问会话来源
-     *
-     * @param videoSource
-     * @return
-     */
-    private Source getSource(MonitorVideoSourceEnum videoSource) {
-        if (videoSource == MonitorVideoSourceEnum.MOBILE_FIRST) {
-            return Source.MOBILE_MONITOR_FIRST;
-        } else if (videoSource == MonitorVideoSourceEnum.MOBILE_SECOND) {
-            return Source.MOBILE_MONITOR_SECOND;
-        }
-        return null;
-    }
 }

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/util/OssUtil.java

@@ -227,7 +227,7 @@ public class OssUtil {
      * @return
      */
     public String getPrivateUrl(String objectPath) {
-        Date expiration = new Date(System.currentTimeMillis() + 60 * 1000);
+        Date expiration = new Date(System.currentTimeMillis() + 5 * 60 * 1000);
         GeneratePresignedUrlRequest generatePresignedUrlRequest;
         generatePresignedUrlRequest = new GeneratePresignedUrlRequest(aliYunOssPrivateDomain.getPrivateBucket(),
                 objectPath);

+ 2 - 2
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -219,7 +219,7 @@ public class TEStudentController {
         }
         //添加用户会话缓存
         String sessionId = SessionUtil
-                .digest(teStudent.getIdentity(), Math.abs(authDto.getRoleCodes().toString().hashCode()), source);
+                .digest(teStudent.getId(), Math.abs(authDto.getRoleCodes().toString().hashCode()), source);
 
         ExpireTimeDTO expireTime = SystemConstant.getExpireTime(source, platform);
         TBSession tbSession = new TBSession(sessionId, String.valueOf(teStudent.getId()),
@@ -305,7 +305,7 @@ public class TEStudentController {
         boolean delete = true;
         for (Source s : Source.values()) {
             String sessionId = SessionUtil
-                    .digest(teStudent.getIdentity(), Math.abs(authDto.getRoleCodes().toString().hashCode()), s.name());
+                    .digest(teStudent.getId(), Math.abs(authDto.getRoleCodes().toString().hashCode()), s.name());
             if (Objects.nonNull(redisUtil.getUserSession(sessionId))) {
                 delete = false;
                 break;