Commit 05af9845eb9c10317710a33e94b691d3fb742604
1 parent
28c1afd5
文件上传下载初版提交
Signed-off-by: TanYibin <5491541@qq.com>
Showing
7 changed files
with
66 additions
and
52 deletions
.gitignore
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/CommonController.java
... | ... | @@ -2,6 +2,8 @@ package org.jeecg.modules.system.controller; |
2 | 2 | |
3 | 3 | import com.alibaba.fastjson.JSON; |
4 | 4 | import com.alibaba.fastjson.JSONObject; |
5 | + | |
6 | +import io.swagger.annotations.ApiOperation; | |
5 | 7 | import lombok.extern.slf4j.Slf4j; |
6 | 8 | import org.jeecg.common.api.vo.Result; |
7 | 9 | import org.jeecg.common.constant.CommonConstant; |
... | ... | @@ -11,6 +13,7 @@ import org.jeecg.common.util.CommonUtils; |
11 | 13 | import org.jeecg.common.util.RestUtil; |
12 | 14 | import org.jeecg.common.util.TokenUtils; |
13 | 15 | import org.jeecg.common.util.oConvertUtils; |
16 | +import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; | |
14 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
15 | 18 | import org.springframework.beans.factory.annotation.Value; |
16 | 19 | import org.springframework.http.HttpHeaders; |
... | ... | @@ -53,6 +56,12 @@ public class CommonController { |
53 | 56 | */ |
54 | 57 | @Value(value = "${jeecg.uploadType}") |
55 | 58 | private String uploadType; |
59 | + | |
60 | + /** | |
61 | + * 允许上传的文件类型 | |
62 | + */ | |
63 | + @Value(value = "${jeecg.uploadFileType}") | |
64 | + private String uploadFileType; | |
56 | 65 | |
57 | 66 | /** |
58 | 67 | * @Author 政辉 |
... | ... | @@ -70,29 +79,34 @@ public class CommonController { |
70 | 79 | * @return |
71 | 80 | */ |
72 | 81 | @PostMapping(value = "/upload") |
82 | + @ApiLogger(apiName = "文件上传", from = "WMS") | |
73 | 83 | public Result<?> upload(HttpServletRequest request, HttpServletResponse response) { |
74 | 84 | Result<?> result = new Result<>(); |
75 | 85 | String savePath = ""; |
76 | 86 | String bizPath = request.getParameter("biz"); |
77 | - | |
78 | 87 | // LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞 |
79 | 88 | if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) { |
80 | - throw new JeecgBootException("上传目录bizPath,格式非法!"); | |
89 | + throw new JeecgBootException("上传路径格式非法!"); | |
81 | 90 | } |
82 | - | |
83 | 91 | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request; |
84 | 92 | MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象 |
93 | + if (file == null) { | |
94 | + throw new JeecgBootException("未找到上传文件!"); | |
95 | + } | |
85 | 96 | if (oConvertUtils.isEmpty(bizPath)) { |
86 | 97 | if (CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)) { |
87 | - // 未指定目录,则用阿里云默认目录 upload | |
88 | - bizPath = "upload"; | |
89 | - // result.setMessage("使用阿里云文件上传时,必须添加目录!"); | |
90 | - // result.setSuccess(false); | |
91 | - // return result; | |
98 | + result.setMessage("使用阿里云文件上传时,必须添加目录!"); | |
99 | + result.setSuccess(false); | |
100 | + return result; | |
92 | 101 | } else { |
93 | 102 | bizPath = ""; |
94 | 103 | } |
95 | 104 | } |
105 | + String orgName = file.getOriginalFilename();// 获取文件名 | |
106 | + String suffix = orgName.substring(orgName.lastIndexOf(".") + 1); // 文件后缀 | |
107 | + if (orgName.equals(suffix) || !uploadFileType.contains(suffix)) { | |
108 | + throw new JeecgBootException("上传文件类型非法!"); | |
109 | + } | |
96 | 110 | if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) { |
97 | 111 | // update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传 |
98 | 112 | savePath = this.uploadLocal(file, bizPath); |
... | ... | @@ -130,24 +144,17 @@ public class CommonController { |
130 | 144 | * @param bizPath 自定义路径 |
131 | 145 | * @return |
132 | 146 | */ |
133 | - private String uploadLocal(MultipartFile mf, String bizPath) { | |
147 | + private String uploadLocal(MultipartFile multipartFile, String bizPath) { | |
134 | 148 | try { |
135 | 149 | String ctxPath = uploadpath; |
136 | - String fileName = null; | |
137 | 150 | File file = new File(ctxPath + File.separator + bizPath + File.separator); |
138 | 151 | if (!file.exists()) { |
139 | 152 | file.mkdirs();// 创建文件根目录 |
140 | 153 | } |
141 | - String orgName = mf.getOriginalFilename();// 获取文件名 | |
142 | - orgName = CommonUtils.getFileName(orgName); | |
143 | - if (orgName.indexOf(".") != -1) { | |
144 | - fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); | |
145 | - } else { | |
146 | - fileName = orgName + "_" + System.currentTimeMillis(); | |
147 | - } | |
154 | + String fileName = CommonUtils.getFileName(multipartFile.getOriginalFilename()); | |
148 | 155 | String savePath = file.getPath() + File.separator + fileName; |
149 | 156 | File savefile = new File(savePath); |
150 | - FileCopyUtils.copy(mf.getBytes(), savefile); | |
157 | + FileCopyUtils.copy(multipartFile.getBytes(), savefile); | |
151 | 158 | String dbpath = null; |
152 | 159 | if (oConvertUtils.isNotEmpty(bizPath)) { |
153 | 160 | dbpath = bizPath + File.separator + fileName; |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLogAspect.java renamed to huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLoggerAspect.java
... | ... | @@ -52,8 +52,8 @@ import okhttp3.Response; |
52 | 52 | @Aspect |
53 | 53 | @Component |
54 | 54 | @EnableAsync |
55 | -public class ApiLogAspect { | |
56 | - private static final Logger log = LoggerFactory.getLogger(ApiLogAspect.class); | |
55 | +public class ApiLoggerAspect { | |
56 | + private static final Logger log = LoggerFactory.getLogger(ApiLoggerAspect.class); | |
57 | 57 | |
58 | 58 | private static IApiLogService apiLogService; |
59 | 59 | |
... | ... | @@ -61,12 +61,12 @@ public class ApiLogAspect { |
61 | 61 | |
62 | 62 | @Autowired |
63 | 63 | public void setApiLogService(IApiLogService apiLogService) { |
64 | - ApiLogAspect.apiLogService = apiLogService; | |
64 | + ApiLoggerAspect.apiLogService = apiLogService; | |
65 | 65 | } |
66 | 66 | |
67 | 67 | @Autowired |
68 | 68 | public void setAddressService(IAddressService addressService) { |
69 | - ApiLogAspect.addressService = addressService; | |
69 | + ApiLoggerAspect.addressService = addressService; | |
70 | 70 | } |
71 | 71 | |
72 | 72 | // 配置织入点 |
... | ... | @@ -285,7 +285,7 @@ public class ApiLogAspect { |
285 | 285 | } catch (Exception e) { |
286 | 286 | e.printStackTrace(); |
287 | 287 | } |
288 | - SpringUtils.getBean(ApiLogAspect.class).saveApiLog(log); | |
288 | + SpringUtils.getBean(ApiLoggerAspect.class).saveApiLog(log); | |
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
... | ... | @@ -491,7 +491,7 @@ public class ApiLogAspect { |
491 | 491 | private void rebuildResponseHeader(ApiLog log) { |
492 | 492 | try { |
493 | 493 | HttpServletResponse resp = ServletUtils.getResponse(); |
494 | - Collection names = resp.getHeaderNames(); | |
494 | + Collection<String> names = resp.getHeaderNames(); | |
495 | 495 | ArrayList<String> headerList = new ArrayList<>(); |
496 | 496 | Iterator<String> it = names.iterator(); |
497 | 497 | while (it.hasNext()) { |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java
... | ... | @@ -10,7 +10,7 @@ import antlr.StringUtils; |
10 | 10 | import cn.hutool.core.util.StrUtil; |
11 | 11 | import net.bytebuddy.asm.Advice.This; |
12 | 12 | import okhttp3.*; |
13 | -import org.jeecg.modules.wms.framework.aspectj.ApiLogAspect; | |
13 | +import org.jeecg.modules.wms.framework.aspectj.ApiLoggerAspect; | |
14 | 14 | import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; |
15 | 15 | import org.slf4j.Logger; |
16 | 16 | import org.slf4j.LoggerFactory; |
... | ... | @@ -104,16 +104,16 @@ public class OkHttpUtils { |
104 | 104 | Response response = null; |
105 | 105 | String result = null; |
106 | 106 | try { |
107 | - ApiLogAspect.initApiLog(apiLog, request, param); | |
107 | + ApiLoggerAspect.initApiLog(apiLog, request, param); | |
108 | 108 | response = HTTP_CLIENT.newCall(request).execute(); |
109 | 109 | result = response.body().string(); |
110 | 110 | } catch (Exception e) { |
111 | 111 | String errorString = |
112 | 112 | StrUtil.format("执行GET请求异常,url:{},header:{},param:{},errorMessage:{}", url, JSON.toJSONString(headers), param, e.getMessage()); |
113 | - ApiLogAspect.setApiLogException(apiLog, e); | |
113 | + ApiLoggerAspect.setApiLogException(apiLog, e); | |
114 | 114 | throw new RuntimeException(errorString, e); |
115 | 115 | } finally { |
116 | - ApiLogAspect.finishApiLog(apiLog, response, result); | |
116 | + ApiLoggerAspect.finishApiLog(apiLog, response, result); | |
117 | 117 | } |
118 | 118 | if (response.isSuccessful() && Objects.nonNull(response.body())) {// 调用成功 |
119 | 119 | log.info("执行GET请求成功,url:{},header:{},param:{},result:{}", url, JSON.toJSONString(headers), param, result); |
... | ... | @@ -154,16 +154,16 @@ public class OkHttpUtils { |
154 | 154 | Response response = null; |
155 | 155 | String result = null; |
156 | 156 | try { |
157 | - ApiLogAspect.initApiLog(apiLog, request, param); | |
157 | + ApiLoggerAspect.initApiLog(apiLog, request, param); | |
158 | 158 | response = HTTP_CLIENT.newCall(request).execute(); |
159 | 159 | result = response.body().string(); |
160 | 160 | } catch (Exception e) { |
161 | 161 | String errorString = |
162 | 162 | StrUtil.format("执行POST请求异常,url:{},header:{},param:{},errorMessage:{}", url, JSON.toJSONString(headers), param, e.getMessage()); |
163 | - ApiLogAspect.setApiLogException(apiLog, e); | |
163 | + ApiLoggerAspect.setApiLogException(apiLog, e); | |
164 | 164 | throw new RuntimeException(errorString, e); |
165 | 165 | } finally { |
166 | - ApiLogAspect.finishApiLog(apiLog, response, result); | |
166 | + ApiLoggerAspect.finishApiLog(apiLog, response, result); | |
167 | 167 | } |
168 | 168 | if (response.isSuccessful() && Objects.nonNull(response.body())) {// 调用成功 |
169 | 169 | log.info("执行POST请求成功,url:{},header:{},param:{},result:{}", url, JSON.toJSONString(headers), param, result); |
... | ... | @@ -196,15 +196,15 @@ public class OkHttpUtils { |
196 | 196 | Response response = null; |
197 | 197 | String result = null; |
198 | 198 | try { |
199 | - ApiLogAspect.initApiLog(apiLog, request, jsonString); | |
199 | + ApiLoggerAspect.initApiLog(apiLog, request, jsonString); | |
200 | 200 | response = HTTP_CLIENT.newCall(request).execute(); |
201 | 201 | result = response.body().string(); |
202 | 202 | } catch (Exception e) { |
203 | 203 | String errorString = StrUtil.format("执行POST请求异常,url:{},header:{},param:{},errorMessage:{}", url, JSON.toJSONString(headers), jsonString, e.getMessage()); |
204 | - ApiLogAspect.setApiLogException(apiLog, e); | |
204 | + ApiLoggerAspect.setApiLogException(apiLog, e); | |
205 | 205 | throw new RuntimeException(errorString); |
206 | 206 | } finally { |
207 | - ApiLogAspect.finishApiLog(apiLog, response, result); | |
207 | + ApiLoggerAspect.finishApiLog(apiLog, response, result); | |
208 | 208 | } |
209 | 209 | if (response.isSuccessful() && Objects.nonNull(response.body())) {// 调用成功 |
210 | 210 | log.info("执行POST请求成功,url:{},header:{},param:{},result:{}", url, JSON.toJSONString(headers), jsonString, result); |
... | ... |
huaheng-wms-core/src/main/resources/application-dev.yml
... | ... | @@ -22,8 +22,8 @@ management: |
22 | 22 | spring: |
23 | 23 | servlet: |
24 | 24 | multipart: |
25 | - max-file-size: 10MB | |
26 | - max-request-size: 10MB | |
25 | + max-file-size: 100MB | |
26 | + max-request-size: 100MB | |
27 | 27 | mail: |
28 | 28 | host: smtp.163.com |
29 | 29 | username: jeecgos@163.com |
... | ... | @@ -189,14 +189,16 @@ jeecg: |
189 | 189 | # 签名密钥串(前后端要一致,正式发布请自行修改) |
190 | 190 | signatureSecret: dd05f1c54d63749eda95f9fa6d49v442a |
191 | 191 | # 本地:local\Minio:minio\阿里云:alioss |
192 | - uploadType: minio | |
192 | + uploadType: local | |
193 | + # 允许上传的文件类型,使用,分割 | |
194 | + uploadFileType: sh | |
193 | 195 | path: |
194 | 196 | #文件上传根目录 设置 |
195 | - upload: /opt/upFiles | |
197 | + upload: ./upFiles | |
196 | 198 | #webapp文件路径 |
197 | - webapp: /opt/webapp | |
199 | + webapp: ./webapp | |
198 | 200 | shiro: |
199 | - excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/sys/getWarehouseByUserCode,/test/test**,/api/**,/sys/cas/client/validateLogin | |
201 | + excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/sys/getWarehouseByUserCode,/test/test**,/api/**,/sys/cas/client/validateLogin,/sys/common/static/** | |
200 | 202 | #阿里云oss存储和大鱼短信秘钥配置 |
201 | 203 | oss: |
202 | 204 | accessKey: ?? |
... | ... |
huaheng-wms-core/src/main/resources/application-prod.yml
... | ... | @@ -22,8 +22,8 @@ management: |
22 | 22 | spring: |
23 | 23 | servlet: |
24 | 24 | multipart: |
25 | - max-file-size: 10MB | |
26 | - max-request-size: 10MB | |
25 | + max-file-size: 100MB | |
26 | + max-request-size: 100MB | |
27 | 27 | mail: |
28 | 28 | host: smtp.163.com |
29 | 29 | username: jeecgos@163.com |
... | ... | @@ -187,14 +187,16 @@ jeecg: |
187 | 187 | # 签名密钥串(前后端要一致,正式发布请自行修改) |
188 | 188 | signatureSecret: dd05f1c54d63749eda95f9fa6d49v442a |
189 | 189 | # 本地:local\Minio:minio\阿里云:alioss |
190 | - uploadType: alioss | |
190 | + uploadType: local | |
191 | + # 允许上传的文件类型,使用,分割 | |
192 | + uploadFileType: sh | |
191 | 193 | path: |
192 | 194 | #文件上传根目录 设置 |
193 | - upload: /opt/jeecg-boot/upload | |
195 | + upload: ./upload | |
194 | 196 | #webapp文件路径 |
195 | - webapp: /opt/jeecg-boot/webapp | |
197 | + webapp: ./webapp | |
196 | 198 | shiro: |
197 | - excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/sys/getWarehouseByUserCode,/test/test**,/api/**,/sys/cas/client/validateLogin | |
199 | + excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/sys/getWarehouseByUserCode,/test/test**,/api/**,/sys/cas/client/validateLogin,/sys/common/static/** | |
198 | 200 | #阿里云oss存储和大鱼短信秘钥配置 |
199 | 201 | oss: |
200 | 202 | accessKey: ?? |
... | ... |
huaheng-wms-core/src/main/resources/application-test.yml
... | ... | @@ -22,8 +22,8 @@ management: |
22 | 22 | spring: |
23 | 23 | servlet: |
24 | 24 | multipart: |
25 | - max-file-size: 10MB | |
26 | - max-request-size: 10MB | |
25 | + max-file-size: 100MB | |
26 | + max-request-size: 100MB | |
27 | 27 | mail: |
28 | 28 | host: smtp.163.com |
29 | 29 | username: jeecgos@163.com |
... | ... | @@ -189,14 +189,16 @@ jeecg: |
189 | 189 | # 签名密钥串(前后端要一致,正式发布请自行修改) |
190 | 190 | signatureSecret: dd05f1c54d63749eda95f9fa6d49v442a |
191 | 191 | # 本地:local\Minio:minio\阿里云:alioss |
192 | - uploadType: minio | |
192 | + uploadType: local | |
193 | + # 允许上传的文件类型,使用,分割 | |
194 | + uploadFileType: sh | |
193 | 195 | path: |
194 | 196 | #文件上传根目录 设置 |
195 | - upload: /opt/upFiles | |
197 | + upload: ./upFiles | |
196 | 198 | #webapp文件路径 |
197 | - webapp: /opt/webapp | |
199 | + webapp: ./webapp | |
198 | 200 | shiro: |
199 | - excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/sys/getWarehouseByUserCode,/api/**,/sys/cas/client/validateLogin | |
201 | + excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/sys/getWarehouseByUserCode,/api/**,/sys/cas/client/validateLogin,/sys/common/static/** | |
200 | 202 | #阿里云oss存储和大鱼短信秘钥配置 |
201 | 203 | oss: |
202 | 204 | accessKey: ?? |
... | ... |