浏览代码

先缓存删除后无法持久化的BUG

wangliang 2 年之前
父节点
当前提交
d33c5491d0

+ 2 - 6
themis-business/src/main/java/com/qmth/themis/business/service/impl/CommonServiceImpl.java

@@ -62,16 +62,12 @@ public class CommonServiceImpl implements CommonService {
     @Override
     public void persisted(Long recordId, Long studentId) {
         String lockKey = SystemConstant.REDIS_LOCK_EXAM_RECORD_PERSISTED_PREFIX + recordId;
-        Boolean lock = redisUtil.lock(lockKey, SystemConstant.REDIS_CACHE_TIME_OUT);
-        if (!lock) {
-            log.info("persisted doing,request ignore recordId:" + recordId);
-            return;
-        }
+        redisUtil.waitLock(lockKey, SystemConstant.REDIS_CACHE_TIME_OUT);
 
         try {
             ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(recordId);
             Double score = ExamRecordCacheUtil.getObjectiveScore(recordId);
-            if (Objects.isNull(status)) {
+            if (Objects.isNull(status) || Objects.isNull(score)) {
                 TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
                 status = tOeExamRecord.getStatus();
                 score = tOeExamRecord.getObjectiveScore();

+ 7 - 12
themis-task/src/main/java/com/qmth/themis/task/quartz/MqJob.java

@@ -55,18 +55,13 @@ public class MqJob extends QuartzJobBean {
             Map map = redisUtil.getHashEntries(redisKey);
             map.forEach((k, v) -> {
                 MqDto mqDto = (MqDto) v;
-//                if (Objects.nonNull(mqDto.getType()) && !mqDto.getType().name().contains(("Import".toUpperCase()))
-//                        && !mqDto.getType().name().contains(("Export".toUpperCase()))
-//                        && !mqDto.getType().name().contains(("Push".toUpperCase()))
-//                        && !mqDto.getType().name().contains(("Sync".toUpperCase()))) {
-                    if (mqDto.getReconsume() >= SystemConstant.MAXRECONSUMETIMES) {
-                        tmRocketMessageService.saveMqMessageError(mqDto, redisKey);
-                    } else {
-                        mqDto.setReconsume(mqDto.getReconsume() + 1);
-                        redisUtil.set(redisKey, mqDto.getId(), mqDto);
-                        producerServer.sendOneWay(mqDto);
-                    }
-//                }
+                if (mqDto.getReconsume() >= SystemConstant.MAXRECONSUMETIMES) {
+                    tmRocketMessageService.saveMqMessageError(mqDto, redisKey);
+                } else {
+                    mqDto.setReconsume(mqDto.getReconsume() + 1);
+                    redisUtil.set(redisKey, mqDto.getId(), mqDto);
+                    producerServer.sendOneWay(mqDto);
+                }
             });
         }
     }

+ 110 - 110
themis-task/src/main/java/com/qmth/themis/task/quartz/RepairJob.java

@@ -1,110 +1,110 @@
-package com.qmth.themis.task.quartz;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
-import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
-import com.qmth.themis.business.entity.TEExamStudent;
-import com.qmth.themis.business.entity.TOeExamRecord;
-import com.qmth.themis.business.enums.ExamRecordStatusEnum;
-import com.qmth.themis.business.service.CacheService;
-import com.qmth.themis.business.service.CommonService;
-import com.qmth.themis.business.service.TEExamStudentService;
-import com.qmth.themis.business.service.TOeExamRecordService;
-import org.quartz.JobExecutionContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.scheduling.quartz.QuartzJobBean;
-import org.springframework.util.CollectionUtils;
-
-import javax.annotation.Resource;
-import java.util.List;
-
-/**
- * @Description: repair job
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2022/11/1
- */
-public class RepairJob extends QuartzJobBean {
-    private final static Logger log = LoggerFactory.getLogger(RepairJob.class);
-
-    @Resource
-    TOeExamRecordService tOeExamRecordService;
-
-    @Resource
-    TEExamStudentService teExamStudentService;
-
-    @Resource
-    CommonService commonService;
-
-    @Resource
-    CacheService cacheService;
-
-    @Override
-    protected void executeInternal(JobExecutionContext context) {
-        log.info("repairJob进来了,context:{}", context);
-        this.persistedJob();
-    }
-
-    /**
-     * 持久化补救
-     */
-    public void persistedJob() {
-        log.info("persistedJob进来了");
-        QueryWrapper<TOeExamRecord> tOeExamRecordQueryWrapper = new QueryWrapper<>();
-        tOeExamRecordQueryWrapper.lambda().isNotNull(TOeExamRecord::getFirstStartTime)
-                .isNotNull(TOeExamRecord::getFinishTime)
-                .eq(TOeExamRecord::getStatus, ExamRecordStatusEnum.FINISHED);
-        List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.list(tOeExamRecordQueryWrapper);
-        if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
-            for (TOeExamRecord t : tOeExamRecordList) {
-                if ((System.currentTimeMillis() - t.getFinishTime().longValue()) / 1000 / 60 >= 30) {//超过30分钟则改状态
-                    try {
-                        ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(t.getExamStudentId());
-                        TEStudentCacheDto teStudent = cacheService.addStudentAccountCache(examStudentCacheBean.getStudentId());
-                        commonService.persisted(t.getId(), teStudent.getId());
-                    } catch (Exception e) {
-                    }
-                }
-            }
-        }
-        this.answerJob();
-        this.examStudentExamCountJob();
-    }
-
-    /**
-     * 答案补救
-     */
-    public void answerJob() {
-        log.info("answerJob进来了");
-        List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.persistedAnswerBatch(null, null, null);
-        if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
-            for (TOeExamRecord t : tOeExamRecordList) {
-                try {
-                    if ((System.currentTimeMillis() - t.getFinishTime().longValue()) / 1000 / 60 >= 30) {//超过30分钟则改状态
-                        tOeExamRecordService.saveDataByCachePersistedAnswer(t.getId());
-                    }
-                } catch (Exception e) {
-                }
-            }
-        }
-    }
-
-    /**
-     * 更新考生缓存
-     */
-    public void examStudentExamCountJob() {
-        log.info("examStudentExamCountJob进来了");
-        List<TEExamStudent> teExamStudentList = teExamStudentService.findAlreadyExamCountZero(null, null, null, null);
-        if (!CollectionUtils.isEmpty(teExamStudentList)) {
-            for (TEExamStudent t : teExamStudentList) {
-                try {
-                    teExamStudentService.updateExamStudentByCache(t.getId());
-                } catch (Exception e) {
-                }
-            }
-        }
-    }
-}
+//package com.qmth.themis.task.quartz;
+//
+//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+//import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
+//import com.qmth.themis.business.constant.SystemConstant;
+//import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
+//import com.qmth.themis.business.entity.TEExamStudent;
+//import com.qmth.themis.business.entity.TOeExamRecord;
+//import com.qmth.themis.business.enums.ExamRecordStatusEnum;
+//import com.qmth.themis.business.service.CacheService;
+//import com.qmth.themis.business.service.CommonService;
+//import com.qmth.themis.business.service.TEExamStudentService;
+//import com.qmth.themis.business.service.TOeExamRecordService;
+//import org.quartz.JobExecutionContext;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.scheduling.quartz.QuartzJobBean;
+//import org.springframework.util.CollectionUtils;
+//
+//import javax.annotation.Resource;
+//import java.util.List;
+//
+///**
+// * @Description: repair job
+// * @Param:
+// * @return:
+// * @Author: wangliang
+// * @Date: 2022/11/1
+// */
+//public class RepairJob extends QuartzJobBean {
+//    private final static Logger log = LoggerFactory.getLogger(RepairJob.class);
+//
+//    @Resource
+//    TOeExamRecordService tOeExamRecordService;
+//
+//    @Resource
+//    TEExamStudentService teExamStudentService;
+//
+//    @Resource
+//    CommonService commonService;
+//
+//    @Resource
+//    CacheService cacheService;
+//
+//    @Override
+//    protected void executeInternal(JobExecutionContext context) {
+//        log.info("repairJob进来了,context:{}", context);
+//        this.persistedJob();
+//    }
+//
+//    /**
+//     * 持久化补救
+//     */
+//    public void persistedJob() {
+//        log.info("persistedJob进来了");
+//        QueryWrapper<TOeExamRecord> tOeExamRecordQueryWrapper = new QueryWrapper<>();
+//        tOeExamRecordQueryWrapper.lambda().isNotNull(TOeExamRecord::getFirstStartTime)
+//                .isNotNull(TOeExamRecord::getFinishTime)
+//                .eq(TOeExamRecord::getStatus, ExamRecordStatusEnum.FINISHED);
+//        List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.list(tOeExamRecordQueryWrapper);
+//        if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
+//            for (TOeExamRecord t : tOeExamRecordList) {
+//                if ((System.currentTimeMillis() - t.getFinishTime().longValue()) / 1000 / 60 >= 30) {//超过30分钟则改状态
+//                    try {
+//                        ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(t.getExamStudentId());
+//                        TEStudentCacheDto teStudent = cacheService.addStudentAccountCache(examStudentCacheBean.getStudentId());
+//                        commonService.persisted(t.getId(), teStudent.getId());
+//                    } catch (Exception e) {
+//                    }
+//                }
+//            }
+//        }
+//        this.answerJob();
+//        this.examStudentExamCountJob();
+//    }
+//
+//    /**
+//     * 答案补救
+//     */
+//    public void answerJob() {
+//        log.info("answerJob进来了");
+//        List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.persistedAnswerBatch(null, null, null);
+//        if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
+//            for (TOeExamRecord t : tOeExamRecordList) {
+//                try {
+//                    if ((System.currentTimeMillis() - t.getFinishTime().longValue()) / 1000 / 60 >= 30) {//超过30分钟则改状态
+//                        tOeExamRecordService.saveDataByCachePersistedAnswer(t.getId());
+//                    }
+//                } catch (Exception e) {
+//                }
+//            }
+//        }
+//    }
+//
+//    /**
+//     * 更新考生缓存
+//     */
+//    public void examStudentExamCountJob() {
+//        log.info("examStudentExamCountJob进来了");
+//        List<TEExamStudent> teExamStudentList = teExamStudentService.findAlreadyExamCountZero(null, null, null, null);
+//        if (!CollectionUtils.isEmpty(teExamStudentList)) {
+//            for (TEExamStudent t : teExamStudentList) {
+//                try {
+//                    teExamStudentService.updateExamStudentByCache(t.getId());
+//                } catch (Exception e) {
+//                }
+//            }
+//        }
+//    }
+//}

+ 6 - 7
themis-task/src/main/java/com/qmth/themis/task/start/StartRunning.java

@@ -12,7 +12,6 @@ import com.qmth.themis.task.listener.QuartzOrderlyImpl;
 import com.qmth.themis.task.quartz.MqActivityJob;
 import com.qmth.themis.task.quartz.MqJob;
 import com.qmth.themis.task.quartz.ObjectiveAnswerCacheLoadJob;
-import com.qmth.themis.task.quartz.RepairJob;
 import com.qmth.themis.task.service.QuartzService;
 import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
 import org.slf4j.Logger;
@@ -77,12 +76,12 @@ public class StartRunning implements CommandLineRunner {
         quartzService.addJob(ObjectiveAnswerCacheLoadJob.class, QuartzTaskEnum.OBJECTIVE_ANSWER_CACHE_LOAD_JOB_NAME.name(), QuartzTaskEnum.OBJECTIVE_ANSWER_CACHE_LOAD_JOB_GROUP_NAME.name(), "0 0 1 * * ?", objectiveAnswerCacheMap);
         log.info("增加客观题答案缓存加载job end");
 
-        log.info("增加修复job start");
-        Map repairMap = new HashMap();
-        repairMap.put(SystemConstant.NAME, RepairJob.class.getName());
-        quartzService.deleteJob(QuartzTaskEnum.REPAIR_JOB_NAME.name(), QuartzTaskEnum.REPAIR_JOB_GROUP_NAME.name());
-        quartzService.addJob(RepairJob.class, QuartzTaskEnum.REPAIR_JOB_NAME.name(), QuartzTaskEnum.REPAIR_JOB_GROUP_NAME.name(), "0 0/10 * * * ?", repairMap);
-        log.info("增加修复job end");
+//        log.info("增加修复job start");
+//        Map repairMap = new HashMap();
+//        repairMap.put(SystemConstant.NAME, RepairJob.class.getName());
+//        quartzService.deleteJob(QuartzTaskEnum.REPAIR_JOB_NAME.name(), QuartzTaskEnum.REPAIR_JOB_GROUP_NAME.name());
+//        quartzService.addJob(RepairJob.class, QuartzTaskEnum.REPAIR_JOB_NAME.name(), QuartzTaskEnum.REPAIR_JOB_GROUP_NAME.name(), "0 0/10 * * * ?", repairMap);
+//        log.info("增加修复job end");
 
         /**
          * session