This commit is contained in:
2026-01-19 16:41:29 +08:00
8 changed files with 39 additions and 194 deletions

View File

@@ -1,5 +1,6 @@
package com.sdm.common.entity.resp;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -51,4 +52,8 @@ public class BaseResp {
@Schema(description = "所属算列id")
private String ownRunId;
@Schema(description= "文件业务类型1模型文件 2仿真报告、3计算文件、4曲线文件、5云图文件6网格文件7计算过程文件")
@TableField("fileType")
private Integer fileType;
}

View File

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -59,9 +61,11 @@ public class DimensionTemplate implements Serializable {
@Schema(description = "创建时间")
@TableField("createdAt")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createdAt;
@Schema(description = "更新时间")
@TableField("updatedAt")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updatedAt;
}

View File

@@ -68,7 +68,18 @@ public class MinioService implements IMinioService {
} catch (Exception e) {
log.error("桶{}初始化失败", minioConfig.getSecretBusinessBucket(), e);
}
createBucketLifecycle(minioConfig.getSpdmBucket(),minioConfig.getLifecycleConfig());
// 设置各个桶标签
try {
List<Bucket> buckets = minioClient.listBuckets();
for (Bucket bucket : buckets) {
if(!Objects.isNull(bucket)
&&org.apache.commons.lang3.StringUtils.isNotBlank(bucket.name())) {
createBucketLifecycle(bucket.name(),minioConfig.getLifecycleConfig());
}
}
}catch (Exception ex){
log.error("data启动初始化桶的生命周期规则失败{}", ex.getMessage());
}
}
@@ -110,7 +121,7 @@ public class MinioService implements IMinioService {
if (!found) {
log.info("系统初始化:创建缺失的租户桶 -> {}", bucketName);
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
// TODO: 如果需要,可以在这里设置生命周期策略 (Lifecycle Config)
createBucketLifecycle(bucketName,minioConfig.getLifecycleConfig());
}
existingBucketsCache.add(bucketName);
} catch (Exception e) {
@@ -150,6 +161,7 @@ public class MinioService implements IMinioService {
if (!found) {
log.info("运行时检测到新租户桶不存在,正在创建: {}", bucketName);
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
createBucketLifecycle(bucketName,minioConfig.getLifecycleConfig());
}
existingBucketsCache.add(bucketName);
} catch (Exception e) {
@@ -545,6 +557,7 @@ public class MinioService implements IMinioService {
minioClient.makeBucket(MakeBucketArgs.builder()
.bucket(bucketName)
.build());
createBucketLifecycle(bucketName,minioConfig.getLifecycleConfig());
}
}

View File

@@ -1,181 +0,0 @@
package com.sdm.data;
import com.sdm.data.dao.MapperCompatibilityTest;
import com.sdm.data.dao.PostgreSQLCompatibilityTest;
import com.sdm.data.service.ServiceCrudTest;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import java.lang.reflect.Method;
import java.util.*;
/**
* 交互式测试运行器
* 启动一次Spring容器后可以反复执行不同的测试方法
*
* 使用方法直接运行此类的main方法然后在控制台输入测试方法编号
*/
public class InteractiveTestRunner {
private static ConfigurableApplicationContext context;
private static final Map<String, TestMethodInfo> testMethods = new LinkedHashMap<>();
public static void main(String[] args) {
System.out.println("========================================");
System.out.println(" 交互式测试运行器 - 启动Spring容器");
System.out.println("========================================");
// 启动Spring容器
System.setProperty("spring.profiles.active", "test");
context = SpringApplication.run(DataApplication.class, args);
System.out.println("\n✓ Spring容器启动成功\n");
// 注册测试类和方法
registerTestClass(MapperCompatibilityTest.class);
registerTestClass(ServiceCrudTest.class);
registerTestClass(PostgreSQLCompatibilityTest.class);
// 交互式运行
runInteractively();
}
private static void registerTestClass(Class<?> testClass) {
for (Method method : testClass.getDeclaredMethods()) {
if (method.isAnnotationPresent(org.junit.jupiter.api.Test.class)) {
String key = testClass.getSimpleName() + "." + method.getName();
testMethods.put(key, new TestMethodInfo(testClass, method));
}
}
}
private static void runInteractively() {
Scanner scanner = new Scanner(System.in);
while (true) {
printMenu();
System.out.print("\n请输入编号 (q退出, a运行全部): ");
String input = scanner.nextLine().trim();
if ("q".equalsIgnoreCase(input)) {
System.out.println("退出测试...");
context.close();
break;
}
if ("a".equalsIgnoreCase(input)) {
runAllTests();
continue;
}
if ("l".equalsIgnoreCase(input)) {
continue; // 重新显示菜单
}
try {
int index = Integer.parseInt(input);
runTestByIndex(index);
} catch (NumberFormatException e) {
// 尝试按方法名匹配
runTestByName(input);
}
}
}
private static void printMenu() {
System.out.println("\n========== 可用测试方法 ==========");
int index = 1;
String currentClass = "";
for (Map.Entry<String, TestMethodInfo> entry : testMethods.entrySet()) {
String className = entry.getValue().testClass.getSimpleName();
if (!className.equals(currentClass)) {
currentClass = className;
System.out.println("\n【" + className + "");
}
System.out.printf(" %3d. %s%n", index++, entry.getValue().method.getName());
}
System.out.println("\n==================================");
System.out.println("命令: [编号]执行单个 | [a]执行全部 | [l]列表 | [q]退出");
}
private static void runTestByIndex(int index) {
if (index < 1 || index > testMethods.size()) {
System.out.println("❌ 无效编号: " + index);
return;
}
int i = 1;
for (TestMethodInfo info : testMethods.values()) {
if (i++ == index) {
runTest(info);
return;
}
}
}
private static void runTestByName(String name) {
for (Map.Entry<String, TestMethodInfo> entry : testMethods.entrySet()) {
if (entry.getKey().contains(name) || entry.getValue().method.getName().contains(name)) {
runTest(entry.getValue());
return;
}
}
System.out.println("❌ 未找到匹配的测试方法: " + name);
}
private static void runTest(TestMethodInfo info) {
System.out.println("\n▶ 运行: " + info.testClass.getSimpleName() + "." + info.method.getName());
System.out.println("----------------------------------------");
try {
// 从Spring容器获取测试实例
Object testInstance = context.getBean(info.testClass);
long start = System.currentTimeMillis();
info.method.invoke(testInstance);
long duration = System.currentTimeMillis() - start;
System.out.println("----------------------------------------");
System.out.printf("✓ 测试通过! (耗时: %dms)%n", duration);
} catch (Exception e) {
System.out.println("----------------------------------------");
System.out.println("✗ 测试失败!");
Throwable cause = e.getCause() != null ? e.getCause() : e;
System.out.println("错误: " + cause.getMessage());
cause.printStackTrace();
}
}
private static void runAllTests() {
System.out.println("\n▶ 运行全部测试...");
int passed = 0, failed = 0;
long totalStart = System.currentTimeMillis();
for (TestMethodInfo info : testMethods.values()) {
System.out.print(" " + info.method.getName() + " ... ");
try {
Object testInstance = context.getBean(info.testClass);
info.method.invoke(testInstance);
System.out.println("");
passed++;
} catch (Exception e) {
System.out.println("");
failed++;
}
}
long totalDuration = System.currentTimeMillis() - totalStart;
System.out.println("\n========================================");
System.out.printf("总计: %d 通过, %d 失败 (耗时: %dms)%n", passed, failed, totalDuration);
}
private static class TestMethodInfo {
Class<?> testClass;
Method method;
TestMethodInfo(Class<?> testClass, Method method) {
this.testClass = testClass;
this.method = method;
}
}
}

View File

@@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.*;
* Mapper层兼容性测试 - MySQL转PostgreSQL验证
* 覆盖所有Mapper接口的基础CRUD和自定义SQL方法
*/
@Component // 让测试类成为Spring Bean支持交互式运行
@SpringBootTest
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -92,7 +92,6 @@ public class MapperCompatibilityTest {
entity.setFileBizType(1);
entity.setFileSize(2048L);
entity.setCreateTime(LocalDateTime.now());
entity.setUpdateTime(LocalDateTime.now());
int insertResult = fileStorageMapper.insert(entity);
assertEquals(1, insertResult);
@@ -104,9 +103,11 @@ public class MapperCompatibilityTest {
assertEquals("mapper_test.txt", selected.getFileName());
// UPDATE
selected.setFileName("mapper_test_updated.txt");
selected.setFileSize(4096L);
int updateResult = fileStorageMapper.updateById(selected);
FileStorage updateFileStorage = new FileStorage();
updateFileStorage.setId(selected.getId());
updateFileStorage.setFileName("mapper_test_updated.txt");
updateFileStorage.setFileSize(4096L);
int updateResult = fileStorageMapper.updateById(updateFileStorage);
assertEquals(1, updateResult);
// VERIFY UPDATE
@@ -194,13 +195,16 @@ public class MapperCompatibilityTest {
FileMetadataInfo entity = new FileMetadataInfo();
entity.setRelatedResourceUuid("test-uuid-mapper");
entity.setRelatedResourceUuidOwnType("node");
entity.setBucketName("buck");
entity.setObjectKey("objectKey");
entity.setVersionNo(1L);
entity.setOriginalName("mapper_metadata.txt");
entity.setIsRoot(false);
entity.setApproveType(1);
entity.setDataType(2);
entity.setIsLatest(true);
entity.setTenantId(1L);
entity.setCreatorId(1L);
entity.setCreateTime(LocalDateTime.now());
entity.setUpdateTime(LocalDateTime.now());
int insertResult = fileMetadataInfoMapper.insert(entity);
assertEquals(1, insertResult);

View File

@@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.*;
* 4. Boolean字段处理
* 5. 字段名大小写敏感性
*/
@Component // 让测试类成为Spring Bean支持交互式运行
@SpringBootTest
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)

View File

@@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.*;
* Service层CRUD测试 - MySQL转PostgreSQL验证
* 覆盖所有Service的基础CRUD操作
*/
@Component // 让测试类成为Spring Bean支持交互式运行
@SpringBootTest
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)

View File

@@ -4,7 +4,7 @@ spring:
datasource:
username: spdm
password: Spdm@2026
jdbc-url: jdbc:postgresql://192.168.65.161:25432/spdm_baseline?currentSchema=public&stringtype=unspecified
jdbc-url: jdbc:postgresql://192.168.65.161:25432/spdm_baseline?currentSchema=public&stringtype=unspecified&TimeZone=Asia/Shanghai
driver-class-name: org.postgresql.Driver
hikari:
# 设置连接池能够容纳的最大连接数。建议值CPU核心数 * 2 + 有效磁盘I/O数。一个常见的经验值是 10-20。
@@ -20,7 +20,7 @@ spring:
master:
username: spdm
password: Spdm@2026
jdbc-url: jdbc:postgresql://192.168.65.161:25432/spdm_baseline?currentSchema=public&stringtype=unspecified
jdbc-url: jdbc:postgresql://192.168.65.161:25432/spdm_baseline?currentSchema=public&stringtype=unspecified&TimeZone=Asia/Shanghai
driver-class-name: org.postgresql.Driver
slave:
username: root