+43
-3
@@ -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<String> 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<String> 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<String> processUrls(List<String> 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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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 # 迁移后是否删除源文件
|
||||
@@ -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
|
||||
# 默认域名
|
||||
|
||||
+4
-4
@@ -168,8 +168,8 @@ public class OrderController {
|
||||
Map<String,String> 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<String, String> 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));
|
||||
|
||||
+26
-2
@@ -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}")
|
||||
|
||||
+5
-5
@@ -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<Boolean> 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<WechatConfig> getCurrentConfig(@PathVariable String type) {
|
||||
return Result.succeed(wechatConfigService.getConfig(type, TenantContextHolder.getTenant()));
|
||||
return Result.succeed(wechatConfigService.getConfigByTypeTenantId(type, TenantContextHolder.getTenant()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ public interface WechatConfigService extends IService<WechatConfig> {
|
||||
* @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<WechatConfig> {
|
||||
* @param appId 商户ID
|
||||
* @return 微信配置
|
||||
*/
|
||||
WechatConfig getConfig(String appId);
|
||||
WechatConfig getConfigByAppIdAndType(String appId, String type);
|
||||
|
||||
/**
|
||||
* 获取微信配置
|
||||
|
||||
+3
-2
@@ -31,7 +31,7 @@ public class WechatConfigServiceImpl extends ServiceImpl<WechatConfigMapper, Wec
|
||||
|
||||
@Override
|
||||
// @Cacheable(value = CACHE_NAME, key = CACHE_KEY_PATTERN, unless = "#result == null")
|
||||
public WechatConfig getConfig(String type, String tenantId) {
|
||||
public WechatConfig getConfigByTypeTenantId(String type, String tenantId) {
|
||||
return getOne(new LambdaQueryWrapper<WechatConfig>()
|
||||
.eq(WechatConfig::getType, type)
|
||||
.eq(WechatConfig::getTenantId, tenantId)
|
||||
@@ -39,9 +39,10 @@ public class WechatConfigServiceImpl extends ServiceImpl<WechatConfigMapper, Wec
|
||||
}
|
||||
|
||||
@Override
|
||||
public WechatConfig getConfig(String appId) {
|
||||
public WechatConfig getConfigByAppIdAndType(String appId, String type) {
|
||||
return getOne(new LambdaQueryWrapper<WechatConfig>()
|
||||
.eq(WechatConfig::getAppId, appId)
|
||||
.eq(WechatConfig::getType,type)
|
||||
.eq(WechatConfig::getStatus, 1));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class WechatConfigServiceFallbackFactory implements FallbackFactory<Wecha
|
||||
}
|
||||
|
||||
@Override
|
||||
public WechatConfig getConfigByAppId(String appId) {
|
||||
public WechatConfig getConfigByAppId(String appId,String type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
########################## bootstrap级别通用配置 ##########################
|
||||
# 默认开发环境
|
||||
spring.profiles.active=dev
|
||||
spring.profiles.active=prod
|
||||
|
||||
##### nacos(注册中心和配置中心)地址
|
||||
#spring.cloud.nacos.server-addr=81.70.164.178:8848
|
||||
spring.cloud.nacos.server-addr=127.0.0.1:8848
|
||||
spring.cloud.nacos.server-addr=81.70.164.178:8848
|
||||
#spring.cloud.nacos.server-addr=127.0.0.1:8848
|
||||
spring.cloud.nacos.username=nacos
|
||||
spring.cloud.nacos.password=nacos
|
||||
#spring.cloud.nacos.password=nacosGFLY
|
||||
#spring.cloud.nacos.password=nacos
|
||||
spring.cloud.nacos.password=nacosGFLY
|
||||
spring.cloud.nacos.config.file-extension=yml
|
||||
spring.cloud.nacos.config.shared-configs[0].data-id=common.yml
|
||||
spring.cloud.nacos.config.shared-configs[0].refresh=true
|
||||
|
||||
@@ -44,5 +44,5 @@ public interface ZltUserDetailsService extends UserDetailsService {
|
||||
* @param appId
|
||||
* @return
|
||||
*/
|
||||
WechatConfig loadMiniAppConfig(String appId);
|
||||
WechatConfig loadMiniAppConfig(String appId, String type);
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ public class UserDetailServiceImpl implements ZltUserDetailsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public WechatConfig loadMiniAppConfig(String appId) {
|
||||
return wechatConfigService.getConfigByAppId(appId);
|
||||
public WechatConfig loadMiniAppConfig(String appId, String type) {
|
||||
return wechatConfigService.getConfigByAppId(appId, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public class TencentAuthenticationProvider extends BaseAuthenticationProvider {
|
||||
String appCode = authToken.getAppCode(); // 前端需传递
|
||||
|
||||
// 1. 根据appid查找配置
|
||||
WechatConfig config = userDetailsServiceFactory.getService(authToken).loadMiniAppConfig(appCode);
|
||||
WechatConfig config = userDetailsServiceFactory.getService(authToken).loadMiniAppConfig(appCode,"MINI");
|
||||
if (config == null) {
|
||||
throw new CustomOAuth2AuthenticationException("不支持的appid");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user