package com.dgtis.data.api; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.arronlong.httpclientutil.HttpClientUtil; import com.arronlong.httpclientutil.common.HttpConfig; import com.arronlong.httpclientutil.exception.HttpProcessException; import com.dgtis.common.core.utils.DateUtils; import com.dgtis.common.core.utils.StringUtils; import com.dgtis.common.core.utils.sql.EsJsonUtil; import com.dgtis.common.core.web.domain.AjaxResult; import org.apache.http.HttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.nio.entity.NStringEntity; 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; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.*; /** * @description:客户信息列表api * @author:qxm * @date:2021/1/22 10:24 */ @Controller @RequestMapping("/customer") public class CustomerApiController { private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class); @Autowired private RestClient restClient; @GetMapping("/getCustomerList") @ResponseBody public AjaxResult getCustomerList(int pageNum,int pageSize) { // 获取索引的别名,字段,创建时间 try { Map paramMap = new HashMap(); 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()); List listMap = new ArrayList<>(); Map map = new HashMap(); for (int i = 0; i paramMap = new HashMap(); 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(); JSONObject jsonObject = JSON.parseObject(result); Map mpInfo = new HashMap(); String indid = jsonObject.getString("_id"); mpInfo.put("id",indid); JSONObject source = JSON.parseObject(jsonObject.getString("_source")); mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class)); //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday"))); if(mpInfo.containsKey("birthday")){ Date date = source.getDate("birthday"); if(date!=null){ mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",date)); mpInfo.put("age",DateUtils.getAge(date)); } }else{ mpInfo.put("birthday",""); mpInfo.put("age",""); } map.put("custInfo",mpInfo); Map query =new HashMap(); query.put("indid1",indid); HttpEntity entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON); response= restClient.performRequest("GET", "/shanglifeecif.indrelationship/_search",Collections.emptyMap(),entity); result = EntityUtils.toString(response.getEntity()); jsonObject = JSON.parseObject(result); JSONObject hitsobject = (JSONObject) jsonObject.get("hits"); JSONArray array = JSON.parseArray(hitsobject.get("hits").toString()); List relationship = new ArrayList<>(); for (int i = 0; i emptyMap(),entity); result = EntityUtils.toString(response.getEntity()); jsonObject = JSON.parseObject(result); hitsobject = (JSONObject) jsonObject.get("hits"); array = JSON.parseArray(hitsobject.get("hits").toString()); List insuranceclaimthread = new ArrayList<>(); for (int i = 0; i paramMap = new HashMap(); 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(); JSONObject jsonObject = JSON.parseObject(result); Map mpInfo = new HashMap(); String indid = jsonObject.getString("_id"); mpInfo.put("id",indid); JSONObject source = JSON.parseObject(jsonObject.getString("_source")); mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class)); //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday"))); if(mpInfo.containsKey("birthday")){ Date date = source.getDate("birthday"); if(date!=null){ mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",date)); mpInfo.put("age",DateUtils.getAge(date)); } }else{ mpInfo.put("birthday",""); mpInfo.put("age",""); } map.put("custInfo",mpInfo); return AjaxResult.success(map); } catch (Exception e) { e.printStackTrace(); return AjaxResult.error(); } } }