|
|
@@ -1,91 +0,0 @@
|
|
|
-package org.ruoyi.mcpserve.service.impl;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
-import org.ruoyi.mcpserve.entity.McpTool;
|
|
|
-import org.ruoyi.mcpserve.entity.ThinkMcp;
|
|
|
-import org.ruoyi.mcpserve.entity.ToolSchema;
|
|
|
-import org.ruoyi.mcpserve.mapper.McpToolMapper;
|
|
|
-import org.ruoyi.mcpserve.mapper.ThinkMcpMapper;
|
|
|
-import org.ruoyi.mcpserve.service.McpToolService;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-@Service
|
|
|
-public class McpToolServiceImpl implements McpToolService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private McpToolMapper mcpToolMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ThinkMcpMapper thinkMcpMapper;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void saveToolSchema(ToolSchema ts) {
|
|
|
- McpTool e = new McpTool();
|
|
|
- e.setName(ts.getName());
|
|
|
- e.setDescription(ts.getDescription());
|
|
|
- e.setSchemaJson(ts.getSchema());
|
|
|
- e.setEnabled(1);
|
|
|
- mcpToolMapper.insert(e);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<ToolSchema> loadEnabledToolSchemas() {
|
|
|
- return mcpToolMapper.selectList(
|
|
|
- new LambdaQueryChainWrapper<>(mcpToolMapper)
|
|
|
- .eq(McpTool::getEnabled, 1)
|
|
|
- ).stream()
|
|
|
- .map(e -> new ToolSchema(e.getName(), e.getDescription(), e.getSchemaJson()))
|
|
|
- .toList();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public McpTool getMcpData(McpTool mcpTool) {
|
|
|
- try {
|
|
|
- return new LambdaQueryChainWrapper<>(mcpToolMapper)
|
|
|
- .eq(McpTool::getEnabled, 1)
|
|
|
- .eq(McpTool::getName, mcpTool.getName())
|
|
|
- .list()
|
|
|
- .stream()
|
|
|
- .findFirst()
|
|
|
- .orElse(null);
|
|
|
- } catch (Exception e) {
|
|
|
- // 如果是表不存在的异常,可以判断异常类型或内容
|
|
|
- if (e.getCause() instanceof java.sql.SQLSyntaxErrorException) {
|
|
|
- String msg = e.getCause().getMessage();
|
|
|
- if (msg != null && msg.contains("doesn't exist")) {
|
|
|
- // 表不存在,返回空
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- throw e; // 其他异常继续抛出
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ThinkMcp getThinkMcpData(ThinkMcp thinkMcp) {
|
|
|
- try {
|
|
|
- return new LambdaQueryChainWrapper<>(thinkMcpMapper)
|
|
|
- .eq(ThinkMcp::getState, 1)
|
|
|
- .eq(ThinkMcp::getMcp, thinkMcp.getMcp())
|
|
|
- .list()
|
|
|
- .stream()
|
|
|
- .findFirst()
|
|
|
- .orElse(null);
|
|
|
- } catch (Exception e) {
|
|
|
- // 如果是表不存在的异常,可以判断异常类型或内容
|
|
|
- if (e.getCause() instanceof java.sql.SQLSyntaxErrorException) {
|
|
|
- String msg = e.getCause().getMessage();
|
|
|
- if (msg != null && msg.contains("doesn't exist")) {
|
|
|
- // 表不存在,返回空
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- throw e; // 其他异常继续抛出
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|