|
@@ -1,39 +1,52 @@
|
|
|
package cn.com.qmth.stmms.api.controller;
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+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 cn.com.qmth.stmms.api.dto.PaperDTO;
|
|
|
+import cn.com.qmth.stmms.api.dto.QuestionDTO;
|
|
|
import cn.com.qmth.stmms.api.exception.ApiException;
|
|
|
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.ExamStudent;
|
|
|
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.query.ExamStudentSearchQuery;
|
|
|
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.MarkGroupService;
|
|
|
import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
|
+import cn.com.qmth.stmms.biz.user.model.User;
|
|
|
+import cn.com.qmth.stmms.biz.user.service.UserService;
|
|
|
import cn.com.qmth.stmms.biz.utils.ScoreItem;
|
|
|
import cn.com.qmth.stmms.common.annotation.RoleRequire;
|
|
|
import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
|
-import cn.com.qmth.stmms.common.enums.*;
|
|
|
+import cn.com.qmth.stmms.common.enums.ExamStatus;
|
|
|
+import cn.com.qmth.stmms.common.enums.ExamType;
|
|
|
+import cn.com.qmth.stmms.common.enums.ObjectiveStatus;
|
|
|
+import cn.com.qmth.stmms.common.enums.Role;
|
|
|
+import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
|
|
|
import cn.com.qmth.stmms.common.utils.DateUtils;
|
|
|
import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
-import net.sf.json.JSONArray;
|
|
|
-import net.sf.json.JSONObject;
|
|
|
-
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-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 javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-import java.text.DecimalFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@Controller("coreApiController")
|
|
|
@RequestMapping("/api")
|
|
@@ -62,6 +75,12 @@ public class CoreController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private ExamSubjectService subjectService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkGroupService groupService;
|
|
|
+
|
|
|
@RequestMapping(value = "/exam/save", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
@RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV })
|
|
@@ -253,7 +272,7 @@ public class CoreController extends BaseApiController {
|
|
|
@RequestParam(required = false) String examCode, @RequestParam(required = false) String examNumber,
|
|
|
@RequestParam(required = false) String studentCode, @RequestParam(required = false) String subjectCode,
|
|
|
@RequestParam(required = false) String college, @RequestParam(required = false) String className,
|
|
|
- @RequestParam(required = false) String teacher,
|
|
|
+ @RequestParam(required = false) String teacher, @RequestParam(required = false) Boolean withMarkTrack,
|
|
|
@RequestParam(required = false, defaultValue = "1") Integer pageNumber,
|
|
|
@RequestParam(required = false, defaultValue = "20") Integer pageSize) {
|
|
|
ApiUser user = RequestUtils.getApiUser(request);
|
|
@@ -357,6 +376,10 @@ public class CoreController extends BaseApiController {
|
|
|
}
|
|
|
obj.accumulate("objectiveScoreDetail", objective);
|
|
|
obj.accumulate("subjectiveScoreDetail", subjective);
|
|
|
+ // 构造给分轨迹
|
|
|
+ if (withMarkTrack != null && withMarkTrack.booleanValue()) {
|
|
|
+ obj.accumulate("markTags", studentService.buildSheetTags(student, false));
|
|
|
+ }
|
|
|
// 构造原图下载地址
|
|
|
if (student.isUpload()) {
|
|
|
obj.accumulate(
|
|
@@ -455,4 +478,148 @@ public class CoreController extends BaseApiController {
|
|
|
result.accumulate("updateTime", DateUtils.formatDateTime(new Date()));
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/user/save", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV })
|
|
|
+ public JSONObject subjectSave(HttpServletRequest request, @RequestParam String account,
|
|
|
+ @RequestParam(required = false) String name, @RequestParam(required = false) String password,
|
|
|
+ @RequestParam(required = false) Role role, @RequestParam boolean enable) {
|
|
|
+ ApiUser user = RequestUtils.getApiUser(request);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ // 输入字段预处理并初步校验
|
|
|
+ account = validate("account", account, true, 32);
|
|
|
+ name = validate("name", name, true, 32);
|
|
|
+ password = validate("password", password, false, 32);
|
|
|
+ User u = userService.externalLogin(user.getSchoolId(), account, name, password, role);
|
|
|
+ if (u.isEnable() != enable) {
|
|
|
+ u.setEnable(enable);
|
|
|
+ userService.save(u);
|
|
|
+ }
|
|
|
+ result.accumulate("updateTime", DateUtils.formatDateTime(new Date()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exam/paper/save", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV })
|
|
|
+ public JSONObject paperSave(HttpServletRequest request, @RequestBody PaperDTO paper) {
|
|
|
+ ApiUser user = RequestUtils.getApiUser(request);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ // 输入字段预处理并初步校验
|
|
|
+ Exam exam = examService.findById(paper.getExamId());
|
|
|
+ if (exam == null) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.replaceMessage("examId invalid");
|
|
|
+ } else if (!exam.getSchoolId().equals(user.getSchoolId()) || exam.getStatus() != ExamStatus.START) {
|
|
|
+ throw ApiException.EXAM_NOT_ACCESSIBLED;
|
|
|
+ }
|
|
|
+ ExamSubject subject = subjectService.find(paper.getExamId(), paper.getSubjectCode());
|
|
|
+ if (subject == null) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.replaceMessage("subjectCode invalid");
|
|
|
+ }
|
|
|
+ validate("paperType", paper.getPaperType(), false, 16);
|
|
|
+ if (StringUtils.isNotBlank(paper.getPaperType()) && !paper.getPaperType().matches(PAPER_TYPES_REGEX)) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.replaceMessage("paperType invalid");
|
|
|
+ }
|
|
|
+ // 客观题更新
|
|
|
+ if (paper.getObjective()) {
|
|
|
+ if (0 != questionService.countByExamIdAndSubjectAndObjectiveAndGroupNumberIsNull(paper.getExamId(),
|
|
|
+ subject.getCode(), true)) {
|
|
|
+ questionService.deleteByExamAndSubjectAndObjective(paper.getExamId(), subject.getCode(), true);
|
|
|
+ }
|
|
|
+ List<ExamQuestion> oList = parseQustionList(paper.getQuestions(), paper.getExamId(),
|
|
|
+ paper.getSubjectCode(), paper.getPaperType(), paper.getObjective());
|
|
|
+ questionService.save(oList);
|
|
|
+ examService.updateObjectiveStatus(paper.getExamId(), ObjectiveStatus.WAITING);
|
|
|
+ subjectService.updateScore(paper.getExamId(), subject.getCode(), true,
|
|
|
+ questionService.sumTotalScore(paper.getExamId(), subject.getCode(), true));
|
|
|
+ } else {
|
|
|
+ List<MarkGroup> groups = groupService.findByExamAndSubject(paper.getExamId(), subject.getCode());
|
|
|
+ if (groups == null || groups.size() == 0) {
|
|
|
+ if (0 != questionService.countByExamIdAndSubjectAndObjectiveAndGroupNumberIsNull(paper.getExamId(),
|
|
|
+ subject.getCode(), false)) {
|
|
|
+ questionService.deleteByExamAndSubjectAndObjective(paper.getExamId(), subject.getCode(), false);
|
|
|
+ }
|
|
|
+ List<ExamQuestion> sList = parseQustionList(paper.getQuestions(), paper.getExamId(),
|
|
|
+ paper.getSubjectCode(), paper.getPaperType(), paper.getObjective());
|
|
|
+ questionService.save(sList);
|
|
|
+ subjectService.updateScore(paper.getExamId(), subject.getCode(), false,
|
|
|
+ questionService.sumTotalScore(paper.getExamId(), subject.getCode(), false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.accumulate("updateTime", DateUtils.formatDateTime(new Date()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ExamQuestion> parseQustionList(QuestionDTO[] questions, Integer examId, String subjectCode,
|
|
|
+ String paperType, boolean objective) {
|
|
|
+ List<ExamQuestion> list = new ArrayList<ExamQuestion>();
|
|
|
+ for (QuestionDTO dto : questions) {
|
|
|
+ ExamQuestion q = dto.transform();
|
|
|
+ q.setExamId(examId);
|
|
|
+ q.setSubjectCode(subjectCode);
|
|
|
+ if (StringUtils.isNotBlank(paperType)) {
|
|
|
+ q.setPaperType(paperType);
|
|
|
+ } else {
|
|
|
+ q.setPaperType(NULL_PAPER_TYPE_PLACEHOLDER);
|
|
|
+ }
|
|
|
+ q.setObjective(objective);
|
|
|
+ list.add(q);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exam/paper/query", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV })
|
|
|
+ public JSONArray paperQuery(HttpServletRequest request, @RequestParam Integer examId,
|
|
|
+ @RequestParam String subjectCode, @RequestParam(required = false, defaultValue = "#") String paperType) {
|
|
|
+ ApiUser user = RequestUtils.getApiUser(request);
|
|
|
+ JSONArray result = new JSONArray();
|
|
|
+ // 输入字段预处理并初步校验
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
+ if (exam == null || !exam.getSchoolId().equals(user.getSchoolId()) || exam.getStatus() != ExamStatus.START) {
|
|
|
+ throw ApiException.EXAM_NOT_ACCESSIBLED;
|
|
|
+ }
|
|
|
+ subjectCode = validate("subjectCode", subjectCode, true, 64);
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ if (subject == null) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": subjectCode error");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(paperType)) {
|
|
|
+ List<String> paperTypes = questionService.getPaperType(examId, subjectCode);
|
|
|
+ if (!contains(subject.getObjectiveScore() > 0, paperTypes, paperType)) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": paperType error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ExamQuestion> list = new ArrayList<ExamQuestion>();
|
|
|
+ list.addAll(questionService.findByExamAndSubjectAndObjectiveAndPaperType(examId, subjectCode, true, paperType));
|
|
|
+ list.addAll(questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false));
|
|
|
+ for (ExamQuestion q : list) {
|
|
|
+ JSONObject value = new JSONObject();
|
|
|
+ value.accumulate("objective", q.isObjective());
|
|
|
+ value.accumulate("mainNumber", q.getMainNumber());
|
|
|
+ value.accumulate("subNumber", q.getSubNumber());
|
|
|
+ value.accumulate("mainTitle", q.getMainNumber());
|
|
|
+ value.accumulate("totalScore", q.getTotalScore());
|
|
|
+ value.accumulate("answer", q.getAnswer() == null ? "" : q.getAnswer());
|
|
|
+ result.add(value);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean contains(boolean objective, List<String> paperTypes, String paperType) {
|
|
|
+ if (NULL_PAPER_TYPE_PLACEHOLDER.equals(paperType)) {
|
|
|
+ if (!objective) {
|
|
|
+ // 纯主观题
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String s : paperTypes) {
|
|
|
+ if (paperType.equalsIgnoreCase(s)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|