refactor: flatten infrastructure packages

This commit is contained in:
wh
2026-04-14 13:19:39 +08:00
parent e3c796da27
commit 0af19cf1b5
10 changed files with 66 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
package com.label.common.aop;
package com.label.annotation;
import java.lang.annotation.*;

View File

@@ -1,5 +1,6 @@
package com.label.common.aop;
package com.label.aspect;
import com.label.annotation.OperationLog;
import com.label.common.context.CompanyContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@@ -3,10 +3,12 @@ package com.label.common.ai;
import lombok.Builder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;
import jakarta.annotation.PostConstruct;
import java.time.Duration;
import java.util.List;
import java.util.Map;
@@ -19,11 +21,15 @@ public class AiServiceClient {
@Value("${ai-service.timeout:30000}")
private int timeoutMs;
private RestClient restClient;
private RestTemplate restTemplate;
@PostConstruct
public void init() {
restClient = RestClient.builder().baseUrl(baseUrl).build();
restTemplate = new RestTemplateBuilder()
.rootUri(baseUrl)
.setConnectTimeout(Duration.ofMillis(timeoutMs))
.setReadTimeout(Duration.ofMillis(timeoutMs))
.build();
}
// DTO classes
@@ -83,34 +89,34 @@ public class AiServiceClient {
// The 8 endpoints:
public ExtractionResponse extractText(ExtractionRequest request) {
return restClient.post().uri("/extract/text").body(request).retrieve().body(ExtractionResponse.class);
return restTemplate.postForObject("/extract/text", request, ExtractionResponse.class);
}
public ExtractionResponse extractImage(ExtractionRequest request) {
return restClient.post().uri("/extract/image").body(request).retrieve().body(ExtractionResponse.class);
return restTemplate.postForObject("/extract/image", request, ExtractionResponse.class);
}
public void extractFrames(VideoProcessRequest request) {
restClient.post().uri("/video/extract-frames").body(request).retrieve().toBodilessEntity();
restTemplate.postForLocation("/video/extract-frames", request);
}
public void videoToText(VideoProcessRequest request) {
restClient.post().uri("/video/to-text").body(request).retrieve().toBodilessEntity();
restTemplate.postForLocation("/video/to-text", request);
}
public QaGenResponse genTextQa(ExtractionRequest request) {
return restClient.post().uri("/qa/gen-text").body(request).retrieve().body(QaGenResponse.class);
return restTemplate.postForObject("/qa/gen-text", request, QaGenResponse.class);
}
public QaGenResponse genImageQa(ExtractionRequest request) {
return restClient.post().uri("/qa/gen-image").body(request).retrieve().body(QaGenResponse.class);
return restTemplate.postForObject("/qa/gen-image", request, QaGenResponse.class);
}
public FinetuneResponse startFinetune(FinetuneRequest request) {
return restClient.post().uri("/finetune/start").body(request).retrieve().body(FinetuneResponse.class);
return restTemplate.postForObject("/finetune/start", request, FinetuneResponse.class);
}
public FinetuneStatusResponse getFinetuneStatus(String jobId) {
return restClient.get().uri("/finetune/status/{jobId}", jobId).retrieve().body(FinetuneStatusResponse.class);
return restTemplate.getForObject("/finetune/status/{jobId}", FinetuneStatusResponse.class, jobId);
}
}

View File

@@ -1,4 +1,4 @@
package com.label.common.config;
package com.label.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;

View File

@@ -1,4 +1,4 @@
package com.label.common.config;
package com.label.config;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;

View File

@@ -1,4 +1,4 @@
package com.label.common.config;
package com.label.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -1,4 +1,4 @@
package com.label.module.annotation.event;
package com.label.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

View File

@@ -1,16 +1,16 @@
package com.label.module.annotation.service;
package com.label.listener;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.label.common.ai.AiServiceClient;
import com.label.common.context.CompanyContext;
import com.label.module.annotation.entity.TrainingDataset;
import com.label.module.annotation.event.ExtractionApprovedEvent;
import com.label.module.annotation.mapper.AnnotationResultMapper;
import com.label.module.annotation.mapper.TrainingDatasetMapper;
import com.label.module.source.entity.SourceData;
import com.label.module.source.mapper.SourceDataMapper;
import com.label.module.task.service.TaskClaimService;
import com.label.module.task.service.TaskService;
import com.label.event.ExtractionApprovedEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;

View File

@@ -9,7 +9,7 @@ import com.label.common.statemachine.StateValidator;
import com.label.common.statemachine.TaskStatus;
import com.label.module.annotation.entity.AnnotationResult;
import com.label.module.annotation.entity.TrainingDataset;
import com.label.module.annotation.event.ExtractionApprovedEvent;
import com.label.event.ExtractionApprovedEvent;
import com.label.module.annotation.mapper.AnnotationResultMapper;
import com.label.module.annotation.mapper.TrainingDatasetMapper;
import com.label.module.source.entity.SourceData;

View File

@@ -0,0 +1,39 @@
package com.label.unit;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@DisplayName("标准目录扁平化迁移守卫测试")
class PackageStructureMigrationTest {
@Test
@DisplayName("基础设施类已迁移到目标目录")
void infrastructureTypesMoved() {
assertClassExists("com.label.annotation.OperationLog");
assertClassExists("com.label.aspect.AuditAspect");
assertClassExists("com.label.config.MybatisPlusConfig");
assertClassExists("com.label.config.OpenApiConfig");
assertClassExists("com.label.config.RedisConfig");
assertClassExists("com.label.event.ExtractionApprovedEvent");
assertClassExists("com.label.listener.ExtractionApprovedEventListener");
assertClassMissing("com.label.common.aop.OperationLog");
assertClassMissing("com.label.common.aop.AuditAspect");
assertClassMissing("com.label.common.config.MybatisPlusConfig");
assertClassMissing("com.label.common.config.OpenApiConfig");
assertClassMissing("com.label.common.config.RedisConfig");
assertClassMissing("com.label.module.annotation.event.ExtractionApprovedEvent");
assertClassMissing("com.label.module.annotation.service.ExtractionApprovedEventListener");
}
private static void assertClassExists(String fqcn) {
assertThatCode(() -> Class.forName(fqcn)).doesNotThrowAnyException();
}
private static void assertClassMissing(String fqcn) {
assertThatThrownBy(() -> Class.forName(fqcn)).isInstanceOf(ClassNotFoundException.class);
}
}