refactor: 数据库的附件地址取配置上的

This commit is contained in:
caiyuchao
2025-09-28 16:50:16 +08:00
parent 386422bc84
commit a09994c76b

View File

@@ -1,6 +1,7 @@
package org.agt.module.infra.framework.file.core.client.db;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import org.agt.module.infra.dal.dataobject.file.FileContentDO;
import org.agt.module.infra.dal.mysql.file.FileContentMapper;
@@ -18,6 +19,13 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
private FileContentMapper fileContentMapper;
/**
* 邮件的开关,默认为 true
*/
private String domain;
private String port;
public DBFileClient(Long id, DBFileClientConfig config) {
super(id, config);
}
@@ -25,6 +33,8 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
@Override
protected void doInit() {
fileContentMapper = SpringUtil.getBean(FileContentMapper.class);
domain = SpringUtil.getProperty("agt.domain", "http://localhost");
port = SpringUtil.getProperty("server.port", "48080");
}
@Override
@@ -33,7 +43,11 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
.setPath(path).setContent(content);
fileContentMapper.insert(contentDO);
// 拼接返回路径
return super.formatFileUrl(config.getDomain(), path);
String fileDomain = config.getDomain();
if (StrUtil.isBlank(fileDomain)) {
fileDomain = domain + ":" + port;
}
return super.formatFileUrl(fileDomain, path);
}
@Override