|
|
@@ -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();
|
|
|
}
|