Browse Source

审批通过,统计错题数量减一

master
luogw 2 months ago
parent
commit
15eb8be98a
  1. 14
      src/main/java/com/project/appeal/domain/service/Impl/SaveAppealDomainServiceImpl.java
  2. 5
      src/main/java/com/project/statistics/application/StatisticsApplicationService.java
  3. 5
      src/main/java/com/project/statistics/application/impl/StatisticsApplicationServiceImpl.java
  4. 10
      src/main/java/com/project/statistics/domain/service/SaveErrorProneStatisticsDomainService.java
  5. 67
      src/main/java/com/project/statistics/domain/service/impl/SaveSaveErrorProneStatisticsDomainServiceImpl.java

14
src/main/java/com/project/appeal/domain/service/Impl/SaveAppealDomainServiceImpl.java

@ -15,6 +15,7 @@ import com.project.ding.utils.SecurityUtils;
import com.project.exam.domain.dto.ExamRecordDTO; import com.project.exam.domain.dto.ExamRecordDTO;
import com.project.exam.domain.entity.ExamRecordEntity; import com.project.exam.domain.entity.ExamRecordEntity;
import com.project.exam.mapper.ExamRecordMapper; import com.project.exam.mapper.ExamRecordMapper;
import com.project.statistics.application.StatisticsApplicationService;
import com.project.task.domain.entity.TaskEntity; import com.project.task.domain.entity.TaskEntity;
import com.project.task.domain.entity.TaskUserEntity; import com.project.task.domain.entity.TaskUserEntity;
import com.project.task.domain.enums.QuestionTypeEnum; import com.project.task.domain.enums.QuestionTypeEnum;
@ -44,6 +45,9 @@ public class SaveAppealDomainServiceImpl implements SaveAppealDomainService {
@Autowired @Autowired
private DingUtil dingUtil; private DingUtil dingUtil;
@Autowired
private StatisticsApplicationService statisticsApplicationService;
@Override @Override
@Transactional(rollbackFor = BusinessErrorException.class) @Transactional(rollbackFor = BusinessErrorException.class)
@ -101,6 +105,16 @@ public class SaveAppealDomainServiceImpl implements SaveAppealDomainService {
}else if(appealDTO.getStatus().equals(AppealStatusEnum.PASS_REVIEW.getValue()) && !Boolean.TRUE.equals(questionSnapshotDTO.getIsRight())){ }else if(appealDTO.getStatus().equals(AppealStatusEnum.PASS_REVIEW.getValue()) && !Boolean.TRUE.equals(questionSnapshotDTO.getIsRight())){
//审批通过需要加分 //审批通过需要加分
calculateScore(appealDTO, examRecord, index, questionSnapshotDTO.getType()); calculateScore(appealDTO, examRecord, index, questionSnapshotDTO.getType());
//加分后试题变正确,减少错题数
List<ExamRecordEntity.QuestionSnapshot> snapshots = examRecord.getAnswerSnapshot();
ExamRecordEntity.QuestionSnapshot updatedSnapshot = snapshots.get(index);
if (Boolean.TRUE.equals(updatedSnapshot.getIsRight())) {
TaskEntity taskEntity = taskMapper.getTaskByTaskUserId(examRecord.getTaskUserId());
statisticsApplicationService.decreaseErrorCountAfterAppeal(
taskEntity.getId(), appealDTO.getQuestionId(),
updatedSnapshot.getType(), appealDTO.getRevisedScore());
}
} }
//通知用户 //通知用户
dingUtil.sendWorkNotice(appealDTO); dingUtil.sendWorkNotice(appealDTO);

5
src/main/java/com/project/statistics/application/StatisticsApplicationService.java

@ -16,6 +16,11 @@ public interface StatisticsApplicationService {
void collectShortAnswerErrorProneStatistics(TaskDTO taskDTO, List<ExamRecordEntity.QuestionSnapshot> answerSnapshot); void collectShortAnswerErrorProneStatistics(TaskDTO taskDTO, List<ExamRecordEntity.QuestionSnapshot> answerSnapshot);
/**
* 审批通过后减少错题数
*/
void decreaseErrorCountAfterAppeal(Long taskId, Long questionId, Integer questionType, Double revisedScore);
Result<List<ErrorProneStatisticsDTO>> searchErrorProneTop(Long taskId); Result<List<ErrorProneStatisticsDTO>> searchErrorProneTop(Long taskId);
void singleExamStatistics(Long examRecordId) throws Exception; void singleExamStatistics(Long examRecordId) throws Exception;

5
src/main/java/com/project/statistics/application/impl/StatisticsApplicationServiceImpl.java

@ -58,6 +58,11 @@ public class StatisticsApplicationServiceImpl implements StatisticsApplicationSe
return searchErrorProneStatisticsDomainService.searchTopByTaskId(taskId); return searchErrorProneStatisticsDomainService.searchTopByTaskId(taskId);
} }
@Override
public void decreaseErrorCountAfterAppeal(Long taskId, Long questionId, Integer questionType, Double revisedScore) {
saveErrorProneStatisticsDomainService.decreaseErrorCountAfterAppeal(taskId, questionId, questionType, revisedScore);
}
@Override @Override
public void singleExamStatistics(Long examRecordId) throws Exception { public void singleExamStatistics(Long examRecordId) throws Exception {
ExamRecordDTO detail = getDetailExamRecordDomainService.getDetail(examRecordId).getData(); ExamRecordDTO detail = getDetailExamRecordDomainService.getDetail(examRecordId).getData();

10
src/main/java/com/project/statistics/domain/service/SaveErrorProneStatisticsDomainService.java

@ -22,4 +22,14 @@ public interface SaveErrorProneStatisticsDomainService {
* @param snapshots 已评分的简答题快照 * @param snapshots 已评分的简答题快照
*/ */
void collectShortAnswerErrorProneStatistics(TaskDTO taskDTO, List<ExamRecordEntity.QuestionSnapshot> snapshots); void collectShortAnswerErrorProneStatistics(TaskDTO taskDTO, List<ExamRecordEntity.QuestionSnapshot> snapshots);
/**
* 审批通过后减少错题数
*
* @param taskId 考试任务ID
* @param questionId 题目ID
* @param questionType 题目类型用于判断是否为简答题
* @param revisedScore 审批修改后的分数简答题判断是否得满分用
*/
void decreaseErrorCountAfterAppeal(Long taskId, Long questionId, Integer questionType, Double revisedScore);
} }

67
src/main/java/com/project/statistics/domain/service/impl/SaveSaveErrorProneStatisticsDomainServiceImpl.java

@ -47,6 +47,9 @@ public class SaveSaveErrorProneStatisticsDomainServiceImpl implements SaveErrorP
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
@Autowired
private TaskBaseService taskBaseService;
private static final String LOCK_PREFIX = "lock:error_prone:"; private static final String LOCK_PREFIX = "lock:error_prone:";
// 锁自动过期时间5秒,防止死锁(拿到锁后程序崩溃没释放,5s自动失效) // 锁自动过期时间5秒,防止死锁(拿到锁后程序崩溃没释放,5s自动失效)
private static final int LOCK_EXPIRE_SECONDS = 5; private static final int LOCK_EXPIRE_SECONDS = 5;
@ -347,4 +350,68 @@ public class SaveSaveErrorProneStatisticsDomainServiceImpl implements SaveErrorP
} }
return Boolean.FALSE.equals(snapshot.getIsRight()); 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);
}
}
} }

Loading…
Cancel
Save