Explorar o código

项目兼容达梦数据库

Gaokun Wang hai 5 meses
pai
achega
501c6d3e67

+ 5 - 2
eco-ai/ai-text-sql-biz/src/main/java/org/eco/vip/ai/text2sql/mapper/Text2SqlMapper.java

@@ -26,11 +26,14 @@ public interface Text2SqlMapper {
     List<Map<String, Object>> executeSql(@Param("sqlText") String sqlText);
 
     @Select("show create table ${tableName} ")
-    Map<String, String> selectTableDdl(@Param("tableName") String tableName);
+    Map<String, String> selectTableDdlByMysql(@Param("tableName") String tableName);
+
+    @Select("select convert(varchar(5000), dbms_metadata.get_ddl('TABLE','${tableName}','${schema}')) as \"create table\" from dual")
+    Map<String, String> selectTableDdlDm(@Param("schema") String schema, @Param("tableName") String tableName);
 
     @Select("select column_name as name, column_comment as comment  from information_schema.COLUMNS where table_schema = #{schema} and table_name = #{tableName}")
     List<CommentVo> selectCommentsByMysql(@Param("schema") String schema, @Param("tableName") String tableName);
 
-    @Select("select column_name as name, comments as comment  from USER_COL_COMMENTS where OWNER = #{schema} and TABLE_NAME = #{tableName}")
+    @Select("select column_name as name, comments as \"comment\"  from USER_COL_COMMENTS where OWNER = #{schema} and TABLE_NAME = #{tableName}")
     List<CommentVo> selectCommentsByDm(@Param("schema") String schema, @Param("tableName") String tableName);
 }

+ 13 - 5
eco-ai/ai-text-sql-biz/src/main/java/org/eco/vip/ai/text2sql/service/Text2SqlService.java

@@ -25,9 +25,8 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * @description Text2SqlService
- *
  * @author GaoKunW
+ * @description Text2SqlService
  * @date 2025/3/12 10:54
  */
 @Slf4j
@@ -88,16 +87,25 @@ public class Text2SqlService implements IText2SqlService {
             return new JSONArray().put("只支持查询");
         }
         List<Map<String, Object>> mapList = text2SqlMapper.executeSql(sql);
-        List<CommentVo> tableNames = this.commentByTableName("eco-boot", question.getTableName());
+        List<CommentVo> tableNames = this.commentByTableName(DataBaseHelper.getSchema(), question.getTableName());
         return this.getCommentData(mapList, tableNames);
     }
 
     @Override
     public ContentVo getQuestion(String question) {
         String tableName = this.tableNameByNl(question);
-        Map<String, String> map = text2SqlMapper.selectTableDdl(tableName);
+        Map<String, String> map = Collections.emptyMap();
+        if (DataBaseHelper.isMySql()) {
+            map = text2SqlMapper.selectTableDdlByMysql(tableName);
+        } else if (DataBaseHelper.isDmSql()) {
+            map = text2SqlMapper.selectTableDdlDm(DataBaseHelper.getSchema(), tableName);
+        }
         String ddl = map.get("create table");
-        return ContentVo.builder().content(ddl + "\n" + question + ",根据需求生成Mysql的查询SQL,不要需求外的条件,只输出sql语句不需要任何格式样式,就是一串sql").tableName(tableName).build();
+        return ContentVo.builder().content(ddl + "\n" + question + ",根据需求生成Mysql的查询SQL.\n" +
+                        "1.不要需求外的条件.\n" +
+                        "2.只输出sql语句不需要任何格式样式,就是一串sql.\n" +
+                        "3.不需要带Schema:" + DataBaseHelper.getSchema()).
+                tableName(tableName).build();
 
     }
 

+ 9 - 0
eco-bom/pom.xml

@@ -30,6 +30,7 @@
         <deepseek4j.version>1.4.5</deepseek4j.version>
         <milvus.version>2.3.5</milvus.version>
         <jsqlparser.version>5.1</jsqlparser.version>
+        <DmJdbcDriver18.version>8.1.3.140</DmJdbcDriver18.version>
     </properties>
 
     <!-- 全局的依赖配置-->
@@ -134,6 +135,14 @@
                 <version>${jsqlparser.version}</version>
             </dependency>
 
+            <!-- https://mvnrepository.com/artifact/com.dameng/DmJdbcDriver18 -->
+            <dependency>
+                <groupId>com.dameng</groupId>
+                <artifactId>DmJdbcDriver18</artifactId>
+                <version>${DmJdbcDriver18.version}</version>
+            </dependency>
+
+
         </dependencies>
     </dependencyManagement>
 

+ 6 - 0
eco-common/com-core/pom.xml

@@ -40,6 +40,12 @@
             <artifactId>hutool-all</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.dameng</groupId>
+            <artifactId>DmJdbcDriver18</artifactId>
+        </dependency>
+
+
         <!-- JSON工具类 -->
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>

+ 15 - 0
eco-common/com-orm/src/main/java/org/eco/vip/orm/utils/DataBaseHelper.java

@@ -8,12 +8,16 @@ package org.eco.vip.orm.utils;
 
 import com.mybatisflex.core.FlexGlobalConfig;
 import com.mybatisflex.core.dialect.DbType;
+import lombok.extern.slf4j.Slf4j;
+
+import java.sql.SQLException;
 
 /**
  * @author GaoKunW
  * @description DataBaseHelper
  * @date 2025/3/16 03:28
  */
+@Slf4j
 public class DataBaseHelper {
     public static boolean isMySql() {
         return DbType.MYSQL == FlexGlobalConfig.getDefaultConfig().getDbType();
@@ -22,4 +26,15 @@ public class DataBaseHelper {
     public static boolean isDmSql() {
         return DbType.DM == FlexGlobalConfig.getDefaultConfig().getDbType();
     }
+
+    public static String getSchema() {
+        try {
+            return FlexGlobalConfig.getDefaultConfig().getDataSource().getConnection().getSchema();
+        } catch (SQLException e) {
+            log.error(e.getMessage());
+        }
+        return null;
+    }
+
+
 }

+ 10 - 4
eco-start/src/main/resources/application-local.yml

@@ -12,10 +12,16 @@ mybatis-flex:
     # 数据源1
     ds1:
       type: ${spring.datasource.type}
-      driver-class-name: com.mysql.cj.jdbc.Driver
-      url: jdbc:mysql://localhost:3306/eco-boot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
-      username: root
-      password: root123
+      # MySql
+#      driver-class-name: com.mysql.cj.jdbc.Driver
+#      url: jdbc:mysql://localhost:3306/eco-boot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
+#      username: root
+#      password: root123
+      #DM8数据库
+      driver-class-name: dm.jdbc.driver.DmDriver
+      url: jdbc:dm://127.0.0.1:5236?schema=eco-boot&useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
+      username: SYSDBA
+      password: SYSdba123
       # 最大连接池数量
       maximum-pool-size: 20
       # 最小空闲线程数量