feat(studio): 补齐剩余工作台聚合接口与真实对接
This commit is contained in:
@@ -12,6 +12,7 @@ import com.bruce.agent.vo.AgentSessionDetailVO;
|
||||
import com.bruce.common.enums.EnableStatusEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -25,7 +26,7 @@ public class AgentSessionServiceImpl extends ServiceImpl<AgentSessionMapper, Age
|
||||
private static final String SESSION_STATUS_ACTIVE = "ACTIVE";
|
||||
private static final String SESSION_STATUS_CLOSED = "CLOSED";
|
||||
|
||||
private final IAgentDefinitionService agentDefinitionService;
|
||||
private final ObjectProvider<IAgentDefinitionService> agentDefinitionServiceProvider;
|
||||
private final AgentSessionFactory agentSessionFactory;
|
||||
|
||||
@Override
|
||||
@@ -40,6 +41,10 @@ public class AgentSessionServiceImpl extends ServiceImpl<AgentSessionMapper, Age
|
||||
@Override
|
||||
public AgentSession createSessionEntity(AgentSessionCreateDTO request) {
|
||||
validateCreateRequest(request);
|
||||
IAgentDefinitionService agentDefinitionService = agentDefinitionServiceProvider.getIfAvailable();
|
||||
if (agentDefinitionService == null) {
|
||||
throw new IllegalStateException("Agent定义服务未就绪,暂无法创建会话");
|
||||
}
|
||||
AgentDefinition agent = agentDefinitionService.getById(request.getAgentId());
|
||||
if (agent == null) {
|
||||
throw new IllegalArgumentException("Agent不存在,ID: " + request.getAgentId());
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -32,6 +33,9 @@ class AgentSessionServiceTests {
|
||||
@Mock
|
||||
private IAgentDefinitionService agentDefinitionService;
|
||||
|
||||
@Mock
|
||||
private ObjectProvider<IAgentDefinitionService> agentDefinitionServiceProvider;
|
||||
|
||||
@Spy
|
||||
@InjectMocks
|
||||
private AgentSessionServiceImpl agentSessionService;
|
||||
@@ -42,6 +46,7 @@ class AgentSessionServiceTests {
|
||||
|
||||
@Test
|
||||
void createSessionShouldRejectDisabledAgent() {
|
||||
when(agentDefinitionServiceProvider.getIfAvailable()).thenReturn(agentDefinitionService);
|
||||
AgentDefinition agent = new AgentDefinition();
|
||||
agent.setId(1L);
|
||||
agent.setStatus("DISABLED");
|
||||
@@ -56,6 +61,7 @@ class AgentSessionServiceTests {
|
||||
|
||||
@Test
|
||||
void createSessionShouldPersistActiveSession() {
|
||||
when(agentDefinitionServiceProvider.getIfAvailable()).thenReturn(agentDefinitionService);
|
||||
AgentDefinition agent = new AgentDefinition();
|
||||
agent.setId(1L);
|
||||
agent.setStatus(EnableStatusEnum.ENABLED.name());
|
||||
|
||||
Reference in New Issue
Block a user