CustomerApiController.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package com.dgtis.data.api;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.arronlong.httpclientutil.HttpClientUtil;
  6. import com.arronlong.httpclientutil.common.HttpConfig;
  7. import com.arronlong.httpclientutil.exception.HttpProcessException;
  8. import com.dgtis.common.core.utils.DateUtils;
  9. import com.dgtis.common.core.utils.StringUtils;
  10. import com.dgtis.common.core.utils.sql.EsJsonUtil;
  11. import com.dgtis.common.core.web.domain.AjaxResult;
  12. import org.apache.http.HttpEntity;
  13. import org.apache.http.entity.ContentType;
  14. import org.apache.http.nio.entity.NStringEntity;
  15. import org.apache.http.util.EntityUtils;
  16. import org.elasticsearch.client.Response;
  17. import org.elasticsearch.client.RestClient;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Controller;
  23. import org.springframework.web.bind.annotation.GetMapping;
  24. import org.springframework.web.bind.annotation.RequestMapping;
  25. import org.springframework.web.bind.annotation.ResponseBody;
  26. import java.util.*;
  27. /**
  28. * @description:客户信息列表api
  29. * @author:qxm
  30. * @date:2021/1/22 10:24
  31. */
  32. @Controller
  33. @RequestMapping("/customer")
  34. public class CustomerApiController {
  35. private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class);
  36. @Autowired
  37. private RestClient restClient;
  38. @GetMapping("/getCustomerList")
  39. @ResponseBody
  40. public AjaxResult getCustomerList(int pageNum,int pageSize) {
  41. // 获取索引的别名,字段,创建时间
  42. try {
  43. Map<String, String> paramMap = new HashMap<String, String>();
  44. paramMap.put("pretty", "true");
  45. paramMap.put("from", pageNum+"");
  46. paramMap.put("size", pageSize+"");
  47. Response response = restClient.performRequest("GET", "shanglifeecif.individual/_search?", paramMap);
  48. String result = EntityUtils.toString(response.getEntity());
  49. JSONObject jsonObject = JSON.parseObject(result);
  50. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  51. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  52. List listMap = new ArrayList<>();
  53. Map map = new HashMap();
  54. for (int i = 0; i <array.size() ; i++) {
  55. JSONObject json = (JSONObject)array.get(i);
  56. Map mp = new HashMap();
  57. mp.put("id",json.getString("_id"));
  58. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  59. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  60. if(mp.containsKey("birthday")){
  61. Date date = jsonOb.getDate("birthday");
  62. if(date!=null){
  63. mp.put("birthday", DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date));
  64. mp.put("age",DateUtils.getAge(date));
  65. }else{
  66. mp.put("birthday", "");
  67. mp.put("age","");
  68. }
  69. }else{
  70. mp.put("birthday", "");
  71. mp.put("age","");
  72. }
  73. listMap.add(mp);
  74. }
  75. long total = hitsobject.getLong("total");
  76. map.put("list",listMap);
  77. map.put("total",total);
  78. return AjaxResult.success(map);
  79. } catch (Exception e) {
  80. e.printStackTrace();
  81. return AjaxResult.error();
  82. }
  83. }
  84. @GetMapping("/getCustomerById")
  85. @ResponseBody
  86. public AjaxResult getCustomerById(String id) {
  87. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  88. try {
  89. Map<String, String> paramMap = new HashMap<String, String>();
  90. paramMap.put("pretty", "true");
  91. Response response = restClient.performRequest("GET", "/shanglifeecif.individual/default_type_/"+id, paramMap);
  92. String result = EntityUtils.toString(response.getEntity());
  93. Map map = new HashMap();
  94. JSONObject jsonObject = JSON.parseObject(result);
  95. Map mpInfo = new HashMap();
  96. String indid = jsonObject.getString("_id");
  97. mpInfo.put("id",indid);
  98. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  99. mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
  100. //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday")));
  101. if(mpInfo.containsKey("birthday")){
  102. Date date = source.getDate("birthday");
  103. if(date!=null){
  104. mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",date));
  105. mpInfo.put("age",DateUtils.getAge(date));
  106. }
  107. }else{
  108. mpInfo.put("birthday","");
  109. mpInfo.put("age","");
  110. }
  111. map.put("custInfo",mpInfo);
  112. Map query =new HashMap();
  113. query.put("indid1",indid);
  114. HttpEntity entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
  115. response= restClient.performRequest("GET", "/shanglifeecif.indrelationship/_search",Collections.<String, String>emptyMap(),entity);
  116. result = EntityUtils.toString(response.getEntity());
  117. jsonObject = JSON.parseObject(result);
  118. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  119. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  120. List relationship = new ArrayList<>();
  121. for (int i = 0; i <array.size() ; i++) {
  122. JSONObject json = (JSONObject)array.get(i);
  123. Map mp = new HashMap();
  124. mp.put("id",json.getString("_id"));
  125. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  126. relationship.add(mp);
  127. }
  128. map.put("relationship",relationship);
  129. query =new HashMap();
  130. query.put("applicantid",indid);
  131. entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
  132. response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>emptyMap(),entity);
  133. result = EntityUtils.toString(response.getEntity());
  134. jsonObject = JSON.parseObject(result);
  135. hitsobject = (JSONObject) jsonObject.get("hits");
  136. array = JSON.parseArray(hitsobject.get("hits").toString());
  137. List insuranceclaimthread = new ArrayList<>();
  138. for (int i = 0; i <array.size() ; i++) {
  139. JSONObject json = (JSONObject)array.get(i);
  140. Map mp = new HashMap();
  141. mp.put("id",json.getString("_id"));
  142. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  143. insuranceclaimthread.add(mp);
  144. }
  145. map.put("insuranceclaimthread",insuranceclaimthread);
  146. map.put("custInfo3",null);
  147. map.put("custInfo4",null);
  148. map.put("custInfo5",null);
  149. map.put("custInfo6",null);
  150. map.put("custInfo7",null);
  151. map.put("custInfo8",null);
  152. return AjaxResult.success(map);
  153. } catch (Exception e) {
  154. e.printStackTrace();
  155. return AjaxResult.error();
  156. }
  157. }
  158. @GetMapping("/getCustomerOverViewById")
  159. @ResponseBody
  160. public AjaxResult getCustomerOverViewById(String id) {
  161. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  162. try {
  163. Map<String, String> paramMap = new HashMap<String, String>();
  164. paramMap.put("pretty", "true");
  165. Response response = restClient.performRequest("GET", "shanglifeecif.individual/default_type_/"+id, paramMap);
  166. String result = EntityUtils.toString(response.getEntity());
  167. Map map = new HashMap();
  168. JSONObject jsonObject = JSON.parseObject(result);
  169. Map mpInfo = new HashMap();
  170. String indid = jsonObject.getString("_id");
  171. mpInfo.put("id",indid);
  172. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  173. mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
  174. //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday")));
  175. if(mpInfo.containsKey("birthday")){
  176. Date date = source.getDate("birthday");
  177. if(date!=null){
  178. mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",date));
  179. mpInfo.put("age",DateUtils.getAge(date));
  180. }
  181. }else{
  182. mpInfo.put("birthday","");
  183. mpInfo.put("age","");
  184. }
  185. map.put("custInfo",mpInfo);
  186. return AjaxResult.success(map);
  187. } catch (Exception e) {
  188. e.printStackTrace();
  189. return AjaxResult.error();
  190. }
  191. }
  192. }