Browse Source

加入清除考试缓存方法

wangliang 2 năm trước cách đây
mục cha
commit
000da98548

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

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.bean.admin.CountStopBean;
+import com.qmth.themis.business.cache.ExamingDataCacheUtil;
+import com.qmth.themis.business.cache.RedisKeyHelper;
 import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.constant.SystemConstant;
@@ -735,4 +737,34 @@ public class TEExamController {
         }
         return ResultUtil.ok(true);
     }
+
+    @ApiOperation(value = "清除考试缓存")
+    @RequestMapping(value = "/clean_exam_first_prepare_cache", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "考试信息")})
+    public Result cleanExamFirstPrepareCache(@ApiParam(value = "考试批次ids") @RequestParam(required = false) Set<Long> examIds) {
+        if (!CollectionUtils.isEmpty(examIds)) {
+            List<Map> list = tOeExamRecordService.cleanExamFirstPrepareCache(examIds);
+            if (!CollectionUtils.isEmpty(list)) {
+                Set<Long> examRecordIds = new HashSet<>();
+                for (Map map : list) {
+                    try {
+                        Long recordId = Long.parseLong(String.valueOf(map.get("examRecordId")));
+                        Long studentId = Long.parseLong(String.valueOf(map.get("studentId")));
+                        examRecordIds.add(recordId);
+                        ExamingDataCacheUtil.deleteUnFinishedRecordId(studentId);
+                        ExamingDataCacheUtil.deleteExamingRecordId(studentId);
+                        redisUtil.delete(RedisKeyHelper.examRecordCacheKey(recordId));
+                        redisUtil.delete(RedisKeyHelper.examAnswerKey(recordId));
+                        redisUtil.delete(RedisKeyHelper.audioLeftPlayCountKey(recordId));
+                        redisUtil.delete(RedisKeyHelper.livenessVerifyCacheKey(recordId));
+                        redisUtil.delete(RedisKeyHelper.faceVerifyCacheKey(recordId));
+                        redisUtil.delete(RedisKeyHelper.studentPaperStructKey(recordId));
+                    } catch (Exception e) {
+                    }
+                }
+                tOeExamRecordService.removeByIds(examRecordIds);
+            }
+        }
+        return ResultUtil.ok(true);
+    }
 }

+ 8 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/TOeExamRecordMapper.java

@@ -550,4 +550,12 @@ public interface TOeExamRecordMapper extends BaseMapper<TOeExamRecord> {
      * @return
      */
     public List<TOeExamRecord> persistedAnswerBatch(@Param("examId") Long examId, @Param("examActivityId") Long examActivityId, @Param("status") String status);
+
+    /**
+     * 清除考试缓存
+     *
+     * @param examIds
+     * @return
+     */
+    public List<Map> cleanExamFirstPrepareCache(@Param("examIds") Set<Long> examIds);
 }

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

@@ -555,4 +555,12 @@ public interface TOeExamRecordService extends IService<TOeExamRecord> {
      * @return
      */
     public List<TOeExamRecord> updateExamStatus();
+
+    /**
+     * 清除考试缓存
+     *
+     * @param examIds
+     * @return
+     */
+    public List<Map> cleanExamFirstPrepareCache(Set<Long> examIds);
 }

+ 11 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -1506,4 +1506,15 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
                 .eq(TOeExamRecord::getStatus, ExamRecordStatusEnum.FINISHED);
         return this.list(tOeExamRecordQueryWrapper);
     }
+
+    /**
+     * 清除考试缓存
+     *
+     * @param examIds
+     * @return
+     */
+    @Override
+    public List<Map> cleanExamFirstPrepareCache(Set<Long> examIds) {
+        return tOeExamRecordMapper.cleanExamFirstPrepareCache(examIds);
+    }
 }

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

@@ -1835,4 +1835,41 @@
             group by toer.id
             having count(toea.id) = 0
     </select>
+
+    <select id="cleanExamFirstPrepareCache" resultType="java.util.Map">
+        select
+        a.*
+        from
+        (
+        select
+        tes.id as studentId,
+        toer.id as examRecordId,
+        DATE_FORMAT(FROM_UNIXTIME(toer.first_prepare_time  / 1000), '%Y-%m-%d %H:%i:%s') as 'firstPrepareTime',
+        DATE_FORMAT(FROM_UNIXTIME(toer.finish_time / 1000), '%Y-%m-%d %H:%i:%s') as 'finishTime',
+        DATE_FORMAT(FROM_UNIXTIME(toer.first_start_time / 1000), '%Y-%m-%d %H:%i:%s') as 'firstStartTime',
+        DATE_FORMAT(FROM_UNIXTIME(toer.start_time / 1000), '%Y-%m-%d %H:%i:%s') as 'startTime',
+        DATE_FORMAT(FROM_UNIXTIME(toer.end_time / 1000), '%Y-%m-%d %H:%i:%s') as 'endTime'
+        from
+        t_oe_exam_record toer
+        join t_e_exam_student tees on tees.id = toer.exam_student_id
+        join t_e_student tes on tes.id = tees.student_id
+        <where>
+            toer.status = 'FIRST_PREPARE'
+            <if test="examIds != null and examIds != ''">
+                and toer.exam_id in
+                <foreach collection="examIds" item="examId" index="index" open="(" close=")" separator=",">
+                    #{examId}
+                </foreach>
+            </if>
+            and toer.first_prepare_time is not null
+            and toer.first_start_time is null
+            and toer.finish_time is null
+            and (toer.objective_score is null
+            or toer.objective_score = 0)
+        </where>
+        group by
+        toer.id
+        having
+        count(toer.id) > 0) a;
+    </select>
 </mapper>