From 8458e64aab474c0fc2f49ae4ff22fb11ce5cf6e2 Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: 星期一, 11 十一月 2024 16:55:28 +0800
Subject: [PATCH] 批次新增学员查询条件,新增题目导入接口

---
 exam-framework/src/main/java/com/gkhy/exam/framework/job/UserStudyJob.java |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/exam-framework/src/main/java/com/gkhy/exam/framework/job/UserStudyJob.java b/exam-framework/src/main/java/com/gkhy/exam/framework/job/UserStudyJob.java
index 2e376f8..68ed589 100644
--- a/exam-framework/src/main/java/com/gkhy/exam/framework/job/UserStudyJob.java
+++ b/exam-framework/src/main/java/com/gkhy/exam/framework/job/UserStudyJob.java
@@ -8,7 +8,9 @@
 import com.gkhy.exam.system.domain.ExStudentStudy;
 import com.gkhy.exam.system.mapper.ExResourceMapper;
 import com.gkhy.exam.system.mapper.ExStudentStudyMapper;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
@@ -17,6 +19,7 @@
 /**
  * 学习进度job
  */
+@Slf4j
 @Component
 public class UserStudyJob {
     @Autowired
@@ -26,22 +29,36 @@
     @Autowired
     private RedisUtils redisUtils;
 
-    public void progress(){
-        Set<String> keys = redisUtils.keys(CacheConstant.STUDY_PROCESS_KEY + "*");
-        if(ObjectUtil.isNotEmpty(keys)){
-            for(String key:keys){
-                ExStudentStudy studentStudy = (ExStudentStudy) redisUtils.get(key);
-                ExResource resource=resourceMapper.selectById(studentStudy.getResourceId());
-                if(ResourceTypeEnum.VIDEO.getCode().equals(resource.getResourceType())||ResourceTypeEnum.AUDIO.getCode().equals(resource.getResourceType())){
-                    studentStudy.setProgress(new BigDecimal(studentStudy.getCurrentDuration()).divide(new BigDecimal(resource.getResourceLength()),BigDecimal.ROUND_CEILING).multiply(BigDecimal.valueOf(100)));
-                }else{
-                    studentStudy.setProgress(BigDecimal.valueOf(studentStudy.getCurrentPage()).divide(BigDecimal.valueOf(resource.getDocPage()).multiply(BigDecimal.valueOf(100))));
-
+    /**
+     * 建议:每10秒执行一次
+     */
+    @Scheduled(cron = "*/10 * * * * ?")
+    public void doprogress(){
+        try {
+            Set<String> keys = redisUtils.keys(CacheConstant.STUDY_PROCESS_KEY + "*");
+            if (ObjectUtil.isNotEmpty(keys)) {
+                for (String key : keys) {
+                    ExStudentStudy studentStudy = (ExStudentStudy) redisUtils.get(key);
+                    ExResource resource = resourceMapper.selectById(studentStudy.getResourceId());
+                    if (ResourceTypeEnum.VIDEO.getCode().equals(resource.getResourceType()) || ResourceTypeEnum.AUDIO.getCode().equals(resource.getResourceType())) {
+                        studentStudy.setProgress(new BigDecimal(studentStudy.getCurrentDuration()).divide(new BigDecimal(resource.getResourceLength()), BigDecimal.ROUND_CEILING).multiply(BigDecimal.valueOf(100)));
+                    } else {
+                        studentStudy.setProgress(BigDecimal.valueOf(studentStudy.getCurrentPage()).divide(BigDecimal.valueOf(resource.getDocPage()).multiply(BigDecimal.valueOf(100))));
+                    }
+                    studentStudyMapper.updateById(studentStudy);
+                    redisUtils.del(key);
                 }
-                studentStudyMapper.updateById(studentStudy);
-                redisUtils.del(key);
             }
+        }catch (Exception e){
+            log.error("UserStudyJob doprogress error:{}",e.getMessage());
         }
 
     }
+
+    /**
+     * 统计学员学习总进度
+     */
+    public void staticProgress(){
+
+    }
 }

--
Gitblit v1.9.2