From d5e3533d2d326b47027db86a61a69af003871727 Mon Sep 17 00:00:00 2001 From: zhangsz Date: Thu, 16 Jan 2025 11:53:04 +0800 Subject: [PATCH] feat: return gateway url and local url while upload file --- sql/wfc_config_db/wfc_config_db.sql | 2 +- .../org/wfc/system/api/domain/SysFile.java | 14 ++++++++ .../file/controller/SysFileController.java | 9 +++-- .../service/FastDfsSysFileServiceImpl.java | 9 ++--- .../org/wfc/file/service/ISysFileService.java | 3 +- .../file/service/LocalSysFileServiceImpl.java | 33 ++++++++++++++++--- .../file/service/MinioSysFileServiceImpl.java | 7 ++-- .../src/main/resources/application.yml | 2 ++ 8 files changed, 63 insertions(+), 16 deletions(-) diff --git a/sql/wfc_config_db/wfc_config_db.sql b/sql/wfc_config_db/wfc_config_db.sql index e54a8b3..1af73e5 100644 --- a/sql/wfc_config_db/wfc_config_db.sql +++ b/sql/wfc_config_db/wfc_config_db.sql @@ -93,7 +93,7 @@ INSERT INTO `config_info` VALUES (64, 'wfc-monitor-prod.yml', 'DEFAULT_GROUP', ' INSERT INTO `config_info` VALUES (65, 'wfc-system-prod.yml', 'DEFAULT_GROUP', '# spring配置\nspring:\n redis:\n host: wfc-redis\n port: 6379\n password:\n datasource:\n druid:\n stat-view-servlet:\n enabled: true\n loginUsername: admin\n loginPassword: 123456\n dynamic:\n druid:\n initial-size: 5\n min-idle: 5\n maxActive: 20\n maxWait: 60000\n connectTimeout: 30000\n socketTimeout: 60000\n timeBetweenEvictionRunsMillis: 60000\n minEvictableIdleTimeMillis: 300000\n validationQuery: SELECT 1 FROM DUAL\n testWhileIdle: true\n testOnBorrow: false\n testOnReturn: false\n poolPreparedStatements: true\n maxPoolPreparedStatementPerConnectionSize: 20\n filters: stat,slf4j\n connectionProperties: druid.stat.mergeSql\\=true;druid.stat.slowSqlMillis\\=5000\n datasource:\n # 主库数据源\n master:\n driver-class-name: com.mysql.cj.jdbc.Driver\n url: jdbc:mysql://wfc-mysql:3306/wfc_system_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8\n username: root\n password: 123456\n # 从库数据源\n # slave:\n # username: \n # password: \n # url: \n # driver-class-name: \n\n# mybatis配置\nmybatis:\n # 搜索指定包别名\n typeAliasesPackage: org.wfc.system\n # 配置mapper的扫描,找到所有的mapper.xml映射文件\n mapperLocations: classpath:mapper/**/*.xml\n\n# swagger配置\nswagger:\n title: 系统模块接口文档\n license: Powered By wfc\n licenseUrl: https://wfc.vip', 'a355587121f711511c9010a4a8c0d797', '2024-12-13 11:52:34', '2024-12-13 11:54:49', NULL, '192.168.2.116', '', 'wfc-prod', '系统模块', '', '', 'yaml', '', ''); INSERT INTO `config_info` VALUES (66, 'wfc-gen-prod.yml', 'DEFAULT_GROUP', '# spring配置\nspring:\n redis:\n host: wfc-redis\n port: 6379\n password:\n datasource:\n driver-class-name: com.mysql.cj.jdbc.Driver\n url: jdbc:mysql://wfc-mysql:3306/wfc_system_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8\n username: root\n password: 123456\n\n# mybatis配置\nmybatis:\n # 搜索指定包别名\n typeAliasesPackage: org.wfc.gen.domain\n # 配置mapper的扫描,找到所有的mapper.xml映射文件\n mapperLocations: classpath:mapper/**/*.xml\n\n# swagger配置\nswagger:\n title: 代码生成接口文档\n license: Powered By wfc\n licenseUrl: https://wfc.vip\n\n# 代码生成\ngen:\n # 作者\n author: wfc\n # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool\n packageName: org.wfc.system\n # 自动去除表前缀,默认是false\n autoRemovePre: false\n # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)\n tablePrefix: sys_\n', '5ec7d9b8eb46eca656316e5f817aadb2', '2024-12-13 11:52:34', '2024-12-13 11:55:28', NULL, '192.168.2.116', '', 'wfc-prod', '代码生成', '', '', 'yaml', '', ''); INSERT INTO `config_info` VALUES (67, 'wfc-job-prod.yml', 'DEFAULT_GROUP', '# spring配置\nspring:\n redis:\n host: wfc-redis\n port: 6379\n password: \n datasource:\n driver-class-name: com.mysql.cj.jdbc.Driver\n url: jdbc:mysql://wfc-mysql:3306/wfc_system_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8\n username: root\n password: 123456\n\n# mybatis配置\nmybatis:\n # 搜索指定包别名\n typeAliasesPackage: org.wfc.job.domain\n # 配置mapper的扫描,找到所有的mapper.xml映射文件\n mapperLocations: classpath:mapper/**/*.xml\n\n# swagger配置\nswagger:\n title: 定时任务接口文档\n license: Powered By wfc\n licenseUrl: https://wfc.vip\n', '1376deec876c0878df743b4d96c7f125', '2024-12-13 11:52:34', '2024-12-13 11:56:07', NULL, '192.168.2.116', '', 'wfc-prod', '定时任务', '', '', 'yaml', '', ''); -INSERT INTO `config_info` VALUES (68, 'wfc-file-prod.yml', 'DEFAULT_GROUP', '# 本地文件上传 \nfile:\n domain: wfc-file:9201\n path: /opt/wfc/upload\n prefix: /kyc\n\n# FastDFS配置\nfdfs:\n domain: http://wfc-file\n soTimeout: 3000\n connectTimeout: 2000\n trackerList: wfc-file:22122\n\n# Minio配置\nminio:\n url: http://wfc-file:9000\n accessKey: minioadmin\n secretKey: minioadmin\n bucketName: test', '788c4d2b226a744eefc465bf31c3824b', '2024-12-13 11:52:34', '2025-01-07 12:15:07', NULL, '172.19.0.1', '', 'wfc-prod', '文件服务', '', '', 'yaml', '', ''); +INSERT INTO `config_info` VALUES (68, 'wfc-file-prod.yml', 'DEFAULT_GROUP', '# 本地文件上传 \nfile:\n domain: wfc-file:9201\n path: /opt/wfc/upload\n prefix: /kyc\n gateway: http://192.168.2.116:8080\n\n# FastDFS配置\nfdfs:\n domain: http://wfc-file\n soTimeout: 3000\n connectTimeout: 2000\n trackerList: wfc-file:22122\n\n# Minio配置\nminio:\n url: http://wfc-file:9000\n accessKey: minioadmin\n secretKey: minioadmin\n bucketName: test', '67ac8270276a9e28271471cbbd6c7784', '2024-12-13 11:52:34', '2025-01-16 01:46:26', NULL, '172.19.0.1', '', 'wfc-prod', '文件服务', '', '', 'yaml', '', ''); INSERT INTO `config_info` VALUES (69, 'wfc-user-prod.yml', 'DEFAULT_GROUP', '# spring配置\nspring:\n redis:\n host: wfc-redis\n port: 6379\n password:\n datasource:\n druid:\n stat-view-servlet:\n enabled: true\n loginUsername: admin\n loginPassword: 123456\n dynamic:\n druid:\n initial-size: 5\n min-idle: 5\n maxActive: 20\n maxWait: 60000\n connectTimeout: 30000\n socketTimeout: 60000\n timeBetweenEvictionRunsMillis: 60000\n minEvictableIdleTimeMillis: 300000\n validationQuery: SELECT 1 FROM DUAL\n testWhileIdle: true\n testOnBorrow: false\n testOnReturn: false\n poolPreparedStatements: true\n maxPoolPreparedStatementPerConnectionSize: 20\n filters: stat,slf4j\n connectionProperties: druid.stat.mergeSql\\=true;druid.stat.slowSqlMillis\\=5000\n datasource:\n # 主库数据源\n master:\n driver-class-name: com.mysql.cj.jdbc.Driver\n url: jdbc:mysql://wfc-mysql:3306/wfc_user_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8\n username: root\n password: 123456\n # 从库数据源\n # slave:\n # username:\n # password:\n # url:\n # driver-class-name:\n\n# mybatis配置\nmybatis:\n # 搜索指定包别名\n typeAliasesPackage: org.wfc.user\n config-location: classpath:mybatis-config.xml\n # 配置mapper的扫描,找到所有的mapper.xml映射文件\n mapperLocations: classpath:mapper/**/*.xml\n\n# swagger配置\nswagger:\n title: 系统模块接口文档\n license: Powered By wfc\n licenseUrl: https://wfc.vip\n\nlogging:\n level:\n root: INFO\n org.springframework.web: INFO\n org.mybatis.mapper: DEBUG\n org.wfc.user: DEBUG\n', 'a4a5091fab85f9a67ba3800e6254c086', '2024-12-28 19:17:13', '2025-01-14 09:00:36', NULL, '172.19.0.1', '', 'wfc-prod', '用户平台模块', '', '', 'yaml', '', ''); INSERT INTO `config_info` VALUES (70, 'wfc-payment-prod.yml', 'DEFAULT_GROUP', '# spring配置\nspring:\n application:\n name: wfc-payment\n cloud:\n nacos:\n discovery:\n server-addr: ${NACOS_SERVER_ADDR:wfc-nacos}:${NACOS_SERVER_PORT:8848}\n namespace: ${NACOS_NAMESPACE:wfc-prod}\n \n main:\n allow-bean-definition-overriding: true\n \n redis:\n host: wfc-redis\n port: 6379\n password:\n datasource:\n druid:\n stat-view-servlet:\n enabled: true\n loginUsername: admin\n loginPassword: 123456\n dynamic:\n druid:\n initial-size: 5\n min-idle: 5\n maxActive: 20\n maxWait: 60000\n connectTimeout: 30000\n socketTimeout: 60000\n timeBetweenEvictionRunsMillis: 60000\n minEvictableIdleTimeMillis: 300000\n validationQuery: SELECT 1 FROM DUAL\n testWhileIdle: true\n testOnBorrow: false\n testOnReturn: false\n poolPreparedStatements: true\n maxPoolPreparedStatementPerConnectionSize: 20\n filters: stat,slf4j\n connectionProperties: druid.stat.mergeSql\\=true;druid.stat.slowSqlMillis\\=5000\n datasource:\n # 主库数据源\n master:\n driver-class-name: com.mysql.cj.jdbc.Driver\n url: jdbc:mysql://wfc-mysql:3306/wfc_user_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8\n username: root\n password: 123456\n # 从库数据源\n # slave:\n # username:\n # password:\n # url:\n # driver-class-name:\n\n# mybatis-plus配置\nmybatis-plus:\n # 搜索指定包别名\n type-aliases-package: org.wfc.payment\n # 配置mapper的扫描,找到所有的mapper.xml映射文件\n mapper-locations: classpath:mapper/**/*.xml\n global-config:\n db-config:\n logic-delete-field: del_flag\n logic-delete-value: 1\n logic-not-delete-value: 0\n\n# swagger配置\nswagger:\n title: 系统模块接口文档\n license: Powered By wfc\n licenseUrl: https://wfc.vip\n\nlogging:\n level:\n root: INFO\n org.springframework.web: INFO\n org.mybatis.mapper: DEBUG\n com.github.binarywang: DEBUG\n\nwxpay:\n appId: wxd678efh567hg6787\n mchId: 1230000109\n mchKey: 1525342aa\n subAppId: #服务商模式下的子商户公众账号ID\n subMchId: #服务商模式下的子商户号 \n keyPath: /opt/wfc/conf/wxpay/wxpay_key.pem\n useSandboxEnv: true\n\nalipay:\n appId: 121412414112\n privateKey: MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC3/5tHX5ioibCWXzUYVVIgd0wexio5CbRITNQ2saPOb17jioe0Q5Qu/xjcdjEu8JQ17PQzjDHciHV8E/fcJ1qgWjYcpvLptp/jRJ7C75kckj7Z3maajgzwxjk2ylmhgTkd5yJiX+7ywNX/48D/Bx906TXUlEUMIN+AO19MZzfc5NwDL5DAAsUOIVbGP/OTAJIfr1yPms9NoFtOad/L3Bb8OEo2xVi2ac07yyU8bftVPEtYgH6Ox+ubtYQ74dRszk4h6Qoeuqcqo4YeWA9XO471J8y6tc+oMsf3rF8zjo69W+HsfxfBNvUzheKCym4XyS3bI0KHwe7yFC7v/qR7ahMxAgMBAAECggEBAJ7cEi3KTJxe3NbHdqj+qTyco10CjNvYFA5EPwjF0H7gSxW7ujSaECuPVeCqLwau8depMKH8zePw8TZiayJp2+YMXSHZxmqgoWTwDv6RLSms3pTuXrncITIUgrtac45samr17wrudviiI2GeOzg05yTiYPab2Q2CqFUnbb0idOnCOEWK37z2ojA9XgNDukoA+1Wpm1HqoTNNRNHZOq8ZfbxyZY3iq4nuoEDQf741kzNe4skmw21N6rC21QJ8nrCfc70C47iz5XW8lfuVNkUeJc+E595HrLBp7he5cEBWKsZ4xi+X0tlyNgg9OlLuP+8twOxl9rwP/0d4pjKnnfEa0a0CgYEA+EM7FqCFhExZHoO6/c9igbtqlIc93UNT5YVrujgmgfq0ACq6X8tWV1j+1WPcYwLqOKlgprNCoW+aT0rUTI3Nq/wFr5AkAdNClje707Ec8n5NTNUSX3i2zpdgTIKFHFEgl13BsKgb5ABosexlXU/gxpJCZctQ33tfYtZfnA5Zr3MCgYEAvbukhHBv1UcSH54UULoY1tNkFKwiiAbJIcSRV+ZLqxW9adREFLxSJOqk90B9t8CXdRVgT+7Oap0GztACQ63psqxbeKeXdHnJNL4CEl4RWcge6isI3V7kU0/yx+/miWhyYGByZ816D/QUdbbF1kU14dD79TVD171uS9IJxKTRgcsCgYAopYlFGR8DHCTzNAoniA7Owsqeas4cLevMhl2u7YaQfWV/KX++M2J9hpqigWkR5OZIRKMIaA0etVEEbnH33rev0uFzbxwWGGqsgY+FB1h/82HglHofm3oCtRIVNMFqc3XsknMl40A9wjth9hxafLuGh2fLltA05tQlMIgS2t6gNQKBgQCzRHJDeIESAR7MpO4JAGyrvfwX1DSkVdUAhNvXM49XTSk0rwzMkssCenn37AVc8ymnxNTFcZuy/D8MdVlOXSosWdHrhF4D/XXw0X7fn+XA8ObU1mh/0ULmvOllo/Qs7HT1PuuZzHmCTVpvhowS0j4A6RbHLta1JxTpqsDz/c6+VQKBgQDubC69oYbaBjxOKsQGvYUhpS9RsqZCxmg1GzLcPiUOvjWzi8fNx3JrrJ8PFOcpxs+OhRT0rlzlePfHGu/lzrSuL0sCol9enFk80rKLFAw4oXAdnTbtEjaoxA1dFTrrUIxFQkHpeH0NAkqU6BVaxbCPH22zH6/BZt2J9225lBuelQ==\n publicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt/+bR1+YqImwll81GFVSIHdMHsYqOQm0SEzUNrGjzm9e44qHtEOULv8Y3HYxLvCUNez0M4wx3Ih1fBP33CdaoFo2HKby6baf40Sewu+ZHJI+2d5mmo4M8MY5NspZoYE5HeciYl/u8sDV/+PA/wcfdOk11JRFDCDfgDtfTGc33OTcAy+QwALFDiFWxj/zkwCSH69cj5rPTaBbTmnfy9wW/DhKNsVYtmnNO8slPG37VTxLWIB+jsfrm7WEO+HUbM5OIekKHrqnKqOGHlgPVzuO9SfMurXPqDLH96xfM46OvVvh7H8XwTb1M4XigspuF8kt2yNCh8Hu8hQu7/6ke2oTMQIDAQAB\n notifyUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/alipay/notify\n returnUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/alipay/return\n signType: RSA2\n charset: utf-8\n gatewayUrl: https://openapi.alipaydev.com/gateway.do\n logPath: /opt/wfc/logs/alipay/alipay_log.txt\n maxQueryRetry: 5\n queryDuration: 5\n maxCancelRetry: 3\n cancelDuration: 2\n heartbeatDelay: 5\n heartbeatDuration: 5\n storeId: \n storeName: \n supportEmail: \n supportPhone:\n\nccpay:\n url: https://api.paymentgateway.com/v1/payments\n apiKey: api-key-from-nacos\n merchantId: merchant-id-from-nacos\n currency: USD\n timeout: 30\n callbackUrl: https://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/payment/callback\n\nunionpay:\n merId: 700000000000001\n keyPrivateCert: /opt/wfc/conf/cert/unionpay/wfc-root.pfx\n keyPrivateCertPwd: 123456\n signCertType: PKCS12\n encryptCertPath: /opt/wfc/conf/cert/unionpay/wfc-root.cer\n acpMiddleCert: /opt/wfc/conf/cert/unionpay/wfc-middle.cer\n acpRootCert: /opt/wfc/conf/cert/unionpay/wfc-root.cer\n frontUrl: https://gateway.test.95516.com/gateway/api/frontTransReq.do\n backUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/notify\n signMethod: 01\n version: 5.1.0\n channelType: 07\n accessType: 0\n currencyCode: 156\n bizType: 000201\n txnType: 01\n txnSubType: 01\n payTimeout: 30\n queryTimeout: 30\n refundTimeout: 30\n frontFailUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/fail\n frontSuccessUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/success\n frontBackUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/front\n backBackUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/back\n frontNotifyUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/front/notify\n backNotifyUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/back/notify\n refundNotifyUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/refund/notify\n queryNotifyUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/query/notify\n refundSuccessUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/refund/success\n refundFailUrl: http://wfc-gateway:${GATEWAY_SERVER_PORT:8080}/unionpay/refund/fail\n querySuccessUrl: ', '43039c5e1b2bd1a823fcb3e0ca73cbde', '2024-12-28 19:17:46', '2025-01-07 11:14:01', NULL, '172.19.0.1', '', 'wfc-prod', 'wfc-modules-payment production yaml', '', '', 'yaml', '', ''); INSERT INTO `config_info` VALUES (71, 'sentinel-wfc-gateway-prod', 'DEFAULT_GROUP', '[\r\n {\r\n \"resource\": \"wfc-auth\",\r\n \"count\": 500,\r\n \"grade\": 1,\r\n \"limitApp\": \"default\",\r\n \"strategy\": 0,\r\n \"controlBehavior\": 0\r\n },\r\n {\r\n \"resource\": \"wfc-system\",\r\n \"count\": 1000,\r\n \"grade\": 1,\r\n \"limitApp\": \"default\",\r\n \"strategy\": 0,\r\n \"controlBehavior\": 0\r\n },\r\n {\r\n \"resource\": \"wfc-gen\",\r\n \"count\": 200,\r\n \"grade\": 1,\r\n \"limitApp\": \"default\",\r\n \"strategy\": 0,\r\n \"controlBehavior\": 0\r\n },\r\n {\r\n \"resource\": \"wfc-job\",\r\n \"count\": 300,\r\n \"grade\": 1,\r\n \"limitApp\": \"default\",\r\n \"strategy\": 0,\r\n \"controlBehavior\": 0\r\n }\r\n]', 'a8b3ec396dd09d5f2ba494cc80a7afa0', '2024-12-28 19:27:43', '2024-12-28 19:27:43', NULL, '172.19.0.1', '', 'wfc-prod', '限流策略', NULL, NULL, 'json', NULL, ''); diff --git a/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/domain/SysFile.java b/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/domain/SysFile.java index 2e6b9b4..c04086b 100644 --- a/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/domain/SysFile.java +++ b/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/domain/SysFile.java @@ -15,6 +15,11 @@ public class SysFile */ private String name; + /** + * 文件内部地址 + */ + private String localUrl; + /** * 文件地址 */ @@ -30,6 +35,14 @@ public class SysFile this.name = name; } + public String getLocalUrl() { + return localUrl; + } + + public void setLocalUrl(String localUrl) { + this.localUrl = localUrl; + } + public String getUrl() { return url; @@ -44,6 +57,7 @@ public class SysFile public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("name", getName()) + .append("localUrl", getLocalUrl()) .append("url", getUrl()) .toString(); } diff --git a/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java b/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java index c8e5ce9..454caa0 100644 --- a/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java +++ b/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java @@ -9,6 +9,7 @@ import org.springframework.web.multipart.MultipartFile; import org.wfc.common.core.domain.R; import org.wfc.common.core.utils.file.FileUtils; import org.wfc.file.service.ISysFileService; +import org.wfc.file.service.LocalSysFileServiceImpl.FileUploadResult; import org.wfc.system.api.domain.SysFile; /** @@ -30,10 +31,12 @@ public class SysFileController { public R upload(MultipartFile file) { try { // 上传并返回访问地址 - String url = sysFileService.uploadFile(file); + FileUploadResult urlResult = sysFileService.uploadFile(file); SysFile sysFile = new SysFile(); - sysFile.setName(FileUtils.getName(url)); - sysFile.setUrl(url); + sysFile.setName(FileUtils.getName(urlResult.getLocalUrl())); + sysFile.setName(FileUtils.getName(urlResult.getGatewayUrl())); + sysFile.setLocalUrl(urlResult.getLocalUrl()); + sysFile.setUrl(urlResult.getGatewayUrl()); return R.ok(sysFile); } catch (Exception e) { log.error("上传文件失败", e); diff --git a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/FastDfsSysFileServiceImpl.java b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/FastDfsSysFileServiceImpl.java index 02fb6aa..455b21c 100644 --- a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/FastDfsSysFileServiceImpl.java +++ b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/FastDfsSysFileServiceImpl.java @@ -28,19 +28,20 @@ public class FastDfsSysFileServiceImpl implements ISysFileService private FastFileStorageClient storageClient; /** - * FastDfs文件上传接口 + * FastDFS文件上传接口 * * @param file 上传的文件 - * @return 访问地址 + * @return FileUploadResult 包含本地和网关访问地址 * @throws Exception */ @Override - public String uploadFile(MultipartFile file) throws Exception + public LocalSysFileServiceImpl.FileUploadResult uploadFile(MultipartFile file) throws Exception { InputStream inputStream = file.getInputStream(); StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), FileTypeUtils.getExtension(file), null); IoUtils.closeQuietly(inputStream); - return domain + "/" + storePath.getFullPath(); + String fileUrl = domain + "/" + storePath.getFullPath(); + return new LocalSysFileServiceImpl.FileUploadResult(fileUrl, fileUrl); } } diff --git a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/ISysFileService.java b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/ISysFileService.java index cf315c6..226cc10 100644 --- a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/ISysFileService.java +++ b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/ISysFileService.java @@ -1,6 +1,7 @@ package org.wfc.file.service; import org.springframework.web.multipart.MultipartFile; +import org.wfc.file.service.LocalSysFileServiceImpl.FileUploadResult; /** * 文件上传接口 @@ -16,5 +17,5 @@ public interface ISysFileService * @return 访问地址 * @throws Exception */ - public String uploadFile(MultipartFile file) throws Exception; + public FileUploadResult uploadFile(MultipartFile file) throws Exception; } diff --git a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/LocalSysFileServiceImpl.java b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/LocalSysFileServiceImpl.java index 1d99387..1fa4020 100644 --- a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/LocalSysFileServiceImpl.java +++ b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/LocalSysFileServiceImpl.java @@ -33,17 +33,42 @@ public class LocalSysFileServiceImpl implements ISysFileService @Value("${file.path}") private String localFilePath; + @Value("${file.gateway}") + public String gateway; + + @Value("${file.pathPrefix}") + public String pathPrefix; + /** * 本地文件上传接口 * * @param file 上传的文件 - * @return 访问地址 + * @return FileUploadResult 包含本地和网关访问地址 * @throws Exception */ @Override - public String uploadFile(MultipartFile file) throws Exception - { + public FileUploadResult uploadFile(MultipartFile file) throws Exception { String name = FileUploadUtils.upload(localFilePath, file); - return domain + localFilePrefix + name; + String localUrl = domain + localFilePrefix + name; + String gatewayUrl = gateway + pathPrefix + localFilePrefix + name; + return new FileUploadResult(localUrl, gatewayUrl); + } + + public static class FileUploadResult { + private final String localUrl; + private final String gatewayUrl; + + public FileUploadResult(String localUrl, String gatewayUrl) { + this.localUrl = localUrl; + this.gatewayUrl = gatewayUrl; + } + + public String getLocalUrl() { + return localUrl; + } + + public String getGatewayUrl() { + return gatewayUrl; + } } } diff --git a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/MinioSysFileServiceImpl.java b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/MinioSysFileServiceImpl.java index 9b5686b..edecac2 100644 --- a/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/MinioSysFileServiceImpl.java +++ b/wfc-modules/wfc-file/src/main/java/org/wfc/file/service/MinioSysFileServiceImpl.java @@ -28,11 +28,11 @@ public class MinioSysFileServiceImpl implements ISysFileService * Minio文件上传接口 * * @param file 上传的文件 - * @return 访问地址 + * @return FileUploadResult 包含本地和网关访问地址 * @throws Exception */ @Override - public String uploadFile(MultipartFile file) throws Exception + public LocalSysFileServiceImpl.FileUploadResult uploadFile(MultipartFile file) throws Exception { String fileName = FileUploadUtils.extractFilename(file); InputStream inputStream = file.getInputStream(); @@ -44,6 +44,7 @@ public class MinioSysFileServiceImpl implements ISysFileService .build(); client.putObject(args); IoUtils.closeQuietly(inputStream); - return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName; + String fileUrl = minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName; + return new LocalSysFileServiceImpl.FileUploadResult(fileUrl, fileUrl); } } diff --git a/wfc-modules/wfc-file/src/main/resources/application.yml b/wfc-modules/wfc-file/src/main/resources/application.yml index bcf63f2..5644b14 100644 --- a/wfc-modules/wfc-file/src/main/resources/application.yml +++ b/wfc-modules/wfc-file/src/main/resources/application.yml @@ -3,6 +3,8 @@ file: domain: wfc-file:${WFC_FILE_PORT:9201} path: /opt/wfc/upload prefix: /kyc + gateway: http://${GATEWAY_SERVER_IP}:${GATEWAY_SERVER_PORT} # 新增网关地址配置 + pathPrefix: /file # 新增文件模块地址前缀 # FastDFS配置 fdfs: