服务调用
This commit is contained in:
@@ -56,6 +56,12 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
@@ -64,6 +70,12 @@
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
|
||||
@@ -10,15 +10,15 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
@SpringBootApplication
|
||||
@EnableDubbo // 启用 Dubbo 服务
|
||||
@ComponentScan(basePackages = {
|
||||
"org.xyzh.agent", // 当前agent模块
|
||||
"org.xyzh.ai", // 当前ai模块
|
||||
"org.xyzh.common" // 公共模块
|
||||
})
|
||||
public class AgentApp {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AgentApp.class);
|
||||
public class AiApp {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AiApp.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
logger.info("======================== AgentApp 启动中 =========================");
|
||||
SpringApplication.run(AgentApp.class, args);
|
||||
logger.info("======================== AgentApp 启动成功 =========================");
|
||||
logger.info("======================== AI服务启动中 =========================");
|
||||
SpringApplication.run(AiApp.class, args);
|
||||
logger.info("======================== AI服务启动完成 =========================");
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@ package org.xyzh.ai.config;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.xyzh.api.system.service.SysConfigService;
|
||||
|
||||
@@ -21,7 +22,7 @@ import jakarta.annotation.PostConstruct;
|
||||
@Configuration
|
||||
public class DifyConfig {
|
||||
|
||||
@Autowired
|
||||
@DubboReference(version = "1.0.0", group = "system", timeout = 30000, retries = 0)
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.xyzh.ai.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xyzh.ai.service.impl.AgentServiceImpl;
|
||||
import org.xyzh.api.ai.service.AgentService;
|
||||
import org.xyzh.api.ai.dto.TbAgent;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.page.PageRequest;
|
||||
@@ -30,8 +30,8 @@ import java.util.Arrays;
|
||||
@RequestMapping("/ai/agent")
|
||||
public class AgentController {
|
||||
|
||||
@Autowired
|
||||
private AgentServiceImpl agentService;
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 3000, retries = 0, scope = "local")
|
||||
private AgentService agentService;
|
||||
|
||||
/**
|
||||
* @description 创建智能体
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.xyzh.ai.controller;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -38,10 +38,10 @@ import java.util.Map;
|
||||
@RequestMapping("/ai/chat")
|
||||
public class ChatController {
|
||||
|
||||
@Autowired
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
private AgentChatService chatService;
|
||||
|
||||
@Autowired
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
private AIFileUploadService fileUploadService;
|
||||
|
||||
// ====================== 会话管理 ======================
|
||||
|
||||
@@ -7,14 +7,14 @@ import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.xyzh.ai.service.impl.DifyProxyServiceImpl;
|
||||
import org.xyzh.ai.service.impl.KnowledgeServiceImpl;
|
||||
import org.xyzh.api.ai.service.DifyProxyService;
|
||||
import org.xyzh.api.ai.service.KnowledgeService;
|
||||
import org.xyzh.api.ai.dto.TbKnowledge;
|
||||
import org.xyzh.api.ai.dto.TbKnowledgeFile;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
@@ -40,11 +40,11 @@ import java.util.Map;
|
||||
public class KnowledgeController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(KnowledgeController.class);
|
||||
|
||||
@Autowired
|
||||
private KnowledgeServiceImpl knowledgeService;
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
private KnowledgeService knowledgeService;
|
||||
|
||||
@Autowired
|
||||
private DifyProxyServiceImpl difyProxyService;
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
private DifyProxyService difyProxyService;
|
||||
|
||||
// ====================== 知识库管理 ======================
|
||||
|
||||
@@ -183,7 +183,7 @@ public class KnowledgeController {
|
||||
* @since 2025-12-18
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermission('ai:knowledge:file:upload')")
|
||||
@PostMapping(name = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResultDomain<TbKnowledgeFile> uploadToKnowledge(
|
||||
@RequestParam("file") @NotNull MultipartFile file,
|
||||
@RequestParam("knowledgeId") @NotBlank String knowledgeId,
|
||||
@@ -201,7 +201,7 @@ public class KnowledgeController {
|
||||
* @since 2025-12-18
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermission('ai:knowledge:file:upload')")
|
||||
@PostMapping(name = "/file/batch-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@PostMapping(value = "/file/batch-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResultDomain<TbKnowledgeFile> batchUploadToKnowledge(
|
||||
@RequestParam("files") @NotEmpty List<MultipartFile> files,
|
||||
@RequestParam("knowledgeId") @NotBlank String knowledgeId,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.xyzh.ai.service.impl;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -12,6 +13,7 @@ import org.xyzh.ai.client.dto.DocumentUploadRequest;
|
||||
import org.xyzh.ai.client.dto.DocumentUploadResponse;
|
||||
import org.xyzh.api.ai.dto.TbAgent;
|
||||
import org.xyzh.api.ai.service.AIFileUploadService;
|
||||
import org.xyzh.api.ai.service.AgentService;
|
||||
import org.xyzh.common.auth.utils.LoginUtil;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
|
||||
@@ -33,8 +35,8 @@ public class AIFileUploadServiceImpl implements AIFileUploadService {
|
||||
@Autowired
|
||||
private DifyApiClient difyApiClient;
|
||||
|
||||
@Autowired
|
||||
private AgentServiceImpl agentService;
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
private AgentService agentService;
|
||||
|
||||
// ============================ 对话文件管理 ============================
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class AgentChatServiceImpl implements AgentChatService {
|
||||
@Autowired
|
||||
private TbChatMessageMapper chatMessageMapper;
|
||||
|
||||
@DubboReference
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 3000, retries = 0, scope = "local")
|
||||
private AgentService agentService;
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -54,7 +54,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
||||
@DubboReference(version = "1.0.0", group = "file", timeout = 30000)
|
||||
private FileService fileService;
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000)
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, scope = "local")
|
||||
private AIFileUploadService aiFileUploadService;
|
||||
|
||||
// ================================= 知识库管理 =================================
|
||||
|
||||
85
urbanLifelineServ/ai/src/main/resources/application-dev.yml
Normal file
85
urbanLifelineServ/ai/src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,85 @@
|
||||
# ================== Server ==================
|
||||
server:
|
||||
port: 8090
|
||||
# servlet:
|
||||
# context-path: /urban-lifeline/agent
|
||||
|
||||
# ================== Auth ====================
|
||||
auth:
|
||||
enabled: true
|
||||
gateway-mode: true
|
||||
whitelist:
|
||||
- /swagger-ui/**
|
||||
- /swagger-ui.html
|
||||
- /v3/api-docs/**
|
||||
- /webjars/**
|
||||
- /favicon.ico
|
||||
- /error
|
||||
- /actuator/health
|
||||
- /actuator/info
|
||||
- /ai/chat/* # AI对话,有非系统用户对话的接口,无登录状态
|
||||
|
||||
security:
|
||||
aes:
|
||||
# AES-256 密钥(Base64编码,必须与所有服务保持一致)
|
||||
# 警告:这是开发环境密钥,生产环境请使用密钥管理系统
|
||||
secret-key: MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=
|
||||
|
||||
# ================== Spring ==================
|
||||
spring:
|
||||
application:
|
||||
name: ai-service
|
||||
|
||||
# ================== Spring Cloud Nacos ==================
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
namespace: dev
|
||||
group: DEFAULT_GROUP
|
||||
|
||||
# ================== DataSource ==================
|
||||
datasource:
|
||||
url: jdbc:postgresql://127.0.0.1:5432/urban_lifeline
|
||||
username: postgres
|
||||
password: postgres
|
||||
driver-class-name: org.postgresql.Driver
|
||||
|
||||
# ================== Redis ==================
|
||||
data:
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
database: 0
|
||||
# password: ""
|
||||
|
||||
# ================== SpringDoc ==================
|
||||
springdoc:
|
||||
api-docs:
|
||||
enabled: true
|
||||
path: /v3/api-docs
|
||||
swagger-ui:
|
||||
enabled: true
|
||||
path: /swagger-ui.html
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
display-name: 'AI代理服务 API'
|
||||
paths-to-match: '/**'
|
||||
|
||||
# ================== Dubbo + Nacos ==================
|
||||
dubbo:
|
||||
application:
|
||||
name: urban-lifeline-agent
|
||||
qos-enable: false
|
||||
protocol:
|
||||
name: dubbo
|
||||
port: -1
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848
|
||||
scan:
|
||||
base-packages: org.xyzh.ai.service.impl
|
||||
|
||||
# ================== MyBatis ==================
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/**/*.xml
|
||||
type-aliases-package: org.xyzh.common.dto, org.xyzh.api
|
||||
@@ -21,12 +21,14 @@ auth:
|
||||
|
||||
security:
|
||||
aes:
|
||||
secret-key: 1234567890qwer
|
||||
# AES-256 密钥(Base64编码,必须与所有服务保持一致)
|
||||
# 警告:这是开发环境密钥,生产环境请使用密钥管理系统
|
||||
secret-key: MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=
|
||||
|
||||
# ================== Spring ==================
|
||||
spring:
|
||||
application:
|
||||
name: agent-service
|
||||
name: ai-service
|
||||
|
||||
# ================== Spring Cloud Nacos ==================
|
||||
cloud:
|
||||
@@ -75,7 +77,7 @@ dubbo:
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848
|
||||
scan:
|
||||
base-packages: org.xyzh.agent.service.impl
|
||||
base-packages: org.xyzh.ai.service.impl
|
||||
|
||||
# ================== MyBatis ==================
|
||||
mybatis-plus:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Properties>
|
||||
<property name="LOG_PATTERN" value="%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
|
||||
<property name="FILE_PATH" value="./logs" />
|
||||
<property name="FILE_NAME" value="agent-service" />
|
||||
<property name="FILE_NAME" value="ai-service" />
|
||||
<property name="file.encoding" value="UTF-8" />
|
||||
<property name="console.encoding" value="UTF-8" />
|
||||
</Properties>
|
||||
|
||||
Reference in New Issue
Block a user