|
|
|
@ -47,6 +47,9 @@ public class SaveSaveErrorProneStatisticsDomainServiceImpl implements SaveErrorP |
|
|
|
@Autowired |
|
|
|
private StringRedisTemplate redisTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TaskBaseService taskBaseService; |
|
|
|
|
|
|
|
private static final String LOCK_PREFIX = "lock:error_prone:"; |
|
|
|
// 锁自动过期时间5秒,防止死锁(拿到锁后程序崩溃没释放,5s自动失效)
|
|
|
|
private static final int LOCK_EXPIRE_SECONDS = 5; |
|
|
|
@ -347,4 +350,68 @@ public class SaveSaveErrorProneStatisticsDomainServiceImpl implements SaveErrorP |
|
|
|
} |
|
|
|
return Boolean.FALSE.equals(snapshot.getIsRight()); |
|
|
|
} |
|
|
|
|
|
|
|
// ==================== 审批通过减少错题数 ====================
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void decreaseErrorCountAfterAppeal(Long taskId, Long questionId, Integer questionType, Double revisedScore) { |
|
|
|
TaskEntity task = taskBaseService.getById(taskId); |
|
|
|
if (task == null) return; |
|
|
|
|
|
|
|
if (ExamModeEnum.GENERATIVE.getValue().equals(task.getExamMode())) { |
|
|
|
decreaseGenerativeErrorCount(taskId, questionId); |
|
|
|
} else if (ExamModeEnum.CLASSIC.getValue().equals(task.getExamMode())) { |
|
|
|
decreaseClassicErrorCount(taskId, questionId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成式:该题关联的所有知识点错题数减一 |
|
|
|
*/ |
|
|
|
private void decreaseGenerativeErrorCount(Long taskId, Long questionId) { |
|
|
|
QuestionEntity question = questionBaseService.getById(questionId); |
|
|
|
if (question == null || CollUtil.isEmpty(question.getKpIdList())) return; |
|
|
|
|
|
|
|
for (Long kpId : question.getKpIdList()) { |
|
|
|
String lockKey = LOCK_PREFIX + "gen:" + taskId + ":" + kpId; |
|
|
|
boolean locked = tryLock(lockKey); |
|
|
|
if (!locked) continue; |
|
|
|
|
|
|
|
try { |
|
|
|
ErrorProneStatisticsEntity entity = errorProneStatisticsBaseService.lambdaQuery() |
|
|
|
.eq(ErrorProneStatisticsEntity::getTaskId, taskId) |
|
|
|
.eq(ErrorProneStatisticsEntity::getKpId, kpId) |
|
|
|
.one(); |
|
|
|
if (entity != null && entity.getErrorCount() != null && entity.getErrorCount() > 0) { |
|
|
|
entity.setErrorCount(entity.getErrorCount() - 1); |
|
|
|
errorProneStatisticsBaseService.updateById(entity); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
unlock(lockKey); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 经典套题:该题错题数减一 |
|
|
|
*/ |
|
|
|
private void decreaseClassicErrorCount(Long taskId, Long questionId) { |
|
|
|
String lockKey = LOCK_PREFIX + "classic:" + taskId + ":" + questionId; |
|
|
|
boolean locked = tryLock(lockKey); |
|
|
|
if (!locked) return; |
|
|
|
|
|
|
|
try { |
|
|
|
ErrorProneStatisticsEntity entity = errorProneStatisticsBaseService.lambdaQuery() |
|
|
|
.eq(ErrorProneStatisticsEntity::getTaskId, taskId) |
|
|
|
.eq(ErrorProneStatisticsEntity::getExamMode, ExamModeEnum.CLASSIC.getValue()) |
|
|
|
.apply("JSON_CONTAINS(question_id_list, CAST({0} AS JSON))", questionId) |
|
|
|
.one(); |
|
|
|
if (entity != null && entity.getErrorCount() != null && entity.getErrorCount() > 0) { |
|
|
|
entity.setErrorCount(entity.getErrorCount() - 1); |
|
|
|
errorProneStatisticsBaseService.updateById(entity); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
unlock(lockKey); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|