|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.qmth.stmms.api.controller;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
@@ -13,6 +14,8 @@ import net.sf.json.JSONObject;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.core.task.AsyncTaskExecutor;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -20,7 +23,10 @@ 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.admin.thread.MarkGroupDeleteThread;
|
|
|
+import cn.com.qmth.stmms.api.dto.GroupDTO;
|
|
|
import cn.com.qmth.stmms.api.dto.PaperDTO;
|
|
|
+import cn.com.qmth.stmms.api.dto.PaperStructureDTO;
|
|
|
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;
|
|
@@ -28,13 +34,17 @@ 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.model.Marker;
|
|
|
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.exam.service.MarkerService;
|
|
|
import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
|
+import cn.com.qmth.stmms.biz.lock.LockService;
|
|
|
+import cn.com.qmth.stmms.biz.mark.service.MarkService;
|
|
|
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;
|
|
@@ -42,6 +52,7 @@ import cn.com.qmth.stmms.common.annotation.RoleRequire;
|
|
|
import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
|
import cn.com.qmth.stmms.common.enums.ExamStatus;
|
|
|
import cn.com.qmth.stmms.common.enums.ExamType;
|
|
|
+import cn.com.qmth.stmms.common.enums.LockType;
|
|
|
import cn.com.qmth.stmms.common.enums.ObjectiveStatus;
|
|
|
import cn.com.qmth.stmms.common.enums.Role;
|
|
|
import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
|
|
@@ -81,6 +92,19 @@ public class CoreController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private MarkGroupService groupService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MarkerService markerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkService markService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LockService lockService;
|
|
|
+
|
|
|
+ @Qualifier("task-executor")
|
|
|
+ @Autowired
|
|
|
+ private AsyncTaskExecutor taskExecutor;
|
|
|
+
|
|
|
@RequestMapping(value = "/exam/save", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
@RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV })
|
|
@@ -626,4 +650,147 @@ public class CoreController extends BaseApiController {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exam/mark_group/delete", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV, Role.SUBJECT_HEADER })
|
|
|
+ public JSONObject groupDelete(HttpServletRequest request, @RequestParam Integer examId,
|
|
|
+ @RequestParam String subjectCode) {
|
|
|
+ ApiUser user = RequestUtils.getApiUser(request);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ // 输入字段预处理并初步校验
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
|
+ for (MarkGroup markGroup : groups) {
|
|
|
+ if (markGroup.getMarkedCount() > 0) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": subject is marking");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (MarkGroup group : groups) {
|
|
|
+ if (lockService
|
|
|
+ .trylock(LockType.GROUP_DELETE, group.getExamId(), group.getSubjectCode(), group.getNumber())) {
|
|
|
+ taskExecutor.submit(new MarkGroupDeleteThread(group, markService, lockService));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.accumulate("updateTime", DateUtils.formatDateTime(new Date()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exam/mark_group/count", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV, Role.SUBJECT_HEADER })
|
|
|
+ public JSONObject groupCount(HttpServletRequest request, @RequestParam Integer examId,
|
|
|
+ @RequestParam String subjectCode) {
|
|
|
+ ApiUser user = RequestUtils.getApiUser(request);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ // 输入字段预处理并初步校验
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ result.accumulate("totalCount", groupService.countByExamAndSubject(examId, subjectCode));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exam/mark_group/save", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV, Role.SUBJECT_HEADER })
|
|
|
+ public JSONObject groupSave(HttpServletRequest request, @RequestBody PaperStructureDTO dto) {
|
|
|
+ ApiUser user = RequestUtils.getApiUser(request);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ // 输入字段预处理并初步校验
|
|
|
+ Exam exam = examService.findById(dto.getExamId());
|
|
|
+ if (exam == null || !exam.getSchoolId().equals(user.getSchoolId()) || exam.getStatus() != ExamStatus.START) {
|
|
|
+ throw ApiException.EXAM_NOT_ACCESSIBLED;
|
|
|
+ }
|
|
|
+ String subjectCode = validate("subjectCode", dto.getSubjectCode(), true, 64);
|
|
|
+ ExamSubject subject = subjectService.find(dto.getExamId(), subjectCode);
|
|
|
+ if (subject == null) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": subjectCode error");
|
|
|
+ }
|
|
|
+ long count = groupService.countByExamAndSubject(dto.getExamId(), subjectCode);
|
|
|
+ if (count != 0) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": subjectCode error");
|
|
|
+ }
|
|
|
+ for (GroupDTO g : dto.getGroups()) {
|
|
|
+ List<ExamQuestion> questionGroup = new ArrayList<ExamQuestion>();
|
|
|
+ BigDecimal totalScore = BigDecimal.ZERO;
|
|
|
+ for (QuestionDTO q : g.getQuestions()) {
|
|
|
+ ExamQuestion old = questionService.findByExamAndSubjectAndObjectiveAndMainNumberAndSubNumber(
|
|
|
+ dto.getExamId(), dto.getSubjectCode(), false, q.getMainNumber(), q.getSubNumber());
|
|
|
+ if (old == null) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": question error");
|
|
|
+ }
|
|
|
+ totalScore = totalScore.add(BigDecimal.valueOf(old.getTotalScore()));
|
|
|
+ old.setGroupNumber(g.getNumber());
|
|
|
+ questionGroup.add(old);
|
|
|
+ }
|
|
|
+ MarkGroup group = new MarkGroup(dto.getExamId(), dto.getSubjectCode(), g.getNumber(), g.getPicConfig(),
|
|
|
+ totalScore.doubleValue(), g.getDoubleRate(), g.getArbitrateThreshold(), g.getScorePolicy(),
|
|
|
+ g.getMarkMode(), dto.getTrialCount(), false, g.getEnableAllZero(), null, false);
|
|
|
+ if (!questionGroup.isEmpty()) {
|
|
|
+ questionService.save(questionGroup);
|
|
|
+ groupService.save(group);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ subjectService.updateTrialCount(dto.getExamId(), dto.getSubjectCode(), dto.getTrialCount());
|
|
|
+ studentService.updateSubjectiveStatusAndScoreAndInspectorId(dto.getExamId(), dto.getSubjectCode(),
|
|
|
+ SubjectiveStatus.UNMARK, 0, null, null, null);
|
|
|
+ result.accumulate("updateTime", DateUtils.formatDateTime(new Date()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exam/marker/save", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV, Role.SUBJECT_HEADER })
|
|
|
+ public JSONObject markerSave(HttpServletRequest request, @RequestParam Integer examId,
|
|
|
+ @RequestParam String subjectCode, @RequestParam Integer groupNumber, @RequestParam String account) {
|
|
|
+ ApiUser user = RequestUtils.getApiUser(request);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ // 输入字段预处理并初步校验
|
|
|
+ account = validate("account", account, true, 32);
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ MarkGroup group = groupService.findOne(examId, subjectCode, groupNumber);
|
|
|
+ if (group == null) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": groupNumber error");
|
|
|
+ }
|
|
|
+ User u = userService.findByAccount(user.getSchoolId(), account);
|
|
|
+ if (u == null || !Role.MARKER.equals(u.getRole())) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": account error");
|
|
|
+ }
|
|
|
+ Marker marker = markerService.findByExamAndSubjectAndNumberAndUserId(examId, subjectCode, groupNumber,
|
|
|
+ u.getId());
|
|
|
+ if (marker == null) {
|
|
|
+ marker = new Marker();
|
|
|
+ marker.setExamId(examId);
|
|
|
+ marker.setSubjectCode(subjectCode);
|
|
|
+ marker.setGroupNumber(groupNumber);
|
|
|
+ marker.setUserId(u.getId());
|
|
|
+ marker.setEnable(true);
|
|
|
+ markerService.save(marker);
|
|
|
+ }
|
|
|
+ result.accumulate("updateTime", DateUtils.formatDateTime(new Date()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|