瀏覽代碼

格式化代码

chenshudong 2 周之前
父節點
當前提交
0d2b4165cf
共有 1 個文件被更改,包括 20 次插入40 次删除
  1. 20 40
      airport-admin/src/main/java/com/sundot/airport/web/controller/common/CommonController.java

+ 20 - 40
airport-admin/src/main/java/com/sundot/airport/web/controller/common/CommonController.java

@@ -4,6 +4,7 @@ import java.util.ArrayList;
4
 import java.util.List;
4
 import java.util.List;
5
 import javax.servlet.http.HttpServletRequest;
5
 import javax.servlet.http.HttpServletRequest;
6
 import javax.servlet.http.HttpServletResponse;
6
 import javax.servlet.http.HttpServletResponse;
7
+
7
 import org.slf4j.Logger;
8
 import org.slf4j.Logger;
8
 import org.slf4j.LoggerFactory;
9
 import org.slf4j.LoggerFactory;
9
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,13 +23,12 @@ import com.sundot.airport.framework.config.ServerConfig;
22
 
23
 
23
 /**
24
 /**
24
  * 通用请求处理
25
  * 通用请求处理
25
- * 
26
+ *
26
  * @author ruoyi
27
  * @author ruoyi
27
  */
28
  */
28
 @RestController
29
 @RestController
29
 @RequestMapping("/common")
30
 @RequestMapping("/common")
30
-public class CommonController
31
-{
31
+public class CommonController {
32
     private static final Logger log = LoggerFactory.getLogger(CommonController.class);
32
     private static final Logger log = LoggerFactory.getLogger(CommonController.class);
33
 
33
 
34
     @Autowired
34
     @Autowired
@@ -38,17 +38,14 @@ public class CommonController
38
 
38
 
39
     /**
39
     /**
40
      * 通用下载请求
40
      * 通用下载请求
41
-     * 
41
+     *
42
      * @param fileName 文件名称
42
      * @param fileName 文件名称
43
      * @param delete 是否删除
43
      * @param delete 是否删除
44
      */
44
      */
45
     @GetMapping("/download")
45
     @GetMapping("/download")
46
-    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
47
-    {
48
-        try
49
-        {
50
-            if (!FileUtils.checkAllowDownload(fileName))
51
-            {
46
+    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
47
+        try {
48
+            if (!FileUtils.checkAllowDownload(fileName)) {
52
                 throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
49
                 throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
53
             }
50
             }
54
             String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
51
             String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
@@ -57,13 +54,10 @@ public class CommonController
57
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
54
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
58
             FileUtils.setAttachmentResponseHeader(response, realFileName);
55
             FileUtils.setAttachmentResponseHeader(response, realFileName);
59
             FileUtils.writeBytes(filePath, response.getOutputStream());
56
             FileUtils.writeBytes(filePath, response.getOutputStream());
60
-            if (delete)
61
-            {
57
+            if (delete) {
62
                 FileUtils.deleteFile(filePath);
58
                 FileUtils.deleteFile(filePath);
63
             }
59
             }
64
-        }
65
-        catch (Exception e)
66
-        {
60
+        } catch (Exception e) {
67
             log.error("下载文件失败", e);
61
             log.error("下载文件失败", e);
68
         }
62
         }
69
     }
63
     }
@@ -72,10 +66,8 @@ public class CommonController
72
      * 通用上传请求(单个)
66
      * 通用上传请求(单个)
73
      */
67
      */
74
     @PostMapping("/upload")
68
     @PostMapping("/upload")
75
-    public AjaxResult uploadFile(MultipartFile file) throws Exception
76
-    {
77
-        try
78
-        {
69
+    public AjaxResult uploadFile(MultipartFile file) throws Exception {
70
+        try {
79
             // 上传文件路径
71
             // 上传文件路径
80
             String filePath = RuoYiConfig.getUploadPath();
72
             String filePath = RuoYiConfig.getUploadPath();
81
             // 上传并返回新文件名称
73
             // 上传并返回新文件名称
@@ -87,9 +79,7 @@ public class CommonController
87
             ajax.put("newFileName", FileUtils.getName(fileName));
79
             ajax.put("newFileName", FileUtils.getName(fileName));
88
             ajax.put("originalFilename", file.getOriginalFilename());
80
             ajax.put("originalFilename", file.getOriginalFilename());
89
             return ajax;
81
             return ajax;
90
-        }
91
-        catch (Exception e)
92
-        {
82
+        } catch (Exception e) {
93
             return AjaxResult.error(e.getMessage());
83
             return AjaxResult.error(e.getMessage());
94
         }
84
         }
95
     }
85
     }
@@ -98,18 +88,15 @@ public class CommonController
98
      * 通用上传请求(多个)
88
      * 通用上传请求(多个)
99
      */
89
      */
100
     @PostMapping("/uploads")
90
     @PostMapping("/uploads")
101
-    public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
102
-    {
103
-        try
104
-        {
91
+    public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception {
92
+        try {
105
             // 上传文件路径
93
             // 上传文件路径
106
             String filePath = RuoYiConfig.getUploadPath();
94
             String filePath = RuoYiConfig.getUploadPath();
107
             List<String> urls = new ArrayList<String>();
95
             List<String> urls = new ArrayList<String>();
108
             List<String> fileNames = new ArrayList<String>();
96
             List<String> fileNames = new ArrayList<String>();
109
             List<String> newFileNames = new ArrayList<String>();
97
             List<String> newFileNames = new ArrayList<String>();
110
             List<String> originalFilenames = new ArrayList<String>();
98
             List<String> originalFilenames = new ArrayList<String>();
111
-            for (MultipartFile file : files)
112
-            {
99
+            for (MultipartFile file : files) {
113
                 // 上传并返回新文件名称
100
                 // 上传并返回新文件名称
114
                 String fileName = FileUploadUtils.upload(filePath, file);
101
                 String fileName = FileUploadUtils.upload(filePath, file);
115
                 String url = serverConfig.getUrl() + fileName;
102
                 String url = serverConfig.getUrl() + fileName;
@@ -124,9 +111,7 @@ public class CommonController
124
             ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
111
             ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
125
             ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
112
             ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
126
             return ajax;
113
             return ajax;
127
-        }
128
-        catch (Exception e)
129
-        {
114
+        } catch (Exception e) {
130
             return AjaxResult.error(e.getMessage());
115
             return AjaxResult.error(e.getMessage());
131
         }
116
         }
132
     }
117
     }
@@ -136,12 +121,9 @@ public class CommonController
136
      */
121
      */
137
     @GetMapping("/download/resource")
122
     @GetMapping("/download/resource")
138
     public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
123
     public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
139
-            throws Exception
140
-    {
141
-        try
142
-        {
143
-            if (!FileUtils.checkAllowDownload(resource))
144
-            {
124
+            throws Exception {
125
+        try {
126
+            if (!FileUtils.checkAllowDownload(resource)) {
145
                 throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
127
                 throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
146
             }
128
             }
147
             // 本地资源路径
129
             // 本地资源路径
@@ -153,9 +135,7 @@ public class CommonController
153
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
135
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
154
             FileUtils.setAttachmentResponseHeader(response, downloadName);
136
             FileUtils.setAttachmentResponseHeader(response, downloadName);
155
             FileUtils.writeBytes(downloadPath, response.getOutputStream());
137
             FileUtils.writeBytes(downloadPath, response.getOutputStream());
156
-        }
157
-        catch (Exception e)
158
-        {
138
+        } catch (Exception e) {
159
             log.error("下载文件失败", e);
139
             log.error("下载文件失败", e);
160
         }
140
         }
161
     }
141
     }