|
@@ -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")
|