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