提交 | 用户 | age
|
9e1c8d
|
1 |
package com.hx.other.service.util; |
G |
2 |
|
|
3 |
import com.alibaba.fastjson.JSONObject; |
|
4 |
import com.hx.other.service.api.ai.SqlAiApi; |
|
5 |
import lombok.extern.slf4j.Slf4j; |
|
6 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
7 |
|
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
|
|
11 |
/** |
|
12 |
* ai查询工具类 |
|
13 |
* @Author: cmg |
|
14 |
* @Date: 2023/4/23 11:01 |
|
15 |
*/ |
|
16 |
@Slf4j |
|
17 |
public class AiQueryUtil { |
|
18 |
|
|
19 |
/** |
|
20 |
* ai查询 |
|
21 |
* @param sqlAiApi |
|
22 |
* @param obj |
|
23 |
* @return |
|
24 |
*/ |
|
25 |
public static JSONObject aiQuery(SqlAiApi sqlAiApi, JSONObject obj) |
|
26 |
{ |
|
27 |
try{ |
|
28 |
return sqlAiApi.getSqlShort(obj.toJSONString()); |
|
29 |
}catch (Exception e) |
|
30 |
{ |
|
31 |
log.error("调用ai接口出错", obj.toJSONString(), e.getMessage()); |
|
32 |
return null; |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* jdbc查询 |
|
38 |
* @param jdbcTemplate |
|
39 |
* @param sql |
|
40 |
* @return |
|
41 |
*/ |
|
42 |
public static List<Map<String, Object>> jdbcQuery(JdbcTemplate jdbcTemplate, String sql) |
|
43 |
{ |
|
44 |
try{ |
|
45 |
return jdbcTemplate.queryForList(sql); |
|
46 |
}catch (Exception e) |
|
47 |
{ |
|
48 |
log.error("sql查询出错", sql, e.getMessage()); |
|
49 |
return null; |
|
50 |
} |
|
51 |
} |
|
52 |
} |