|
@@ -0,0 +1,95 @@
|
|
|
|
+package com.qmth.teachcloud.report.business.service.impl;
|
|
|
|
+
|
|
|
|
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
|
+import com.qmth.teachcloud.report.business.bean.params.CalculateParams;
|
|
|
|
+import com.qmth.teachcloud.report.business.entity.TBSyncTask;
|
|
|
|
+import com.qmth.teachcloud.report.business.enums.DataCalculateSequenceEnum;
|
|
|
|
+import com.qmth.teachcloud.report.business.service.AnalyzeDataCalculateService;
|
|
|
|
+import com.qmth.teachcloud.report.business.service.AnalyzeForReportService;
|
|
|
|
+import com.qmth.teachcloud.report.business.service.TBExamCourseService;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Description: 分析计算及进度控制及断点续算服务实现类
|
|
|
|
+ * @Author: CaoZixuan
|
|
|
|
+ * @Date: 2022-06-10
|
|
|
|
+ */
|
|
|
|
+public class AnalyzeDataCalculateServiceImpl implements AnalyzeDataCalculateService {
|
|
|
|
+ @Resource
|
|
|
|
+ private TBExamCourseService tbExamCourseService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void dataCalculateStart(CalculateParams calculateParams) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
|
|
|
+ Long examId = calculateParams.getExamId();
|
|
|
|
+ Long schoolId = calculateParams.getSchoolId();
|
|
|
|
+ List<String> courseCodeList = calculateParams.getCourseCode();
|
|
|
|
+ TBSyncTask tbSyncTask = calculateParams.getTbSyncTask();
|
|
|
|
+ List<String> needRepeatCourseCodeList = calculateParams.getRepeatCalculateCourseCodeList();
|
|
|
|
+
|
|
|
|
+ // 上次计算失败的课程和表
|
|
|
|
+ String errorCourseCode = tbSyncTask.getObj();
|
|
|
|
+
|
|
|
|
+ // 总任务数
|
|
|
|
+ AtomicInteger totalTask = new AtomicInteger(courseCodeList.size() * DataCalculateSequenceEnum.getTotalWeight());
|
|
|
|
+ AtomicInteger currentTask = new AtomicInteger(0);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (String courseCode : courseCodeList) {
|
|
|
|
+ // 判断是否不需要计算
|
|
|
|
+ if (!needRepeatCourseCodeList.contains(courseCode)){
|
|
|
|
+ // 如果不用重算,判断是否已经算过
|
|
|
|
+ if (tbExamCourseService.checkFinishCalculate(schoolId,examId,courseCode)){
|
|
|
|
+ // 如果不用重算且已经算过(记录进度)
|
|
|
|
+ currentTask.addAndGet(DataCalculateSequenceEnum.getTotalWeight());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 上次计算异常且不需要重算的 - 断点续算
|
|
|
|
+ if (courseCode.equals(errorCourseCode) && needRepeatCourseCodeList.contains(courseCode)){
|
|
|
|
+ // 上次计算异常的课程,且不需要重算
|
|
|
|
+ String errorMethod = tbSyncTask.getRemark();
|
|
|
|
+ DataCalculateSequenceEnum error = DataCalculateSequenceEnum.valueOf(errorMethod);
|
|
|
|
+ int errorIndex = error.getIndex();
|
|
|
|
+
|
|
|
|
+ for (DataCalculateSequenceEnum dataCalculateSequenceEnum : DataCalculateSequenceEnum.values()) {
|
|
|
|
+ int currentIndex = dataCalculateSequenceEnum.getIndex();
|
|
|
|
+ if (currentIndex < errorIndex){
|
|
|
|
+ // 已经计算过的方法,不用重算,但进度需要累加
|
|
|
|
+ currentTask.addAndGet(dataCalculateSequenceEnum.getWeight());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 没有计算的方法和断点的方法都需要重新计算
|
|
|
|
+ tbSyncTask.setRemark(dataCalculateSequenceEnum.name());
|
|
|
|
+ String currentMethodName = dataCalculateSequenceEnum.getMethodName();
|
|
|
|
+ AnalyzeForReportService analyzeForReportService = SpringContextHolder.getBean(AnalyzeForReportService.class);
|
|
|
|
+ Method currenMethod = analyzeForReportService.getClass().getDeclaredMethod(currentMethodName,Long.class,String.class);
|
|
|
|
+ currenMethod.invoke(analyzeForReportService,examId,courseCode); // 实例化对象,参数
|
|
|
|
+ currentTask.addAndGet(dataCalculateSequenceEnum.getWeight());
|
|
|
|
+ tbSyncTask.setProgress(BigDecimal.valueOf(currentTask.get()).divide(BigDecimal.valueOf(totalTask.get()),2, RoundingMode.HALF_UP));
|
|
|
|
+ // TODO: 2022/6/10 回调 ↓
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 正常计算和重算
|
|
|
|
+ for (DataCalculateSequenceEnum dataCalculateSequenceEnum : DataCalculateSequenceEnum.values()) {
|
|
|
|
+ // 没有计算的方法和断点的方法都需要重新计算
|
|
|
|
+ tbSyncTask.setRemark(dataCalculateSequenceEnum.name());
|
|
|
|
+ String currentMethodName = dataCalculateSequenceEnum.getMethodName();
|
|
|
|
+ AnalyzeForReportService analyzeForReportService = SpringContextHolder.getBean(AnalyzeForReportService.class);
|
|
|
|
+ Method currenMethod = analyzeForReportService.getClass().getDeclaredMethod(currentMethodName,Long.class,String.class);
|
|
|
|
+ currenMethod.invoke(analyzeForReportService,examId,courseCode); // 实例化对象,参数
|
|
|
|
+ currentTask.addAndGet(dataCalculateSequenceEnum.getWeight());
|
|
|
|
+ tbSyncTask.setProgress(BigDecimal.valueOf(currentTask.get()).divide(BigDecimal.valueOf(totalTask.get()),2, RoundingMode.HALF_UP));
|
|
|
|
+ // TODO: 2022/6/10 回调 ↓
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|