添加ai功能开关

This commit is contained in:
liuhanqing
2025-11-04 08:59:46 +08:00
parent 597f92b566
commit cb32173d1c
23 changed files with 225 additions and 229 deletions

View File

@@ -1,35 +1,23 @@
package com.ruoyi.ai.chat.config; package com.ruoyi.ai.chat.config;
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceBuilder;
import com.mysql.cj.jdbc.MysqlDataSource;
import com.ruoyi.ai.chat.service.impl.InSqlMemory; import com.ruoyi.ai.chat.service.impl.InSqlMemory;
import com.ruoyi.ai.util.service.BasStockToolService; import com.ruoyi.ai.util.service.BasStockToolService;
import com.ruoyi.ai.util.service.ToolService;
import org.mariadb.jdbc.MariaDbDataSource; import org.mariadb.jdbc.MariaDbDataSource;
import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor; import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.embedding.EmbeddingModel; import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.openai.OpenAiChatModel; import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore; import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.mariadb.MariaDBVectorStore; import org.springframework.ai.vectorstore.mariadb.MariaDBVectorStore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
import java.sql.SQLException; import java.sql.SQLException;
@Configuration @Configuration
@@ -40,6 +28,11 @@ public class ChatModelConfig {
@Bean @Bean
@ConditionalOnProperty(
name = "spring.ai.enable", // 配置项名称
havingValue = "true", // 期望的值
matchIfMissing = false // 配置不存在时是否匹配(false=不注册)
)
public ChatClient chatClient(OpenAiChatModel openAiChatModel, ChatMemory chatMemory, BasStockToolService toolService/*, ToolCallbackProvider toolCallbackProvider*/) { public ChatClient chatClient(OpenAiChatModel openAiChatModel, ChatMemory chatMemory, BasStockToolService toolService/*, ToolCallbackProvider toolCallbackProvider*/) {
return ChatClient return ChatClient
//使用的模型 //使用的模型
@@ -63,11 +56,21 @@ public class ChatModelConfig {
* @return * @return
*/ */
@Bean @Bean
@ConditionalOnProperty(
name = "spring.ai.enable", // 配置项名称
havingValue = "true", // 期望的值
matchIfMissing = false // 配置不存在时是否匹配(false=不注册)
)
public ChatMemory chatMemory() { public ChatMemory chatMemory() {
return new InSqlMemory(); return new InSqlMemory();
} }
@Bean @Bean
@ConditionalOnProperty(
name = "spring.ai.enable", // 配置项名称
havingValue = "true", // 期望的值
matchIfMissing = false // 配置不存在时是否匹配(false=不注册)
)
@ConfigurationProperties("spring.datasource.druid.slave") @ConfigurationProperties("spring.datasource.druid.slave")
public MariaDbDataSource dataSource() throws SQLException { public MariaDbDataSource dataSource() throws SQLException {
return DataSourceBuilder.create().username("root") return DataSourceBuilder.create().username("root")
@@ -77,6 +80,11 @@ public class ChatModelConfig {
@Bean @Bean
@ConditionalOnProperty(
name = "spring.ai.enable", // 配置项名称
havingValue = "true", // 期望的值
matchIfMissing = false // 配置不存在时是否匹配(false=不注册)
)
public VectorStore vectorStore(MariaDbDataSource dataSource, EmbeddingModel embeddingModel) throws SQLException { public VectorStore vectorStore(MariaDbDataSource dataSource, EmbeddingModel embeddingModel) throws SQLException {
JdbcTemplate customJdbcTemplate = new JdbcTemplate(dataSource); JdbcTemplate customJdbcTemplate = new JdbcTemplate(dataSource);
return MariaDBVectorStore.builder(customJdbcTemplate, embeddingModel) return MariaDBVectorStore.builder(customJdbcTemplate, embeddingModel)

View File

@@ -3,7 +3,9 @@ package com.ruoyi.ai.chat.controller;
import com.ruoyi.ai.chat.domain.CustomMessage; import com.ruoyi.ai.chat.domain.CustomMessage;
import com.ruoyi.ai.chat.service.ChatService; import com.ruoyi.ai.chat.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
@RestController @RestController

View File

@@ -12,17 +12,16 @@ import org.springframework.core.io.FileSystemResource;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/api/embedding") @RequestMapping("/api/embedding")
public class EmbeddingDemoController { public class EmbeddingDemoController {
@Autowired @Autowired(required = false)
private OpenAiEmbeddingModel embeddingModel; private OpenAiEmbeddingModel embeddingModel;
@Autowired @Autowired(required = false)
private VectorStore vectorStore; private VectorStore vectorStore;
/** /**

View File

@@ -6,39 +6,34 @@ import com.ruoyi.ai.chat.domain.CustomMessage;
import com.ruoyi.ai.chat.service.ChatService; import com.ruoyi.ai.chat.service.ChatService;
import com.ruoyi.ai.conversation.domain.Conversations; import com.ruoyi.ai.conversation.domain.Conversations;
import com.ruoyi.ai.conversation.service.IConversationsService; import com.ruoyi.ai.conversation.service.IConversationsService;
import com.ruoyi.ai.message.domain.ChatMessage;
import com.ruoyi.ai.message.service.IChatMessageService; import com.ruoyi.ai.message.service.IChatMessageService;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor; import org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.prompt.PromptTemplate; import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.ai.document.Document;
import org.springframework.ai.openai.OpenAiChatModel; import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.template.st.StTemplateRenderer; import org.springframework.ai.template.st.StTemplateRenderer;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore; import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import java.util.Date; import java.util.Date;
import java.util.List;
@Service @Service
public class ChatServiceImpl implements ChatService { public class ChatServiceImpl implements ChatService {
@Autowired @Autowired(required = false)
private ChatClient chatClient; private ChatClient chatClient;
@Autowired @Autowired(required = false)
private OpenAiChatModel openAiChatModel; private OpenAiChatModel openAiChatModel;
@Autowired @Autowired(required = false)
private ChatMemory chatMemory; private ChatMemory chatMemory;
@Autowired @Autowired(required = false)
private VectorStore vectorStore; private VectorStore vectorStore;
@Autowired @Autowired(required = false)
private IChatMessageService chatMessageService; private IChatMessageService chatMessageService;
@Autowired @Autowired(required = false)
private IConversationsService conversationsService; private IConversationsService conversationsService;
// 定义问答模板 // 定义问答模板
@@ -110,6 +105,10 @@ public class ChatServiceImpl implements ChatService {
*/ */
@Override @Override
public Flux<String> chatByUserContent(CustomMessage customMessage) { public Flux<String> chatByUserContent(CustomMessage customMessage) {
if (chatClient == null){
return Flux.just("未开启聊天模型");
}
// 生成唯一会话ID // 生成唯一会话ID
Long sessionId = IdUtil.getSnowflakeNextId(); Long sessionId = IdUtil.getSnowflakeNextId();
//修改会话 //修改会话

View File

@@ -1,10 +1,9 @@
package com.ruoyi.ai.chat.service.impl; package com.ruoyi.ai.chat.service.impl;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import com.ruoyi.ai.message.domain.ChatMessage;
import com.ruoyi.ai.chat.domain.CustomMessage; import com.ruoyi.ai.chat.domain.CustomMessage;
import com.ruoyi.ai.message.domain.ChatMessage;
import com.ruoyi.ai.message.service.IChatMessageService; import com.ruoyi.ai.message.service.IChatMessageService;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.ai.chat.memory.ChatMemory; import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.AssistantMessage; import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.messages.Message; import org.springframework.ai.chat.messages.Message;

View File

@@ -1,32 +1,22 @@
package com.ruoyi.ai.conversation.controller; package com.ruoyi.ai.conversation.controller;
import java.util.List;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.ai.conversation.domain.Conversations;
import jakarta.servlet.http.HttpServletResponse; import com.ruoyi.ai.conversation.service.IConversationsService;
import org.springframework.security.access.prepost.PreAuthorize; import com.ruoyi.ai.message.service.IChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai.conversation.domain.Conversations;
import com.ruoyi.ai.conversation.service.IConversationsService;
import com.ruoyi.ai.message.domain.ChatMessage;
import com.ruoyi.ai.message.service.IChatMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import java.util.HashMap; import com.ruoyi.common.enums.BusinessType;
import java.util.Map; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* RAG项目会话管理Controller * RAG项目会话管理Controller
@@ -40,7 +30,7 @@ public class ConversationsController extends BaseController
{ {
@Autowired @Autowired
private IConversationsService conversationsService; private IConversationsService conversationsService;
@Autowired @Autowired
private IChatMessageService chatMessageService; private IChatMessageService chatMessageService;

View File

@@ -1,11 +1,12 @@
package com.ruoyi.ai.conversation.domain; package com.ruoyi.ai.conversation.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
/** /**
* RAG项目会话管理对象 conversations * RAG项目会话管理对象 conversations

View File

@@ -1,19 +1,20 @@
package com.ruoyi.ai.conversation.mapper; package com.ruoyi.ai.conversation.mapper;
import java.util.List;
import com.ruoyi.ai.conversation.domain.Conversations; import com.ruoyi.ai.conversation.domain.Conversations;
import java.util.List;
/** /**
* RAG项目会话管理Mapper接口 * RAG项目会话管理Mapper接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-08-27 * @date 2025-08-27
*/ */
public interface ConversationsMapper public interface ConversationsMapper
{ {
/** /**
* 查询RAG项目会话管理 * 查询RAG项目会话管理
* *
* @param id RAG项目会话管理主键 * @param id RAG项目会话管理主键
* @return RAG项目会话管理 * @return RAG项目会话管理
*/ */
@@ -21,7 +22,7 @@ public interface ConversationsMapper
/** /**
* 查询RAG项目会话管理列表 * 查询RAG项目会话管理列表
* *
* @param conversations RAG项目会话管理 * @param conversations RAG项目会话管理
* @return RAG项目会话管理集合 * @return RAG项目会话管理集合
*/ */
@@ -29,7 +30,7 @@ public interface ConversationsMapper
/** /**
* 新增RAG项目会话管理 * 新增RAG项目会话管理
* *
* @param conversations RAG项目会话管理 * @param conversations RAG项目会话管理
* @return 结果 * @return 结果
*/ */
@@ -37,7 +38,7 @@ public interface ConversationsMapper
/** /**
* 修改RAG项目会话管理 * 修改RAG项目会话管理
* *
* @param conversations RAG项目会话管理 * @param conversations RAG项目会话管理
* @return 结果 * @return 结果
*/ */
@@ -45,7 +46,7 @@ public interface ConversationsMapper
/** /**
* 删除RAG项目会话管理 * 删除RAG项目会话管理
* *
* @param id RAG项目会话管理主键 * @param id RAG项目会话管理主键
* @return 结果 * @return 结果
*/ */
@@ -53,7 +54,7 @@ public interface ConversationsMapper
/** /**
* 批量删除RAG项目会话管理 * 批量删除RAG项目会话管理
* *
* @param ids 需要删除的数据主键集合 * @param ids 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */

View File

@@ -1,19 +1,20 @@
package com.ruoyi.ai.conversation.service; package com.ruoyi.ai.conversation.service;
import java.util.List;
import com.ruoyi.ai.conversation.domain.Conversations; import com.ruoyi.ai.conversation.domain.Conversations;
import java.util.List;
/** /**
* RAG项目会话管理Service接口 * RAG项目会话管理Service接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-08-27 * @date 2025-08-27
*/ */
public interface IConversationsService public interface IConversationsService
{ {
/** /**
* 查询RAG项目会话管理 * 查询RAG项目会话管理
* *
* @param id RAG项目会话管理主键 * @param id RAG项目会话管理主键
* @return RAG项目会话管理 * @return RAG项目会话管理
*/ */
@@ -21,7 +22,7 @@ public interface IConversationsService
/** /**
* 查询RAG项目会话管理列表 * 查询RAG项目会话管理列表
* *
* @param conversations RAG项目会话管理 * @param conversations RAG项目会话管理
* @return RAG项目会话管理集合 * @return RAG项目会话管理集合
*/ */
@@ -29,7 +30,7 @@ public interface IConversationsService
/** /**
* 新增RAG项目会话管理 * 新增RAG项目会话管理
* *
* @param conversations RAG项目会话管理 * @param conversations RAG项目会话管理
* @return 结果 * @return 结果
*/ */
@@ -37,7 +38,7 @@ public interface IConversationsService
/** /**
* 修改RAG项目会话管理 * 修改RAG项目会话管理
* *
* @param conversations RAG项目会话管理 * @param conversations RAG项目会话管理
* @return 结果 * @return 结果
*/ */
@@ -45,7 +46,7 @@ public interface IConversationsService
/** /**
* 批量删除RAG项目会话管理 * 批量删除RAG项目会话管理
* *
* @param ids 需要删除的RAG项目会话管理主键集合 * @param ids 需要删除的RAG项目会话管理主键集合
* @return 结果 * @return 结果
*/ */
@@ -53,7 +54,7 @@ public interface IConversationsService
/** /**
* 删除RAG项目会话管理信息 * 删除RAG项目会话管理信息
* *
* @param id RAG项目会话管理主键 * @param id RAG项目会话管理主键
* @return 结果 * @return 结果
*/ */

View File

@@ -1,15 +1,15 @@
package com.ruoyi.ai.conversation.service.impl; package com.ruoyi.ai.conversation.service.impl;
import java.util.Date;
import java.util.List;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import com.ruoyi.ai.conversation.domain.Conversations;
import com.ruoyi.ai.conversation.mapper.ConversationsMapper;
import com.ruoyi.ai.conversation.service.IConversationsService;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.ai.conversation.mapper.ConversationsMapper;
import com.ruoyi.ai.conversation.domain.Conversations; import java.util.Date;
import com.ruoyi.ai.conversation.service.IConversationsService; import java.util.List;
/** /**
* RAG项目会话管理Service业务层处理 * RAG项目会话管理Service业务层处理

View File

@@ -1,29 +1,23 @@
package com.ruoyi.ai.message.controller; package com.ruoyi.ai.message.controller;
import java.util.List; import com.ruoyi.ai.message.domain.ChatMessage;
import jakarta.servlet.http.HttpServletResponse; import com.ruoyi.ai.message.service.IChatMessageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai.message.domain.ChatMessage;
import com.ruoyi.ai.message.service.IChatMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 聊天消息Controller * 聊天消息Controller
* *
* @author ruoyi * @author ruoyi
* @date 2025-08-27 * @date 2025-08-27
*/ */

View File

@@ -1,14 +1,15 @@
package com.ruoyi.ai.message.domain; package com.ruoyi.ai.message.domain;
import java.math.BigDecimal;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
/** /**
* 聊天消息对象 chat_message * 聊天消息对象 chat_message
* *
* @author ruoyi * @author ruoyi
* @date 2025-08-27 * @date 2025-08-27
*/ */
@@ -51,92 +52,92 @@ public class ChatMessage extends BaseEntity
@Excel(name = "创建部门") @Excel(name = "创建部门")
private Long createDept; private Long createDept;
public void setId(Long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
} }
public Long getId() public Long getId()
{ {
return id; return id;
} }
public void setSessionId(Long sessionId) public void setSessionId(Long sessionId)
{ {
this.sessionId = sessionId; this.sessionId = sessionId;
} }
public Long getSessionId() public Long getSessionId()
{ {
return sessionId; return sessionId;
} }
public void setConversationId(Long conversationId) public void setConversationId(Long conversationId)
{ {
this.conversationId = conversationId; this.conversationId = conversationId;
} }
public Long getConversationId() public Long getConversationId()
{ {
return conversationId; return conversationId;
} }
public void setContent(String content) public void setContent(String content)
{ {
this.content = content; this.content = content;
} }
public String getContent() public String getContent()
{ {
return content; return content;
} }
public void setRole(String role) public void setRole(String role)
{ {
this.role = role; this.role = role;
} }
public String getRole() public String getRole()
{ {
return role; return role;
} }
public void setDeductCost(BigDecimal deductCost) public void setDeductCost(BigDecimal deductCost)
{ {
this.deductCost = deductCost; this.deductCost = deductCost;
} }
public BigDecimal getDeductCost() public BigDecimal getDeductCost()
{ {
return deductCost; return deductCost;
} }
public void setTotalTokens(Long totalTokens) public void setTotalTokens(Long totalTokens)
{ {
this.totalTokens = totalTokens; this.totalTokens = totalTokens;
} }
public Long getTotalTokens() public Long getTotalTokens()
{ {
return totalTokens; return totalTokens;
} }
public void setModelName(String modelName) public void setModelName(String modelName)
{ {
this.modelName = modelName; this.modelName = modelName;
} }
public String getModelName() public String getModelName()
{ {
return modelName; return modelName;
} }
public void setCreateDept(Long createDept) public void setCreateDept(Long createDept)
{ {
this.createDept = createDept; this.createDept = createDept;
} }
public Long getCreateDept() public Long getCreateDept()
{ {
return createDept; return createDept;
} }

View File

@@ -1,19 +1,20 @@
package com.ruoyi.ai.message.mapper; package com.ruoyi.ai.message.mapper;
import java.util.List;
import com.ruoyi.ai.message.domain.ChatMessage; import com.ruoyi.ai.message.domain.ChatMessage;
import java.util.List;
/** /**
* 聊天消息Mapper接口 * 聊天消息Mapper接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-08-27 * @date 2025-08-27
*/ */
public interface ChatMessageMapper public interface ChatMessageMapper
{ {
/** /**
* 查询聊天消息 * 查询聊天消息
* *
* @param id 聊天消息主键 * @param id 聊天消息主键
* @return 聊天消息 * @return 聊天消息
*/ */
@@ -21,7 +22,7 @@ public interface ChatMessageMapper
/** /**
* 查询聊天消息列表 * 查询聊天消息列表
* *
* @param chatMessage 聊天消息 * @param chatMessage 聊天消息
* @return 聊天消息集合 * @return 聊天消息集合
*/ */
@@ -29,7 +30,7 @@ public interface ChatMessageMapper
/** /**
* 新增聊天消息 * 新增聊天消息
* *
* @param chatMessage 聊天消息 * @param chatMessage 聊天消息
* @return 结果 * @return 结果
*/ */
@@ -37,7 +38,7 @@ public interface ChatMessageMapper
/** /**
* 修改聊天消息 * 修改聊天消息
* *
* @param chatMessage 聊天消息 * @param chatMessage 聊天消息
* @return 结果 * @return 结果
*/ */
@@ -45,7 +46,7 @@ public interface ChatMessageMapper
/** /**
* 删除聊天消息 * 删除聊天消息
* *
* @param id 聊天消息主键 * @param id 聊天消息主键
* @return 结果 * @return 结果
*/ */
@@ -53,7 +54,7 @@ public interface ChatMessageMapper
/** /**
* 批量删除聊天消息 * 批量删除聊天消息
* *
* @param ids 需要删除的数据主键集合 * @param ids 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */

View File

@@ -1,19 +1,20 @@
package com.ruoyi.ai.message.service; package com.ruoyi.ai.message.service;
import java.util.List;
import com.ruoyi.ai.message.domain.ChatMessage; import com.ruoyi.ai.message.domain.ChatMessage;
import java.util.List;
/** /**
* 聊天消息Service接口 * 聊天消息Service接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-08-27 * @date 2025-08-27
*/ */
public interface IChatMessageService public interface IChatMessageService
{ {
/** /**
* 查询聊天消息 * 查询聊天消息
* *
* @param id 聊天消息主键 * @param id 聊天消息主键
* @return 聊天消息 * @return 聊天消息
*/ */
@@ -21,7 +22,7 @@ public interface IChatMessageService
/** /**
* 查询聊天消息列表 * 查询聊天消息列表
* *
* @param chatMessage 聊天消息 * @param chatMessage 聊天消息
* @return 聊天消息集合 * @return 聊天消息集合
*/ */
@@ -29,7 +30,7 @@ public interface IChatMessageService
/** /**
* 新增聊天消息 * 新增聊天消息
* *
* @param chatMessage 聊天消息 * @param chatMessage 聊天消息
* @return 结果 * @return 结果
*/ */
@@ -37,7 +38,7 @@ public interface IChatMessageService
/** /**
* 修改聊天消息 * 修改聊天消息
* *
* @param chatMessage 聊天消息 * @param chatMessage 聊天消息
* @return 结果 * @return 结果
*/ */
@@ -45,7 +46,7 @@ public interface IChatMessageService
/** /**
* 批量删除聊天消息 * 批量删除聊天消息
* *
* @param ids 需要删除的聊天消息主键集合 * @param ids 需要删除的聊天消息主键集合
* @return 结果 * @return 结果
*/ */
@@ -53,7 +54,7 @@ public interface IChatMessageService
/** /**
* 删除聊天消息信息 * 删除聊天消息信息
* *
* @param id 聊天消息主键 * @param id 聊天消息主键
* @return 结果 * @return 结果
*/ */

View File

@@ -1,12 +1,13 @@
package com.ruoyi.ai.message.service.impl; package com.ruoyi.ai.message.service.impl;
import java.util.List; import com.ruoyi.ai.message.domain.ChatMessage;
import com.ruoyi.ai.message.mapper.ChatMessageMapper;
import com.ruoyi.ai.message.service.IChatMessageService;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.ai.message.mapper.ChatMessageMapper;
import com.ruoyi.ai.message.domain.ChatMessage; import java.util.List;
import com.ruoyi.ai.message.service.IChatMessageService;
/** /**
* 聊天消息Service业务层处理 * 聊天消息Service业务层处理

View File

@@ -1,29 +1,23 @@
package com.ruoyi.ai.vector.controller; package com.ruoyi.ai.vector.controller;
import java.util.List; import com.ruoyi.ai.vector.domain.KnowledgeFile;
import jakarta.servlet.http.HttpServletResponse; import com.ruoyi.ai.vector.service.IKnowledgeFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai.vector.domain.KnowledgeFile;
import com.ruoyi.ai.vector.service.IKnowledgeFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 知识库文件Controller * 知识库文件Controller
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-02 * @date 2025-09-02
*/ */

View File

@@ -1,15 +1,16 @@
package com.ruoyi.ai.vector.domain; package com.ruoyi.ai.vector.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
/** /**
* 知识库文件对象 knowledge_file * 知识库文件对象 knowledge_file
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-02 * @date 2025-09-02
*/ */
@@ -67,122 +68,122 @@ public class KnowledgeFile extends BaseEntity
@Excel(name = "是否可用") @Excel(name = "是否可用")
private Long isDeleted; private Long isDeleted;
public void setId(Long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
} }
public Long getId() public Long getId()
{ {
return id; return id;
} }
public void setKnowledgeBaseId(Long knowledgeBaseId) public void setKnowledgeBaseId(Long knowledgeBaseId)
{ {
this.knowledgeBaseId = knowledgeBaseId; this.knowledgeBaseId = knowledgeBaseId;
} }
public Long getKnowledgeBaseId() public Long getKnowledgeBaseId()
{ {
return knowledgeBaseId; return knowledgeBaseId;
} }
public void setFileName(String fileName) public void setFileName(String fileName)
{ {
this.fileName = fileName; this.fileName = fileName;
} }
public String getFileName() public String getFileName()
{ {
return fileName; return fileName;
} }
public void setFilePath(String filePath) public void setFilePath(String filePath)
{ {
this.filePath = filePath; this.filePath = filePath;
} }
public String getFilePath() public String getFilePath()
{ {
return filePath; return filePath;
} }
public void setFileSize(Long fileSize) public void setFileSize(Long fileSize)
{ {
this.fileSize = fileSize; this.fileSize = fileSize;
} }
public Long getFileSize() public Long getFileSize()
{ {
return fileSize; return fileSize;
} }
public void setFileType(String fileType) public void setFileType(String fileType)
{ {
this.fileType = fileType; this.fileType = fileType;
} }
public String getFileType() public String getFileType()
{ {
return fileType; return fileType;
} }
public void setDescription(String description) public void setDescription(String description)
{ {
this.description = description; this.description = description;
} }
public String getDescription() public String getDescription()
{ {
return description; return description;
} }
public void setIsVectorized(Long isVectorized) public void setIsVectorized(Long isVectorized)
{ {
this.isVectorized = isVectorized; this.isVectorized = isVectorized;
} }
public Long getIsVectorized() public Long getIsVectorized()
{ {
return isVectorized; return isVectorized;
} }
public void setVectorizedTime(Date vectorizedTime) public void setVectorizedTime(Date vectorizedTime)
{ {
this.vectorizedTime = vectorizedTime; this.vectorizedTime = vectorizedTime;
} }
public Date getVectorizedTime() public Date getVectorizedTime()
{ {
return vectorizedTime; return vectorizedTime;
} }
public void setUploadTime(Date uploadTime) public void setUploadTime(Date uploadTime)
{ {
this.uploadTime = uploadTime; this.uploadTime = uploadTime;
} }
public Date getUploadTime() public Date getUploadTime()
{ {
return uploadTime; return uploadTime;
} }
public void setUpdatedAt(Date updatedAt) public void setUpdatedAt(Date updatedAt)
{ {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
public Date getUpdatedAt() public Date getUpdatedAt()
{ {
return updatedAt; return updatedAt;
} }
public void setIsDeleted(Long isDeleted) public void setIsDeleted(Long isDeleted)
{ {
this.isDeleted = isDeleted; this.isDeleted = isDeleted;
} }
public Long getIsDeleted() public Long getIsDeleted()
{ {
return isDeleted; return isDeleted;
} }

View File

@@ -1,19 +1,20 @@
package com.ruoyi.ai.vector.mapper; package com.ruoyi.ai.vector.mapper;
import java.util.List;
import com.ruoyi.ai.vector.domain.KnowledgeFile; import com.ruoyi.ai.vector.domain.KnowledgeFile;
import java.util.List;
/** /**
* 知识库文件Mapper接口 * 知识库文件Mapper接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-02 * @date 2025-09-02
*/ */
public interface KnowledgeFileMapper public interface KnowledgeFileMapper
{ {
/** /**
* 查询知识库文件 * 查询知识库文件
* *
* @param id 知识库文件主键 * @param id 知识库文件主键
* @return 知识库文件 * @return 知识库文件
*/ */
@@ -21,7 +22,7 @@ public interface KnowledgeFileMapper
/** /**
* 查询知识库文件列表 * 查询知识库文件列表
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 知识库文件集合 * @return 知识库文件集合
*/ */
@@ -29,7 +30,7 @@ public interface KnowledgeFileMapper
/** /**
* 新增知识库文件 * 新增知识库文件
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 结果 * @return 结果
*/ */
@@ -37,7 +38,7 @@ public interface KnowledgeFileMapper
/** /**
* 修改知识库文件 * 修改知识库文件
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 结果 * @return 结果
*/ */
@@ -45,7 +46,7 @@ public interface KnowledgeFileMapper
/** /**
* 删除知识库文件 * 删除知识库文件
* *
* @param id 知识库文件主键 * @param id 知识库文件主键
* @return 结果 * @return 结果
*/ */
@@ -53,7 +54,7 @@ public interface KnowledgeFileMapper
/** /**
* 批量删除知识库文件 * 批量删除知识库文件
* *
* @param ids 需要删除的数据主键集合 * @param ids 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */

View File

@@ -14,7 +14,6 @@ import org.springframework.ai.reader.pdf.config.PdfDocumentReaderConfig;
import org.springframework.ai.reader.tika.TikaDocumentReader; import org.springframework.ai.reader.tika.TikaDocumentReader;
import org.springframework.ai.vectorstore.VectorStore; import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -24,7 +23,7 @@ import java.util.List;
@Service @Service
public class DataVectorService { public class DataVectorService {
@Autowired @Autowired(required = false)
private VectorStore vectorStore; private VectorStore vectorStore;
/** /**

View File

@@ -1,19 +1,20 @@
package com.ruoyi.ai.vector.service; package com.ruoyi.ai.vector.service;
import java.util.List;
import com.ruoyi.ai.vector.domain.KnowledgeFile; import com.ruoyi.ai.vector.domain.KnowledgeFile;
import java.util.List;
/** /**
* 知识库文件Service接口 * 知识库文件Service接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-02 * @date 2025-09-02
*/ */
public interface IKnowledgeFileService public interface IKnowledgeFileService
{ {
/** /**
* 查询知识库文件 * 查询知识库文件
* *
* @param id 知识库文件主键 * @param id 知识库文件主键
* @return 知识库文件 * @return 知识库文件
*/ */
@@ -21,7 +22,7 @@ public interface IKnowledgeFileService
/** /**
* 查询知识库文件列表 * 查询知识库文件列表
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 知识库文件集合 * @return 知识库文件集合
*/ */
@@ -29,7 +30,7 @@ public interface IKnowledgeFileService
/** /**
* 新增知识库文件 * 新增知识库文件
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 结果 * @return 结果
*/ */
@@ -37,7 +38,7 @@ public interface IKnowledgeFileService
/** /**
* 修改知识库文件 * 修改知识库文件
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 结果 * @return 结果
*/ */
@@ -45,7 +46,7 @@ public interface IKnowledgeFileService
/** /**
* 批量删除知识库文件 * 批量删除知识库文件
* *
* @param ids 需要删除的知识库文件主键集合 * @param ids 需要删除的知识库文件主键集合
* @return 结果 * @return 结果
*/ */
@@ -53,7 +54,7 @@ public interface IKnowledgeFileService
/** /**
* 删除知识库文件信息 * 删除知识库文件信息
* *
* @param id 知识库文件主键 * @param id 知识库文件主键
* @return 结果 * @return 结果
*/ */

View File

@@ -1,27 +1,28 @@
package com.ruoyi.ai.vector.service.impl; package com.ruoyi.ai.vector.service.impl;
import java.util.List; import com.ruoyi.ai.vector.domain.KnowledgeFile;
import com.ruoyi.ai.vector.mapper.KnowledgeFileMapper;
import com.ruoyi.ai.vector.service.IKnowledgeFileService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.ai.vector.mapper.KnowledgeFileMapper;
import com.ruoyi.ai.vector.domain.KnowledgeFile; import java.util.List;
import com.ruoyi.ai.vector.service.IKnowledgeFileService;
/** /**
* 知识库文件Service业务层处理 * 知识库文件Service业务层处理
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-02 * @date 2025-09-02
*/ */
@Service @Service
public class KnowledgeFileServiceImpl implements IKnowledgeFileService public class KnowledgeFileServiceImpl implements IKnowledgeFileService
{ {
@Autowired @Autowired
private KnowledgeFileMapper knowledgeFileMapper; private KnowledgeFileMapper knowledgeFileMapper;
/** /**
* 查询知识库文件 * 查询知识库文件
* *
* @param id 知识库文件主键 * @param id 知识库文件主键
* @return 知识库文件 * @return 知识库文件
*/ */
@@ -33,7 +34,7 @@ public class KnowledgeFileServiceImpl implements IKnowledgeFileService
/** /**
* 查询知识库文件列表 * 查询知识库文件列表
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 知识库文件 * @return 知识库文件
*/ */
@@ -45,7 +46,7 @@ public class KnowledgeFileServiceImpl implements IKnowledgeFileService
/** /**
* 新增知识库文件 * 新增知识库文件
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 结果 * @return 结果
*/ */
@@ -57,7 +58,7 @@ public class KnowledgeFileServiceImpl implements IKnowledgeFileService
/** /**
* 修改知识库文件 * 修改知识库文件
* *
* @param knowledgeFile 知识库文件 * @param knowledgeFile 知识库文件
* @return 结果 * @return 结果
*/ */
@@ -69,7 +70,7 @@ public class KnowledgeFileServiceImpl implements IKnowledgeFileService
/** /**
* 批量删除知识库文件 * 批量删除知识库文件
* *
* @param ids 需要删除的知识库文件主键 * @param ids 需要删除的知识库文件主键
* @return 结果 * @return 结果
*/ */
@@ -81,7 +82,7 @@ public class KnowledgeFileServiceImpl implements IKnowledgeFileService
/** /**
* 删除知识库文件信息 * 删除知识库文件信息
* *
* @param id 知识库文件主键 * @param id 知识库文件主键
* @return 结果 * @return 结果
*/ */

View File

@@ -5,15 +5,15 @@ import com.ruoyi.out.productAndStock.domain.ViewProductAndStock;
/** /**
* 库存物资Service接口 * 库存物资Service接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-12 * @date 2025-09-12
*/ */
public interface IViewProductAndStockService public interface IViewProductAndStockService
{ {
/** /**
* 查询库存物资 * 查询库存物资
* *
* @param onlyIdentity 库存物资主键 * @param onlyIdentity 库存物资主键
* @return 库存物资 * @return 库存物资
*/ */
@@ -21,7 +21,7 @@ public interface IViewProductAndStockService
/** /**
* 查询库存物资列表 * 查询库存物资列表
* *
* @param viewProductAndStock 库存物资 * @param viewProductAndStock 库存物资
* @return 库存物资集合 * @return 库存物资集合
*/ */
@@ -29,7 +29,7 @@ public interface IViewProductAndStockService
/** /**
* 新增库存物资 * 新增库存物资
* *
* @param viewProductAndStock 库存物资 * @param viewProductAndStock 库存物资
* @return 结果 * @return 结果
*/ */
@@ -37,7 +37,7 @@ public interface IViewProductAndStockService
/** /**
* 修改库存物资 * 修改库存物资
* *
* @param viewProductAndStock 库存物资 * @param viewProductAndStock 库存物资
* @return 结果 * @return 结果
*/ */
@@ -45,7 +45,7 @@ public interface IViewProductAndStockService
/** /**
* 批量删除库存物资 * 批量删除库存物资
* *
* @param onlyIdentitys 需要删除的库存物资主键集合 * @param onlyIdentitys 需要删除的库存物资主键集合
* @return 结果 * @return 结果
*/ */
@@ -53,7 +53,7 @@ public interface IViewProductAndStockService
/** /**
* 删除库存物资信息 * 删除库存物资信息
* *
* @param onlyIdentity 库存物资主键 * @param onlyIdentity 库存物资主键
* @return 结果 * @return 结果
*/ */

View File

@@ -92,6 +92,7 @@ spring:
max-wait: -1ms max-wait: -1ms
ai: ai:
enable: false
openai: openai:
api-key: sk-dzftrybcpjujsjgehjgtsjzjuhqxciosldcncjtlazxvjams # 密钥key api-key: sk-dzftrybcpjujsjgehjgtsjzjuhqxciosldcncjtlazxvjams # 密钥key
base-url: https://api.siliconflow.cn # 产商地址 base-url: https://api.siliconflow.cn # 产商地址
@@ -120,9 +121,9 @@ spring:
#向量数据库 #向量数据库
vectorstore: vectorstore:
mariadb: mariadb:
initialize-schema: true initialize-schema: truea
distance-type: COSINE distance-type: COSINEa
dimensions: 1024 dimensions: 1024a
# token配置 # token配置