Redeem 1 год назад
Родитель
Сommit
a1ddb71b31

+ 73 - 28
src/main/java/com/steerinfo/dil/controller/SystemFileController.java

@@ -16,6 +16,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.MultiValueMap;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartRequest;
@@ -157,11 +158,11 @@ public class SystemFileController extends BaseRESTfulController {
     public RESTfulResult insertFiles(String[] fileUuids, String[] fileNames, String[] fileTypes, Map<Object, MultipartFile> FileList, MultipartRequest request) throws Exception {
 
 
-        List<MultipartFile> files  = new ArrayList<>();
-        int index=-1;
-        for(int j = 0 ; j < fileTypes.length ; j ++ ) {
-            for(int i=0;i<21;i++) {
-                MultipartFile file = request.getFile("file" +j +"" + i);
+        List<MultipartFile> files = new ArrayList<>();
+        int index = -1;
+        for (int j = 0; j < fileTypes.length; j++) {
+            for (int i = 0; i < 21; i++) {
+                MultipartFile file = request.getFile("file" + j + "" + i);
                 if (file != null) {
                     files.add(file);
                     if (index < 0) {
@@ -171,7 +172,7 @@ public class SystemFileController extends BaseRESTfulController {
             }
         }
 
-        if(files.size() == 0) {
+        if (files.size() == 0) {
             return failed("传输失败");
         }
         for (int i = 0; i < fileUuids.length; i++) {
@@ -233,22 +234,22 @@ public class SystemFileController extends BaseRESTfulController {
 
         SystemFile value = systemFileMapper.selectByPrimaryKey(parmas.get("id").toString());
 
-            String fileName = value.getFilename();
-            String filepath = value.getFilepath();
-            if (fileName == null || fileName.isEmpty()) {
-                return failed("该图片不存在!");
-            }
-            if (filepath == null || filepath.isEmpty()) {
-                return failed("该图片地址不存在!");
-            }
+        String fileName = value.getFilename();
+        String filepath = value.getFilepath();
+        if (fileName == null || fileName.isEmpty()) {
+            return failed("该图片不存在!");
+        }
+        if (filepath == null || filepath.isEmpty()) {
+            return failed("该图片地址不存在!");
+        }
 
-            try {
-                String result = ftpFileUtil.downloadFile(fileName, filepath);
-                return success(result);
-            } catch (IOException e) {
-                e.getMessage();
-                return failed();
-            }
+        try {
+            String result = ftpFileUtil.downloadFile(fileName, filepath);
+            return success(result);
+        } catch (IOException e) {
+            e.getMessage();
+            return failed();
+        }
 
     }
 
@@ -303,22 +304,24 @@ public class SystemFileController extends BaseRESTfulController {
 
     @PostMapping("/previewfileList")
     public RESTfulResult previewfileList(@RequestBody HashMap map) {
-        String uuid =  map.get("uuid").toString();
+        String uuid = map.get("uuid").toString();
         String[] uuidList = uuid.split(";");
         //遍历数组,去找文件名称和路径
-        List<Map<String,Object>> mapList = systemFileMapper.getFileInfo(uuidList);
-        List<Map<String,Object>> resultList = new ArrayList<>();
-        for (Map<String,Object> parmas : mapList) {
+        List<Map<String, Object>> mapList = systemFileMapper.getFileInfo(uuidList);
+        List<Map<String, Object>> resultList = new ArrayList<>();
+        for (Map<String, Object> parmas : mapList) {
             String filename = parmas.get("FILENAME").toString();
             String filepath = parmas.get("FILEPATH").toString();
-            if (filename == null ||filename.isEmpty()) {
+            if (filename == null || filename.isEmpty()) {
                 return failed("该图片不存在!");
             }
-            if (filepath == null ||filepath.isEmpty()) {
+            if (filepath == null || filepath.isEmpty()) {
                 return failed("该图片地址不存在!");
             }
             try {
-                Map<String,Object> result = ftpFileUtil.downloadFileNew(filename, filepath);
+                Map<String, Object> result = ftpFileUtil.downloadFileNew(filename, filepath);
+                //如果是返回base64,则给这个;网络路径则给netUrl
+                result.put("dataType","base");
                 resultList.add(result);
             } catch (IOException e) {
                 e.getMessage();
@@ -330,4 +333,46 @@ public class SystemFileController extends BaseRESTfulController {
     }
 
 
+    @PostMapping("/insertFilesReal")
+    public RESTfulResult insertFilesReal(MultipartRequest request, String[] uuidTypes) throws Exception {
+        //List<MultipartFile> files  = new ArrayList<>();
+        //获取多个文件
+        MultiValueMap<String, MultipartFile> multiFileMap = request.getMultiFileMap();
+        List<MultipartFile> files = multiFileMap.get("file");
+        System.out.println(uuidTypes + "uuidTypes");
+        System.out.println(request);
+        if (files.size() == 0) {
+            return failed("传输失败");
+        }
+        int index = 0;
+        for (MultipartFile file : files) {
+            String uuidType = uuidTypes[index];
+            String fileMediaType = file.getContentType();
+            String newName = uuidType.split(";")[0];
+            if (fileMediaType != null && fileMediaType.contains("image")) {
+                newName = uuidType.split(";")[0] + "." +fileMediaType.split("/")[1];
+            }
+            String uuid = uuidType.split(";")[0];
+            String fileType = uuidType.split(";")[1];
+            InputStream inputStream = file.getInputStream();
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("/yyyy/MM/dd");
+            String filePath = simpleDateFormat.format(new Date()) + "/" + fileType;
+            boolean result = ftpFileUtil.uploadToFtp(inputStream, filePath, newName, false);
+            inputStream.close();
+            if (result) {
+                SystemFile uploadFile = new SystemFile();
+                uploadFile.setFilename(newName);
+                uploadFile.setFilepath(filePath + "/" + newName);
+                uploadFile.setId(uuid);
+                SystemFile modela = systemFileService.add(uploadFile);
+                if (modela != null) {
+                    uuid += "," + modela.getId();
+                }
+            } else {
+                return failed(null, "上传文件失败");
+            }
+            index++;
+        }
+        return success();
+}
 }

+ 2 - 0
src/main/java/com/steerinfo/dil/controller/UniversalController.java

@@ -65,6 +65,8 @@ public class UniversalController extends BaseRESTfulController {
         return success(list);
     }
 
+
+
     @ApiModelProperty(value = "边输边查运力类型")
     @PostMapping("/getCapacityTypeByLike")
     public RESTfulResult getCapacityTypeByLike(@RequestBody(required = false) Map<String,Object> map) {