feat: 本地上传

新增本地上传功能,上传路径可配置
This commit is contained in:
2023-04-28 09:10:23 +08:00
parent ebd2750533
commit aed4b71395
2 changed files with 41 additions and 29 deletions
@@ -18,7 +18,7 @@
#spring.datasource.password = adc_forecast #spring.datasource.password = adc_forecast
#kylin数据库 ds1 #kylin\u6570\u636E\u5E93 ds1
#spring.datasource.kylin.name=PROJECT_MI #spring.datasource.kylin.name=PROJECT_MI
#spring.datasource.kylin.driverClassName=org.apache.kylin.jdbc.Driver #spring.datasource.kylin.driverClassName=org.apache.kylin.jdbc.Driver
#spring.datasource.kylin.url=jdbc:kylin://10.64.23.8:7070/PROJECT_MI #spring.datasource.kylin.url=jdbc:kylin://10.64.23.8:7070/PROJECT_MI
@@ -28,7 +28,7 @@
#spring.datasource.kylin.maxWaitTime=10000 #spring.datasource.kylin.maxWaitTime=10000
#spring.datasource.kylin.poolSize=10 #spring.datasource.kylin.poolSize=10
# #
##mysql数据库 ds2 ##mysql\u6570\u636E\u5E93 ds2
#spring.datasource.mysql.driverClassName = com.mysql.jdbc.Driver #spring.datasource.mysql.driverClassName = com.mysql.jdbc.Driver
#spring.datasource.mysql.url = jdbc:mysql://192.168.144.80:3306/cadata?characterEncoding=utf-8&&zeroDateTimeBehavior=convertToNull #spring.datasource.mysql.url = jdbc:mysql://192.168.144.80:3306/cadata?characterEncoding=utf-8&&zeroDateTimeBehavior=convertToNull
#spring.datasource.mysql.username = root #spring.datasource.mysql.username = root
@@ -39,21 +39,21 @@ spring.datasource.url = jdbc:mysql://121.36.69.172:3307/report-library?character
spring.datasource.username = root spring.datasource.username = root
spring.datasource.password = hzwlsoft.com spring.datasource.password = hzwlsoft.com
#后端端口 #\u540E\u7AEF\u7AEF\u53E3
server.port=7060 server.port=7060
#验证码后台模式,默认为1:1为不开启,2为开启,3为输错 用户名或密码 ${maxLoginErrorCount} 次 才开启 #\u9A8C\u8BC1\u7801\u540E\u53F0\u6A21\u5F0F\uFF0C\u9ED8\u8BA4\u4E3A1\uFF1A1\u4E3A\u4E0D\u5F00\u542F\uFF0C2\u4E3A\u5F00\u542F\uFF0C3\u4E3A\u8F93\u9519 \u7528\u6237\u540D\u6216\u5BC6\u7801 ${maxLoginErrorCount} \u6B21 \u624D\u5F00\u542F
verifyCodeMode=3 verifyCodeMode=3
#仅当验证码模式 ${verifyCodeMode} 为 3时生效,设置错误登录出现验证码的阈值,默认为3 #\u4EC5\u5F53\u9A8C\u8BC1\u7801\u6A21\u5F0F ${verifyCodeMode} \u4E3A 3\u65F6\u751F\u6548\uFF0C\u8BBE\u7F6E\u9519\u8BEF\u767B\u5F55\u51FA\u73B0\u9A8C\u8BC1\u7801\u7684\u9608\u503C\uFF0C\u9ED8\u8BA4\u4E3A3
maxLoginErrorCount=3 maxLoginErrorCount=3
#密码Base64加密开关,true为开启,false为关闭 #\u5BC6\u7801Base64\u52A0\u5BC6\u5F00\u5173,true\u4E3A\u5F00\u542F,false\u4E3A\u5173\u95ED
isPassEncrypted=true isPassEncrypted=true
#{ #{
#"password": "YWJjMTIz", #"password": "YWJjMTIz",
#"username": "YWRtaW4x" #"username": "YWRtaW4x"
#} #}
#swagger 显示api1为只显示${restPath:/api}前缀的api,0为显示所有api,其他为不显示api #swagger \u663E\u793Aapi\uFF0C1\u4E3A\u53EA\u663E\u793A${restPath:/api}\u524D\u7F00\u7684api,0\u4E3A\u663E\u793A\u6240\u6709api\uFF0C\u5176\u4ED6\u4E3A\u4E0D\u663E\u793Aapi
swaggerLevel=0 swaggerLevel=0
@@ -61,9 +61,14 @@ swaggerLevel=0
# #
#picPath=/EPR/file/home/pic/ #picPath=/EPR/file/home/pic/
# 本地存储文件的磁盘地址 # \u672C\u5730\u6587\u4EF6\u5B58\u50A8\u8DEF\u5F84\u65B9\u5F0F jar\u5305\u8DEF\u5F84\uFF1Ajar \u5DE5\u4F5C\u76EE\u5F55\uFF1Auserdir \u56FA\u5B9A\u76EE\u5F55\uFF1Asettled
uploadFile=D:\\work\\idea\\changan\\ localSaveFileType=settled
# 本地文件访问的url地址 #localSaveFileType=userdir
# \u672C\u5730\u5B58\u50A8\u6587\u4EF6\u7684\u78C1\u76D8\u5730\u5740
#uploadFile=D:\\work\\idea\\changan\\
uploadFile=/data/DeploymentPackage/report_library/uploadfile
# \u672C\u5730\u6587\u4EF6\u8BBF\u95EE\u7684url\u5730\u5740
picPath=/api/home/pic/ picPath=/api/home/pic/
@@ -89,42 +94,42 @@ MAIL_POP_PORT=110
IPANDPORT=http://localhost:7061/ IPANDPORT=http://localhost:7061/
#redis #redis
#Redis服务器地址 #Redis\u670D\u52A1\u5668\u5730\u5740
spring.redis.host=192.168.144.29 spring.redis.host=192.168.144.29
#spring.redis.host=localhost #spring.redis.host=localhost
## Redis服务器连接端口 ## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3
spring.redis.port=6379 spring.redis.port=6379
## Redis服务器连接密码(默认为空) ## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09
spring.redis.password=123321 spring.redis.password=123321
## 连接超时时间(毫秒) ## \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09
spring.redis.timeout=200000ms spring.redis.timeout=200000ms
## 连接池中的最大空闲连接,默认值是8。 ## \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u662F8\u3002
spring.redis.jedis.pool.max-idle=50 spring.redis.jedis.pool.max-idle=50
##连接池中的最小空闲连接,默认值是0。 ##\u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u662F0\u3002
spring.redis.jedis.pool.min-idle=10 spring.redis.jedis.pool.min-idle=10
## 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。 ## \u5982\u679C\u8D4B\u503C\u4E3A-1\uFF0C\u5219\u8868\u793A\u4E0D\u9650\u5236\uFF1B\u5982\u679Cpool\u5DF2\u7ECF\u5206\u914D\u4E86maxActive\u4E2Ajedis\u5B9E\u4F8B\uFF0C\u5219\u6B64\u65F6pool\u7684\u72B6\u6001\u4E3Aexhausted(\u8017\u5C3D)\u3002
spring.redis.jedis.pool.max-active=2000 spring.redis.jedis.pool.max-active=2000
## 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException ## \u7B49\u5F85\u53EF\u7528\u8FDE\u63A5\u7684\u6700\u5927\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2\uFF0C\u9ED8\u8BA4\u503C\u4E3A-1\uFF0C\u8868\u793A\u6C38\u4E0D\u8D85\u65F6\u3002\u5982\u679C\u8D85\u8FC7\u7B49\u5F85\u65F6\u95F4\uFF0C\u5219\u76F4\u63A5\u629B\u51FAJedisConnectionException
spring.redis.jedis.pool.max-wait=2000ms spring.redis.jedis.pool.max-wait=2000ms
spring.redis.database=6 spring.redis.database=6
# 上传方式:阿里云:alioss 华为云:hwobs # \u4E0A\u4F20\u65B9\u5F0F\uFF1A\u963F\u91CC\u4E91\uFF1Aalioss \u534E\u4E3A\u4E91\uFF1Ahwobs \u672C\u5730\uFF1Alocal
uploadType: hwobs uploadType: hwobs
# ======= 阿里OSS配置 ========= # ======= \u963F\u91CCOSS\u914D\u7F6E =========
aliyun.OSS.endpoint=https://oss-cn-hangzhou.aliyuncs.com aliyun.OSS.endpoint=https://oss-cn-hangzhou.aliyuncs.com
aliyun.OSS.accessKeyId= LTAI5tBmUfVF6Z8R6sHTdTG7 aliyun.OSS.accessKeyId= LTAI5tBmUfVF6Z8R6sHTdTG7
aliyun.OSS.accessKeySecret= mY6UvWv20Tg2R46ORe6uV5gL6TQloC aliyun.OSS.accessKeySecret= mY6UvWv20Tg2R46ORe6uV5gL6TQloC
aliyun.OSS.bucketName=qqxexamplebucket aliyun.OSS.bucketName=qqxexamplebucket
aliyun.OSS.fileMaxSize=10 #文件上传最大M数 aliyun.OSS.fileMaxSize=10 #\u6587\u4EF6\u4E0A\u4F20\u6700\u5927M\u6570
# ======= 华为OBS配置 ========= # ======= \u534E\u4E3AOBS\u914D\u7F6E =========
huawei.OBS.endPoint=https://obs.cn-north-4.myhuaweicloud.com huawei.OBS.endPoint=https://obs.cn-north-4.myhuaweicloud.com
huawei.OBS.accessKey=EEMAGYTHP9KKPF18TZCL huawei.OBS.accessKey=EEMAGYTHP9KKPF18TZCL
huawei.OBS.secretKey=3NmFNf1uX3EV1LbCEzgw6gDv0tZ6WAVwG37BGq1p huawei.OBS.secretKey=3NmFNf1uX3EV1LbCEzgw6gDv0tZ6WAVwG37BGq1p
huawei.OBS.bucketName=gcpa huawei.OBS.bucketName=gcpa
huawei.OBS.fileMaxSize=10 #文件上传最大M数 huawei.OBS.fileMaxSize=10 #\u6587\u4EF6\u4E0A\u4F20\u6700\u5927M\u6570
logging.level.com.adc: debug logging.level.com.adc: debug
@@ -5,6 +5,7 @@ import com.adc.da.report.eo.FileEntity;
import com.adc.da.report.eo.ReportEntity; import com.adc.da.report.eo.ReportEntity;
import com.adc.da.report.service.IFileService; import com.adc.da.report.service.IFileService;
import com.adc.da.report.service.IReportService; import com.adc.da.report.service.IReportService;
import com.adc.da.report.util.LocalFileUtil;
import com.adc.da.report.util.OSSClientUtil; import com.adc.da.report.util.OSSClientUtil;
import com.adc.da.report.util.ObsBootUtil; import com.adc.da.report.util.ObsBootUtil;
import com.adc.da.report.vo.ReportQueryVo; import com.adc.da.report.vo.ReportQueryVo;
@@ -63,6 +64,9 @@ public class ReportManageConroller {
@Autowired @Autowired
private ObsBootUtil obsBootUtil; private ObsBootUtil obsBootUtil;
@Autowired
private LocalFileUtil localFileUtil;
@Value("${uploadType}") @Value("${uploadType}")
private String uploadType; private String uploadType;
@@ -192,6 +196,7 @@ public class ReportManageConroller {
} }
@ApiOperation("testPath") @ApiOperation("testPath")
@GetMapping("/testPath") @GetMapping("/testPath")
@Deprecated
public ResponseMessage testPath() throws URISyntaxException { public ResponseMessage testPath() throws URISyntaxException {
HashMap<String, String> pathMap = new HashMap<>(); HashMap<String, String> pathMap = new HashMap<>();
String jarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath(); String jarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath();
@@ -201,8 +206,6 @@ public class ReportManageConroller {
return Result.success(pathMap); return Result.success(pathMap);
} }
/** /**
* 上传文件 * 上传文件
* @param file * @param file
@@ -236,10 +239,12 @@ public class ReportManageConroller {
try{ try{
String result=""; String result="";
// 上传方式:阿里云:alioss 华为云:hwobs // 上传方式:阿里云:alioss 华为云:hwobs
if (uploadType.equals("hwobs")){ if ("hwobs".equals(uploadType)){
result = obsBootUtil.upload(file, fileName); result = obsBootUtil.upload(file, fileName);
}else if (uploadType.equals("alioss")){ }else if ("alioss".equals(uploadType)) {
result = ossClientUtil.uploadFile2OSS(file.getInputStream(),fileName); result = ossClientUtil.uploadFile2OSS(file.getInputStream(),fileName);
}else if ("local".equals(uploadType)) {
localFileUtil.saveFile(file.getInputStream(), fileName);
} }
resultMap.put("key", date + num); resultMap.put("key", date + num);
resultMap.put("value", path + "//" + fileName); resultMap.put("value", path + "//" + fileName);
@@ -351,10 +356,12 @@ public class ReportManageConroller {
response.setContentType("application/x-download"); response.setContentType("application/x-download");
// File file = new File(uploadFile, entity.getSavePath()); // File file = new File(uploadFile, entity.getSavePath());
// 上传方式:阿里云:alioss 华为云:hwobs // 上传方式:阿里云:alioss 华为云:hwobs
if (uploadType.equals("hwobs")){ if ("hwobs".equals(uploadType)){
obsBootUtil.downFile(entity.getSavePath(), response); obsBootUtil.downFile(entity.getSavePath(), response);
}else if (uploadType.equals("alioss")){ }else if ("alioss".equals(uploadType)){
ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response); ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response);
}else if ("local".equals(uploadType)){
//do nothing
} }
} catch (Exception ex) { } catch (Exception ex) {