Browse Source

Merge remote-tracking branch 'origin/dev/precSR' into dev/precSR

wangyu 5 years ago
parent
commit
3672eefb73

+ 2 - 2
prec-service/src/main/java/com/diagbot/service/impl/UploadServiceImpl.java

@@ -37,7 +37,7 @@ public class UploadServiceImpl implements UploadService {
             return new FileDTO("FAILURE", "文件上传失败,超出大小限制4MB");
         }
         try {
-            FileDTO fileDTO = saveFile(file, null);
+            FileDTO fileDTO = saveFile(file, false);
             return fileDTO;
         } catch (Exception e) {
             log.error("文件上传失败", e);
@@ -65,7 +65,7 @@ public class UploadServiceImpl implements UploadService {
             }
 
             try {
-                FileDTO fileDTO = saveFile(file, null);
+                FileDTO fileDTO = saveFile(file, false);
                 fileDTOS.add(fileDTO);
             } catch (Exception e) {
                 log.error("文件上传失败", e);

+ 42 - 29
prec-service/src/main/java/com/diagbot/web/UploadController.java

@@ -2,8 +2,10 @@ package com.diagbot.web;
 
 import com.diagbot.dto.FileDTO;
 import com.diagbot.dto.FileThumDTO;
+import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.UploadFacade;
 import com.diagbot.util.FastJsonUtils;
+import com.diagbot.util.ListUtil;
 import com.diagbot.util.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -32,46 +34,57 @@ public class UploadController {
     @ApiOperation(value = "智能预问诊-单个文件上传")
     @CrossOrigin(allowCredentials = "true", allowedHeaders = "*", methods = { RequestMethod.POST }, origins = "*")
     @PostMapping(value = "/uploadImage", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
-    public String singleFileUpload(@RequestParam("upfile") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
-        FileDTO fileDTO = uploadFacade.singleFileUpload(file);
-        String data = FastJsonUtils.getBeanToJson(fileDTO);
-        response.setContentType("text/plain;charset=UTF-8");
-
-        String callback = request.getParameter("callback");//客户端请求参数
-        if (callback != null && StringUtil.isNotBlank(callback)) {
-            data = callback + "(" + data + ")";
+    public RespDTO<FileDTO> singleFileUpload(@RequestParam("upfile") MultipartFile file) {
+        FileDTO data = uploadFacade.singleFileUpload(file);
+        if (data.getState().equals("FAILURE")) {
+            return RespDTO.onError(data.getInfo());
+        } else {
+            return RespDTO.onSuc(data);
         }
-        return data;
     }
 
+
     @ApiOperation(value = "智能预问诊-多个文件上传")
     @CrossOrigin(allowCredentials = "true", allowedHeaders = "*", methods = { RequestMethod.POST }, origins = "*")
-    @PostMapping(value = "/uploadImages", produces = MediaType.MULTIPART_FORM_DATA_VALUE)
-    public String multiFileUpload(@RequestParam("upfiles") MultipartFile[] file, HttpServletRequest request, HttpServletResponse response) {
-        List<FileDTO> fileDTO = uploadFacade.multiFileUpload(file);
-        String data = FastJsonUtils.getBeanToJson(fileDTO);
-        response.setContentType("text/plain;charset=UTF-8");
-
-        String callback = request.getParameter("callback");//客户端请求参数
-        if (callback != null && StringUtil.isNotBlank(callback)) {
-            data = callback + "(" + data + ")";
+    @PostMapping(value = "/uploadImages", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+    public RespDTO<List<FileDTO>> multiFileUpload(@RequestParam("upfiles") MultipartFile[] file) {
+        List<FileDTO> data = uploadFacade.multiFileUpload(file);
+        String msg = "";
+        if (ListUtil.isNotEmpty(data)) {
+            for (int i = 0; i < data.size(); i++) {
+                if (data.get(i).getState().equals("FAILURE")) {
+                    msg += "第【" + (i + 1) + "】张图片上传失败," + data.get(i).getInfo() + ";";
+                }
+            }
+        }
+        if (StringUtil.isNotBlank(msg)) {
+            return RespDTO.onError(msg);
+        } else {
+            return RespDTO.onSuc(data);
         }
-        return data;
     }
 
     @ApiOperation(value = "智能预问诊-多个文件上传同时生成缩略图")
     @CrossOrigin(allowCredentials = "true", allowedHeaders = "*", methods = { RequestMethod.POST }, origins = "*")
-    @PostMapping(value = "/uploadImageThums", produces = MediaType.MULTIPART_FORM_DATA_VALUE)
-    public String multiFileThumUpload(@RequestParam("upfiles") MultipartFile[] file, @RequestParam("type") Integer[] type, HttpServletRequest request, HttpServletResponse response) {
-        List<FileThumDTO> fileDTO = uploadFacade.multiFileThumUpload(file, type);
-        String data = FastJsonUtils.getBeanToJson(fileDTO);
-        response.setContentType("text/plain;charset=UTF-8");
-
-        String callback = request.getParameter("callback");//客户端请求参数
-        if (callback != null && StringUtil.isNotBlank(callback)) {
-            data = callback + "(" + data + ")";
+    @PostMapping(value = "/uploadImageThums", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+    public RespDTO<List<FileThumDTO>> multiFileThumUpload(@RequestParam("upfiles") MultipartFile[] file, @RequestParam("type") Integer[] type) {
+        List<FileThumDTO> data = uploadFacade.multiFileThumUpload(file, type);
+        String msg = "";
+        if (ListUtil.isNotEmpty(data)) {
+            for (int i = 0; i < data.size(); i++) {
+                if (data.get(i).getSource() != null && data.get(i).getSource().getState().equals("FAILURE")) {
+                    msg += "第【" + (i + 1) + "】张图片上传失败," + data.get(i).getSource().getInfo() + ";";
+                }
+                if (data.get(i).getThumbnail() != null && data.get(i).getThumbnail().getState().equals("FAILURE")) {
+                    msg += "第【" + (i + 1) + "】张图片缩略图上传失败," + data.get(i).getThumbnail().getInfo() + ";";
+                }
+            }
+        }
+        if (StringUtil.isNotBlank(msg)) {
+            return RespDTO.onError(msg);
+        } else {
+            return RespDTO.onSuc(data);
         }
-        return data;
     }
 
     @PostMapping("/deleteRemoteFile")

+ 14 - 12
precman-service/src/main/java/com/diagbot/web/UploadController.java

@@ -1,6 +1,7 @@
 package com.diagbot.web;
 
 import com.diagbot.dto.FileDTO;
+import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.UploadFacade;
 import com.diagbot.util.FastJsonUtils;
 import com.diagbot.util.StringUtil;
@@ -30,22 +31,23 @@ public class UploadController {
     @ApiOperation(value = "文件上传")
     @CrossOrigin(allowCredentials = "true", allowedHeaders = "*", methods = { RequestMethod.POST }, origins = "*")
     @PostMapping(value = "/uploadImage", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
-    public String singleFileUpload(@RequestParam("upfile") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
-        FileDTO fileDTO = uploadFacade.singleFileUpload(file);
-        String data = FastJsonUtils.getBeanToJson(fileDTO);
-        response.setContentType("text/plain;charset=UTF-8");
-
-        String callback = request.getParameter("callback");//客户端请求参数
-        if (callback != null && StringUtil.isNotBlank(callback)) {
-            data = callback + "(" + data + ")";
+    public RespDTO<FileDTO> singleFileUpload(@RequestParam("upfile") MultipartFile file) {
+        FileDTO data = uploadFacade.singleFileUpload(file);
+        if (data.getState().equals("FAILURE")) {
+            return RespDTO.onError(data.getInfo());
+        } else {
+            return RespDTO.onSuc(data);
         }
-        return data;
     }
 
     @PostMapping("/deleteRemoteFile")
     @ApiOperation(value = "文件删除")
-    public String deleteRemoteFile(@RequestParam("path") String path) {
-        String data = FastJsonUtils.getBeanToJson(uploadFacade.deleteRemoteFile(path));
-        return data;
+    public RespDTO<FileDTO> deleteRemoteFile(@RequestParam("path") String path) {
+        FileDTO data = uploadFacade.deleteRemoteFile(path);
+        if (data.getState().equals("FAILURE")) {
+            return RespDTO.onError(data.getInfo());
+        } else {
+            return RespDTO.onSuc(data);
+        }
     }
 }