Merge branch 'feature_lsl' of gitee.com:L-Shilin/go-fly-platform-services into feature_dzc
This commit is contained in:
+37
-21
@@ -8,7 +8,6 @@ import com.central.file.mapper.FileMapper;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -45,10 +44,10 @@ public class TimeWindowStorageService {
|
|||||||
|
|
||||||
// 配置参数
|
// 配置参数
|
||||||
// @Value("${zlt.storage.hot-data-days}")
|
// @Value("${zlt.storage.hot-data-days}")
|
||||||
private int hotDataDays = 30; // 热数据保留天数,默认30天
|
private int hotDataDays = 90; // 热数据保留天数,默认30天
|
||||||
|
|
||||||
// @Value("${zlt.storage.enable-time-window:true}")
|
// @Value("${zlt.storage.enable-time-window:true}")
|
||||||
private boolean enableTimeWindow = true; // 是否启用时间窗口存储
|
private boolean enableTimeWindow = false; // 是否启用时间窗口存储
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 智能获取文件访问URL
|
* 智能获取文件访问URL
|
||||||
@@ -103,26 +102,43 @@ public class TimeWindowStorageService {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 若DB无记录,退回统一路径策略:S3优先,其次OSS
|
// 若DB无记录,仍按时间窗口开关执行策略:
|
||||||
log.warn("[PATH] 数据库未找到文件信息,按统一策略查询: path={}", filePath);
|
// - 若未启用时间窗口:按热数据策略(OSS)
|
||||||
// 1) 先尝试S3(不触发任何自动同步)
|
// - 若启用时间窗口:作为未知创建时间,采用冷优先(S3→OSS)的策略
|
||||||
String s3Url = queryFromS3ByPath(filePath);
|
if (!enableTimeWindow) {
|
||||||
if (s3Url != null && !s3Url.isEmpty()) {
|
log.warn("[PATH] 数据库未找到文件信息,时间窗口关闭,直接从OSS获取: path={}", filePath);
|
||||||
log.debug("S3查询成功: path={}", filePath);
|
try {
|
||||||
return s3Url;
|
String ossUrl = ossService.getViewUrlByPath(filePath);
|
||||||
}
|
if (ossUrl != null && !ossUrl.isEmpty()) {
|
||||||
// 2) 再尝试OSS
|
log.debug("OSS查询成功: path={}", filePath);
|
||||||
try {
|
return ossUrl;
|
||||||
String ossUrl = ossService.getViewUrlByPath(filePath);
|
}
|
||||||
if (ossUrl != null && !ossUrl.isEmpty()) {
|
} catch (Exception e) {
|
||||||
log.debug("OSS查询成功: path={}", filePath);
|
log.warn("OSS查询失败: path={}, error={}", filePath, e.getMessage());
|
||||||
return ossUrl;
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
log.warn("路径查询失败(OSS未命中): path={}", filePath);
|
||||||
log.warn("OSS查询失败: path={}, error={}", filePath, e.getMessage());
|
return "";
|
||||||
|
} else {
|
||||||
|
log.warn("[PATH] 数据库未找到文件信息,时间窗口开启,按冷优先策略查询: path={}", filePath);
|
||||||
|
// 1) 先尝试S3(不触发任何自动同步)
|
||||||
|
String s3Url = queryFromS3ByPath(filePath);
|
||||||
|
if (s3Url != null && !s3Url.isEmpty()) {
|
||||||
|
log.debug("S3查询成功: path={}", filePath);
|
||||||
|
return s3Url;
|
||||||
|
}
|
||||||
|
// 2) 再尝试OSS
|
||||||
|
try {
|
||||||
|
String ossUrl = ossService.getViewUrlByPath(filePath);
|
||||||
|
if (ossUrl != null && !ossUrl.isEmpty()) {
|
||||||
|
log.debug("OSS查询成功: path={}", filePath);
|
||||||
|
return ossUrl;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("OSS查询失败: path={}, error={}", filePath, e.getMessage());
|
||||||
|
}
|
||||||
|
log.warn("路径查询失败(OSS/S3均未命中): path={}", filePath);
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
log.warn("路径查询失败(OSS/S3均未命中): path={}", filePath);
|
|
||||||
return "";
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("智能存储路径查询异常: path={}, error={}", filePath, e.getMessage(), e);
|
log.error("智能存储路径查询异常: path={}, error={}", filePath, e.getMessage(), e);
|
||||||
|
|||||||
+10
-9
@@ -68,17 +68,18 @@ public class EnhancedS3Service extends AbstractIFileService {
|
|||||||
try {
|
try {
|
||||||
S3Object s3Object = parsePath(name);
|
S3Object s3Object = parsePath(name);
|
||||||
log.info("解析S3路径: {} -> bucket: {}, object: {}", name, s3Object.bucketName, s3Object.objectName);
|
log.info("解析S3路径: {} -> bucket: {}, object: {}", name, s3Object.bucketName, s3Object.objectName);
|
||||||
|
// 打印未签名的S3完整访问路径(endpoint/bucket/object)
|
||||||
// 检查文件是否存在
|
try {
|
||||||
boolean exists = s3Template.doesObjectExist(s3Object.bucketName, s3Object.objectName);
|
String endpoint = fileServerProperties.getS3().getEndpoint();
|
||||||
log.info("S3文件存在检查: bucket={}, object={}, exists={}", s3Object.bucketName, s3Object.objectName, exists);
|
if (endpoint != null && !endpoint.isEmpty()) {
|
||||||
|
String normalizedEndpoint = endpoint.endsWith("/") ? endpoint.substring(0, endpoint.length() - 1) : endpoint;
|
||||||
if (!exists) {
|
String rawUrl = normalizedEndpoint + "/" + s3Object.bucketName + "/" + s3Object.objectName;
|
||||||
log.warn("S3文件不存在: bucket={}, object={}", s3Object.bucketName, s3Object.objectName);
|
log.info("S3访问完整路径(未签名): {}", rawUrl);
|
||||||
return "";
|
}
|
||||||
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用getViewUrl方法获取预签名URL
|
// 直接生成预签名URL,避免额外的HEAD存在性检查引发的握手问题
|
||||||
String url = s3Template.getViewUrl(s3Object.bucketName, s3Object.objectName, 60); // 60分钟有效期
|
String url = s3Template.getViewUrl(s3Object.bucketName, s3Object.objectName, 60); // 60分钟有效期
|
||||||
log.info("生成S3 URL: {}", url);
|
log.info("生成S3 URL: {}", url);
|
||||||
return url;
|
return url;
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ zlt.fdfs.trackerList=${zlt.fdfs.web-url}:22122
|
|||||||
##### s3配置
|
##### s3配置
|
||||||
zlt.s3.access-key=Hq78CaYg2BI6ZfxCRMKI
|
zlt.s3.access-key=Hq78CaYg2BI6ZfxCRMKI
|
||||||
zlt.s3.accessKeySecret=DJCt5q9K7GQ2zcBEfr3twb1vQ6BgUW1LKFlI5NSw
|
zlt.s3.accessKeySecret=DJCt5q9K7GQ2zcBEfr3twb1vQ6BgUW1LKFlI5NSw
|
||||||
zlt.s3.endpoint=https://local.goflytec.com:9194
|
#zlt.s3.endpoint=http://local.goflytec.com:9194
|
||||||
|
zlt.s3.endpoint=https://local.goflytec.com
|
||||||
|
#zlt.s3.endpoint=http://220.205.16.27:9000
|
||||||
zlt.s3.bucketName=goflymedia
|
zlt.s3.bucketName=goflymedia
|
||||||
zlt.s3.region=us-east-1
|
zlt.s3.region=us-east-1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user