From ab3024e6f8a3bc765bee326bf90afc07391ae449 Mon Sep 17 00:00:00 2001
From: 钟日健 <5689795+arsn@user.noreply.gitee.com>
Date: Thu, 24 Feb 2022 11:28:19 +0800
Subject: [PATCH] 新增保安公司密码未修改查询
---
src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java | 126 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 119 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java b/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
index 5048244..6092a32 100644
--- a/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
+++ b/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
@@ -3,8 +3,7 @@
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;
import org.springblade.modules.exam.entity.ExamSubjectOption;
@@ -14,10 +13,13 @@
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;
+import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@@ -34,6 +36,9 @@
@Autowired
private ExamAnswerRecordService examAnswerRecordService;
+
+ @Autowired
+ private SimulateExamAnswerRecordService simulateExamAnswerRecordService;
@Override
@@ -350,11 +355,11 @@
/**
* 新增答题记录
- * @param choices
- * @param preSubJectId
- * @param preResult
- * @param scoreId
- * @param result
+ * @param choices 题目
+ * @param preSubJectId 上一题题目id
+ * @param preResult 上一题答题结果
+ * @param scoreId 成绩 id
+ * @param result 答题是否正确
*/
private void saveExamAns(ExamSubjectChoices choices, Long preSubJectId, String preResult, Long scoreId,boolean result) {
ExamAnswerRecord examAnswerRecord = new ExamAnswerRecord();
@@ -378,5 +383,112 @@
examAnswerRecordService.save(examAnswerRecord);
//内网数据同步...
+ String s = "insert into exam_answer_record(id,subject_choices_id,subject_choices_type,answer_option,answer" +
+ ",answer_time,answer_score,answer_result,score_id) " +
+ "values(" + "'" + examAnswerRecord.getId() + "'" +
+ "," + "'" + examAnswerRecord.getSubjectChoicesId() + "'" +
+ "," + "'" + examAnswerRecord.getSubjectChoicesType() + "'" +
+ "," + "'" + examAnswerRecord.getAnswerOption() + "'" +
+ "," + "'" + examAnswerRecord.getAnswer() + "'" +
+ "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examAnswerRecord.getAnswerTime()) + "'" +
+ "," + "'" + examAnswerRecord.getAnswerScore() + "'" +
+ "," + "'" + examAnswerRecord.getAnswerResult() + "'" +
+ "," + "'" + examAnswerRecord.getScoreId() + "'" + ")";
+ FtpUtil.sqlFileUpload(s);
+ }
+
+ /**
+ * 随机查询题库120道
+ * @return
+ */
+ @Override
+ 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);
}
}
--
Gitblit v1.9.3