Commit 05af9845eb9c10317710a33e94b691d3fb742604

Authored by 谭毅彬
1 parent 28c1afd5

文件上传下载初版提交

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