suerprisePlus
2024-09-09 623cee8be4846e5762ff2949e519335ef8dee2bb
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.yb.service;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yb.config.XzConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
 
@Service
public class IntentionService {
    @Autowired
    private XzConfig xzConfig;
    @Autowired
    private AgentService agentService;
    @Autowired
    private XzService xzService;
 
    public HashMap<String, Object> getFunctionMatch(String orderString) throws Exception {
        HashMap<String, Object> mapObj = new HashMap<String, Object>();
        JSONObject orderObject = JSON.parseObject(orderString);
        String func = orderObject.getString("name");
 
        if (func.equals(xzConfig.funcName[0])) {
            mapObj = getPoiMap(orderObject, xzConfig.funcName[0]);
        } else if (func.equals(xzConfig.funcName[1])) {
            mapObj = getAroundPoi(orderObject, xzConfig.funcName[1]);
        } else if (func.equals(xzConfig.funcName[2])) {
            mapObj = getQueryMeta(orderObject, xzConfig.funcName[2]);
        } else if (func.equals(xzConfig.funcName[2])) {
            mapObj = getQueryMeta(orderObject, xzConfig.funcName[2]);
        } else if (func.equals(xzConfig.funcName[3])) {
            mapObj = getQueryRelationship(orderObject, xzConfig.funcName[3]);
        }
 
 
        return mapObj;
 
    }
 
    //查看某个区域内各个实体/对象之间的关系
    private HashMap<String, Object> getQueryRelationship(JSONObject orderObject, String func) throws Exception {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("func", func);
        JSONObject argsObject = JSON.parseObject(orderObject.getString("args"));
        String place = argsObject.getString("place");
        HashMap<String,Object> poiMap = agentService.getQueryRelationship(place, xzConfig.queryFiled);
        hashMap.put("data", poiMap);
        return hashMap;
    }
 
    //查询数据统计
    private HashMap<String, Object> getQueryMeta(JSONObject orderObject, String func) throws Exception {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("func", func);
        String filedString = xzService.getQueryMeta(xzConfig.layerId, xzConfig.dbid, xzConfig.typeFiled, xzConfig.queryEntity);
        JSONObject metaObject = JSON.parseObject(filedString);
        JSONArray dataArray = metaObject.getJSONArray("data");
        String markDown = "| 数据类型 | 数据量 |\n|------|------|\n";
        for (int i = 0; i < dataArray.size(); i++) {
            JSONObject dataObj = dataArray.getJSONObject(i);
            System.out.println("rec queryMeta:" + dataObj);
            String[] filedValue = new String[2];
 
            for (String key : dataObj.keySet()) {
                System.out.println("rec 1:" + key+":"+xzConfig.typeFiled);
                 String itemObj = dataObj.getString(key);
                System.out.println("rec 2:" +itemObj);
 
                if (key.equals(xzConfig.typeFiled) ) {
                    filedValue[0] = dataObj.getString(key);
                }else{
                    filedValue[1] = dataObj.getString(key);
                }
 
            }
            markDown += "| " + filedValue[0] + " | " + filedValue[1] + " |\n";
 
        }
        hashMap.put("data", markDown);
        return hashMap;
 
    }
 
    //根据范围查询数据
    private HashMap<String, Object> getAroundPoi(JSONObject orderString, String func) throws Exception {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("func", func);
        JSONObject argsObject = JSON.parseObject(orderString.getString("args"));
        String place = argsObject.getString("place");
        String type = argsObject.getString("attris");
        String dis = argsObject.getString("redius");
        int radius = 5000;
        if (dis != null) {
            dis = dis.replace("m", "");
            radius = Integer.parseInt(dis);
        }
        String aroundPoi = agentService.getAgentAroundPoi(place, type, radius, xzConfig.queryFiled, xzConfig.typeFiled);
        JSONArray dataArray = JSONArray.parseArray(aroundPoi);
        System.out.println("aroundPoi: " + dataArray);
        hashMap.put("data", dataArray);
        return hashMap;
 
    }
 
    //查询点位
    public HashMap<String, Object> getPoiMap(JSONObject orderString, String func) throws Exception {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        JSONObject argsObject = JSON.parseObject(orderString.getString("args"));
        String place = argsObject.getString("place");
        String poiMap = agentService.getAgentPoiMap(place, xzConfig.queryFiled);
        System.out.println("poiMap: " + poiMap);
        JSONObject poiObj = JSONObject.parseObject(poiMap);
        System.out.println("poiMap: " + poiObj);
        hashMap.put("func", func);
        hashMap.put("data", poiObj);
        return hashMap;
    }
 
 
}