Explorar o código

增加获取题卡文件下载URL接口

luoshi %!s(int64=4) %!d(string=hai) anos
pai
achega
99795f5d31

+ 6 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/api/controller/BaseApiController.java

@@ -39,6 +39,12 @@ public class BaseApiController extends BaseController {
         return obj;
     }
 
+    protected JSONObject result(String key, String value) {
+        JSONObject obj = new JSONObject();
+        obj.accumulate(key, value);
+        return obj;
+    }
+
     protected String validate(String name, String value, boolean required, int maxLength) {
         value = StringUtils.trimToNull(value);
         if (required && value == null) {

+ 26 - 3
stmms-web/src/main/java/cn/com/qmth/stmms/api/controller/FileController.java

@@ -93,10 +93,14 @@ public class FileController extends BaseApiController {
         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) {
@@ -261,4 +265,23 @@ public class FileController extends BaseApiController {
         }
         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));
+    }
 }

+ 2 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/api/exception/ApiException.java

@@ -39,4 +39,6 @@ public class ApiException extends RuntimeException {
 
     public static final ApiException FILE_UPLOAD_ERROR = new ApiException(500, "file upload error");
 
+    public static final ApiException FORMAT_TYPE_ERROR = new ApiException(500, "format type error");
+
 }