浏览代码

进度查询sql优化

wangliang 1 年之前
父节点
当前提交
68ea572e02

+ 10 - 0
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamController.java

@@ -336,6 +336,16 @@ public class TEExamController {
         teExam.setUpdateId(tbUser.getId());
         teExamService.updateById(teExam);
         teExamService.updateExamCacheBean(teExam.getId());
+
+        List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda().eq(TEExamActivity::getExamId, teExam.getId()).eq(TEExamActivity::getEnable, 1));
+        for (TEExamActivity t : teExamActivityList) {
+            if (Objects.nonNull(t.getEnable()) && t.getEnable().intValue() == 1 && (Objects.nonNull(t.getFinishTime()) && t.getFinishTime().longValue() > System.currentTimeMillis())) {
+                themisCacheService.updateTodayExamListCache(t.getExamId().toString(), t.getId());
+            } else {
+                themisCacheService.removeTodayExamListCache(t.getExamId().toString(), t.getId());
+            }
+            themisCacheService.updateOrgExamListCache(teExam.getOrgId().toString(), t.getExamId().toString(), t.getId());
+        }
         return ResultUtil.ok(true);
     }
 

+ 7 - 0
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateController.java

@@ -528,6 +528,13 @@ public class TIeInvigilateController {
             userId = tbUser.getId();
         }
         List<InvigilateListProgressExcelBean> invigilateListProgressExcelBeanList = tOeExamRecordService.invigilatePageProgressListExport(examId, examActivityId, roomCode, courseCode, name, identity, status, userId, tbUser.getOrgId(), breachStatus);
+
+        if (!CollectionUtils.isEmpty(invigilateListProgressExcelBeanList)) {
+            for (InvigilateListProgressExcelBean i : invigilateListProgressExcelBeanList) {
+                i.setCourseName(i.getCourseName() + "(" + i.getCourseCode() + ")");
+                i.setRoomName(i.getRoomName() + "(" + i.getRoomCode() + ")");
+            }
+        }
         ExportUtils.exportEXCEL("进度信息", InvigilateListProgressExcelBean.class, invigilateListProgressExcelBeanList, ServletUtil.getResponse());
     }
 

+ 30 - 8
themis-business/src/main/java/com/qmth/themis/business/bean/admin/InvigilateListProgressExcelBean.java

@@ -59,6 +59,28 @@ public class InvigilateListProgressExcelBean implements Serializable {
     @ExcelProperty(name = "违纪状态", width = 30, index = 10)
     private String breachStatus;
 
+    @ApiModelProperty(name = "虚拟考场编码")
+    private String roomCode;
+
+    @ApiModelProperty(name = "科目代码")
+    private String courseCode;
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getRoomCode() {
+        return roomCode;
+    }
+
+    public void setRoomCode(String roomCode) {
+        this.roomCode = roomCode;
+    }
+
     public String getClassNo() {
         return classNo;
     }
@@ -75,14 +97,6 @@ public class InvigilateListProgressExcelBean implements Serializable {
         this.breachStatus = breachStatus;
     }
 
-    public String getRoomName() {
-        return roomName;
-    }
-
-    public void setRoomName(String roomName) {
-        this.roomName = roomName;
-    }
-
     public String getExamName() {
         return examName;
     }
@@ -99,6 +113,14 @@ public class InvigilateListProgressExcelBean implements Serializable {
         this.examActivityCode = examActivityCode;
     }
 
+    public String getRoomName() {
+        return roomName;
+    }
+
+    public void setRoomName(String roomName) {
+        this.roomName = roomName;
+    }
+
     public String getCourseName() {
         return courseName;
     }

+ 9 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/TMTencentVideoMessageMapper.java

@@ -23,4 +23,13 @@ public interface TMTencentVideoMessageMapper extends BaseMapper<TMTencentVideoMe
      * @return
      */
     public List<TMTencentVideoMessage> videoQuery(@Param("examId") Long examId);
+
+
+    /**
+     * 查询视频源
+     *
+     * @param examRecordId
+     * @return
+     */
+    public String videoSourceQuery(@Param("examRecordId") Long examRecordId);
 }

+ 8 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TMTencentVideoMessageService.java

@@ -29,4 +29,12 @@ public interface TMTencentVideoMessageService extends IService<TMTencentVideoMes
      * @return
      */
     public List<TMTencentVideoMessage> videoQuery(Long examId);
+
+    /**
+     * 查询视频源
+     *
+     * @param examRecordId
+     * @return
+     */
+    public String videoSourceQuery(Long examRecordId);
 }

+ 6 - 5
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamSummaryServiceImpl.java

@@ -84,13 +84,14 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
             }
             log.info("examSummary examId:{},examActivityId:{},startTime:{},finalPrepareTime:{},endTime:{}", examId, ac.getId(), DateUtil.format(new Date(startTime), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(new Date(finalPrepareTime), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(new Date(endTime), "yyyy-MM-dd HH:mm:ss"));
             //最后侯考时间已过且未结束考试,当前侯考数设为0
-            if (finalPrepareTime >= timestamp) {
+            if (finalPrepareTime <= timestamp) {
                 teExamSummary.setPrepareCount(0);
-            }//交卷
-            else if (endTime <= timestamp) {//当考试场次结束时间已过,缺考=全部应考-已完成考试
+            }
+            //交卷
+            if (endTime <= timestamp) {//当考试场次结束时间已过,缺考=全部应考-已完成考试
                 teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getFinishCount());
-            } else {//否则缺考=全部应考-考试中-已完成考试
-                teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getExamCount() - teExamSummary.getFinishCount());
+            } else {//否则缺考=全部应考-侯考数(0)-考试中-已完成考试
+                teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getPrepareCount() - teExamSummary.getExamCount() - teExamSummary.getFinishCount());
             }
             TEExamSummary teExamSummaryDb = this.getOne(new QueryWrapper<TEExamSummary>().lambda()
                     .eq(TEExamSummary::getExamId, examId)

+ 12 - 5
themis-business/src/main/java/com/qmth/themis/business/service/impl/TMTencentVideoMessageServiceImpl.java

@@ -7,7 +7,6 @@ import com.qmth.themis.business.entity.TMTencentVideoMessage;
 import com.qmth.themis.business.service.TMTencentVideoMessageService;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -21,9 +20,6 @@ import java.util.List;
 @Service
 public class TMTencentVideoMessageServiceImpl extends ServiceImpl<TMTencentVideoMessageMapper, TMTencentVideoMessage> implements TMTencentVideoMessageService {
 
-    @Resource
-    TMTencentVideoMessageMapper tmTencentVideoMessageMapper;
-
     /**
      * 保存视频
      *
@@ -50,6 +46,17 @@ public class TMTencentVideoMessageServiceImpl extends ServiceImpl<TMTencentVideo
      */
     @Override
     public List<TMTencentVideoMessage> videoQuery(Long examId) {
-        return tmTencentVideoMessageMapper.videoQuery(examId);
+        return this.baseMapper.videoQuery(examId);
+    }
+
+    /**
+     * 查询视频源
+     *
+     * @param examRecordId
+     * @return
+     */
+    @Override
+    public String videoSourceQuery(Long examRecordId) {
+        return this.baseMapper.videoSourceQuery(examRecordId);
     }
 }

+ 12 - 2
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -115,6 +115,9 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
     @Resource
     TBOrgService tbOrgService;
 
+    @Resource
+    TMTencentVideoMessageService tmTencentVideoMessageService;
+
     @Transactional
     @Override
     public Long saveByPrepare(Long examId, Long examActivityId, Long examStudentId, Long paperId,
@@ -937,6 +940,10 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
                                                                         Long orgId, Integer breachStatus) {
         IPage<InvigilateListProgressBean> invigilateListProgressBeanIPage = tOeExamRecordMapper.invigilatePageProgressList(iPage, examId, examActivityId, roomCode, courseCode, name, identity, status, userId, orgId, breachStatus);
         for (InvigilateListProgressBean t : invigilateListProgressBeanIPage.getRecords()) {
+            if (Objects.isNull(t.getTencentVideoUrl())) {
+                String videoSource = tmTencentVideoMessageService.videoSourceQuery(t.getExamRecordId());
+                t.setVideoSource(videoSource);
+            }
             if (Objects.nonNull(t.getTencentVideoUrl()) && !Objects.equals(t.getTencentVideoUrl().trim(), "")) {
                 List<TEStudentMonitorRecordDto> monitorRecordList = GsonUtil.fromJson(t.getTencentVideoUrl(), new TypeToken<List<TEStudentMonitorRecordDto>>() {
                 }.getType());
@@ -1392,12 +1399,15 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
             Integer durationSeconds = Objects.isNull(ExamRecordCacheUtil.getDurationSeconds(recordId)) ? 0 : ExamRecordCacheUtil.getDurationSeconds(recordId);
             Integer alreadyBreakCount = Objects.isNull(ExamRecordCacheUtil.getAlreadyBreakCount(recordId)) ? 0 : ExamRecordCacheUtil.getAlreadyBreakCount(recordId);
             Integer leftBreakResumeCount = ec.getBreakResumeCount() - alreadyBreakCount;
+            if (ec.getBreakResumeCount().intValue() == 0 && alreadyBreakCount.intValue() == 0) {
+                leftBreakResumeCount = 1;
+            }
             if (Objects.nonNull(lastBreakTime)
-                    && (System.currentTimeMillis() - lastBreakTime) / 1000 >= breakExpireSeconds) {
+                    && (System.currentTimeMillis() - lastBreakTime.longValue()) / 1000 >= breakExpireSeconds) {
                 finished = true;
                 examService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
             } else {
-                if (leftBreakResumeCount <= 0) {
+                if (leftBreakResumeCount.intValue() <= 0) {
                     finished = true;
                     examService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
                 }

+ 6 - 0
themis-business/src/main/resources/mapper/TMTencentVideoMessageMapper.xml

@@ -15,4 +15,10 @@
             </if>
         </where>
     </select>
+
+    <select id="videoSourceQuery" resultType="java.lang.String">
+        select GROUP_CONCAT(tmtvm.video_source) as videoSource
+        from t_m_tencent_video_message tmtvm
+        where tmtvm.exam_record_id = #{examRecordId}
+    </select>
 </mapper>

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

@@ -418,12 +418,6 @@
 
     <select id="invigilatePageProgressList" resultType="com.qmth.themis.business.bean.admin.InvigilateListProgressBean">
         select
-        *,
-        if(t.statusTemp > 0,
-        '已完成',
-        '未完成') as status
-        from
-        (select
         distinct tee.id as examId,
         tee.name as examName,
         teea.id as examActivityId,
@@ -436,25 +430,10 @@
         tees.course_name as courseName,
         if(tee.exam_count - tees.already_exam_count <![CDATA[ < ]]> 0,0,tee.exam_count - tees.already_exam_count) as
         leftExamCount,
-        (select count(1) from t_oe_exam_record toer where 1 = 1
-        <if test="examId != null and examId != ''">
-            and toer.exam_id = #{examId}
-        </if>
-        and toer.exam_student_id = tees.id and toer.status in ('FINISHED','PERSISTED') and toer.first_start_time is not
-        null) as
-        statusTemp,
-        <!--tes.mobile_number as mobileNumber,-->
+        if(tees.already_exam_count > 0,'已完成','未完成') as status,
         t.id as examRecordId,
-        IFNULL(IF(t.tencent_video_url is not null, 1, null),(
-        select
-        count(1)
-        from
-        t_m_tencent_video_message tmtvm
-        where
-        tmtvm.exam_record_id = t.id)) as videoCount,
+        IFNULL(IF(t.tencent_video_url is not null, 1, null),( select count(1) from t_m_tencent_video_message tmtvm where tmtvm.exam_record_id = t.id)) as videoCount,
         t.monitor_record as monitorRecord,
-        (select GROUP_CONCAT(tmtvm.video_source) from t_m_tencent_video_message tmtvm where tmtvm.exam_record_id = t.id)
-        as videoSource,
         t.tencent_video_url as tencentVideoUrl,
         IFNULL(t.breach_status,1) as breachStatus,
         tees.class_no as classNo
@@ -492,67 +471,46 @@
             <if test="identity != null and identity !=''">
                 and tees.identity like CONCAT('%', #{identity},'%')
             </if>
-            and tee.monitor_status <![CDATA[ <> ]]> 'FINISHED'
-        </where>
-        group by t.id,
-        tees.room_code,
-        tees.room_name,
-        tees.course_code,tees.course_name,tee.name,teea.id,teea.code,tees.`identity`,tees.name,leftExamCount,statusTemp,tes.mobile_number,t.breach_status,tees.class_no) t
-        <where>
             <if test="status != null and status != '' or status == 0">
                 <choose>
                     <when test="status == 0">
-                        and t.statusTemp = 0
+                        and tees.already_exam_count = 0
                     </when>
                     <otherwise>
-                        and t.statusTemp <![CDATA[ > ]]> 0
+                        and tees.already_exam_count <![CDATA[ > ]]> 0
                     </otherwise>
                 </choose>
             </if>
             <if test="breachStatus != null and breachStatus != '' or breachStatus == 0">
                 <if test="breachStatus == 0">
-                    and t.breachStatus = #{breachStatus}
+                    and t.breach_status = #{breachStatus}
                 </if>
                 <if test="breachStatus == 1">
-                    and (t.breachStatus = #{breachStatus} or t.breachStatus is null)
+                    and (t.breach_status = #{breachStatus} or t.breach_status is null)
                 </if>
             </if>
+            and tee.monitor_status <![CDATA[ <> ]]> 'FINISHED'
         </where>
-        order by CAST(t.examActivityCode AS UNSIGNED),CAST(t.roomCode AS UNSIGNED)
+        order by CAST(teea.code AS UNSIGNED),CAST(tees.room_code AS UNSIGNED)
     </select>
 
     <select id="invigilatePageProgressListExport"
             resultType="com.qmth.themis.business.bean.admin.InvigilateListProgressExcelBean">
-        select
-        *,
-        if(t.statusTemp > 0,
-        '已完成',
-        '未完成') as status,
-        if(t.breachStatusTemp = 0,
-        '违纪',
-        '正常') as breachStatus
-        from
-        (select
-        distinct tee.id as examId,
+        select distinct tee.id as examId,
         tee.name as examName,
         teea.id as examActivityId,
         teea.code as examActivityCode,
+        tees.room_name as roomName,
         tees.room_code as roomCode,
-        group_concat(tees.room_name,CONCAT(CONCAT('(',tees.room_code),')')) as roomName,
+        tees.course_name as courseName,
+        tees.course_code as courseCode,
+        <!--group_concat(tees.room_name,CONCAT(CONCAT('(',tees.room_code),')')) as roomName,-->
         tees.`identity`,
         tees.name,
-        group_concat(tees.course_name,CONCAT(CONCAT('(',tees.course_code),')')) as courseName,
-        if(tee.exam_count - tees.already_exam_count <![CDATA[ < ]]> 0,0,tee.exam_count - tees.already_exam_count) as
-        leftExamCount,
-        (select count(1) from t_oe_exam_record toer where 1 = 1
-        <if test="examId != null and examId != ''">
-            and toer.exam_id = #{examId}
-        </if>
-        and toer.exam_student_id = tees.id and toer.status in ('FINISHED','PERSISTED') and toer.first_start_time is not
-        null) as
-        statusTemp,
-        <!--tes.mobile_number as mobileNumber,-->
-        t.breach_status as breachStatusTemp,
+        <!--group_concat(tees.course_name,CONCAT(CONCAT('(',tees.course_code),')')) as courseName,-->
+        if(tee.exam_count - tees.already_exam_count <![CDATA[ < ]]> 0,0,tee.exam_count - tees.already_exam_count) as leftExamCount,
+        if(tees.already_exam_count > 0,'已完成','未完成') as status,
+        if(t.breach_status = 0,'违纪','正常') as breachStatus,
         tees.class_no as classNo
         from
         t_e_exam_student tees
@@ -591,33 +549,27 @@
             <if test="identity != null and identity !=''">
                 and tees.identity like CONCAT('%', #{identity},'%')
             </if>
-            and tee.monitor_status <![CDATA[ <> ]]> 'FINISHED'
-        </where>
-        group by t.id,
-        tees.room_code,
-        tees.room_name,
-        tees.course_code,tees.course_name,tee.name,teea.id,teea.code,tees.`identity`,tees.name,leftExamCount,statusTemp,tes.mobile_number,t.breach_status,tees.class_no) t
-        <where>
             <if test="status != null and status != '' or status == 0">
                 <choose>
                     <when test="status == 0">
-                        and t.statusTemp = 0
+                        and tees.already_exam_count = 0
                     </when>
                     <otherwise>
-                        and t.statusTemp <![CDATA[ > ]]> 0
+                        and tees.already_exam_count <![CDATA[ > ]]> 0
                     </otherwise>
                 </choose>
             </if>
             <if test="breachStatus != null and breachStatus != '' or breachStatus == 0">
                 <if test="breachStatus == 0">
-                    and t.breachStatusTemp = #{breachStatus}
+                    and t.breach_status = #{breachStatus}
                 </if>
                 <if test="breachStatus == 1">
-                    and (t.breachStatusTemp = #{breachStatus} or t.breachStatusTemp is null)
+                    and (t.breach_status = #{breachStatus} or t.breach_status is null)
                 </if>
             </if>
+            and tee.monitor_status <![CDATA[ <> ]]> 'FINISHED'
         </where>
-        order by CAST(t.examActivityCode AS UNSIGNED),CAST(t.roomCode AS UNSIGNED)
+        order by CAST(teea.code AS UNSIGNED),CAST(tees.room_code AS UNSIGNED)
     </select>
 
     <select id="invigilatePageListHistory" resultType="com.qmth.themis.business.bean.admin.InvigilateListHistoryBean">