feat(oa): 添加AI数据查询功能
- 新增AI数据查询接口和相关服务 - 实现关键词匹配和AI智能识别表功能 - 添加SQL生成和执行逻辑 - 新增动态数据返回格式和字段信息类 - 优化SQL安全性验证
This commit is contained in:
@@ -26,8 +26,10 @@ import com.ruoyi.oa.domain.bo.SysOaAiMessageBo;
|
||||
import com.ruoyi.oa.service.ISysOaAiConversationService;
|
||||
import com.ruoyi.oa.service.ISysOaAiMessageService;
|
||||
import com.ruoyi.oa.service.ISysOaAiConfigService;
|
||||
import com.ruoyi.oa.service.IAiDataQueryService;
|
||||
import com.ruoyi.oa.utils.AiServiceUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* AI对话管理
|
||||
@@ -39,12 +41,14 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/oa/ai")
|
||||
@Slf4j
|
||||
public class SysOaAiController extends BaseController {
|
||||
|
||||
private final ISysOaAiConversationService conversationService;
|
||||
private final ISysOaAiMessageService messageService;
|
||||
private final ISysOaAiConfigService configService;
|
||||
private final AiServiceUtil aiServiceUtil;
|
||||
private final IAiDataQueryService aiDataQueryService;
|
||||
|
||||
/**
|
||||
* 查询AI对话历史列表
|
||||
@@ -275,4 +279,39 @@ public class SysOaAiController extends BaseController {
|
||||
private String callAiService(String message) {
|
||||
return aiServiceUtil.callDeepSeek(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* AI数据查询接口
|
||||
* 根据用户自然语言描述查询数据库数据
|
||||
*/
|
||||
@PostMapping("/data-query")
|
||||
public R<com.ruoyi.oa.domain.vo.DynamicDataVo> queryDataByAi(@Validated @RequestBody com.ruoyi.oa.domain.bo.OaAiDataQueryBo queryBo) {
|
||||
try {
|
||||
com.ruoyi.oa.domain.vo.DynamicDataVo result = aiDataQueryService.queryDataByAi(queryBo);
|
||||
return R.ok(result);
|
||||
} catch (Exception e) {
|
||||
log.error("AI数据查询失败", e);
|
||||
return R.fail("AI数据查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关键词匹配相关表
|
||||
*/
|
||||
@PostMapping("/match-tables")
|
||||
public R<java.util.List<String>> matchTablesByKeywords(@RequestBody java.util.Map<String, String[]> request) {
|
||||
try {
|
||||
String[] keywords = request.get("keywords");
|
||||
if (keywords == null || keywords.length == 0) {
|
||||
return R.fail("关键词不能为空");
|
||||
}
|
||||
java.util.List<String> matchedTables = aiDataQueryService.matchTablesByKeywords(keywords);
|
||||
return R.ok(matchedTables);
|
||||
} catch (Exception e) {
|
||||
log.error("表匹配失败", e);
|
||||
return R.fail("表匹配失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user