|
@@ -1,42 +1,41 @@
|
|
|
package cn.com.qmth.stmms.api.controller;
|
|
|
|
|
|
-import java.text.DecimalFormat;
|
|
|
-import java.util.Date;
|
|
|
-
|
|
|
-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.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.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.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.file.service.FileService;
|
|
|
+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.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.enums.*;
|
|
|
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")
|
|
|
public class CoreController extends BaseApiController {
|
|
|
|
|
|
- private static final int MAX_QUERY_PAGE_SIZE = 500;
|
|
|
+ private static final int MAX_QUERY_PAGE_SIZE = 100;
|
|
|
|
|
|
@Autowired
|
|
|
private ExamService examService;
|
|
@@ -44,6 +43,12 @@ public class CoreController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private ExamStudentService studentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamQuestionService questionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileService fileService;
|
|
|
+
|
|
|
@RequestMapping(value = "/exam/save", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
@RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV })
|
|
@@ -231,16 +236,19 @@ public class CoreController extends BaseApiController {
|
|
|
@RequestParam(required = false) String college, @RequestParam(required = false) String className,
|
|
|
@RequestParam(required = false) String teacher,
|
|
|
@RequestParam(required = false, defaultValue = "1") Integer pageNumber,
|
|
|
- @RequestParam(required = false, defaultValue = "100") Integer pageSize) {
|
|
|
+ @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
|
|
|
ApiUser user = RequestUtils.getApiUser(request);
|
|
|
if (examId == null && examCode == null) {
|
|
|
- throw ApiException.QUERY_PARAM_ERROR.replaceMessage("examId/examCode both unexists");
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.replaceMessage("examId or examCode is required");
|
|
|
}
|
|
|
Exam exam = examService.findById(examId);
|
|
|
if (exam == null) {
|
|
|
exam = examService.findBySchoolAndCode(user.getSchoolId(), examCode);
|
|
|
}
|
|
|
- if (exam == null || !exam.getSchoolId().equals(user.getSchoolId())) {
|
|
|
+ if (exam == null) {
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.replaceMessage("exam unexists");
|
|
|
+ }
|
|
|
+ if (!exam.getSchoolId().equals(user.getSchoolId())) {
|
|
|
throw ApiException.EXAM_NOT_ACCESSIBLED;
|
|
|
}
|
|
|
JSONArray array = new JSONArray();
|
|
@@ -270,8 +278,62 @@ public class CoreController extends BaseApiController {
|
|
|
obj.accumulate("totalScore", df.format(student.getTotalScore()));
|
|
|
obj.accumulate("objectiveScore", df.format(student.getObjectiveScore()));
|
|
|
obj.accumulate("subjectiveScore", df.format(student.getSubjectiveScore()));
|
|
|
- obj.accumulate("objectiveScoreDetail", StringUtils.trimToEmpty(student.getObjectiveScoreList()));
|
|
|
- obj.accumulate("subjectiveScoreDetail", StringUtils.trimToEmpty(student.getSubjectiveScoreList()));
|
|
|
+ //obj.accumulate("objectiveScoreDetail", StringUtils.trimToEmpty(student.getObjectiveScoreList()));
|
|
|
+ //obj.accumulate("subjectiveScoreDetail", StringUtils.trimToEmpty(student.getSubjectiveScoreList()));
|
|
|
+ // 构造客观题得分明细
|
|
|
+ JSONArray objective = new JSONArray();
|
|
|
+ List<ScoreItem> scoreList = student.getScoreList(true);
|
|
|
+ List<ExamQuestion> questionList = questionService
|
|
|
+ .findByExamAndSubjectAndObjectiveAndPaperType(student.getExamId(), student.getSubjectCode(), true,
|
|
|
+ student.getPaperType());
|
|
|
+ int i = 0;
|
|
|
+ for (ScoreItem item : scoreList) {
|
|
|
+ i++;
|
|
|
+ if (questionList.size() < i) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ExamQuestion question = questionList.get(i - 1);
|
|
|
+ if (question.getTotalScore() == null || question.getTotalScore() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject detail = new JSONObject();
|
|
|
+ detail.accumulate("mainNumber", question.getMainNumber());
|
|
|
+ detail.accumulate("subNumber", question.getSubNumber());
|
|
|
+ detail.accumulate("score", item.getScore());
|
|
|
+ detail.accumulate("answer", item.getAnswer());
|
|
|
+ objective.add(detail);
|
|
|
+ }
|
|
|
+ obj.accumulate("objectiveScoreDetail", objective);
|
|
|
+ // 构造主观题得分明细
|
|
|
+ JSONArray subjective = new JSONArray();
|
|
|
+ scoreList = student.getScoreList(false);
|
|
|
+ questionList = questionService
|
|
|
+ .findByExamAndSubjectAndObjective(student.getExamId(), student.getSubjectCode(), false);
|
|
|
+ i = 0;
|
|
|
+ for (ScoreItem item : scoreList) {
|
|
|
+ i++;
|
|
|
+ if (questionList.size() < i) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ExamQuestion question = questionList.get(i - 1);
|
|
|
+ if (question.getTotalScore() == null || question.getTotalScore() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject detail = new JSONObject();
|
|
|
+ detail.accumulate("mainNumber", question.getMainNumber());
|
|
|
+ detail.accumulate("subNumber", question.getSubNumber());
|
|
|
+ detail.accumulate("score", item.getScore());
|
|
|
+ subjective.add(detail);
|
|
|
+ }
|
|
|
+ obj.accumulate("subjectiveScoreDetail", subjective);
|
|
|
+ // 构造原图下载地址
|
|
|
+ if (student.isUpload()) {
|
|
|
+ obj.accumulate("sheetUrls", fileService
|
|
|
+ .getSheetUris(student.getExamId(), student.getExamNumber(), 1, student.getSheetCount()).stream()
|
|
|
+ .map(uri -> fileService.getFileServer().concat(uri)).collect(Collectors.toList()));
|
|
|
+ } else {
|
|
|
+ obj.accumulate("sheetUrls", new JSONArray());
|
|
|
+ }
|
|
|
array.add(obj);
|
|
|
}
|
|
|
return array;
|