|
@@ -93,10 +93,14 @@ public class FileController extends BaseApiController {
|
|
return subject;
|
|
return subject;
|
|
}
|
|
}
|
|
|
|
|
|
- private void validateFormatType(FormatType format, FormatType... types) {
|
|
|
|
- if (!Arrays.asList(types).contains(format)) {
|
|
|
|
- throw new RuntimeException("format type error");
|
|
|
|
|
|
+ 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;
|
|
}
|
|
}
|
|
|
|
|
|
private void validateIndex(Integer index) {
|
|
private void validateIndex(Integer index) {
|
|
@@ -261,4 +265,23 @@ public class FileController extends BaseApiController {
|
|
}
|
|
}
|
|
return result(true);
|
|
return result(true);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/card/url")
|
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SCHOOL_DEV, Role.SCANNER })
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public JSONObject cardUrl(HttpServletRequest request, @RequestParam Integer examId,
|
|
|
|
+ @RequestParam(required = false) String subjectCode) {
|
|
|
|
+ ApiUser au = RequestUtils.getApiUser(request);
|
|
|
|
+ subjectCode = StringUtils.trimToNull(subjectCode);
|
|
|
|
+ Exam exam = validateExam(au, examId, ExamType.SCAN_IMAGE);
|
|
|
|
+ String uri = "";
|
|
|
|
+ if (subjectCode != null) {
|
|
|
|
+ FormatType type = validateFormatType(validateExamSubject(examId, subjectCode).getCardType());
|
|
|
|
+ uri = fileService.getCardUri(examId, subjectCode, type);
|
|
|
|
+ } else {
|
|
|
|
+ FormatType type = validateFormatType(exam.getCardType());
|
|
|
|
+ uri = fileService.getCardUri(examId, type);
|
|
|
|
+ }
|
|
|
|
+ return result("url", fileService.getFileServer().concat(uri));
|
|
|
|
+ }
|
|
}
|
|
}
|