|
@@ -1,20 +1,8 @@
|
|
|
package cn.com.qmth.stmms.admin.exam;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -31,11 +19,7 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
@@ -52,24 +36,9 @@ import cn.com.qmth.stmms.admin.thread.ScoreCalculateThread;
|
|
|
import cn.com.qmth.stmms.admin.thread.ScoreReportThread;
|
|
|
import cn.com.qmth.stmms.admin.vo.StructFile;
|
|
|
import cn.com.qmth.stmms.admin.vo.StructQuestion;
|
|
|
-import cn.com.qmth.stmms.biz.common.domain.card.AnswerCardSubjectFile;
|
|
|
-import cn.com.qmth.stmms.biz.common.domain.card.AnswerCardSubjectItem;
|
|
|
-import cn.com.qmth.stmms.biz.common.domain.card.CardFile;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.AnswerCard;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.SelectiveGroup;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.AnswerCardService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.ExamQuestionService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.InspectHistoryService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.MarkerService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.SelectiveGroupService;
|
|
|
+import cn.com.qmth.stmms.biz.common.domain.card.*;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.*;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.*;
|
|
|
import cn.com.qmth.stmms.biz.exam.service.query.ExamQuestionSearchQuery;
|
|
|
import cn.com.qmth.stmms.biz.exam.service.query.ExamSubjectSearchQuery;
|
|
|
import cn.com.qmth.stmms.biz.file.enums.FormatType;
|
|
@@ -80,14 +49,7 @@ import cn.com.qmth.stmms.biz.report.service.ReportService;
|
|
|
import cn.com.qmth.stmms.common.annotation.Logging;
|
|
|
import cn.com.qmth.stmms.common.annotation.RoleRequire;
|
|
|
import cn.com.qmth.stmms.common.domain.WebUser;
|
|
|
-import cn.com.qmth.stmms.common.enums.CardSource;
|
|
|
-import cn.com.qmth.stmms.common.enums.LockType;
|
|
|
-import cn.com.qmth.stmms.common.enums.LogType;
|
|
|
-import cn.com.qmth.stmms.common.enums.ObjectivePolicy;
|
|
|
-import cn.com.qmth.stmms.common.enums.ObjectiveStatus;
|
|
|
-import cn.com.qmth.stmms.common.enums.QuestionType;
|
|
|
-import cn.com.qmth.stmms.common.enums.Role;
|
|
|
-import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
|
|
|
+import cn.com.qmth.stmms.common.enums.*;
|
|
|
import cn.com.qmth.stmms.common.utils.ExportExcel;
|
|
|
import cn.com.qmth.stmms.common.utils.ImportExcel;
|
|
|
import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
@@ -208,9 +170,10 @@ public class PaperController extends BaseExamController {
|
|
|
if (subject != null) {
|
|
|
List<ExamQuestion> list = new LinkedList<ExamQuestion>();
|
|
|
if (objective == null || objective) {
|
|
|
- List<ExamQuestion> objectiveList = mainNumber == null ? questionService
|
|
|
- .findByExamAndSubjectAndObjective(examId, subjectCode, true) : questionService
|
|
|
- .findByExamAndSubjectAndObjectiveAndMainNumber(examId, subjectCode, true, mainNumber);
|
|
|
+ List<ExamQuestion> objectiveList = mainNumber == null
|
|
|
+ ? questionService.findByExamAndSubjectAndObjective(examId, subjectCode, true)
|
|
|
+ : questionService.findByExamAndSubjectAndObjectiveAndMainNumber(examId, subjectCode, true,
|
|
|
+ mainNumber);
|
|
|
list.addAll(objectiveList);
|
|
|
}
|
|
|
if (objective == null || !objective) {
|
|
@@ -225,9 +188,10 @@ public class PaperController extends BaseExamController {
|
|
|
for (SelectiveGroup selectiveGroup : selectiveGroups) {
|
|
|
selectiveMap.put(selectiveGroup.getMainNumber(), selectiveGroup);
|
|
|
}
|
|
|
- List<ExamQuestion> subjectiveList = mainNumber == null ? questionService
|
|
|
- .findByExamAndSubjectAndObjective(examId, subjectCode, false) : questionService
|
|
|
- .findByExamAndSubjectAndObjectiveAndMainNumber(examId, subjectCode, false, mainNumber);
|
|
|
+ List<ExamQuestion> subjectiveList = mainNumber == null
|
|
|
+ ? questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false)
|
|
|
+ : questionService.findByExamAndSubjectAndObjectiveAndMainNumber(examId, subjectCode, false,
|
|
|
+ mainNumber);
|
|
|
for (ExamQuestion examQuestion : subjectiveList) {
|
|
|
if (examQuestion.getGroupNumber() != null
|
|
|
&& maps.get(examQuestion.getGroupNumber()).getMarkedCount() > 0) {
|
|
@@ -238,12 +202,12 @@ public class PaperController extends BaseExamController {
|
|
|
// 选做题判分策略
|
|
|
if (selectiveMap.containsKey(examQuestion.getMainNumber())) {
|
|
|
examQuestion.setSelective(true);
|
|
|
- examQuestion.setSelectiveIndex(selectiveMap.get(examQuestion.getMainNumber())
|
|
|
- .getSelectiveIndex());
|
|
|
+ examQuestion
|
|
|
+ .setSelectiveIndex(selectiveMap.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
|
examQuestion
|
|
|
.setSelectivePart(selectiveMap.get(examQuestion.getMainNumber()).getSelectivePart());
|
|
|
- examQuestion.setScorePolicy(selectiveMap.get(examQuestion.getMainNumber()).getScorePolicy()
|
|
|
- .getValue());
|
|
|
+ examQuestion.setScorePolicy(
|
|
|
+ selectiveMap.get(examQuestion.getMainNumber()).getScorePolicy().getValue());
|
|
|
} else {
|
|
|
examQuestion.setSelective(false);
|
|
|
}
|
|
@@ -315,8 +279,8 @@ public class PaperController extends BaseExamController {
|
|
|
query = questionService.findByQuery(query);
|
|
|
for (ExamQuestion q : query.getResult()) {
|
|
|
list.add(objective ? new ObjectiveQuestionDTO(q, subjectMap.get(q.getSubjectCode()))
|
|
|
- : new SubjectiveQuestionDTO(q, subjectMap.get(q.getSubjectCode()), groupMap.get(q.getSubjectCode()
|
|
|
- + "_" + q.getGroupNumber())));
|
|
|
+ : new SubjectiveQuestionDTO(q, subjectMap.get(q.getSubjectCode()),
|
|
|
+ groupMap.get(q.getSubjectCode() + "_" + q.getGroupNumber())));
|
|
|
}
|
|
|
try {
|
|
|
String fileName = objective ? "客观题数据.xlsx" : "主观题数据.xlsx";
|
|
@@ -423,7 +387,8 @@ public class PaperController extends BaseExamController {
|
|
|
@Logging(menu = "导入主观题分组", type = LogType.IMPORT_FILE)
|
|
|
@RequestMapping(value = "/importGroup", method = RequestMethod.POST)
|
|
|
@RoleRequire(Role.SCHOOL_ADMIN)
|
|
|
- public String importGroupFile(HttpServletRequest request, MultipartFile file, RedirectAttributes redirectAttributes) {
|
|
|
+ public String importGroupFile(HttpServletRequest request, MultipartFile file,
|
|
|
+ RedirectAttributes redirectAttributes) {
|
|
|
int examId = getSessionExamId(request);
|
|
|
List<String> error = new LinkedList<String>();
|
|
|
Map<String, SubjectQuestionDTO> map = parseQuestion(file, examId, false, error);
|
|
@@ -464,7 +429,8 @@ public class PaperController extends BaseExamController {
|
|
|
subject.getCode(), false, question.getMainNumber(),
|
|
|
question.getSubNumber());
|
|
|
if (old == null) {
|
|
|
- error.add("[" + group.getSubjectCode() + "_" + group.getNumber() + "] 分组有小题不存在");
|
|
|
+ error.add(
|
|
|
+ "[" + group.getSubjectCode() + "_" + group.getNumber() + "] 分组有小题不存在");
|
|
|
validate = false;
|
|
|
break;
|
|
|
}
|
|
@@ -577,18 +543,17 @@ public class PaperController extends BaseExamController {
|
|
|
@RoleRequire(Role.SCHOOL_ADMIN)
|
|
|
public String update(HttpServletRequest request, RedirectAttributes redirectAttributes, @RequestParam Integer id,
|
|
|
ExamQuestion question, ExamSubjectSearchQuery query, @RequestParam(required = false) Boolean upload) {
|
|
|
- if(question.getCustomizePolicy()!=null) {
|
|
|
- question.setCustomizePolicy(StringEscapeUtils.unescapeHtml(question.getCustomizePolicy()));
|
|
|
- }
|
|
|
+ if (question.getCustomizePolicy() != null) {
|
|
|
+ question.setCustomizePolicy(StringEscapeUtils.unescapeHtml(question.getCustomizePolicy()));
|
|
|
+ }
|
|
|
int examId = getSessionExamId(request);
|
|
|
ExamQuestion old = questionService.findById(id);
|
|
|
String u = upload == null ? "" : upload.toString();
|
|
|
String t = query.getTotalScoreNotEqual() == null ? "" : query.getTotalScoreNotEqual().toString();
|
|
|
ExamQuestion newQ = questionService.findByExamAndSubjectAndObjectiveAndMainNumberAndSubNumber(examId,
|
|
|
question.getSubjectCode(), question.isObjective(), question.getMainNumber(), question.getSubNumber());
|
|
|
- if (old == null
|
|
|
- || ((old.getMainNumber() != question.getMainNumber() || !old.getSubNumber().equals(
|
|
|
- question.getSubNumber())) && newQ != null)) {
|
|
|
+ if (old == null || ((old.getMainNumber() != question.getMainNumber()
|
|
|
+ || !old.getSubNumber().equals(question.getSubNumber())) && newQ != null)) {
|
|
|
addMessage(redirectAttributes, "编辑失败,编辑题目不存在或编辑后的题号已存在");
|
|
|
return "redirect:/admin/exam/paper/detail?subjectCode=" + question.getSubjectCode() + "&pageNumber="
|
|
|
+ query.getPageNumber() + "&code=" + query.getCode() + "&category=" + query.getCategory()
|
|
@@ -603,8 +568,8 @@ public class PaperController extends BaseExamController {
|
|
|
+ "&level=" + query.getLevel() + "&upload=" + u + "&totalScoreNotEqual=" + t;
|
|
|
}
|
|
|
}
|
|
|
- SelectiveGroup selectiveGroup = selectiveGroupService
|
|
|
- .findOne(examId, old.getSubjectCode(), old.getMainNumber());
|
|
|
+ SelectiveGroup selectiveGroup = selectiveGroupService.findOne(examId, old.getSubjectCode(),
|
|
|
+ old.getMainNumber());
|
|
|
if (!old.isObjective() && selectiveGroup != null) {
|
|
|
addMessage(redirectAttributes, "编辑失败,已经存在选做题分组");
|
|
|
return "redirect:/admin/exam/paper/detail?subjectCode=" + question.getSubjectCode() + "&pageNumber="
|
|
@@ -673,9 +638,8 @@ public class PaperController extends BaseExamController {
|
|
|
List<ExamQuestion> list = new ArrayList<ExamQuestion>();
|
|
|
list.add(question);
|
|
|
taskExecutor.submit(new QuestionDeleteThread(list, markService, lockService));
|
|
|
- RequestUtils.setLog(request,
|
|
|
- "开始删除题目,subjectCode:" + subjectCode + " main number:" + question.getMainNumber() + " sub number:"
|
|
|
- + question.getSubNumber());
|
|
|
+ RequestUtils.setLog(request, "开始删除题目,subjectCode:" + subjectCode + " main number:"
|
|
|
+ + question.getMainNumber() + " sub number:" + question.getSubNumber());
|
|
|
}
|
|
|
String u = upload == null ? "" : upload.toString();
|
|
|
String t = query.getTotalScoreNotEqual() == null ? "" : query.getTotalScoreNotEqual().toString();
|
|
@@ -831,9 +795,9 @@ public class PaperController extends BaseExamController {
|
|
|
@RoleRequire(Role.SCHOOL_ADMIN)
|
|
|
public String save(HttpServletRequest request, Model model, RedirectAttributes redirectAttributes,
|
|
|
ExamQuestion question, ExamSubjectSearchQuery query, @RequestParam(required = false) Boolean upload) {
|
|
|
- if(question.getCustomizePolicy()!=null) {
|
|
|
- question.setCustomizePolicy(StringEscapeUtils.unescapeHtml(question.getCustomizePolicy()));
|
|
|
- }
|
|
|
+ if (question.getCustomizePolicy() != null) {
|
|
|
+ question.setCustomizePolicy(StringEscapeUtils.unescapeHtml(question.getCustomizePolicy()));
|
|
|
+ }
|
|
|
int examId = getSessionExamId(request);
|
|
|
ExamQuestion old = questionService.findByExamAndSubjectAndObjectiveAndMainNumberAndSubNumber(examId,
|
|
|
question.getSubjectCode(), question.isObjective(), question.getMainNumber(), question.getSubNumber());
|
|
@@ -857,8 +821,8 @@ public class PaperController extends BaseExamController {
|
|
|
question.setType(null);
|
|
|
}
|
|
|
Map<Integer, String> titleMap = new HashMap<>();
|
|
|
- List<ExamQuestion> current = questionService.findByExamAndSubjectAndObjective(examId,
|
|
|
- question.getSubjectCode(), question.isObjective());
|
|
|
+ List<ExamQuestion> current = questionService.findByExamAndSubjectAndObjective(examId, question.getSubjectCode(),
|
|
|
+ question.isObjective());
|
|
|
for (ExamQuestion q : current) {
|
|
|
titleMap.put(q.getMainNumber(), q.getMainTitle());
|
|
|
}
|
|
@@ -985,6 +949,8 @@ public class PaperController extends BaseExamController {
|
|
|
card.setUpdateTime(new Date());
|
|
|
List<String> asList = new ArrayList<String>();
|
|
|
List<ExamSubject> subjects = new ArrayList<ExamSubject>();
|
|
|
+ List<ExamQuestion> questions = new ArrayList<ExamQuestion>();
|
|
|
+ List<MarkGroup> groups = new ArrayList<MarkGroup>();
|
|
|
for (AnswerCardSubjectItem item : answerCardSubjectFile.getCourses()) {
|
|
|
ExamSubject subject = subjectService.find(examId, item.getCode());
|
|
|
if (subject == null) {
|
|
@@ -994,11 +960,44 @@ public class PaperController extends BaseExamController {
|
|
|
if (answerCardService.hasSubject(examId, item.getCode(), item.getCode())) {
|
|
|
error.add("[" + item.getCode() + "] 科目代码已经绑定卡格式;");
|
|
|
return error;
|
|
|
+ }
|
|
|
+ if (!cardFile.getPaperStruct().isEmpty() && subject.getSubjectiveScore() > 0) {
|
|
|
+ error.add("[" + item.getCode() + "] 科目代码已经有试卷结构或分组;");
|
|
|
+ return error;
|
|
|
+ }
|
|
|
+ if (!cardFile.getPaperStruct().isEmpty() && subject.getSubjectiveScore() > 0) {
|
|
|
+ error.add("[" + item.getCode() + "] 科目代码已经有试卷结构或分组;");
|
|
|
+ return error;
|
|
|
} else {
|
|
|
asList.add(item.getCode());
|
|
|
subject.setSliceConfig(cardFile.getSliceConfig().toString());
|
|
|
subject.setCardType(FormatType.JSON);
|
|
|
subjects.add(subject);
|
|
|
+ for (CardQuestion q : cardFile.getPaperStruct()) {
|
|
|
+ ExamQuestion e = new ExamQuestion();
|
|
|
+ e.setExamId(examId);
|
|
|
+ e.setSubjectCode(subject.getCode());
|
|
|
+ e.setMainNumber(q.getMainNumber());
|
|
|
+ e.setMainTitle(q.getMainTitle());
|
|
|
+ e.setSubNumber(q.getSubNumber().toString());
|
|
|
+ QuestionType questionType = QuestionType.findByValue(q.getType());
|
|
|
+ e.setType(questionType);
|
|
|
+ if (questionType == null) {
|
|
|
+ e.setObjective(false);
|
|
|
+ } else {
|
|
|
+ e.setObjective(true);
|
|
|
+ }
|
|
|
+ e.setPaperType("#");
|
|
|
+ e.setIntervalScore(q.getIntervalScore());
|
|
|
+ e.setTotalScore(q.getScore());
|
|
|
+ questions.add(e);
|
|
|
+ }
|
|
|
+ for (CardGroup g : cardFile.getGroupInfos()) {
|
|
|
+ MarkGroup group = new MarkGroup(examId, subject.getCode(), g.getGroupNumber(),
|
|
|
+ g.getSliceConfig(), g.getTotalScore(), 0d, null, null, MarkMode.TRACK.toString(), 0,
|
|
|
+ false, false, null, false);
|
|
|
+ groups.add(group);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
answerCardService.save(card, asList);
|
|
@@ -1006,6 +1005,10 @@ public class PaperController extends BaseExamController {
|
|
|
for (ExamSubject examSubject : subjects) {
|
|
|
subjectService.save(examSubject);
|
|
|
}
|
|
|
+ questionService.save(questions);
|
|
|
+ for (MarkGroup group : groups) {
|
|
|
+ groupService.save(group);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("parse zip data error", e);
|