智慧保安后台管理-外网项目备份
src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
@@ -3,8 +3,6 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.common.utils.arg;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.exam.entity.ExamAnswerRecord;
import org.springblade.modules.exam.entity.ExamSubjectChoices;
@@ -15,6 +13,8 @@
import org.springblade.modules.exam.service.ExamSubjectChoicesService;
import org.springblade.modules.exam.service.ExamSubjectOptionService;
import org.springblade.modules.exam.vo.ExamSubjectChoicesVO;
import org.springblade.modules.simulateexam.entity.SimulateExamAnswerRecord;
import org.springblade.modules.simulateexam.service.SimulateExamAnswerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -36,6 +36,9 @@
   @Autowired
   private ExamAnswerRecordService examAnswerRecordService;
   @Autowired
   private SimulateExamAnswerRecordService simulateExamAnswerRecordService;
   @Override
@@ -402,4 +405,90 @@
   public List<String> getExamSubjectChoicesList() {
      return baseMapper.getExamSubjectChoicesList();
   }
   /**
    * 判断当前题目的答题结果
    * @param preSubJectId 题目 id
    * @param preResult 提交的结果
    * @param simulateExamId 模拟考试记录 id
    * @return
    */
   @Override
   public Integer getAnswerResultBySimulate(Long preSubJectId, String preResult, Long simulateExamId) {
      //查询题目信息
      ExamSubjectChoices choices = this.getById(preSubJectId);
      //对比答案
      if (choices.getChoicesType() == 2 || choices.getChoicesType() == 3){
         //保存答题记录
         boolean result = preResult.equals(choices.getAnswer());
         int status = 0;
         //判断题逻辑
         if (result){
            status = 1;
         }else {
            status = 2;
         }
         //新增模拟考试答题记录
         saveSimulateExamAns(choices,preSubJectId,preResult,simulateExamId,result);
         //返回
         return status;
      }else if(choices.getChoicesType() == 0 || choices.getChoicesType() == 1){
         //处理多选题的答案排序
         String[] split = preResult.split(",");
         StringBuilder builder = new StringBuilder();
         for (String s : split) {
            builder.append(s);
         }
         char[] arrayCh = builder.toString().toCharArray();
         //利用数组帮助类自动排序
         Arrays.sort(arrayCh);
         String sub0 = Arrays.toString(arrayCh);
         String sub = sub0.substring(1,sub0.length()-1).replaceAll(" ","");
         //保存模拟考试答题记录
         boolean result = sub.equals(choices.getAnswer());
         int status = 0;
         //判断题逻辑
         if (result){
            status = 1;
         }else {
            status = 2;
         }
         //新增模拟考试答题记录
         saveSimulateExamAns(choices,preSubJectId,preResult,simulateExamId,result);
         //返回
         return status;
      }
      return 2;
   }
   /**
    * 新增模拟考试答题记录
    * @param choices 题目信息
    * @param preSubJectId 题目id
    * @param preResult 提交的答案
    * @param simulateExamId 模拟考试id
    * @param result  答题的结果
    */
   private void saveSimulateExamAns(ExamSubjectChoices choices, Long preSubJectId, String preResult, Long simulateExamId, boolean result) {
      SimulateExamAnswerRecord simulateExamAnswerRecord = new SimulateExamAnswerRecord();
      simulateExamAnswerRecord.setSimulateExamId(simulateExamId);
      simulateExamAnswerRecord.setAnswerOption(preResult);
      simulateExamAnswerRecord.setSubjectChoicesId(preSubJectId);
      simulateExamAnswerRecord.setAnswer(choices.getAnswer());
      simulateExamAnswerRecord.setSubjectChoicesType(choices.getChoicesType());
      simulateExamAnswerRecord.setAnswerTime(new Date());
      int status = 0;
      //判断题逻辑
      if (result){
         status = 1;
         simulateExamAnswerRecord.setAnswerScore(choices.getScore());
      }else {
         status = 2;
         simulateExamAnswerRecord.setAnswerScore(0);
      }
      simulateExamAnswerRecord.setAnswerResult(status);
      //新增
      simulateExamAnswerRecordService.save(simulateExamAnswerRecord);
   }
}