|
@@ -91,11 +91,22 @@ public class Text2SqlService implements IText2SqlService {
|
|
|
log.info("\n模型返回的SQL:\n{}", question.getContent());
|
|
|
String sql = cleanRawSql(question.getContent());
|
|
|
if (!SqlValidator.isSelectQuery(sql)) {
|
|
|
- return new JSONArray().put("只支持查询");
|
|
|
+ return null;
|
|
|
}
|
|
|
- List<Map<String, Object>> mapList = SpringUtil.getBean(Text2SqlService.class).executeSql(sql);
|
|
|
- List<CommentVo> tableNames = SpringUtil.getBean(Text2SqlService.class).commentByTableName(DBaseHelper.getSchema(), question.getTableName());
|
|
|
- return SpringUtil.getBean(Text2SqlService.class).getCommentData(mapList, tableNames);
|
|
|
+ List<Map<String, Object>> mapList;
|
|
|
+ List<CommentVo> tableNames;
|
|
|
+ try {
|
|
|
+ mapList = SpringUtil.getBean(Text2SqlService.class).executeSql(sql);
|
|
|
+ tableNames = SpringUtil.getBean(Text2SqlService.class).commentByTableName(DBaseHelper.getSchema(), question.getTableName());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (mapList != null) {
|
|
|
+ return SpringUtil.getBean(Text2SqlService.class).getCommentData(mapList, tableNames);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -110,10 +121,9 @@ public class Text2SqlService implements IText2SqlService {
|
|
|
}
|
|
|
String ddl = map.get("create table");
|
|
|
question= ddl + "\n" + question + ",根据需求生成" + DBaseHelper.getDbType() + "的查询SQL.\n" +
|
|
|
- "1.不要需求外的条件.\n" +
|
|
|
+ "1.严格按照要求,select 后面字段严格按照ddl表结构里面的给出,from 后面的条件不要自己发挥\n" +
|
|
|
"2.只输出sql语句不需要任何格式样式,就是一串sql.\n" +
|
|
|
- "3.字段严格按照ddl表结构里面的给出.\n" +
|
|
|
- "4.不需要带Schema:" + DBaseHelper.getSchema();
|
|
|
+ "3.不需要带Schema:" + DBaseHelper.getSchema();
|
|
|
log.info("\nquestion ____________________:\n{}", question);
|
|
|
return ContentVo.builder().content(question).
|
|
|
tableName(tableName).build();
|