|
@@ -0,0 +1,62 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2025 GaoKunW
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+package org.eco.vip.ai.text2sql.service;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.eco.vip.ai.text2sql.domain.CommentVo;
|
|
|
+import org.eco.vip.ai.text2sql.mapper.Text2SqlMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description Text2SqlService
|
|
|
+ *
|
|
|
+ * @author GaoKunW
|
|
|
+ * @date 2025/3/12 10:54
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class Text2SqlService implements IText2SqlService {
|
|
|
+ @Resource
|
|
|
+ private Text2SqlMapper text2SqlMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> executeSql(String sql) {
|
|
|
+ return text2SqlMapper.executeSql(sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> tableNameByNl(String sql) {
|
|
|
+ return text2SqlMapper.executeSql(sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CommentVo> commentByTableName(String schema, String tableName) {
|
|
|
+ return text2SqlMapper.selectCommentsByMysql(schema, tableName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONArray getCommentData(String question) {
|
|
|
+ List<Map<String, Object>> mapList = text2SqlMapper.executeSql("select * from sys_user");
|
|
|
+ List<CommentVo> tableNames = text2SqlMapper.selectCommentsByMysql("eco-boot", "sys_user");
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ Map<String, Object> commentMap = new HashMap<>();
|
|
|
+ for (Map<String, Object> map : mapList) {
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ CommentVo commentVo = CollUtil.findOne(tableNames, tableName -> StrUtil.equals(StrUtil.toCamelCase(tableName.getName()), key));
|
|
|
+ commentMap.put(commentVo.getComment(), map.get(key));
|
|
|
+ }
|
|
|
+ jsonArray.add(commentMap);
|
|
|
+ }
|
|
|
+ return jsonArray;
|
|
|
+ }
|
|
|
+}
|