|
@@ -0,0 +1,170 @@
|
|
|
+package cn.com.qmth.stmms.api.controller;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+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 org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import cn.com.qmth.stmms.admin.utils.PaperJsonUtils;
|
|
|
+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.ExamPackage;
|
|
|
+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.service.ExamPackageService;
|
|
|
+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.enums.FormatType;
|
|
|
+import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
|
+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.utils.RequestUtils;
|
|
|
+
|
|
|
+import com.google.common.io.ByteStreams;
|
|
|
+
|
|
|
+@Controller("cardController")
|
|
|
+@RequestMapping("/api/card")
|
|
|
+public class CardController extends BaseApiController {
|
|
|
+
|
|
|
+ protected static final Logger log = LoggerFactory.getLogger(CardController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileService fileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamService examService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamSubjectService subjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamPackageService packageService;
|
|
|
+
|
|
|
+ // private Exam validateExam(ApiUser au, Integer examId, ExamType... types)
|
|
|
+ // {
|
|
|
+ // Exam exam = examService.findById(examId);
|
|
|
+ // if (exam == null || !exam.getSchoolId().equals(au.getSchoolId()) ||
|
|
|
+ // exam.getStatus() != ExamStatus.START) {
|
|
|
+ // throw ApiException.EXAM_NOT_ACCESSIBLED;
|
|
|
+ // }
|
|
|
+ // if (types != null && types.length > 0 &&
|
|
|
+ // !Arrays.asList(types).contains(exam.getType())) {
|
|
|
+ // throw ApiException.QUERY_PARAM_ERROR.replaceMessage("exam type invalid");
|
|
|
+ // }
|
|
|
+ // return exam;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // private ExamPackage validateExamPackage(Integer examId, String
|
|
|
+ // packageCode) {
|
|
|
+ // ExamPackage ep = packageService.find(examId, packageCode);
|
|
|
+ // if (ep == null) {
|
|
|
+ // throw
|
|
|
+ // ApiException.QUERY_PARAM_ERROR.appendMessage(": packageCode error");
|
|
|
+ // }
|
|
|
+ // return ep;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // private ExamSubject validateExamSubject(Integer examId, String
|
|
|
+ // subjectCode) {
|
|
|
+ // ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ // if (subject == null) {
|
|
|
+ // throw
|
|
|
+ // ApiException.QUERY_PARAM_ERROR.appendMessage(": subjectCode error");
|
|
|
+ // }
|
|
|
+ // return subject;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // private FormatType validateFormatType(FormatType type, FormatType...
|
|
|
+ // types) {
|
|
|
+ // if (type == null) {
|
|
|
+ // throw
|
|
|
+ // ApiException.FORMAT_TYPE_ERROR.replaceMessage("format type is null");
|
|
|
+ // }
|
|
|
+ // if (types != null && !Arrays.asList(types).contains(type)) {
|
|
|
+ // throw ApiException.FORMAT_TYPE_ERROR;
|
|
|
+ // }
|
|
|
+ // return type;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @RequestMapping(value = "/answer/save", method = RequestMethod.POST)
|
|
|
+ // @RoleRequire({ Role.SCHOOL_ADMIN })
|
|
|
+ // @ResponseBody
|
|
|
+ // public JSONObject uploadSheet(HttpServletRequest request, @RequestParam
|
|
|
+ // Integer examId,
|
|
|
+ // @RequestParam(required = false) String subjectCode,
|
|
|
+ // @RequestParam(required = false) Integer number,
|
|
|
+ // @RequestParam String md5, @RequestParam MultipartFile file) {
|
|
|
+ // ApiUser au = RequestUtils.getApiUser(request);
|
|
|
+ // subjectCode = StringUtils.trimToNull(subjectCode);
|
|
|
+ // Exam exam = validateExam(au, examId, ExamType.SCAN_IMAGE);
|
|
|
+ // ExamSubject subject = subjectCode != null ? validateExamSubject(examId,
|
|
|
+ // subjectCode) : null;
|
|
|
+ // try {
|
|
|
+ // if (subject != null) {
|
|
|
+ // fileService.uploadCard(file.getInputStream(), md5, examId, subjectCode,
|
|
|
+ // FormatType.JSON);
|
|
|
+ // subject.setCardType(FormatType.JSON);
|
|
|
+ // subjectService.save(subject);
|
|
|
+ // uri = fileService.getCardUri(examId, subjectCode, format);
|
|
|
+ // } else {
|
|
|
+ // fileService.uploadCard(file.getInputStream(), md5, examId, format);
|
|
|
+ // exam.setCardType(format);
|
|
|
+ // examService.save(exam);
|
|
|
+ // uri = fileService.getCardUri(examId, format);
|
|
|
+ // }
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // log.error("card upload error", e);
|
|
|
+ // throw ApiException.FILE_UPLOAD_ERROR.replaceMessage("card upload error: "
|
|
|
+ // + e.getMessage());
|
|
|
+ // }
|
|
|
+ // return result(true, fileService.getFileServer().concat(uri));
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @RequestMapping(value = "/answer/query", method = RequestMethod.POST)
|
|
|
+ // @RoleRequire({ Role.SCHOOL_ADMIN })
|
|
|
+ // @ResponseBody
|
|
|
+ // public JSONObject answerQuery(HttpServletRequest request, @RequestParam
|
|
|
+ // Integer examId, @RequestParam Integer number) {
|
|
|
+ // ApiUser au = RequestUtils.getApiUser(request);
|
|
|
+ // validateExam(au, examId, ExamType.SCAN_IMAGE);
|
|
|
+ // ExamStudent student = validateExamStudent(examId, examNumber);
|
|
|
+ // validateIndex(index);
|
|
|
+ // try {
|
|
|
+ // fileService.uploadSlice(file.getInputStream(), md5, examId,
|
|
|
+ // student.getSecretNumber(), index);
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // log.error("slice upload error", e);
|
|
|
+ // throw
|
|
|
+ // ApiException.FILE_UPLOAD_ERROR.replaceMessage("slice upload error: " +
|
|
|
+ // e.getMessage());
|
|
|
+ // }
|
|
|
+ // return result(true,
|
|
|
+ // fileService.getFileServer().concat(fileService.getSliceUri(examId,
|
|
|
+ // student.getSecretNumber(), index)));
|
|
|
+ // }
|
|
|
+
|
|
|
+}
|