|
@@ -1,10 +1,14 @@
|
|
|
package com.qmth.teachcloud.report.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.teachcloud.common.bean.params.TBExamCourseDeleteParams;
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.util.RedisUtil;
|
|
|
import com.qmth.teachcloud.report.business.entity.*;
|
|
|
import com.qmth.teachcloud.report.business.service.*;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -89,6 +93,9 @@ public class TBExamCourseDeleteServiceImpl implements TBExamCourseDeleteService
|
|
|
@Resource
|
|
|
AnalyzeForReportService analyzeForReportService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void deleteBasicTableData(Long schoolId, Long examId, String courseCode) {
|
|
@@ -292,24 +299,48 @@ public class TBExamCourseDeleteServiceImpl implements TBExamCourseDeleteService
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public synchronized void deleteTBExamCourse(List<TBExamCourseDeleteParams> tbExamCourseDeleteParamsList) {
|
|
|
- for (TBExamCourseDeleteParams tbExamCourseDeleteParams : tbExamCourseDeleteParamsList) {
|
|
|
- Long schoolId = tbExamCourseDeleteParams.getSchoolId();
|
|
|
- Long examId = tbExamCourseDeleteParams.getExamId();
|
|
|
- String courseCode = tbExamCourseDeleteParams.getCourseCode();
|
|
|
- if (tbExamCourseService.list(new QueryWrapper<TBExamCourse>()
|
|
|
- .lambda()
|
|
|
- .eq(TBExamCourse::getSchoolId,schoolId)
|
|
|
- .eq(TBExamCourse::getExamId,examId)
|
|
|
- .eq(TBExamCourse::getCourseCode,courseCode)).size() > 0){
|
|
|
- // 教研分析有这个课程再删除,没有不删直接返回
|
|
|
- if (tbExamCourseService.verifyExamCourseCantDelete(schoolId, examId, courseCode)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("考试id为【" + examId + "】,课程编号为【" + courseCode + "】的分析课程当前不能被删除");
|
|
|
+ public void deleteTBExamCourse(List<TBExamCourseDeleteParams> tbExamCourseDeleteParamsList) {
|
|
|
+ List<Long> schoolIdList = tbExamCourseDeleteParamsList.stream().map(TBExamCourseDeleteParams::getSchoolId).distinct().collect(Collectors.toList());
|
|
|
+ if (schoolIdList.size() != 1){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("学校信息异常");
|
|
|
+ }
|
|
|
+ Long lockSchoolId = schoolIdList.get(0);
|
|
|
+
|
|
|
+ List<Long> examIdList = tbExamCourseDeleteParamsList.stream().map(TBExamCourseDeleteParams::getExamId).distinct().collect(Collectors.toList());
|
|
|
+ if (examIdList.size() != 1){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不能删除不同考试下的分析课程");
|
|
|
+ }
|
|
|
+ Long lockExamId = examIdList.get(0);
|
|
|
+ List<String> courseCodeList = tbExamCourseDeleteParamsList.stream().map(TBExamCourseDeleteParams::getCourseCode).distinct().sorted().collect(Collectors.toList());
|
|
|
+ String lockCourseCode = DigestUtils.md5Hex(JSON.toJSONString(courseCodeList));
|
|
|
+ String lockKey = SystemConstant.REDIS_LOCK_GRADE_COURSE_DELETE_PREFIX + lockSchoolId + "-" + lockExamId + "-" + lockCourseCode;
|
|
|
+
|
|
|
+ boolean lock = redisUtil.lock(lockKey, SystemConstant.REDIS_LOCK_BATCH_NO_TIME_OUT);
|
|
|
+ if (!lock) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("正在删除数据,请稍候再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ for (TBExamCourseDeleteParams tbExamCourseDeleteParams : tbExamCourseDeleteParamsList) {
|
|
|
+ Long schoolId = tbExamCourseDeleteParams.getSchoolId();
|
|
|
+ Long examId = tbExamCourseDeleteParams.getExamId();
|
|
|
+ String courseCode = tbExamCourseDeleteParams.getCourseCode();
|
|
|
+ if (tbExamCourseService.list(new QueryWrapper<TBExamCourse>()
|
|
|
+ .lambda()
|
|
|
+ .eq(TBExamCourse::getSchoolId,schoolId)
|
|
|
+ .eq(TBExamCourse::getExamId,examId)
|
|
|
+ .eq(TBExamCourse::getCourseCode,courseCode)).size() > 0){
|
|
|
+ // 教研分析有这个课程再删除,没有不删直接返回
|
|
|
+ if (tbExamCourseService.verifyExamCourseCantDelete(schoolId, examId, courseCode)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("考试id为【" + examId + "】,课程编号为【" + courseCode + "】的分析课程当前不能被删除");
|
|
|
+ }
|
|
|
+ this.deleteBasicTableData(schoolId, examId, courseCode);
|
|
|
+ this.deleteAnalyzeTableData(schoolId, examId, courseCode);
|
|
|
+ this.repeatCalculateTotalTableData(schoolId, examId, courseCode);
|
|
|
}
|
|
|
- this.deleteBasicTableData(schoolId, examId, courseCode);
|
|
|
- this.deleteAnalyzeTableData(schoolId, examId, courseCode);
|
|
|
- this.repeatCalculateTotalTableData(schoolId, examId, courseCode);
|
|
|
}
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(lockKey);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|