|
|
|
@ -1,19 +1,27 @@ |
|
|
|
package com.project.appeal.domain.service.Impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.github.tingyugetc520.ali.dingtalk.error.DtErrorException; |
|
|
|
import com.project.appeal.domain.dto.AppealDTO; |
|
|
|
import com.project.appeal.domain.entity.AppealEntity; |
|
|
|
import com.project.appeal.domain.enums.StatusEnum; |
|
|
|
import com.project.appeal.domain.service.AppealBaseService; |
|
|
|
import com.project.appeal.domain.service.SaveAppealDomainService; |
|
|
|
import com.project.base.domain.exception.BusinessErrorException; |
|
|
|
import com.project.base.domain.result.Result; |
|
|
|
import com.project.ding.utils.DingUtil; |
|
|
|
import com.project.ding.utils.SecurityUtils; |
|
|
|
import com.project.exam.domain.dto.ExamRecordDTO; |
|
|
|
import com.project.exam.domain.entity.ExamRecordEntity; |
|
|
|
import com.project.exam.domain.service.ExamRecordBaseService; |
|
|
|
import com.project.exam.mapper.ExamRecordMapper; |
|
|
|
import com.project.task.domain.entity.TaskEntity; |
|
|
|
import com.project.task.domain.enums.QuestionTypeEnum; |
|
|
|
import com.project.task.mapper.TaskMapper; |
|
|
|
import org.redisson.mapreduce.Collector; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
@ -27,35 +35,55 @@ public class SaveAppealDomainServiceImpl implements SaveAppealDomainService { |
|
|
|
@Autowired |
|
|
|
private AppealBaseService appealBaseService; |
|
|
|
@Autowired |
|
|
|
private ExamRecordBaseService examRecordBaseService; |
|
|
|
private ExamRecordMapper examRecordMapper; |
|
|
|
@Autowired |
|
|
|
private TaskMapper taskMapper; |
|
|
|
@Autowired |
|
|
|
private DingUtil dingUtil; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<AppealDTO> saveOrUpdate(AppealDTO appealDTO) { |
|
|
|
@Transactional(rollbackFor = BusinessErrorException.class) |
|
|
|
public Result<AppealDTO> saveOrUpdate(AppealDTO appealDTO) throws DtErrorException { |
|
|
|
AppealEntity entity = appealDTO.toEntity(AppealEntity::new); |
|
|
|
|
|
|
|
//设置审批人
|
|
|
|
if (appealDTO.getStatus() != StatusEnum.PENDING_REVIEW.getValue()){ |
|
|
|
appealDTO.setAppealUserId(SecurityUtils.getUserId()); |
|
|
|
} |
|
|
|
|
|
|
|
appealBaseService.saveOrUpdate(entity); |
|
|
|
|
|
|
|
//如果审核通过,需要为用户加分
|
|
|
|
if (appealDTO.getStatus() != 2){ |
|
|
|
if (appealDTO.getStatus() != StatusEnum.PASS_REVIEW.getValue()) { |
|
|
|
//审核拒绝,发送工作通知消息,告知用户
|
|
|
|
if (appealDTO.getStatus() == StatusEnum.REFUSE_REVIEW.getValue()) { |
|
|
|
dingUtil.sendWorkNotice(appealDTO); |
|
|
|
} |
|
|
|
return Result.success(appealDTO); |
|
|
|
} |
|
|
|
|
|
|
|
ExamRecordEntity examRecord = examRecordBaseService.getById(appealDTO.getExamId()); |
|
|
|
ExamRecordEntity examRecord = examRecordMapper.selectById(appealDTO.getExamId()); |
|
|
|
if (examRecord == null){ |
|
|
|
throw new BusinessErrorException("用户未该场考试"); |
|
|
|
} |
|
|
|
//找到题目相关信息,获取该类型题目分数
|
|
|
|
ExamRecordDTO examRecordDTO = examRecord.toDTO(ExamRecordDTO::new); |
|
|
|
|
|
|
|
List<ExamRecordDTO.QuestionSnapshotDTO> answerSnapshotDTOList = examRecordDTO.getAnswerSnapshotDTOList(); |
|
|
|
ExamRecordDTO.QuestionSnapshotDTO questionSnapshotDTO = null; |
|
|
|
Optional<? extends ExamRecordDTO.QuestionSnapshotDTO> optionalDTO = examRecordDTO.getAnswerSnapshotDTOList().stream() |
|
|
|
.filter(answerSnapshotDTO -> appealDTO.getQuestionId() != null |
|
|
|
&& appealDTO.getQuestionId().equals(answerSnapshotDTO.getQuestionId())) |
|
|
|
.findFirst(); |
|
|
|
if (optionalDTO.isPresent()) { |
|
|
|
questionSnapshotDTO = optionalDTO.get(); |
|
|
|
|
|
|
|
int index = -1; |
|
|
|
for (int i = 0; i < answerSnapshotDTOList.size(); i++) { |
|
|
|
ExamRecordDTO.QuestionSnapshotDTO dto = answerSnapshotDTOList.get(i); |
|
|
|
if (appealDTO.getQuestionId() != null |
|
|
|
&& appealDTO.getQuestionId().equals(dto.getQuestionId())) { |
|
|
|
index = i; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (index != -1) { |
|
|
|
questionSnapshotDTO = answerSnapshotDTOList.get(index); |
|
|
|
}else { |
|
|
|
throw new BusinessErrorException("题目不存在"); |
|
|
|
} |
|
|
|
@ -67,28 +95,23 @@ public class SaveAppealDomainServiceImpl implements SaveAppealDomainService { |
|
|
|
|
|
|
|
TaskEntity taskEntity = taskMapper.getTaskByTaskUserId(examRecord.getTaskUserId()); |
|
|
|
|
|
|
|
Double questionScore = switch (questionSnapshotDTO.getType()) { |
|
|
|
case 1 -> taskEntity.getSingleChoiceScore(); |
|
|
|
case 2 -> taskEntity.getMultipleChoiceScore(); |
|
|
|
case 3 -> taskEntity.getTrueFalseScore(); |
|
|
|
default -> throw new IllegalArgumentException( |
|
|
|
"不支持的题目类型:" + questionSnapshotDTO.getType() |
|
|
|
); |
|
|
|
QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(questionSnapshotDTO.getType()); |
|
|
|
if (questionType == null) { |
|
|
|
throw new BusinessErrorException("不支持的题目类型:" + questionSnapshotDTO.getType()); |
|
|
|
} |
|
|
|
Double questionScore = switch (questionType) { |
|
|
|
case SINGLE_CHOICE-> taskEntity.getSingleChoiceScore(); |
|
|
|
case MULTIPLE_CHOICE -> taskEntity.getMultipleChoiceScore(); |
|
|
|
case TRUE_FALSE -> taskEntity.getTrueFalseScore(); |
|
|
|
}; |
|
|
|
|
|
|
|
//总分+单题分数
|
|
|
|
BigDecimal score = BigDecimal.valueOf(questionScore).add(BigDecimal.valueOf(examRecordDTO.getScore())).setScale(2, RoundingMode.HALF_UP); |
|
|
|
examRecord.setScore(score.doubleValue()); |
|
|
|
|
|
|
|
questionSnapshotDTO.setHasAppealed(true); |
|
|
|
List<ExamRecordDTO.QuestionSnapshotDTO> questionSnapshotDTOList = examRecordDTO.getAnswerSnapshotDTOList().stream() |
|
|
|
.filter(answerSnapshotDTO -> !appealDTO.getQuestionId().equals(answerSnapshotDTO.getQuestionId())) |
|
|
|
.collect(Collectors.toCollection(ArrayList::new)); |
|
|
|
questionSnapshotDTOList.add(questionSnapshotDTO); |
|
|
|
examRecordDTO.setAnswerSnapshotDTOList(questionSnapshotDTOList); |
|
|
|
|
|
|
|
//保存
|
|
|
|
examRecordBaseService.save(examRecordDTO.toEntity(ExamRecordEntity::new)); |
|
|
|
examRecordMapper.updateScore(index,score.doubleValue(),examRecord.getId()); |
|
|
|
//通知用户
|
|
|
|
dingUtil.sendWorkNotice(appealDTO); |
|
|
|
|
|
|
|
return Result.success(appealDTO); |
|
|
|
} |
|
|
|
|