|
@@ -1,33 +1,67 @@
|
|
|
package com.qmth.themis.business.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qmth.themis.business.bean.backend.OpenExamBean;
|
|
|
import com.qmth.themis.business.bean.backend.OpenExamCourseBean;
|
|
|
-import com.qmth.themis.business.dao.TEExamCourseMapper;
|
|
|
-import com.qmth.themis.business.dao.TEExamMapper;
|
|
|
+import com.qmth.themis.business.bean.backend.OpenRecordAnswerBean;
|
|
|
+import com.qmth.themis.business.bean.backend.OpenRecordNeedMarkBean;
|
|
|
+import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
|
|
|
+import com.qmth.themis.business.config.SystemConfig;
|
|
|
+import com.qmth.themis.business.constant.SpringContextHolder;
|
|
|
+import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.entity.TEExam;
|
|
|
+import com.qmth.themis.business.entity.TEExamCourse;
|
|
|
+import com.qmth.themis.business.enums.InvigilateMonitorStatusEnum;
|
|
|
+import com.qmth.themis.business.service.TEExamCourseService;
|
|
|
+import com.qmth.themis.business.service.TEExamPaperService;
|
|
|
+import com.qmth.themis.business.service.TEExamService;
|
|
|
import com.qmth.themis.business.service.TEOpenService;
|
|
|
+import com.qmth.themis.business.service.TOeExamAnswerService;
|
|
|
+import com.qmth.themis.business.service.TOeExamRecordService;
|
|
|
+import com.qmth.themis.common.exception.BusinessException;
|
|
|
+import com.qmth.themis.common.util.FileUtil;
|
|
|
|
|
|
@Service
|
|
|
public class TEOpenServiceImpl implements TEOpenService {
|
|
|
|
|
|
@Resource
|
|
|
- TEExamMapper teExamMapper;
|
|
|
+ TEExamService examService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEExamCourseService examCourseService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEExamPaperService examPaperService;
|
|
|
|
|
|
@Resource
|
|
|
- TEExamCourseMapper examCourseMapper;
|
|
|
+ TOeExamRecordService examRecordService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TOeExamAnswerService examAnswerService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public IPage<OpenExamBean> examQueryPage(Long examId, String examCode, int pageNumber, int pageSize) {
|
|
|
Page<OpenExamBean> ipage = new Page<>(pageNumber, pageSize);
|
|
|
- ipage.addOrder(OrderItem.desc("t.create_time"));
|
|
|
- return teExamMapper.examQueryForOpen(ipage, examId, examCode);
|
|
|
+ ipage.addOrder(OrderItem.desc("t.id"));
|
|
|
+ return examService.examQueryForOpen(ipage, examId, examCode);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -35,8 +69,202 @@ public class TEOpenServiceImpl implements TEOpenService {
|
|
|
public IPage<OpenExamCourseBean> examCourseQueryPage(Long examId, String courseCode, Boolean hasPaper,
|
|
|
int pageNumber, int pageSize) {
|
|
|
Page<OpenExamCourseBean> ipage = new Page<>(pageNumber, pageSize);
|
|
|
- ipage.addOrder(OrderItem.desc("t.create_time"));
|
|
|
- return examCourseMapper.examCourseQueryForOpen(ipage, examId,courseCode, hasPaper);
|
|
|
+ ipage.addOrder(OrderItem.desc("t.id"));
|
|
|
+ return examCourseService.examCourseQueryForOpen(ipage, examId,courseCode, hasPaper);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject examPaperDetail(Long paperId, String filter) {
|
|
|
+ String tempDir = SystemConstant.TEMP_FILES_DIR;
|
|
|
+ String dir = tempDir + "/" + uuid() + "/";
|
|
|
+ File dfile = new File(dir);
|
|
|
+
|
|
|
+ try {
|
|
|
+ ExamPaperCacheBean paper=examPaperService.getExamPaperCacheBean(paperId);
|
|
|
+ if(paper==null) {
|
|
|
+ throw new BusinessException("未找到试卷信息");
|
|
|
+ }
|
|
|
+ checkExam(paper.getExamId());
|
|
|
+ dfile.mkdirs();
|
|
|
+ String paperPath = paper.getPaperViewPath();
|
|
|
+ String anwserPath = paper.getAnswerPath();
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
+ File paperFile = new File(dir + uuid() + ".json");
|
|
|
+ File anwserFile = new File(dir + uuid() + ".json");
|
|
|
+ FileUtil.saveUrlAsFile(systemConfig.getProperty("aliyun.oss.url") + "/"+paperPath, paperFile);
|
|
|
+ FileUtil.saveUrlAsFile(systemConfig.getProperty("aliyun.oss.url") + "/"+anwserPath, anwserFile);
|
|
|
+ JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(anwserFile));
|
|
|
+ JSONArray answerdetails = answerJson.getJSONArray("details");
|
|
|
+ JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
|
+ structJson.put("id", paperId);
|
|
|
+ structJson.put("code", paper.getCode());
|
|
|
+ JSONArray structdetails = structJson.getJSONArray("details");
|
|
|
+ for (int i = 0; i < answerdetails.size(); i++) {
|
|
|
+ JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
+ JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
+ for (int j = 0; j < structdetailquestions.size(); j++) {
|
|
|
+ JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
|
|
|
+ JSONObject structquestion = structdetailquestions.getJSONObject(j);
|
|
|
+ if("objective".equals(filter)) {
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 1
|
|
|
+ || structquestion.getInteger("structType").intValue() == 2
|
|
|
+ || structquestion.getInteger("structType").intValue() == 3) {
|
|
|
+ if(structquestion.getInteger("structType").intValue() == 3) {
|
|
|
+ structquestion.put("answer", answerquestion.getBoolean("answer"));
|
|
|
+ }else {
|
|
|
+ structquestion.put("answer", answerquestion.getJSONArray("answer"));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
+ JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
+ JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
+ for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
+ JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
|
|
|
+ JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
+ if (structsubquestion.getInteger("structType").intValue() == 1
|
|
|
+ || structsubquestion.getInteger("structType").intValue() == 2
|
|
|
+ || structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
+ if (structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
+ structsubquestion.put("answer", answersubquestion.getBoolean("answer"));
|
|
|
+ }else {
|
|
|
+ structsubquestion.put("answer", answersubquestion.getJSONArray("answer"));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ structsubQuestions.remove(k);
|
|
|
+ k--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ structdetailquestions.remove(j);
|
|
|
+ j--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else if("subjective".equals(filter)) {
|
|
|
+ if (structquestion.getInteger("structType").intValue() != 1
|
|
|
+ && structquestion.getInteger("structType").intValue() != 2
|
|
|
+ && structquestion.getInteger("structType").intValue() != 3) {
|
|
|
+ structquestion.put("answer", answerquestion.getJSONArray("answer"));
|
|
|
+ }else {
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
+ JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
+ JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
+ for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
+ JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
|
|
|
+ JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
+ if (structsubquestion.getInteger("structType").intValue() != 1
|
|
|
+ && structsubquestion.getInteger("structType").intValue() != 2
|
|
|
+ && structsubquestion.getInteger("structType").intValue() != 3) {
|
|
|
+ structsubquestion.put("answer", answersubquestion.getJSONArray("answer"));
|
|
|
+ }else {
|
|
|
+ structsubQuestions.remove(k);
|
|
|
+ k--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ structdetailquestions.remove(j);
|
|
|
+ j--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (structquestion.getInteger("structType").intValue() != 6) {
|
|
|
+ if(structquestion.getInteger("structType").intValue() == 3) {
|
|
|
+ structquestion.put("answer", answerquestion.getBoolean("answer"));
|
|
|
+ }else {
|
|
|
+ structquestion.put("answer", answerquestion.getJSONArray("answer"));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
+ JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
+ for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
+ JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
|
|
|
+ JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
+ if (structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
+ structsubquestion.put("answer", answersubquestion.getBoolean("answer"));
|
|
|
+ }else {
|
|
|
+ structsubquestion.put("answer", answersubquestion.getJSONArray("answer"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return structJson;
|
|
|
+ } finally {
|
|
|
+ FileUtil.deleteFolder(dir);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private String uuid() {
|
|
|
+ return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkExam(Long examId) {
|
|
|
+ TEExam exam=examService.getById(examId);
|
|
|
+ if(exam==null) {
|
|
|
+ throw new BusinessException("未找到考试信息");
|
|
|
+ }
|
|
|
+ if(exam.getEnable()==null||exam.getEnable().intValue()==0) {
|
|
|
+ throw new BusinessException("考试批次已禁用");
|
|
|
+ }
|
|
|
+ if(!InvigilateMonitorStatusEnum.FINISHED.equals(exam.getMonitorStatus())) {
|
|
|
+ throw new BusinessException("考试批次监考未结束");
|
|
|
+ }
|
|
|
+ List<TEExamCourse> courses=examCourseService.findByExamId(examId);
|
|
|
+ if(courses==null||courses.size()==0) {
|
|
|
+ throw new BusinessException("考试批次下没有课程");
|
|
|
+ }
|
|
|
+ for(TEExamCourse course:courses) {
|
|
|
+ if(course.getHasAnswer()==null||course.getHasAnswer().intValue()==0) {
|
|
|
+ throw new BusinessException("考试批次下标答未齐全");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONArray examRecordNeedMark(Long examId, String courseCode, Integer idGt,
|
|
|
+ Integer count) {
|
|
|
+ checkExam(examId);
|
|
|
+ List<OpenRecordNeedMarkBean> list=examRecordService.findExamRecordNeedMark(examId,courseCode,idGt,count);
|
|
|
+ if(list==null||list.size()==0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<Long> ids = list.stream().map(dto -> dto.getId()).collect(Collectors.toList());
|
|
|
+ List<OpenRecordAnswerBean> answers=examAnswerService.findByRecordIds(ids);
|
|
|
+ Map<Long,Integer> map=new HashMap<>();
|
|
|
+ for(int i=0;i<list.size();i++) {
|
|
|
+ map.put(list.get(i).getId(), i);
|
|
|
+ }
|
|
|
+ for(OpenRecordAnswerBean anwser:answers) {
|
|
|
+ OpenRecordNeedMarkBean mark=list.get(map.get(anwser.getRecordId()));
|
|
|
+ List<OpenRecordAnswerBean> ans=mark.getAnswers();
|
|
|
+ if(ans==null) {
|
|
|
+ ans=new ArrayList<OpenRecordAnswerBean>();
|
|
|
+ mark.setAnswers(ans);
|
|
|
+ }
|
|
|
+ ans.add(anwser);
|
|
|
+ }
|
|
|
+ JSONArray ja = JSONArray.parseArray(JSONArray.toJSONString(list));
|
|
|
+ for(int i=0;i<ja.size();i++) {
|
|
|
+ JSONObject job=ja.getJSONObject(i);
|
|
|
+ JSONArray answersJa=job.getJSONArray("answers");
|
|
|
+ if(answersJa!=null) {
|
|
|
+ for(int j=0;j<answersJa.size();j++) {
|
|
|
+ JSONObject answersJob=answersJa.getJSONObject(j);
|
|
|
+ answersJob.remove("recordId");
|
|
|
+ String answerStr=answersJob.getString("answer");
|
|
|
+ if(StringUtils.isNotBlank(answerStr)) {
|
|
|
+ if(answerStr.toLowerCase().startsWith("true")||answerStr.toLowerCase().startsWith("false")) {
|
|
|
+ answersJob.put("answer", Boolean.getBoolean(answerStr.replaceAll("\n","")));
|
|
|
+ }else {
|
|
|
+ answersJob.put("answer", answersJob.getJSONArray("answer"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ja;
|
|
|
+ }
|
|
|
}
|