kouchengxing 4 лет назад
Родитель
Сommit
b533c946e7

+ 25 - 16
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/api/CustomerApiController.java

@@ -8,8 +8,12 @@ import com.arronlong.httpclientutil.common.HttpConfig;
 import com.arronlong.httpclientutil.exception.HttpProcessException;
 import com.dgtis.common.core.utils.DateUtils;
 import com.dgtis.common.core.web.domain.AjaxResult;
+import org.apache.http.util.EntityUtils;
+import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -31,19 +35,19 @@ import java.util.Map;
 public class CustomerApiController {
 
     private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class);
-
-    @Value("${elasticsearch.host}")
-    private String host;
-    @Value("${elasticsearch.port}")
-    private String port;
-
+    @Autowired
+    private RestClient restClient;
     @GetMapping("/getCustomerList")
     @ResponseBody
     public AjaxResult getCustomerList(int pageNum,int pageSize) {
         // 获取索引的别名,字段,创建时间
-        HttpConfig config = HttpConfig.custom().url("http://"+host+":"+port+"/shanglifeecif.individual/_search?from="+pageNum+"&size="+pageSize);
         try {
-            String result = HttpClientUtil.get(config);
+            Map<String, String> paramMap = new HashMap<String, String>();
+            paramMap.put("pretty", "true");
+            paramMap.put("from", pageNum+"");
+            paramMap.put("size", pageSize+"");
+            Response response = restClient.performRequest("GET", "shanglifeecif.individual/_search?", paramMap);
+            String result = EntityUtils.toString(response.getEntity());
             JSONObject jsonObject = JSON.parseObject(result);
             JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
             JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
@@ -64,7 +68,7 @@ public class CustomerApiController {
             map.put("total",total);
 
             return AjaxResult.success(map);
-        } catch (HttpProcessException e) {
+        } catch (Exception e) {
             e.printStackTrace();
             return AjaxResult.error();
         }
@@ -74,10 +78,13 @@ public class CustomerApiController {
     @ResponseBody
     public AjaxResult getCustomerById(String id) {
         // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
-        HttpConfig config = HttpConfig.custom().url("http://"+host+":"+port+"/shanglifeecif.individual/default_type_/"+id);
-        try {
+      try {
+
+            Map<String, String> paramMap = new HashMap<String, String>();
+            paramMap.put("pretty", "true");
+            Response response = restClient.performRequest("GET", "shanglifeecif.individual/default_type_/"+id, paramMap);
+            String result = EntityUtils.toString(response.getEntity());
             Map map = new HashMap();
-            String result = HttpClientUtil.get(config);
             JSONObject jsonObject = JSON.parseObject(result);
             Map mpInfo = new HashMap();
             mpInfo.put("id",jsonObject.getString("_id"));
@@ -93,7 +100,7 @@ public class CustomerApiController {
             map.put("custInfo7",null);
             map.put("custInfo8",null);
             return AjaxResult.success(map);
-        } catch (HttpProcessException e) {
+        } catch (Exception e) {
             e.printStackTrace();
             return AjaxResult.error();
         }
@@ -103,10 +110,12 @@ public class CustomerApiController {
     @ResponseBody
     public AjaxResult getCustomerOverViewById(String id) {
         // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
-        HttpConfig config = HttpConfig.custom().url("http://"+host+":"+port+"/shanglifeecif.individual/default_type_/"+id);
         try {
+            Map<String, String> paramMap = new HashMap<String, String>();
+            paramMap.put("pretty", "true");
+            Response response = restClient.performRequest("GET", "shanglifeecif.individual/default_type_/"+id, paramMap);
+            String result = EntityUtils.toString(response.getEntity());
             Map map = new HashMap();
-            String result = HttpClientUtil.get(config);
             JSONObject jsonObject = JSON.parseObject(result);
             Map mpInfo = new HashMap();
             mpInfo.put("id",jsonObject.getString("_id"));
@@ -114,7 +123,7 @@ public class CustomerApiController {
             mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday")));
             map.put("custInfo",mpInfo);
             return AjaxResult.success(map);
-        } catch (HttpProcessException e) {
+        } catch (Exception e) {
             e.printStackTrace();
             return AjaxResult.error();
         }

+ 21 - 26
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/api/IndexApiController.java

@@ -8,6 +8,10 @@ import com.arronlong.httpclientutil.common.HttpConfig;
 import com.dgtis.common.core.utils.StringUtils;
 import com.dgtis.common.core.web.controller.BaseController;
 import com.dgtis.common.core.web.domain.AjaxResult;
+import org.apache.http.util.EntityUtils;
+import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -33,24 +37,23 @@ import java.util.Map;
 @RequestMapping("/index")
 public class IndexApiController extends BaseController {
 
-    @Value("${elasticsearch.host}")
-    private String esHost;
-
-    @Value("${elasticsearch.port}")
-    private int esPort;
-
+    @Autowired
+    private RestClient restClient;
 
     @GetMapping("/riskcode")
     @ResponseBody
     public AjaxResult riskcode() {
+
+
+
         // 获取索引的别名,字段,创建时间
-        HttpConfig config = HttpConfig.custom().url("http://"+esHost+":"+esPort+"/shanglifeecif.riskcode_statistics/_search?");
-        String jsonStr = null;
         List xaxisData = new ArrayList();//存放险种
         List seriesData = new ArrayList();//客户数量和保单数量
         try {
-
-            jsonStr = HttpClientUtil.get(config);
+            Map<String, String> paramMap = new HashMap<String, String>();
+            paramMap.put("pretty", "true");
+            Response response = restClient.performRequest("GET", "shanglifeecif.riskcode_statistics/_search?", paramMap);
+            String jsonStr = EntityUtils.toString(response.getEntity());
             if(StringUtils.isNotEmpty(jsonStr)){
                 JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
                 jsonObject = jsonObject.getJSONObject("hits");
@@ -97,21 +100,13 @@ public class IndexApiController extends BaseController {
     @ResponseBody
     public AjaxResult bdNumDis() {
         // 获取索引的别名,字段,创建时间
-        HttpConfig config = HttpConfig.custom().url("http://"+esHost+":"+esPort+"/shanglifeecif.bdnum_distribution/_search?");
-        String jsonStr = null;
         Map[] seriesData = new HashMap[8];
-        //List seriesData = new ArrayList();//客户数量和保单数量
-       /* seriesData.add(0,"无保单");
-        seriesData.add(1,"1件保单");
-        seriesData.add(2,"2件保单");
-        seriesData.add(3,"3-5件保单");
-        seriesData.add(4,"6-10件保单");
-        seriesData.add(5,"11-20件保单");
-        seriesData.add(6,"21-50件保单");
-        seriesData.add(7,"50件以上保单");*/
         try {
 
-            jsonStr = HttpClientUtil.get(config);
+            Map<String, String> paramMap = new HashMap<String, String>();
+            paramMap.put("pretty", "true");
+            Response response = restClient.performRequest("GET", "shanglifeecif.bdnum_distribution/_search?", paramMap);
+            String jsonStr = EntityUtils.toString(response.getEntity());
             if(StringUtils.isNotEmpty(jsonStr)){
                 JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
                 jsonObject = jsonObject.getJSONObject("hits");
@@ -169,9 +164,6 @@ public class IndexApiController extends BaseController {
     @ResponseBody
     public AjaxResult ageSexDis() {
         // 获取索引的别名,字段,创建时间
-        HttpConfig config = HttpConfig.custom().url("http://"+esHost+":"+esPort+"/shanglifeecif.age_sex_distribution/_search?");
-        String jsonStr = null;
-
         List legendData = new ArrayList();//性别集合
         legendData.add("男");
         legendData.add("女");
@@ -185,7 +177,10 @@ public class IndexApiController extends BaseController {
 
         try {
 
-            jsonStr = HttpClientUtil.get(config);
+            Map<String, String> paramMap = new HashMap<String, String>();
+            paramMap.put("pretty", "true");
+            Response response = restClient.performRequest("GET", "shanglifeecif.age_sex_distribution/_search?", paramMap);
+            String jsonStr = EntityUtils.toString(response.getEntity());
             if(StringUtils.isNotEmpty(jsonStr)){
                 JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
                 jsonObject = jsonObject.getJSONObject("hits");