fix(shop-data-crawl): 累计档迁独立桶 shufu-shop-data 脱离默认桶30天过期规则+修复批量下载zip恒失败——① 新增 aiimage.oss.shop-data-bucket(默认 shufu-shop-data):上传侧 resolveBucket 按 SHOP_DATA_CRAWL、读取/删除/直链侧 bucketForObjectKey 按 result/shop_data_crawl/ 前缀双路路由(DB 里存的是裸 objectKey 不含桶名,key 不变故存量对象 mc mirror 即无缝切换),configuredBuckets 纳入新桶,启动自检未配置时告警 ② 批量下载 zip 原直接把 df.result_file_url 当绝对 URL(URI.create().toURL()),裸 objectKey 必抛 no protocol 导致整包 100% 失败,改由 loadDownloadRows 统一走 generateFreshDownloadUrl 拼直链 ③ 补 OssStorageServiceTest 5 用例覆盖此前零覆盖的上传选桶/裸key前缀路由

This commit is contained in:
2026-09-10 14:31:00 +08:00
parent 6fe67b648f
commit 08e78ebe55
5 changed files with 148 additions and 6 deletions
@@ -3,14 +3,18 @@ package com.nanri.aiimage.modules.file.service.oss;
import com.nanri.aiimage.config.OssProperties;
import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.UploadObjectArgs;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import java.io.File;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -162,4 +166,66 @@ class OssStorageServiceTest {
private OssProperties properties() {
return properties;
}
// ==================== 店铺数据采集独立桶(shufu-shop-data====================
@Test
void shopDataCrawlResultFilesRouteToDedicatedBucket() throws Exception {
properties().setShopDataBucket("shufu-shop-data");
// 下载/删除侧:DB 存的是裸 objectKey,必须按 result/shop_data_crawl/ 前缀回到独立桶
assertEquals(
"https://oss.aishufu.top/shufu-shop-data/result/shop_data_crawl/abc/out.xlsx",
storageService.generateFreshDownloadUrl("result/shop_data_crawl/abc/out.xlsx"));
// 上传侧:moduleType = SHOP_DATA_CRAWL 决定落独立桶
MinioClient client = mock(MinioClient.class);
ArgumentCaptor<UploadObjectArgs> captor = ArgumentCaptor.forClass(UploadObjectArgs.class);
OssStorageService oss = new OssStorageService(properties, client);
File temp = File.createTempFile("shop-data-crawl-test", ".xlsx");
temp.deleteOnExit();
String objectKey = oss.uploadResultFile(temp, "SHOP_DATA_CRAWL");
verify(client).uploadObject(captor.capture());
assertEquals("shufu-shop-data", captor.getValue().bucket());
assertEquals(objectKey, captor.getValue().object());
assertTrue(objectKey.startsWith("result/shop_data_crawl/"), "对象键前缀应保持 result/shop_data_crawl/");
}
@Test
void otherModulesStillUseDefaultBucket() {
properties().setShopDataBucket("shufu-shop-data");
// 前缀路由不能误伤其它模块
assertEquals(
"https://oss.aishufu.top/nanri-ai-images/result/dedupe/1/re.xlsx",
storageService.generateFreshDownloadUrl("result/dedupe/1/re.xlsx"));
}
@Test
void shopDataCrawlFallsBackToDefaultBucketWhenNotConfigured() {
// 未配置时保持旧行为(落默认桶),由启动自检 checkShopDataBucketConfigured 负责告警
assertEquals(
"https://oss.aishufu.top/nanri-ai-images/result/shop_data_crawl/abc/out.xlsx",
storageService.generateFreshDownloadUrl("result/shop_data_crawl/abc/out.xlsx"));
}
@Test
void shopDataCrawlBucketIsManagedAndNormalized() {
properties().setShopDataBucket("shufu-shop-data");
assertEquals(
"https://oss.aishufu.top/shufu-shop-data/result/shop_data_crawl/abc/out.xlsx",
storageService.normalizeManagedPublicUrl(
"http://47.110.241.161:9000/shufu-shop-data/result/shop_data_crawl/abc/out.xlsx"));
assertEquals(
"https://oss.aishufu.top/shufu-shop-data/result/shop_data_crawl/abc/out.xlsx",
storageService.normalizeManagedPublicUrl(
"https://shufu-shop-data.oss.aishufu.top/result/shop_data_crawl/abc/out.xlsx"));
}
@Test
void shopDataCrawlDownloadEndpointAppliesToResultPrefix() {
properties().setShopDataBucket("shufu-shop-data");
properties().setDownloadEndpoint("https://download.aishufu.top");
assertEquals(
"https://download.aishufu.top/shufu-shop-data/result/shop_data_crawl/abc/out.xlsx",
storageService.generateFreshDownloadUrl("result/shop_data_crawl/abc/out.xlsx"));
}
}