|
@@ -4,15 +4,21 @@ 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.enums.PublishStatusEnum;
|
|
|
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 com.qmth.teachcloud.report.business.templete.strategy.CalculateTaskTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
@@ -21,17 +27,25 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
* @Author: CaoZixuan
|
|
|
* @Date: 2022-06-10
|
|
|
*/
|
|
|
+@Service
|
|
|
public class AnalyzeDataCalculateServiceImpl implements AnalyzeDataCalculateService {
|
|
|
@Resource
|
|
|
private TBExamCourseService tbExamCourseService;
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void dataCalculateStart(CalculateParams calculateParams) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
|
|
+ public void dataCalculateStart(CalculateParams calculateParams) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
|
|
|
+ AnalyzeForReportService analyzeForReportService = SpringContextHolder.getBean(AnalyzeForReportService.class);
|
|
|
+ CalculateTaskTemplate calculateTaskTemplate = SpringContextHolder.getBean(CalculateTaskTemplate.class);
|
|
|
+
|
|
|
+ TBSyncTask tbSyncTask = calculateParams.getTbSyncTask();
|
|
|
Long examId = calculateParams.getExamId();
|
|
|
Long schoolId = calculateParams.getSchoolId();
|
|
|
List<String> courseCodeList = calculateParams.getCourseCode();
|
|
|
- TBSyncTask tbSyncTask = calculateParams.getTbSyncTask();
|
|
|
List<String> needRepeatCourseCodeList = calculateParams.getRepeatCalculateCourseCodeList();
|
|
|
+ if (needRepeatCourseCodeList == null){
|
|
|
+ needRepeatCourseCodeList = new ArrayList<>();
|
|
|
+ }
|
|
|
|
|
|
// 上次计算失败的课程和表
|
|
|
String errorCourseCode = tbSyncTask.getObj();
|
|
@@ -51,45 +65,53 @@ public class AnalyzeDataCalculateServiceImpl implements AnalyzeDataCalculateServ
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
+ // 准备计算
|
|
|
+ analyzeForReportService.realityForCalculate(examId,courseCode);
|
|
|
// 上次计算异常且不需要重算的 - 断点续算
|
|
|
- if (courseCode.equals(errorCourseCode) && needRepeatCourseCodeList.contains(courseCode)){
|
|
|
- // 上次计算异常的课程,且不需要重算
|
|
|
- String errorMethod = tbSyncTask.getRemark();
|
|
|
- DataCalculateSequenceEnum error = DataCalculateSequenceEnum.valueOf(errorMethod);
|
|
|
- int errorIndex = error.getIndex();
|
|
|
+ try {
|
|
|
+ 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();
|
|
|
|
|
|
- for (DataCalculateSequenceEnum dataCalculateSequenceEnum : DataCalculateSequenceEnum.values()) {
|
|
|
- int currentIndex = dataCalculateSequenceEnum.getIndex();
|
|
|
- if (currentIndex < errorIndex){
|
|
|
- // 已经计算过的方法,不用重算,但进度需要累加
|
|
|
+ Method currenMethod = analyzeForReportService.getClass().getDeclaredMethod(currentMethodName,Long.class,String.class);
|
|
|
+ currenMethod.invoke(analyzeForReportService,examId,courseCode); // 实例化对象,参数
|
|
|
currentTask.addAndGet(dataCalculateSequenceEnum.getWeight());
|
|
|
- continue;
|
|
|
+ tbSyncTask.setProgress(BigDecimal.valueOf(currentTask.get()).divide(BigDecimal.valueOf(totalTask.get()),2, RoundingMode.HALF_UP));
|
|
|
+ calculateTaskTemplate.updateProgress(calculateParams);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 正常计算和重算
|
|
|
+ for (DataCalculateSequenceEnum dataCalculateSequenceEnum : DataCalculateSequenceEnum.values()) {
|
|
|
+ // 没有计算的方法和断点的方法都需要重新计算
|
|
|
+ tbSyncTask.setRemark(dataCalculateSequenceEnum.name());
|
|
|
+ String currentMethodName = dataCalculateSequenceEnum.getMethodName();
|
|
|
+ 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));
|
|
|
+ calculateTaskTemplate.updateProgress(calculateParams);
|
|
|
}
|
|
|
- // 没有计算的方法和断点的方法都需要重新计算
|
|
|
- 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 回调 ↓
|
|
|
}
|
|
|
+ // 计算完成
|
|
|
+ analyzeForReportService.updateCoursePublishStatus(examId,courseCode, PublishStatusEnum.UN_PUBLISH);
|
|
|
+ }catch (Exception e){
|
|
|
+ // 教研分析计算部分出错时,需要回归t_b_exam_course表状态为未计算 再向外抛出异常
|
|
|
+ analyzeForReportService.updateCoursePublishStatus(examId,courseCode, PublishStatusEnum.UN_COMPUTE);
|
|
|
+ throw e;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|