kongzy
2024-09-14 f0f00e9ba8a755e4317e029d73b69a92ad9f9df1
exam-framework/src/main/java/com/gkhy/exam/framework/job/UserStudyJob.java
@@ -8,6 +8,7 @@
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;
@@ -18,6 +19,7 @@
/**
 * 学习进度job
 */
@Slf4j
@Component
public class UserStudyJob {
    @Autowired
@@ -31,7 +33,8 @@
     * 建议:每10秒执行一次
     */
    @Scheduled(cron = "*/10 * * * * ?")
    public void progress(){
    public void doprogress(){
        try {
        Set<String> keys = redisUtils.keys(CacheConstant.STUDY_PROCESS_KEY + "*");
        if(ObjectUtil.isNotEmpty(keys)){
            for(String key:keys){
@@ -41,12 +44,21 @@
                    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);
            }
        }
        }catch (Exception e){
            log.error("UserStudyJob doprogress error:{}",e.getMessage());
        }
    }
    /**
     * 统计学员学习总进度
     */
    public void staticProgress(){
    }
}