Jelajahi Sumber

剩余时间修改

wangliang 4 tahun lalu
induk
melakukan
2c453e9ad0

+ 54 - 2
themis-backend/src/main/java/com/qmth/themis/backend/api/TIeInvigilateController.java

@@ -122,13 +122,17 @@ public class TIeInvigilateController {
         IPage<InvigilateListVideoBean> invigilateListVideoBeanIPage = tOeExamRecordService.invigilatePageListVideo(new Page<>(pageNumber, pageSize), examId, examActivityId, roomCode, paperDownload, status, name, identity, minWarningCount, maxWarningCount, clientWebsocketStatus, userId, tbUser.getOrgId());
         if (Objects.nonNull(invigilateListVideoBeanIPage)) {
             List<InvigilateListVideoBean> invigilateListVideoBeanList = invigilateListVideoBeanIPage.getRecords();
-            ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
+            ExamCacheBean examCacheBean = null;
+            if (Objects.nonNull(examId)) {
+                examCacheBean = teExamService.getExamCacheBean(examId);
+            }
             List<String> monitorVideoSourceList = null;
-            if (Objects.nonNull(examCacheBean.getMonitorVideoSource()) && !Objects.equals(examCacheBean.getMonitorVideoSource().toString().trim().replaceAll(" ", ""), "")) {
+            if (Objects.nonNull(examCacheBean) && Objects.nonNull(examCacheBean.getMonitorVideoSource()) && !Objects.equals(examCacheBean.getMonitorVideoSource().toString().trim().replaceAll(" ", ""), "")) {
                 monitorVideoSourceList = Arrays.asList(examCacheBean.getMonitorVideoSource().trim().toUpperCase().replaceAll(" ", "").split(","));
             }
             if (Objects.nonNull(invigilateListVideoBeanList) && invigilateListVideoBeanList.size() > 0) {
                 List<String> finalMonitorVideoSourceList = monitorVideoSourceList;
+                ExamCacheBean finalExamCacheBean = examCacheBean;
                 invigilateListVideoBeanList.forEach(s -> {
                     if (Objects.nonNull(finalMonitorVideoSourceList) && finalMonitorVideoSourceList.size() > 0) {
                         finalMonitorVideoSourceList.forEach(l -> {
@@ -165,6 +169,10 @@ public class TIeInvigilateController {
                     if (Objects.nonNull(paperDownLoad)) {
                         s.setPaperDownload(paperDownLoad);
                     }
+                    //剩余时间计算
+                    if (Objects.nonNull(finalExamCacheBean)) {
+                        s.setRemainTime(this.getRemainTime(finalExamCacheBean.getMode(), s.getExamRecordId()));
+                    }
                 });
             }
         }
@@ -187,6 +195,11 @@ public class TIeInvigilateController {
         }
         List<InvigilateListVideoBean> invigilateListVideoBeanList = tOeExamRecordService.invigilatePageListVideoRandom(examId, userId, randomNum, tbUser.getOrgId());
         if (Objects.nonNull(invigilateListVideoBeanList) && invigilateListVideoBeanList.size() > 0) {
+            ExamCacheBean examCacheBean = null;
+            if (Objects.nonNull(examId)) {
+                examCacheBean = teExamService.getExamCacheBean(examId);
+            }
+            ExamCacheBean finalExamCacheBean = examCacheBean;
             invigilateListVideoBeanList.forEach(s -> {
                 String monitorLiveUrl = ExamRecordCacheUtil.getMonitorLiveUrl(s.getExamRecordId(), MonitorVideoSourceEnum.CLIENT_CAMERA);
                 if (Objects.nonNull(monitorLiveUrl)) {
@@ -200,6 +213,10 @@ public class TIeInvigilateController {
                 if (Objects.nonNull(paperDownLoad)) {
                     s.setPaperDownload(paperDownLoad);
                 }
+                //剩余时间计算
+                if (Objects.nonNull(finalExamCacheBean)) {
+                    s.setRemainTime(this.getRemainTime(finalExamCacheBean.getMode(), s.getExamRecordId()));
+                }
             });
         }
         return ResultUtil.ok(invigilateListVideoBeanList);
@@ -382,11 +399,20 @@ public class TIeInvigilateController {
         if (Objects.nonNull(invigilateListPatrolBeanIPage)) {
             List<InvigilateListPatrolBean> invigilateListPatrolBeanList = invigilateListPatrolBeanIPage.getRecords();
             if (Objects.nonNull(invigilateListPatrolBeanList) && invigilateListPatrolBeanList.size() > 0) {
+                ExamCacheBean examCacheBean = null;
+                if (Objects.nonNull(examId)) {
+                    examCacheBean = teExamService.getExamCacheBean(examId);
+                }
+                ExamCacheBean finalExamCacheBean = examCacheBean;
                 invigilateListPatrolBeanList.forEach(s -> {
                     WebsocketStatusEnum websocketStatusEnum = ExamRecordCacheUtil.getClientWebsocketStatus(s.getExamRecordId());
                     if (Objects.nonNull(websocketStatusEnum)) {
                         s.setClientWebsocketStatus(websocketStatusEnum);
                     }
+                    //剩余时间计算
+                    if (Objects.nonNull(finalExamCacheBean)) {
+                        s.setRemainTime(this.getRemainTime(finalExamCacheBean.getMode(), s.getExamRecordId()));
+                    }
                 });
             }
         }
@@ -652,4 +678,30 @@ public class TIeInvigilateController {
         examPropCountDto.setExamCount(examCount.get());
         return ResultUtil.ok(examPropCountDto);
     }
+
+    /**
+     * 获取剩余时间
+     *
+     * @param mode
+     * @param recordId
+     * @return
+     */
+    private String getRemainTime(ExamModeEnum mode, Long recordId) {
+        String remainTime = null;
+        Integer forceFinish = ExamRecordCacheUtil.getForceFinish(recordId);
+        Integer maxDurationSeconds = Objects.isNull(ExamRecordCacheUtil.getMaxDurationSeconds(recordId)) ? 0 : ExamRecordCacheUtil.getMaxDurationSeconds(recordId);
+        Integer durationSeconds = Objects.isNull(ExamRecordCacheUtil.getDurationSeconds(recordId)) ? 0 : ExamRecordCacheUtil.getDurationSeconds(recordId);
+        Long endTime = Objects.isNull(ExamRecordCacheUtil.getEndTime(recordId)) ? 0 : ExamRecordCacheUtil.getEndTime(recordId);
+        if (Objects.nonNull(mode) && Objects.equals(mode, ExamModeEnum.ANYTIME)) {
+            Long diffTime = maxDurationSeconds.longValue() - durationSeconds.longValue();
+            remainTime = diffTime.intValue() == 0 ? "00:00:00" : SystemConstant.getRemainTime(diffTime);
+        } else if (Objects.nonNull(mode) && Objects.equals(mode, ExamModeEnum.TOGETHER) && Objects.nonNull(forceFinish) && forceFinish.intValue() == 1) {
+            Long diffTime = endTime - System.currentTimeMillis();
+            remainTime = diffTime.intValue() == 0 ? "00:00:00" : SystemConstant.getRemainTime(diffTime);
+        } else {
+            Long diffTime = maxDurationSeconds.longValue() - durationSeconds.longValue();
+            remainTime = diffTime.intValue() == 0 ? "00:00:00" : SystemConstant.getRemainTime(diffTime);
+        }
+        return remainTime;
+    }
 }

+ 21 - 3
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -126,13 +126,13 @@ public class SystemConstant {
 
     //重新算分锁
     public static final String REDIS_LOCK_CALCULATE_SCORE_PREFIX = "lock:calculate_score:exam_id_";
-    
+
     //试卷导入锁
     public static final String REDIS_LOCK_PAPER_IMPORT_PREFIX = "lock:paper_import:exam_id_";
-    
+
     //重新算分和试卷导入互斥锁
     public static final String REDIS_LOCK_CALCULATE_SCORE_PAPER_IMPORT_PREFIX = "lock:calculate_score_paper_import:exam_id_";
-    
+
     //交卷锁
     public static final String REDIS_LOCK_FINISH_EXXAM_PREFIX = "lock:finish_exxam:record_id_";
     /**
@@ -286,4 +286,22 @@ public class SystemConstant {
         FILES_DIR = dir.getPath();
         TEMP_FILES_DIR = tempdir.getPath();
     }
+
+    /**
+     * 获取剩余时间
+     *
+     * @param diff
+     * @return
+     */
+    public static String getRemainTime(Long diff) {
+        long day = 0;
+        long hour = 0;
+        long min = 0;
+        long sec = 0;
+        day = diff / (24 * 60 * 60 * 1000);
+        hour = (diff / (60 * 60 * 1000) - day * 24);
+        min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
+        sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
+        return String.format("%02d", hour) + ":" + String.format("%02d", min) + ":" + String.format("%02d", sec);
+    }
 }

+ 8 - 8
themis-business/src/main/resources/mapper/TOeExamRecordMapper.xml

@@ -218,11 +218,11 @@
 		<include refid="invigilatePageHead"/>
 		,(select count(1) from t_ie_invigilate_warn_info tiiwi where tiiwi.exam_record_id = t.id and
 		tiiwi.approve_status = 0) as warningNew
-		,case
+		<!--,case
 		when tee.mode = 'ANYTIME' then SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
 		when tee.mode = 'TOGETHER' and tee.force_finish = 1 then SEC_TO_TIME((IFNULL(teea.finish_time, tee.end_time) - unix_timestamp(current_timestamp()) * 1000) / 1000)
 		else SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
-		end as remainTime
+		end as remainTime-->
 		<include refid="invigilatePageMiddle"/>
 		<include refid="invigilatePageFoot"/>
 		<if test="paperDownload != null and paperDownload != '' or paperDownload == 0">
@@ -245,11 +245,11 @@
 		<include refid="invigilatePageHead" />
 		,t.monitor_live_url as monitorLiveUrl
 		,(select count(1) from t_ie_invigilate_warn_info tiiwi where tiiwi.exam_record_id = t.id and tiiwi.approve_status = 0) as warningNew
-		,case
+		<!--,case
 		when tee.mode = 'ANYTIME' then SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
 		when tee.mode = 'TOGETHER' and tee.force_finish = 1 then SEC_TO_TIME((IFNULL(teea.finish_time, tee.end_time) - unix_timestamp(current_timestamp()) * 1000) / 1000)
 		else SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
-		end as remainTime
+		end as remainTime-->
 		<include refid="invigilatePageMiddle" />
 		<include refid="invigilatePageFoot" />
 		<if test="paperDownload != null and paperDownload != '' or paperDownload == 0">
@@ -267,11 +267,11 @@
 		<include refid="invigilatePageHead" />
 		,t.monitor_live_url as monitorLiveUrl
 		,(select count(1) from t_ie_invigilate_warn_info tiiwi where tiiwi.exam_record_id = t.id and tiiwi.approve_status = 0) as warningNew
-		,case
+		<!--,case
 		when tee.mode = 'ANYTIME' then SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
 		when tee.mode = 'TOGETHER' and tee.force_finish = 1 then SEC_TO_TIME((IFNULL(teea.finish_time, tee.end_time) - unix_timestamp(current_timestamp()) * 1000) / 1000)
 		else SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
-		end as remainTime
+		end as remainTime-->
 		<include refid="invigilatePageMiddle" />
 		<where> 1 = 1
 			<if test="examId != null and examId != ''">
@@ -290,11 +290,11 @@
 		,(select count(1) from t_ie_invigilate_exception_info tiiei where tiiei.exam_record_id = t.id) as exceptionCount
 		,(select count(1) from t_ie_invigilate_warn_info tiiwi where tiiwi.exam_record_id = t.id and tiiwi.`type` =
 		'FACE_COUNT_ERROR' and tiiwi.`level` = 'D8') as multipleFaceCount
-		,case
+		<!--,case
 		when tee.mode = 'ANYTIME' then SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
 		when tee.mode = 'TOGETHER' and tee.force_finish = 1 then SEC_TO_TIME((IFNULL(teea.finish_time, tee.end_time) - unix_timestamp(current_timestamp()) * 1000) / 1000)
 		else SEC_TO_TIME(IFNULL(teea.max_duration_seconds, tee.max_duration_seconds) - t.duration_seconds)
-		end as remainTime
+		end as remainTime-->
 		<include refid="invigilatePageMiddle" />
 		<include refid="invigilatePageFoot" />
 		<if test="status == null or status == ''">