Explorar el Código

[修改]项目文件存储至阿里云oss

13660505945 hace 1 mes
padre
commit
51e16c3c05

+ 1 - 1
src/main/java/com/jsh/erp/controller/SystemConfigController.java

@@ -201,7 +201,7 @@ public class SystemConfigController extends BaseController {
                 }
                 if(StringUtil.isNotEmpty(savePath)){
                     res.code = 200;
-                    res.data = "http://192.168.2.112:8085/image/" + savePath;
+                    res.data = savePath;
                 }else {
                     res.code = 500;
                     res.data = "上传失败!";

+ 18 - 11
src/main/java/com/jsh/erp/service/SystemConfigService.java

@@ -62,6 +62,21 @@ public class SystemConfigService {
     @Value(value="${file.path}")
     private String filePath;
 
+    @Value(value="${aliyun.oss.endPoint}")
+    private String endpoint;
+
+    @Value(value="${aliyun.accessKeyId}")
+    private String accessKeyId;
+
+    @Value(value="${aliyun.secretAccessKey}")
+    private String accessKeySecret;
+
+    @Value(value="${aliyun.oss.bucketName}")
+    private String bucketName;
+
+    @Value(value="${aliyun.oss.linkUrl}")
+    private String aliOssLinkUrl;
+
     private static String DELETED = "deleted";
 
     public SystemConfig getSystemConfig(long id)throws Exception {
@@ -248,10 +263,6 @@ public class SystemConfigService {
         String token = request.getHeader("X-Access-Token");
         Long tenantId = Tools.getTenantIdByToken(token);
         bizPath = bizPath + "/" + tenantId;
-        String endpoint = platformConfigService.getPlatformConfigByKey("aliOss_endpoint").getPlatformValue();
-        String accessKeyId = platformConfigService.getPlatformConfigByKey("aliOss_accessKeyId").getPlatformValue();
-        String accessKeySecret = platformConfigService.getPlatformConfigByKey("aliOss_accessKeySecret").getPlatformValue();
-        String bucketName = platformConfigService.getPlatformConfigByKey("aliOss_bucketName").getPlatformValue();
         // 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
         String fileName = "";
         String orgName = mf.getOriginalFilename();// 获取文件名
@@ -310,7 +321,7 @@ public class SystemConfigService {
                 ossClient.putObject(putSmallObjectRequest);
             }
             // 返回路径
-            return bizPath + "/" + fileName;
+            return getFileUrlAliOss(bizPath + "/" + fileName);
         } catch (OSSException oe) {
             logger.error("Caught an OSSException, which means your request made it to OSS, "
                     + "but was rejected with an error response for some reason.");
@@ -336,7 +347,7 @@ public class SystemConfigService {
     }
 
     public String getFileUrlAliOss(String imgPath) throws Exception {
-        String linkUrl = platformConfigService.getPlatformConfigByKey("aliOss_linkUrl").getPlatformValue();
+        String linkUrl = aliOssLinkUrl;
         return linkUrl + filePath + "/" + imgPath;
     }
 
@@ -381,10 +392,6 @@ public class SystemConfigService {
             }
         } else if(fileUploadType == 2) {
             //oss
-            String endpoint = platformConfigService.getPlatformConfigByKey("aliOss_endpoint").getPlatformValue();
-            String accessKeyId = platformConfigService.getPlatformConfigByKey("aliOss_accessKeyId").getPlatformValue();
-            String accessKeySecret = platformConfigService.getPlatformConfigByKey("aliOss_accessKeySecret").getPlatformValue();
-            String bucketName = platformConfigService.getPlatformConfigByKey("aliOss_bucketName").getPlatformValue();
             for(String pathStr: pathList) {
                 if(StringUtil.isNotEmpty(pathStr)) {
                     String[] pathArr = pathStr.split(",");
@@ -647,4 +654,4 @@ public class SystemConfigService {
         File file = ExcelUtils.exportObjectsOneSheet(title, tip, names, title, objects);
         ExcelUtils.downloadExcel(file, file.getName(), response);
     }
-}
+}

+ 3 - 2
src/main/resources/application-dev.yml

@@ -6,8 +6,8 @@ server:
 
 #文件上传方式 1-本机 2-oss
 file:
-  uploadType: 1
-  path: F:/kaifa/file #文件上传根目录
+  uploadType: 2
+  path: /pc/dev/upload #文件上传根目录
 
 spring:
   #数据库连接
@@ -29,3 +29,4 @@ aliyun:
     endPoint: oss-cn-hangzhou.aliyuncs.com
     bucketName: xiangli-erp
     miniProgramAppId: wxd716cb744e32271a
+    linkUrl: https://xiangli-erp.oss-cn-hangzhou.aliyuncs.com

+ 4 - 3
src/main/resources/application-pro.yml

@@ -6,13 +6,13 @@ server:
 
 #文件上传方式 1-本机 2-oss
 file:
-  uploadType: 1
-  path: /opt/jshERP/upload #文件上传根目录
+  uploadType: 2
+  path: /pc/pro/upload #文件上传根目录
 
 spring:
   #数据库连接
   datasource:
-    url: jdbc:mysql://localhost:3306/jsh_erp?useUnicode=true&characterEncoding=utf8&useCursorFetch=true&defaultFetchSize=500&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false
+    url: jdbc:mysql://rm-bp1m458hex0a0p5553o.mysql.rds.aliyuncs.com:3306/jsh_erp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&allowMultiQueries=true
     driverClassName: com.mysql.cj.jdbc.Driver
     username: root
     password: jiesuimysql2022
@@ -29,3 +29,4 @@ aliyun:
     endPoint: oss-cn-hangzhou.aliyuncs.com
     bucketName: xiangli-erp
     miniProgramAppId: wxd716cb744e32271a
+    linkUrl: https://xiangli-erp.oss-cn-hangzhou.aliyuncs.com

+ 5 - 4
src/main/resources/application-test.yml

@@ -6,16 +6,16 @@ server:
 
 #文件上传方式 1-本机 2-oss
 file:
-  uploadType: 1
-  path: /opt/jshERP/upload #文件上传根目录
+  uploadType: 2
+  path: /pc/test/upload #文件上传根目录
 
 spring:
   #数据库连接
   datasource:
-    url: jdbc:mysql://localhost:3306/jsh_erp?useUnicode=true&characterEncoding=utf8&useCursorFetch=true&defaultFetchSize=500&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false
+    url: jdbc:mysql://rm-bp1m458hex0a0p5553o.mysql.rds.aliyuncs.com:3306/jsh_erp?useUnicode=true&characterEncoding=utf8&useCursorFetch=true&defaultFetchSize=500&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false
     driverClassName: com.mysql.cj.jdbc.Driver
     username: root
-    password: Hro@2021Hro
+    password: jiesuimysql2022
   # Redis
   redis:
     host: 127.0.0.1
@@ -29,3 +29,4 @@ aliyun:
     endPoint: oss-cn-hangzhou.aliyuncs.com
     bucketName: xiangli-erp
     miniProgramAppId: wxd716cb744e32271a
+    linkUrl: https://xiangli-erp.oss-cn-hangzhou.aliyuncs.com