fix(订单中心):首页统计临时演示修复,二维码租户Id修改

This commit is contained in:
2025-08-03 12:12:58 +08:00
parent 3a48b6f34f
commit ecc482ce13
16 changed files with 1362 additions and 270 deletions
@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.central.common.model.Result;
/**
* 热数据同步控制器
@@ -194,4 +195,88 @@ public class HotDataSyncController {
return result;
}
/**
* 诊断S3配置和URL生成
*/
@Operation(summary = "诊断S3配置和URL生成")
@GetMapping("/diagnose")
public Result<Map<String, Object>> diagnoseS3Config() {
Map<String, Object> result = new HashMap<>();
try {
// 检查S3配置
result.put("s3Enabled", hotDataSyncService.isS3Enabled());
result.put("enhancedS3ServiceAvailable", hotDataSyncService.isEnhancedS3ServiceAvailable());
result.put("s3ServiceAvailable", hotDataSyncService.isS3ServiceAvailable());
// 检查S3配置信息
result.put("s3Config", hotDataSyncService.getS3ConfigInfo());
// 测试URL生成
result.put("urlTest", hotDataSyncService.testUrlGeneration());
// 检查热同步配置
result.put("hotSyncConfig", hotDataSyncService.getHotSyncConfig());
return Result.succeed(result);
} catch (Exception e) {
log.error("诊断S3配置失败", e);
result.put("error", e.getMessage());
return Result.failed("诊断失败:" + e.getMessage());
}
}
/**
* 测试URL访问
*/
@Operation(summary = "测试URL访问")
@PostMapping("/test-url")
public Result<Map<String, Object>> testUrlAccess(@RequestParam String url) {
Map<String, Object> result = new HashMap<>();
try {
log.info("测试URL访问: {}", url);
// 创建HTTP连接
java.net.URL testUrl = new java.net.URL(url);
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) testUrl.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(10000); // 10秒连接超时
connection.setReadTimeout(30000); // 30秒读取超时
// 设置User-Agent
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36");
int responseCode = connection.getResponseCode();
String responseMessage = connection.getResponseMessage();
result.put("url", url);
result.put("responseCode", responseCode);
result.put("responseMessage", responseMessage);
result.put("contentType", connection.getContentType());
result.put("contentLength", connection.getContentLengthLong());
result.put("accessible", responseCode == 200);
// 获取响应头信息
Map<String, String> headers = new HashMap<>();
connection.getHeaderFields().forEach((key, values) -> {
if (key != null && values != null && !values.isEmpty()) {
headers.put(key, String.join(", ", values));
}
});
result.put("headers", headers);
log.info("URL访问测试结果: 状态码={}, 消息={}, 可访问={}", responseCode, responseMessage, responseCode == 200);
return Result.succeed(result);
} catch (Exception e) {
log.error("测试URL访问失败: {}", url, e);
result.put("url", url);
result.put("error", e.getMessage());
result.put("accessible", false);
return Result.failed("URL访问测试失败:" + e.getMessage());
}
}
}
@@ -19,6 +19,8 @@ import java.util.Date;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Map;
import java.util.HashMap;
/**
* 热数据自动同步服务
@@ -203,10 +205,14 @@ public class HotDataSyncService {
log.info("开始同步文件到S3,文件ID: {}, 文件名: {}, 重试次数: {}/{}",
fileInfo.getId(), fileInfo.getName(), retryCount + 1, maxRetries);
// 获取原始OSS路径(不包含hot-sync前缀)
String originalPath = getOriginalPath(fileInfo);
log.debug("原始OSS路径: {}", originalPath);
// 从OSS获取文件URL
String ossUrl = ossService.getViewUrlByPath(fileInfo.getPath());
String ossUrl = ossService.getViewUrlByPath(originalPath);
if (ossUrl == null || ossUrl.isEmpty()) {
log.error("从OSS获取文件URL失败,文件ID: {}", fileInfo.getId());
log.error("从OSS获取文件URL失败,文件ID: {}, 路径: {}", fileInfo.getId(), originalPath);
return false;
}
@@ -230,16 +236,26 @@ public class HotDataSyncService {
}
if (uploadSuccess) {
// 更新文件存储信息
updateFileStorageInfo(fileInfo, s3Path);
log.info("文件同步成功,文件ID: {}, 新路径: {}", fileInfo.getId(), s3Path);
return true;
// 验证文件是否真的上传成功
if (verifyFileUpload(s3Path)) {
// 更新文件存储信息
updateFileStorageInfo(fileInfo, s3Path);
log.info("文件同步成功,文件ID: {}, 新路径: {}", fileInfo.getId(), s3Path);
return true;
} else {
log.error("文件上传验证失败,文件ID: {}", fileInfo.getId());
retryCount++;
if (retryCount < maxRetries) {
log.info("准备重试,等待2秒后重试...");
Thread.sleep(2000);
}
}
} else {
log.error("文件上传到S3失败,文件ID: {}", fileInfo.getId());
retryCount++;
if (retryCount < maxRetries) {
log.info("准备重试,等待2秒后重试...");
Thread.sleep(2000); // 等待2秒后重试
Thread.sleep(2000);
}
}
@@ -254,7 +270,7 @@ public class HotDataSyncService {
if (retryCount < maxRetries) {
try {
log.info("准备重试,等待2秒后重试...");
Thread.sleep(2000); // 等待2秒后重试
Thread.sleep(2000);
} catch (InterruptedException ie) {
log.error("重试等待被中断", ie);
Thread.currentThread().interrupt();
@@ -371,14 +387,55 @@ public class HotDataSyncService {
return "hot-sync/" + fileInfo.getId() + "/" + fileInfo.getName();
}
// 如果原路径包含OSS信息,替换为S3路径
if (originalPath.contains("oss://") || originalPath.contains("aliyun")) {
return originalPath.replace("oss://", "s3://")
.replace("aliyun", "minio");
// 提取文件名,避免路径过长
String fileName = fileInfo.getName();
if (fileName == null || fileName.isEmpty()) {
// 从路径中提取文件名
if (originalPath.contains("/")) {
fileName = originalPath.substring(originalPath.lastIndexOf("/") + 1);
} else {
fileName = originalPath;
}
}
// 否则添加热同步前缀
return "hot-sync/" + originalPath;
// 生成简洁的S3路径
return "hot-sync/" + fileName;
}
/**
* 获取原始OSS路径(去除hot-sync前缀)
*/
private String getOriginalPath(FileInfo fileInfo) {
String path = fileInfo.getPath();
if (path == null || path.isEmpty()) {
return path;
}
// 如果路径包含hot-sync前缀,去除它
if (path.startsWith("hot-sync/")) {
return path.substring("hot-sync/".length());
}
return path;
}
/**
* 验证文件是否上传成功
*/
private boolean verifyFileUpload(String s3Path) {
try {
if (enhancedS3Service != null) {
return enhancedS3Service.fileExists(s3Path);
} else if (s3Service != null) {
// 基础S3服务验证
String url = s3Service.getViewUrlByPath(s3Path);
return url != null && !url.isEmpty();
}
return false;
} catch (Exception e) {
log.warn("验证文件上传失败: {}", s3Path, e);
return false;
}
}
/**
@@ -482,7 +539,105 @@ public class HotDataSyncService {
* 获取配置信息
*/
public String getConfigInfo() {
return String.format("批次大小: %d, 同步间隔: %d分钟, 访问阈值: %d, 热数据天数: %d, 最大线程: %d",
batchSize, syncIntervalMinutes, accessThreshold, hotDataDays, maxThreads);
return String.format("热数据同步配置 - 启用: %s, 批次大小: %d, 同步间隔: %d分钟, 访问阈值: %d, 最大线程数: %d, 热数据天数: %d",
syncEnabled, batchSize, syncIntervalMinutes, accessThreshold, maxThreads, hotDataDays);
}
/**
* 检查S3是否启用
*/
public boolean isS3Enabled() {
return syncEnabled;
}
/**
* 检查增强S3服务是否可用
*/
public boolean isEnhancedS3ServiceAvailable() {
return enhancedS3Service != null;
}
/**
* 检查基础S3服务是否可用
*/
public boolean isS3ServiceAvailable() {
return s3Service != null;
}
/**
* 获取S3配置信息
*/
public Map<String, Object> getS3ConfigInfo() {
Map<String, Object> config = new HashMap<>();
if (enhancedS3Service != null) {
config.put("enhancedS3Service", "可用");
// 尝试获取S3配置信息
try {
// 这里可以添加更多S3配置信息的获取逻辑
config.put("s3Template", enhancedS3Service != null ? "已配置" : "未配置");
} catch (Exception e) {
config.put("s3Template", "配置错误: " + e.getMessage());
}
} else {
config.put("enhancedS3Service", "不可用");
}
if (s3Service != null) {
config.put("s3Service", "可用");
} else {
config.put("s3Service", "不可用");
}
return config;
}
/**
* 测试URL生成
*/
public Map<String, Object> testUrlGeneration() {
Map<String, Object> result = new HashMap<>();
try {
// 测试一个示例路径
String testPath = "hot-sync/test-file.txt";
if (enhancedS3Service != null) {
String url = enhancedS3Service.getViewUrlByPath(testPath);
result.put("enhancedS3Url", url);
result.put("enhancedS3UrlValid", url != null && !url.isEmpty());
}
if (s3Service != null) {
String url = s3Service.getViewUrlByPath(testPath);
result.put("s3ServiceUrl", url);
result.put("s3ServiceUrlValid", url != null && !url.isEmpty());
}
result.put("testPath", testPath);
} catch (Exception e) {
result.put("error", e.getMessage());
}
return result;
}
/**
* 获取热同步配置
*/
public Map<String, Object> getHotSyncConfig() {
Map<String, Object> config = new HashMap<>();
config.put("syncEnabled", syncEnabled);
config.put("batchSize", batchSize);
config.put("syncIntervalMinutes", syncIntervalMinutes);
config.put("accessThreshold", accessThreshold);
config.put("maxThreads", maxThreads);
config.put("hotDataDays", hotDataDays);
config.put("running", running);
config.put("lastSyncTime", lastSyncTime);
config.put("totalSyncedFiles", totalSyncedFiles.get());
config.put("totalFailedFiles", totalFailedFiles.get());
return config;
}
}
@@ -54,7 +54,7 @@ zlt:
delete-source: false # 迁移后是否删除源文件
batch-size: 100 # 迁移批次大小
hot-sync:
enabled: true # 启用热数据同步
enabled: true # 启用热数据同步
batch-size: 100 # 批次大小
interval-minutes: 30 # 同步间隔
access-threshold: 10 # 访问次数阈值