|
@@ -1,10 +1,31 @@
|
|
package cn.com.qmth.stmms.api.controller;
|
|
package cn.com.qmth.stmms.api.controller;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+
|
|
|
|
+import net.sf.json.JSONArray;
|
|
|
|
+import net.sf.json.JSONObject;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+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.admin.vo.ExamSubjectVO;
|
|
import cn.com.qmth.stmms.admin.vo.ExamSubjectVO;
|
|
import cn.com.qmth.stmms.api.exception.ApiException;
|
|
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.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.ExamSubject;
|
|
import cn.com.qmth.stmms.biz.exam.query.ExamSearchQuery;
|
|
import cn.com.qmth.stmms.biz.exam.query.ExamSearchQuery;
|
|
|
|
+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.ExamService;
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
|
|
import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
@@ -18,15 +39,6 @@ import cn.com.qmth.stmms.common.enums.LogType;
|
|
import cn.com.qmth.stmms.common.enums.Role;
|
|
import cn.com.qmth.stmms.common.enums.Role;
|
|
import cn.com.qmth.stmms.common.utils.DateUtils;
|
|
import cn.com.qmth.stmms.common.utils.DateUtils;
|
|
import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
-import net.sf.json.JSONArray;
|
|
|
|
-import net.sf.json.JSONObject;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
-
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
@Controller("examInfoApiController")
|
|
@Controller("examInfoApiController")
|
|
@RequestMapping("/api")
|
|
@RequestMapping("/api")
|
|
@@ -41,6 +53,9 @@ public class ExamInfoController extends BaseApiController {
|
|
@Autowired
|
|
@Autowired
|
|
private FileService fileService;
|
|
private FileService fileService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamQuestionService questionService;
|
|
|
|
+
|
|
@RequestMapping("/version")
|
|
@RequestMapping("/version")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public String version(HttpServletRequest request) {
|
|
public String version(HttpServletRequest request) {
|
|
@@ -71,6 +86,7 @@ public class ExamInfoController extends BaseApiController {
|
|
obj.accumulate("cardUrl",
|
|
obj.accumulate("cardUrl",
|
|
fileService.getFileServer() + fileService.getCardUri(exam.getId(), exam.getCardType()));
|
|
fileService.getFileServer() + fileService.getCardUri(exam.getId(), exam.getCardType()));
|
|
}
|
|
}
|
|
|
|
+ obj.accumulate("sliceConfig", StringUtils.trimToEmpty(exam.getSliceConfig()));
|
|
array.add(obj);
|
|
array.add(obj);
|
|
}
|
|
}
|
|
return array;
|
|
return array;
|
|
@@ -80,15 +96,15 @@ public class ExamInfoController extends BaseApiController {
|
|
@RequestMapping(value = "/campus", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/campus", method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public JSONArray getCampus(HttpServletRequest request) {
|
|
public JSONArray getCampus(HttpServletRequest request) {
|
|
- ApiUser user = RequestUtils.getApiUser(request);
|
|
|
|
|
|
+ // ApiUser user = RequestUtils.getApiUser(request);
|
|
JSONArray array = new JSONArray();
|
|
JSONArray array = new JSONArray();
|
|
- // List<Campus> list = campusService.findBySchoolId(user.getSchoolId());
|
|
|
|
- // for (Campus c : list) {
|
|
|
|
- // JSONObject obj = new JSONObject();
|
|
|
|
- // obj.accumulate("code", c.getId().toString());
|
|
|
|
- // obj.accumulate("name", c.getName());
|
|
|
|
- // array.add(obj);
|
|
|
|
- // }
|
|
|
|
|
|
+ // List<Campus> list = campusService.findBySchoolId(user.getSchoolId());
|
|
|
|
+ // for (Campus c : list) {
|
|
|
|
+ // JSONObject obj = new JSONObject();
|
|
|
|
+ // obj.accumulate("code", c.getId().toString());
|
|
|
|
+ // obj.accumulate("name", c.getName());
|
|
|
|
+ // array.add(obj);
|
|
|
|
+ // }
|
|
return array;
|
|
return array;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -103,9 +119,12 @@ public class ExamInfoController extends BaseApiController {
|
|
obj.accumulate("name", subject.getName());
|
|
obj.accumulate("name", subject.getName());
|
|
if (subject.getCardType() != null) {
|
|
if (subject.getCardType() != null) {
|
|
obj.accumulate("cardType", subject.getCardType().getExtName());
|
|
obj.accumulate("cardType", subject.getCardType().getExtName());
|
|
- obj.accumulate("cardUrl", fileService.getFileServer() + fileService
|
|
|
|
- .getCardUri(subject.getExamId(), subject.getCode(), subject.getCardType()));
|
|
|
|
|
|
+ obj.accumulate(
|
|
|
|
+ "cardUrl",
|
|
|
|
+ fileService.getFileServer()
|
|
|
|
+ + fileService.getCardUri(subject.getExamId(), subject.getCode(), subject.getCardType()));
|
|
}
|
|
}
|
|
|
|
+ obj.accumulate("sliceConfig", StringUtils.trimToEmpty(subject.getSliceConfig()));
|
|
array.add(obj);
|
|
array.add(obj);
|
|
}
|
|
}
|
|
return array;
|
|
return array;
|
|
@@ -122,13 +141,13 @@ public class ExamInfoController extends BaseApiController {
|
|
if (exam != null && exam.getSchoolId().equals(user.getSchoolId())) {
|
|
if (exam != null && exam.getSchoolId().equals(user.getSchoolId())) {
|
|
ExamSubject es = subjectService.find(subject.getExamId(), subject.getCode());
|
|
ExamSubject es = subjectService.find(subject.getExamId(), subject.getCode());
|
|
if (es != null) {
|
|
if (es != null) {
|
|
- // if (subject.getHasAnswer() != null) {
|
|
|
|
- // es.setHasAnswer(subject.getHasAnswer());
|
|
|
|
- // }
|
|
|
|
- // if (subject.getHasPaper() != null) {
|
|
|
|
- // es.setHasPaper(subject.getHasPaper());
|
|
|
|
- // }
|
|
|
|
- // subjectService.save(es);
|
|
|
|
|
|
+ // if (subject.getHasAnswer() != null) {
|
|
|
|
+ // es.setHasAnswer(subject.getHasAnswer());
|
|
|
|
+ // }
|
|
|
|
+ // if (subject.getHasPaper() != null) {
|
|
|
|
+ // es.setHasPaper(subject.getHasPaper());
|
|
|
|
+ // }
|
|
|
|
+ // subjectService.save(es);
|
|
result.accumulate("code", subject.getCode());
|
|
result.accumulate("code", subject.getCode());
|
|
return result;
|
|
return result;
|
|
} else {
|
|
} else {
|
|
@@ -182,4 +201,45 @@ public class ExamInfoController extends BaseApiController {
|
|
}
|
|
}
|
|
return success;
|
|
return success;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/questions/{examId}", method = RequestMethod.GET)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public JSONArray getQuestion(HttpServletRequest request, @PathVariable Integer examId,
|
|
|
|
+ @RequestParam String[] subjectCodes, @RequestParam(required = false, defaultValue = "#") String paperType,
|
|
|
|
+ @RequestParam Boolean objective) {
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ for (String subjectCode : subjectCodes) {
|
|
|
|
+ subjectCode = validate("subjectCode", subjectCode, true, 64);
|
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
|
+ if (subject == null) {
|
|
|
|
+ throw ApiException.QUERY_PARAM_ERROR.appendMessage(": subjectCode error");
|
|
|
|
+ }
|
|
|
|
+ List<ExamQuestion> list = new ArrayList<ExamQuestion>();
|
|
|
|
+ if (objective == null) {
|
|
|
|
+ list.addAll(questionService.findByExamAndSubjectAndObjectiveAndPaperType(examId, subjectCode, true,
|
|
|
|
+ paperType));
|
|
|
|
+ list.addAll(questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false));
|
|
|
|
+ } else {
|
|
|
|
+ list.addAll(questionService.findByExamAndSubjectAndObjective(examId, subjectCode, objective));
|
|
|
|
+ }
|
|
|
|
+ for (ExamQuestion q : list) {
|
|
|
|
+ JSONObject value = new JSONObject();
|
|
|
|
+ value.accumulate("subjectCode", q.getSubjectCode());
|
|
|
|
+ value.accumulate("objective", q.isObjective());
|
|
|
|
+ value.accumulate("mainNumber", q.getMainNumber());
|
|
|
|
+ value.accumulate("subNumber", q.getSubNumber());
|
|
|
|
+ value.accumulate("mainTitle", q.getMainTitle());
|
|
|
|
+ value.accumulate("totalScore", q.getTotalScore());
|
|
|
|
+ value.accumulate("answer", q.getAnswer() == null ? "" : q.getAnswer());
|
|
|
|
+ result.add(value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|