From b418f0c135918f3cf1375d12d08f24daa687e971 Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Tue, 15 Jul 2025 01:19:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A6=82=E4=B8=8B=EF=BC=9A=201.=20=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=96=B0=E5=A2=9EMINI=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=A4=9A=E4=B8=AAAppid=E9=97=AE?= =?UTF-8?q?=E9=A2=98=202.=20=E6=96=B0=E5=A2=9E=E6=96=87=E4=BB=B6=E9=A2=84?= =?UTF-8?q?=E7=83=AD=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B5=8B=E8=AF=95=E9=80=9A?= =?UTF-8?q?=E8=BF=87=203.=20=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=9B=B4=E6=96=B0=E5=AE=8C=E6=88=90=204.=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=86=B7=E7=83=AD=E5=88=87=E6=8D=A2=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=9B=B4=E6=96=B0=205.=20=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=B4=A0=E6=9D=90=E4=B8=8A=E4=BC=A0=E5=AE=8C=E6=88=90=E5=90=8E?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=96=87=E4=BB=B6cdn=E9=A2=84=E7=83=AD?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E8=AE=BF=E9=97=AE=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/controller/CdnController.java | 46 +++++++++++++++++-- .../src/main/resources/application-cdn.yml | 23 ---------- .../main/resources/application-hot-sync.yml | 23 ---------- .../src/main/resources/application.yml | 6 +-- .../order/controller/OrderController.java | 8 ++-- .../order/controller/OrderFileController.java | 28 ++++++++++- .../controller/WechatConfigController.java | 10 ++-- .../user/service/WechatConfigService.java | 4 +- .../service/impl/WechatConfigServiceImpl.java | 5 +- .../wechat/feign/WechatConfigService.java | 2 +- .../WechatConfigServiceFallbackFactory.java | 2 +- .../src/main/resources/bootstrap.properties | 10 ++-- .../oauth/service/ZltUserDetailsService.java | 2 +- .../service/impl/UserDetailServiceImpl.java | 4 +- .../TencentAuthenticationProvider.java | 2 +- 15 files changed, 97 insertions(+), 78 deletions(-) delete mode 100644 zlt-business/file-center/src/main/resources/application-cdn.yml delete mode 100644 zlt-business/file-center/src/main/resources/application-hot-sync.yml diff --git a/zlt-business/file-center/src/main/java/com/central/file/controller/CdnController.java b/zlt-business/file-center/src/main/java/com/central/file/controller/CdnController.java index 6d2d6ea4..49eca37b 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/controller/CdnController.java +++ b/zlt-business/file-center/src/main/java/com/central/file/controller/CdnController.java @@ -7,6 +7,8 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -24,8 +26,15 @@ import java.util.Map; @RequiredArgsConstructor @RequestMapping("/cdn") public class CdnController { + + @Autowired + private ICdnService cdnService; - private final ICdnService cdnService; + @Value("${file.oss-url:goflyapp.oss-cn-beijing.aliyuncs.com}") + private String cdnOssUrl; + + @Value("${file.cdn-url:cdn.goflytec.com}") + private String cdnUrl; @Operation(summary = "刷新文件缓存") @PostMapping("/refresh/files") @@ -58,7 +67,9 @@ public class CdnController { @Parameter(description = "预热范围:domestic-仅中国内地,overseas-全球(不包含中国内地),不传-全球") @RequestParam(required = false) String area) { try { - String taskId = cdnService.prefetchFiles(urls, area); + // 处理URL,替换OSS域名为CDN域名 + List processedUrls = processUrls(urls); + String taskId = cdnService.prefetchFiles(processedUrls, area); return Result.succeed(taskId, "文件预热任务已提交"); } catch (Exception e) { log.error("预热文件失败", e); @@ -90,7 +101,9 @@ public class CdnController { @Parameter(description = "预热范围:domestic-仅中国内地,overseas-全球(不包含中国内地),不传-全球") @RequestParam(required = false) String area) { try { - boolean result = cdnService.batchPrefetchFiles(urls, batchSize, area); + // 处理URL,替换OSS域名为CDN域名 + List processedUrls = processUrls(urls); + boolean result = cdnService.batchPrefetchFiles(processedUrls, batchSize, area); return Result.succeed(result, "批量预热文件完成"); } catch (Exception e) { log.error("批量预热文件失败", e); @@ -151,4 +164,31 @@ public class CdnController { // 可以通过调用订单服务或文件服务来获取 return List.of(); } + + /** + * 处理URL列表,替换OSS域名为CDN域名 + * @param urls 原始URL列表 + * @return 处理后的URL列表 + */ + private List processUrls(List urls) { + if (urls == null || urls.isEmpty()) { + return urls; + } + + return urls.stream() + .map(url -> { + if (url != null && url.contains(cdnOssUrl)) { + String processedUrl = url.replace(cdnOssUrl, cdnUrl); + // 移除URL参数 + int questionMarkIndex = processedUrl.indexOf('?'); + if (questionMarkIndex != -1) { + processedUrl = processedUrl.substring(0, questionMarkIndex); + } + log.debug("URL域名替换: {} -> {}", url, processedUrl); + return processedUrl; + } + return url; + }) + .toList(); + } } \ No newline at end of file diff --git a/zlt-business/file-center/src/main/resources/application-cdn.yml b/zlt-business/file-center/src/main/resources/application-cdn.yml deleted file mode 100644 index 6ba41fea..00000000 --- a/zlt-business/file-center/src/main/resources/application-cdn.yml +++ /dev/null @@ -1,23 +0,0 @@ -# CDN配置示例 -aliyun: - cdn: - # 是否启用CDN功能 - enabled: true - # 阿里云AccessKey ID(建议使用环境变量配置) - access-key-id: ${ALIYUN_ACCESS_KEY_ID:your-access-key-id} - # 阿里云AccessKey Secret(建议使用环境变量配置) - access-key-secret: ${ALIYUN_ACCESS_KEY_SECRET:your-access-key-secret} - # 地域ID - region-id: cn-zhangzhou - # 默认域名 - domain: your-cdn-domain.com - # 默认批次大小 - default-batch-size: 100 - # 任务等待超时时间(秒) - task-timeout: 300 - -# 日志配置 -logging: - level: - com.central.file.service.impl.CdnServiceImpl: DEBUG - com.central.file.schedule.CdnScheduleTask: INFO \ No newline at end of file diff --git a/zlt-business/file-center/src/main/resources/application-hot-sync.yml b/zlt-business/file-center/src/main/resources/application-hot-sync.yml deleted file mode 100644 index 36c30712..00000000 --- a/zlt-business/file-center/src/main/resources/application-hot-sync.yml +++ /dev/null @@ -1,23 +0,0 @@ -# 热数据同步配置 -zlt: - storage: - # 热数据同步配置 - hot-sync: - enabled: true # 是否启用热数据同步 - batch-size: 100 # 批次大小 - interval-minutes: 30 # 同步间隔(分钟) - access-threshold: 10 # 访问次数阈值 - max-threads: 5 # 最大线程数 - - # 同步定时任务配置 - sync: - schedule: - enabled: true # 是否启用定时任务 - cron: "0 0 2 * * ?" # 每日同步时间(默认凌晨2点) - status-check: - cron: "0 0 * * * ?" # 状态检查时间(每小时) - - # 迁移配置 - migration: - enable-verification: true # 是否启用迁移验证 - delete-source: false # 迁移后是否删除源文件 \ No newline at end of file diff --git a/zlt-business/file-center/src/main/resources/application.yml b/zlt-business/file-center/src/main/resources/application.yml index 21278625..cb42f708 100644 --- a/zlt-business/file-center/src/main/resources/application.yml +++ b/zlt-business/file-center/src/main/resources/application.yml @@ -80,11 +80,11 @@ zlt: aliyun: cdn: # 是否启用CDN功能 - enabled: false + enabled: true # 阿里云AccessKey ID(建议使用环境变量配置) - access-key-id: ${zlt.oss.secretId:your-access-key-id} + access-key-id: ${zlt.oss.secretId:LTAI5tSNV1RvexXpMMCZhxSe} # 阿里云AccessKey Secret(建议使用环境变量配置) - access-key-secret: ${zlt.oss.secretKey:your-access-key-secret} + access-key-secret: ${zlt.oss.secretKey:XocJRWU8emwjjvYLTrc04l91VZMkQK} # 地域ID region-id: cn-beijing # 默认域名 diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java index 796334be..a5169ee5 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java @@ -168,8 +168,8 @@ public class OrderController { Map imgMap = new HashMap<>(); String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath()); // 去掉URL中的参数并替换域名 - String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl)); - imgMap.put("url", cleanUrl); +// String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl)); + imgMap.put("url", url.replace(cdnOssUrl, cdnUrl)); imgMap.put("contentType", orderFile.getFileType()); fileMap.put("path",orderFile.getFilePath()); imgMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap)); @@ -620,8 +620,8 @@ public class OrderController { Map fileInfo = new HashMap<>(); String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath()); // 去掉URL中的参数并替换域名 - String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl)); - fileInfo.put("url", cleanUrl); +// String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl)); + fileInfo.put("url", url.replace(cdnOssUrl, cdnUrl)); fileInfo.put("contentType", orderFile.getFileType()); fileMap.put("path", orderFile.getFilePath()); fileInfo.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap)); diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java index eb51d4df..0f749ad3 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java @@ -63,6 +63,12 @@ public class OrderFileController { @Value("${cdn.prefetch.area:domestic}") private String cdnPrefetchArea; + @Value("${file.oss-url}") + private String cdnOssUrl; + + @Value("${file.cdn-url}") + private String cdnUrl; + @Autowired private UserCenterService userCenterService; @@ -364,8 +370,10 @@ public class OrderFileController { try { String viewUrl = fileCenterService.getViewUrlByPath(orderFile.getFilePath()); if (viewUrl != null && !viewUrl.trim().isEmpty()) { - fileUrls.add(viewUrl); - log.debug("添加文件URL到预热列表: {}", viewUrl); + // 替换OSS域名为CDN域名,并移除URL参数 + String cleanUrl = viewUrl.replace(cdnOssUrl, cdnUrl); + fileUrls.add(cleanUrl); + log.debug("添加文件URL到预热列表: {}", cleanUrl); } } catch (Exception e) { log.warn("获取文件URL失败,文件路径: {}", orderFile.getFilePath(), e); @@ -395,6 +403,22 @@ public class OrderFileController { } } + /** + * 移除URL中的参数 + * @param url 原始URL + * @return 移除参数后的URL + */ + private String removeUrlParams(String url) { + if (url == null || url.isEmpty()) { + return url; + } + int questionMarkIndex = url.indexOf('?'); + if (questionMarkIndex != -1) { + return url.substring(0, questionMarkIndex); + } + return url; + } + @Operation(summary = "删除文件") @DeleteMapping( "/{id}") diff --git a/zlt-business/user-center/src/main/java/com/central/user/controller/WechatConfigController.java b/zlt-business/user-center/src/main/java/com/central/user/controller/WechatConfigController.java index 9e8244cc..8fa82bd2 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/controller/WechatConfigController.java +++ b/zlt-business/user-center/src/main/java/com/central/user/controller/WechatConfigController.java @@ -42,7 +42,7 @@ public class WechatConfigController { @Operation(summary = "根据类型和租户ID查询微信配置") @GetMapping("/type/{type}") public WechatConfig getConfig(@PathVariable String type, @RequestParam String tenantId) { - WechatConfig config = wechatConfigService.getConfig(type, tenantId); + WechatConfig config = wechatConfigService.getConfigByTypeTenantId(type, tenantId); return config; } @@ -113,8 +113,8 @@ public class WechatConfigController { @Operation(summary = "获取微信配置") @GetMapping("/app/{id}") - public WechatConfig getConfigByAppId(@PathVariable("id") String appId) { - return wechatConfigService.getConfig(appId); + public WechatConfig getConfigByAppId(@PathVariable("id") String appId, @RequestParam String type) { + return wechatConfigService.getConfigByAppIdAndType(appId,type); } @GetMapping(value = "/serial/{serialNumber}") @@ -128,7 +128,7 @@ public class WechatConfigController { public Result uploadPrivateKey(@RequestParam("file") MultipartFile file) { try { String privateKey = new String(file.getBytes()); - WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",TenantContextHolder.getTenant()); + WechatConfig wechatConfig = wechatConfigService.getConfigByTypeTenantId("PAY",TenantContextHolder.getTenant()); wechatConfig.setPrivateKey(privateKey); return Result.succeed(wechatConfigService.updateConfig(wechatConfig)); } catch (Exception e) { @@ -140,7 +140,7 @@ public class WechatConfigController { @Operation(summary = "获取当前配置") @GetMapping("/current/{type}") public Result getCurrentConfig(@PathVariable String type) { - return Result.succeed(wechatConfigService.getConfig(type, TenantContextHolder.getTenant())); + return Result.succeed(wechatConfigService.getConfigByTypeTenantId(type, TenantContextHolder.getTenant())); } } diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/WechatConfigService.java b/zlt-business/user-center/src/main/java/com/central/user/service/WechatConfigService.java index 1aba18e6..52d35342 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/service/WechatConfigService.java +++ b/zlt-business/user-center/src/main/java/com/central/user/service/WechatConfigService.java @@ -23,7 +23,7 @@ public interface WechatConfigService extends IService { * @param tenantId 商户ID * @return 微信配置 */ - WechatConfig getConfig(String type, String tenantId); + WechatConfig getConfigByTypeTenantId(String type, String tenantId); /** * 获取微信配置 @@ -31,7 +31,7 @@ public interface WechatConfigService extends IService { * @param appId 商户ID * @return 微信配置 */ - WechatConfig getConfig(String appId); + WechatConfig getConfigByAppIdAndType(String appId, String type); /** * 获取微信配置 diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/impl/WechatConfigServiceImpl.java b/zlt-business/user-center/src/main/java/com/central/user/service/impl/WechatConfigServiceImpl.java index 694e9e2c..0d7fbead 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/service/impl/WechatConfigServiceImpl.java +++ b/zlt-business/user-center/src/main/java/com/central/user/service/impl/WechatConfigServiceImpl.java @@ -31,7 +31,7 @@ public class WechatConfigServiceImpl extends ServiceImpl() .eq(WechatConfig::getType, type) .eq(WechatConfig::getTenantId, tenantId) @@ -39,9 +39,10 @@ public class WechatConfigServiceImpl extends ServiceImpl() .eq(WechatConfig::getAppId, appId) + .eq(WechatConfig::getType,type) .eq(WechatConfig::getStatus, 1)); } diff --git a/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/WechatConfigService.java b/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/WechatConfigService.java index 17ccb498..c1160d13 100644 --- a/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/WechatConfigService.java +++ b/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/WechatConfigService.java @@ -26,7 +26,7 @@ public interface WechatConfigService { WechatConfig getConfig(@PathVariable("type") String type,@RequestParam("tenantId") String tenantId); @GetMapping(value = "/wechat/config/app/{id}") - WechatConfig getConfigByAppId(@PathVariable("id") String appId); + WechatConfig getConfigByAppId(@PathVariable("id") String appId, @RequestParam("type") String type); @GetMapping(value = "/wechat/config/serial/{serialNumber}") WechatConfig getConfigBySerialNumber(@PathVariable("serialNumber") String serialNumber); diff --git a/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/fallback/WechatConfigServiceFallbackFactory.java b/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/fallback/WechatConfigServiceFallbackFactory.java index 3e6db240..67c2aa22 100644 --- a/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/fallback/WechatConfigServiceFallbackFactory.java +++ b/zlt-commons/zlt-wechat-common-core/src/main/java/com/central/wechat/feign/fallback/WechatConfigServiceFallbackFactory.java @@ -25,7 +25,7 @@ public class WechatConfigServiceFallbackFactory implements FallbackFactory