| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- 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<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());
- List listMap = new ArrayList<>();
- Map map = new HashMap();
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- mp.put("id",json.getString("_id"));
- JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- if(mp.containsKey("birthday")){
- Date date = jsonOb.getDate("birthday");
- if(date!=null){
- mp.put("birthday", DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date));
- mp.put("age",DateUtils.getAge(date));
- }else{
- mp.put("birthday", "");
- mp.put("age","");
- }
- }else{
- mp.put("birthday", "");
- mp.put("age","");
- }
- listMap.add(mp);
- }
- long total = hitsobject.getLong("total");
- map.put("list",listMap);
- map.put("total",total);
- return AjaxResult.success(map);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- @GetMapping("/getCustomerById")
- @ResponseBody
- public AjaxResult getCustomerById(String id) {
- // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
- 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();
- 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.<String, String>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 <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- mp.put("id",json.getString("_id"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- relationship.add(mp);
- }
- map.put("relationship",relationship);
- query =new HashMap();
- query.put("applicantid",indid);
- entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
- response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>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 <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- mp.put("id",json.getString("_id"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- insuranceclaimthread.add(mp);
- }
- map.put("insuranceclaimthread",insuranceclaimthread);
- map.put("custInfo3",null);
- map.put("custInfo4",null);
- map.put("custInfo5",null);
- map.put("custInfo6",null);
- map.put("custInfo7",null);
- map.put("custInfo8",null);
- return AjaxResult.success(map);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- @GetMapping("/getCustomerOverViewById")
- @ResponseBody
- public AjaxResult getCustomerOverViewById(String id) {
- // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
- 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();
- 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();
- }
- }
- }
|