From 7293f04d18fb2e882e152f962c3aa1d8fcb1f93e Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Wed, 17 Nov 2021 15:46:35 +0800
Subject: [PATCH] 证书打印信息导出修改
---
src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java | 273 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 259 insertions(+), 14 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 71ed432..ec41545 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
@@ -5,15 +5,22 @@
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.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;
@@ -22,10 +29,14 @@
* @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;
+
@Override
public IPage<ExamSubjectChoicesVO> selectExamSubjectChoicesPage(IPage<ExamSubjectChoicesVO> page, ExamSubjectChoicesVO examSubjectChoices) {
@@ -89,12 +100,6 @@
});
return true;
}
- //内网数据同步
- try {
-// arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
- } catch (Exception e) {
- e.printStackTrace();
- }
}else {
//修改
ExamSubjectChoices subjectChoices = new ExamSubjectChoices();
@@ -139,13 +144,253 @@
});
return true;
}
- //内网数据同步
- try {
-// arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
- } catch (Exception e) {
- e.printStackTrace();
- }
}
return status;
}
+
+
+ /**
+ * 题库导入
+ * @param data 导入数据
+ * @param isCovered
+ */
+ @Override
+ public void importSubject(List<ExamSubjectExcel> data, Boolean isCovered) {
+ data.forEach(examSubjectExcel -> {
+ //题目对象
+ ExamSubjectChoices subjectChoices = new ExamSubjectChoices();
+ subjectChoices.setCreateDate(new Date());
+ subjectChoices.setDelFlag(0);
+ subjectChoices.setAnswer(examSubjectExcel.getAnswer());
+ if (null != examSubjectExcel.getAnalysis() && examSubjectExcel.getAnalysis() != "") {
+ subjectChoices.setAnalysis(examSubjectExcel.getAnalysis());
+ }
+ subjectChoices.setChoicesType(examSubjectExcel.getChoicesType());
+ subjectChoices.setSubjectName(examSubjectExcel.getSubjectName());
+ subjectChoices.setScore(examSubjectExcel.getScore());
+ subjectChoices.setTktype(examSubjectExcel.getTktype());
+ //题目新增
+ this.save(subjectChoices);
+
+
+ //判断类型,单选,多选选项新增
+ if (examSubjectExcel.getChoicesType() == 0 || examSubjectExcel.getChoicesType() == 1) {
+ //A选项新增
+ ExamSubjectOption examSubjectOption = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption.setCreateDate(new Date());
+ examSubjectOption.setDelFlag(0);
+ examSubjectOption.setOptionName("A");
+ examSubjectOption.setOptionContent(examSubjectExcel.getOptionContentA());
+ //新增
+ examSubjectOptionService.save(examSubjectOption);
+
+ //B选项新增
+ ExamSubjectOption examSubjectOption1 = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption1.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption1.setCreateDate(new Date());
+ examSubjectOption1.setDelFlag(0);
+ examSubjectOption1.setOptionName("B");
+ examSubjectOption1.setOptionContent(examSubjectExcel.getOptionContentB());
+ //新增
+ examSubjectOptionService.save(examSubjectOption1);
+
+ //C选项新增
+ ExamSubjectOption examSubjectOption2 = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption2.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption2.setCreateDate(new Date());
+ examSubjectOption2.setDelFlag(0);
+ examSubjectOption2.setOptionName("C");
+ examSubjectOption2.setOptionContent(examSubjectExcel.getOptionContentC());
+ //新增
+ examSubjectOptionService.save(examSubjectOption2);
+
+ //D选项新增
+ ExamSubjectOption examSubjectOption3 = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption3.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption3.setCreateDate(new Date());
+ examSubjectOption3.setDelFlag(0);
+ examSubjectOption3.setOptionName("D");
+ examSubjectOption3.setOptionContent(examSubjectExcel.getOptionContentD());
+ //新增
+ examSubjectOptionService.save(examSubjectOption3);
+ }
+
+
+ //多选选项新增
+ if (examSubjectExcel.getChoicesType() == 3) {
+ //1选项新增
+ if (null!=examSubjectExcel.getOptionContentA() && examSubjectExcel.getOptionContentA()!="") {
+ ExamSubjectOption examSubjectOption = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption.setCreateDate(new Date());
+ examSubjectOption.setDelFlag(0);
+ examSubjectOption.setOptionName("1");
+ examSubjectOption.setOptionContent(examSubjectExcel.getOptionContentA());
+ //新增
+ examSubjectOptionService.save(examSubjectOption);
+ }
+
+ //2选项新增
+ if (null!=examSubjectExcel.getOptionContentB() && examSubjectExcel.getOptionContentB()!="") {
+ ExamSubjectOption examSubjectOption1 = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption1.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption1.setCreateDate(new Date());
+ examSubjectOption1.setDelFlag(0);
+ examSubjectOption1.setOptionName("2");
+ examSubjectOption1.setOptionContent(examSubjectExcel.getOptionContentB());
+ //新增
+ examSubjectOptionService.save(examSubjectOption1);
+ }
+
+ //3选项新增
+ if (null!=examSubjectExcel.getOptionContentC() && examSubjectExcel.getOptionContentC()!="") {
+ ExamSubjectOption examSubjectOption2 = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption2.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption2.setCreateDate(new Date());
+ examSubjectOption2.setDelFlag(0);
+ examSubjectOption2.setOptionName("3");
+ examSubjectOption2.setOptionContent(examSubjectExcel.getOptionContentC());
+ //新增
+ examSubjectOptionService.save(examSubjectOption2);
+ }
+
+ //4选项新增
+ if (null!=examSubjectExcel.getOptionContentD() && examSubjectExcel.getOptionContentD()!="") {
+ ExamSubjectOption examSubjectOption3 = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption3.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption3.setCreateDate(new Date());
+ examSubjectOption3.setDelFlag(0);
+ examSubjectOption3.setOptionName("4");
+ examSubjectOption3.setOptionContent(examSubjectExcel.getOptionContentD());
+ //新增
+ examSubjectOptionService.save(examSubjectOption3);
+ }
+
+
+ //5选项新增
+ if (null!=examSubjectExcel.getOptionContentE() && examSubjectExcel.getOptionContentE()!="") {
+ ExamSubjectOption examSubjectOption4 = new ExamSubjectOption();
+ //选项新增
+ examSubjectOption4.setSubjectChoicesId(subjectChoices.getId());
+ examSubjectOption4.setCreateDate(new Date());
+ examSubjectOption4.setDelFlag(0);
+ examSubjectOption4.setOptionName("5");
+ examSubjectOption4.setOptionContent(examSubjectExcel.getOptionContentE());
+ //新增
+ examSubjectOptionService.save(examSubjectOption4);
+ }
+ }
+ });
+
+ }
+
+
+ /**
+ * 判断当前题目的答题结果
+ * @param preSubJectId 题目Id
+ * @param preResult 提交的结果
+ * @param scoreId 成绩id
+ * @return
+ */
+ @Override
+ public Integer getAnswerResult(Long preSubJectId, String preResult,Long scoreId) {
+ //查询题目信息
+ 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;
+ }
+ //新增答题记录
+ saveExamAns(choices,preSubJectId,preResult,scoreId,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;
+ }
+ //新增答题记录
+ 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);
+ }
}
--
Gitblit v1.9.3