|
|
@@ -1,5 +1,8 @@
|
|
|
package com.siwei.apply.utils;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.alibaba.fastjson2.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.siwei.apply.domain.NodeAttachment;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
@@ -32,9 +35,10 @@ public class ServiceUtil {
|
|
|
|
|
|
public static final String THIRD_API_DOMAIN = "http://10.224.1.228:10001";
|
|
|
public static final String THIRD_API_BASE_URL = "/dsp-register-server/dspRegisterService/proxyService/proxyThirdPlatformService";
|
|
|
- protected static final Logger logger = LoggerFactory.getLogger(ServiceUtil.class);
|
|
|
|
|
|
+ public static final String ES_API_URL = "http://192.168.60.2:9288/search/getDocByWord";
|
|
|
|
|
|
+ protected static final Logger logger = LoggerFactory.getLogger(ServiceUtil.class);
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -243,4 +247,45 @@ public class ServiceUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 使用HttpClient 获取es查询数据
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static String[] getElasticsearchResultByWord(String keyWord) throws Exception {
|
|
|
+ String url = ES_API_URL;
|
|
|
+ Map<String, Object> dataMap = new HashMap<>(4);
|
|
|
+ dataMap.put("keyWord", keyWord);
|
|
|
+ String resp = HttpClientUtil.doGet(url, dataMap);
|
|
|
+ if (resp == null) {
|
|
|
+ logger.error("ES查询返回响应为空");
|
|
|
+ return new String[0];
|
|
|
+ }
|
|
|
+ JSONObject root = JSON.parseObject(resp);
|
|
|
+ logger.error("ES查询返回结果为: {} ", root);
|
|
|
+ if (Objects.nonNull(root) && root.containsKey("code") && root.getInteger("code") == 200) {
|
|
|
+ JSONObject innerData = root.getJSONObject("data");
|
|
|
+ String resJsonStr = innerData.getString("res");
|
|
|
+ // 先解析为 List<String>
|
|
|
+ List<String> list = JSON.parseObject(resJsonStr, new TypeReference<List<String>>() {});
|
|
|
+ if (list == null) {
|
|
|
+ return new String[0];
|
|
|
+ }
|
|
|
+ // List转String数组
|
|
|
+ return list.toArray(new String[0]);
|
|
|
+ } else {
|
|
|
+ logger.error("ES查询失败,响应原文:{} ", resp);
|
|
|
+ return new String[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ List lll = List.of(getElasticsearchResultByWord("不动产登记"));
|
|
|
+ logger.info("end result:{} ", lll);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|