From 8853292babb2ad94de4a3207966f1e83b767cd2d Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Sun, 17 Sep 2023 16:38:34 +0800
Subject: [PATCH] 新增流程节点进程查询接口

---
 src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java |  238 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 206 insertions(+), 32 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 d8be14a..24c8ff8 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,31 +3,47 @@
 
 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;
 import org.springblade.modules.exam.excel.ExamSubjectExcel;
 import org.springblade.modules.exam.mapper.ExamSubjectChoicesMapper;
+import org.springblade.modules.exam.service.ExamAnswerRecordService;
 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.springblade.modules.system.service.MyAsyncService;
+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;
 
 /**
  * 选择题服务实现类
+ *
  * @author zhongrj
  */
 @Service
-@AllArgsConstructor
 public class ExamSubjectChoicesServiceImpl extends ServiceImpl<ExamSubjectChoicesMapper, ExamSubjectChoices> implements ExamSubjectChoicesService {
 
-	private final ExamSubjectOptionService examSubjectOptionService;
+	@Autowired
+	private ExamSubjectOptionService examSubjectOptionService;
+
+	@Autowired
+	private ExamAnswerRecordService examAnswerRecordService;
+
+	@Autowired
+	private SimulateExamAnswerRecordService simulateExamAnswerRecordService;
+	@Autowired
+	private MyAsyncService myAsyncService;
+
 
 	@Override
 	public IPage<ExamSubjectChoicesVO> selectExamSubjectChoicesPage(IPage<ExamSubjectChoicesVO> page, ExamSubjectChoicesVO examSubjectChoices) {
@@ -41,6 +57,7 @@
 
 	/**
 	 * 详情
+	 *
 	 * @param examSubjectChoices 选择题信息对象
 	 */
 	@Override
@@ -50,11 +67,12 @@
 
 	@Override
 	public boolean updateChoicesValue(String id, String value) {
-		return baseMapper.updateChoicesValue(id,value);
+		return baseMapper.updateChoicesValue(id, value);
 	}
 
 	/**
 	 * 新增题目及选项信息
+	 *
 	 * @param examSubjectChoices 题目信息对象
 	 * @return
 	 */
@@ -91,7 +109,7 @@
 				});
 				return true;
 			}
-		}else {
+		} else {
 			//修改
 			ExamSubjectChoices subjectChoices = new ExamSubjectChoices();
 			subjectChoices.setId(examSubjectChoices.getId());
@@ -142,7 +160,8 @@
 
 	/**
 	 * 题库导入
-	 * @param data 导入数据
+	 *
+	 * @param data      导入数据
 	 * @param isCovered
 	 */
 	@Override
@@ -215,7 +234,7 @@
 			//多选选项新增
 			if (examSubjectExcel.getChoicesType() == 3) {
 				//1选项新增
-				if (null!=examSubjectExcel.getOptionContentA() && examSubjectExcel.getOptionContentA()!="") {
+				if (null != examSubjectExcel.getOptionContentA() && examSubjectExcel.getOptionContentA() != "") {
 					ExamSubjectOption examSubjectOption = new ExamSubjectOption();
 					//选项新增
 					examSubjectOption.setSubjectChoicesId(subjectChoices.getId());
@@ -228,7 +247,7 @@
 				}
 
 				//2选项新增
-				if (null!=examSubjectExcel.getOptionContentB() && examSubjectExcel.getOptionContentB()!="") {
+				if (null != examSubjectExcel.getOptionContentB() && examSubjectExcel.getOptionContentB() != "") {
 					ExamSubjectOption examSubjectOption1 = new ExamSubjectOption();
 					//选项新增
 					examSubjectOption1.setSubjectChoicesId(subjectChoices.getId());
@@ -241,7 +260,7 @@
 				}
 
 				//3选项新增
-				if (null!=examSubjectExcel.getOptionContentC() && examSubjectExcel.getOptionContentC()!="") {
+				if (null != examSubjectExcel.getOptionContentC() && examSubjectExcel.getOptionContentC() != "") {
 					ExamSubjectOption examSubjectOption2 = new ExamSubjectOption();
 					//选项新增
 					examSubjectOption2.setSubjectChoicesId(subjectChoices.getId());
@@ -254,7 +273,7 @@
 				}
 
 				//4选项新增
-				if (null!=examSubjectExcel.getOptionContentD() && examSubjectExcel.getOptionContentD()!="") {
+				if (null != examSubjectExcel.getOptionContentD() && examSubjectExcel.getOptionContentD() != "") {
 					ExamSubjectOption examSubjectOption3 = new ExamSubjectOption();
 					//选项新增
 					examSubjectOption3.setSubjectChoicesId(subjectChoices.getId());
@@ -268,7 +287,7 @@
 
 
 				//5选项新增
-				if (null!=examSubjectExcel.getOptionContentE() && examSubjectExcel.getOptionContentE()!="") {
+				if (null != examSubjectExcel.getOptionContentE() && examSubjectExcel.getOptionContentE() != "") {
 					ExamSubjectOption examSubjectOption4 = new ExamSubjectOption();
 					//选项新增
 					examSubjectOption4.setSubjectChoicesId(subjectChoices.getId());
@@ -280,13 +299,6 @@
 					examSubjectOptionService.save(examSubjectOption4);
 				}
 			}
-
-			//内网数据同步
-			try {
-//				arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
 		});
 
 	}
@@ -294,23 +306,32 @@
 
 	/**
 	 * 判断当前题目的答题结果
+	 *
 	 * @param preSubJectId 题目Id
-	 * @param preResult 提交的结果
+	 * @param preResult    提交的结果
+	 * @param scoreId      成绩id
 	 * @return
 	 */
 	@Override
-	public Integer getAnswerResult(Long preSubJectId, String preResult) {
+	public Integer getAnswerResult(Long preSubJectId, String preResult, Long scoreId) {
 		//查询题目信息
 		ExamSubjectChoices choices = this.getById(preSubJectId);
 		//对比答案
-		if (choices.getChoicesType() == 2 || choices.getChoicesType() == 3){
+		if (choices.getChoicesType() == 2 || choices.getChoicesType() == 3) {
+			//保存答题记录
+			boolean result = preResult.equals(choices.getAnswer());
+			int status = 0;
 			//判断题逻辑
-			if (preResult.equals(choices.getAnswer())) {
-				return 1;
-			}else {
-				return 2;
+			if (result) {
+				status = 1;
+			} else {
+				status = 2;
 			}
-		}else if(choices.getChoicesType() == 0 || choices.getChoicesType() == 1){
+			//新增答题记录
+			saveExamAns(choices, preSubJectId, preResult, scoreId, result);
+			//返回
+			return status;
+		} else if (choices.getChoicesType() == 0 || choices.getChoicesType() == 1) {
 			//处理多选题的答案排序
 			String[] split = preResult.split(",");
 			StringBuilder builder = new StringBuilder();
@@ -321,13 +342,166 @@
 			//利用数组帮助类自动排序
 			Arrays.sort(arrayCh);
 			String sub0 = Arrays.toString(arrayCh);
-			String sub = sub0.substring(1,sub0.length()-1).replaceAll(" ","");
-			if (sub.equals(choices.getAnswer())) {
-				return 1;
-			}else {
-				return 2;
+			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;
 			}
+			//新增答题记录
+			saveExamAns(choices, preSubJectId, preResult, scoreId, result);
+			//返回
+			return status;
 		}
 		return 2;
 	}
+
+	/**
+	 * 新增答题记录
+	 *
+	 * @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();
+		examAnswerRecord.setScoreId(scoreId);
+		examAnswerRecord.setAnswerOption(preResult);
+		examAnswerRecord.setSubjectChoicesId(preSubJectId);
+		examAnswerRecord.setAnswer(choices.getAnswer());
+		examAnswerRecord.setSubjectChoicesType(choices.getChoicesType());
+		examAnswerRecord.setAnswerTime(new Date());
+		int status = 0;
+		//判断题逻辑
+		if (result) {
+			status = 1;
+			examAnswerRecord.setAnswerScore(choices.getScore());
+		} else {
+			status = 2;
+			examAnswerRecord.setAnswerScore(0);
+		}
+		examAnswerRecord.setAnswerResult(status);
+		//新增
+		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);
+		myAsyncService.dataSync(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