CustomerApiController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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.dgtis.common.core.utils.DateUtils;
  6. import com.dgtis.common.core.utils.StringUtils;
  7. import com.dgtis.common.core.utils.sql.EsJsonUtil;
  8. import com.dgtis.common.core.web.domain.AjaxResult;
  9. import org.apache.http.HttpEntity;
  10. import org.apache.http.entity.ContentType;
  11. import org.apache.http.nio.entity.NStringEntity;
  12. import org.apache.http.util.EntityUtils;
  13. import org.elasticsearch.client.Request;
  14. import org.elasticsearch.client.Response;
  15. import org.elasticsearch.client.RestClient;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Controller;
  20. import org.springframework.web.bind.annotation.*;
  21. import java.text.DecimalFormat;
  22. import java.util.*;
  23. /**
  24. * @description:客户信息列表api
  25. * @author:qxm
  26. * @date:2021/1/22 10:24
  27. */
  28. @Controller
  29. @RequestMapping("/customer")
  30. public class CustomerApiController {
  31. private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class);
  32. @Autowired
  33. private RestClient restClient;
  34. @GetMapping("/getCustomerList")
  35. @ResponseBody
  36. public AjaxResult getCustomerList(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize,
  37. String education,//学历
  38. String policybelong,//业绩归属
  39. String payS,String payE, //年缴费区间
  40. String fadate,//投保年份
  41. String productname,//险种类别
  42. String insuredAmountS,String insuredAmountE,//保额区间
  43. String ageS,String ageE,//年龄区间
  44. String gender,//性别
  45. String sobirth,//省份
  46. String NOVPolicy,//保单件数
  47. String custtype,//客户类型 投保人
  48. String SCustID,// 核心客户号
  49. String custclass,//客户等级
  50. String participantsDateS,String participantsDateE,//参与方时间
  51. String PIncomeS,String PIncomeE,//年收入区间
  52. String Insured,//投保对象
  53. String lp,//理赔
  54. String yx,//有效
  55. String gzgw,//关注官微
  56. String zcgw//注册官微
  57. ) {
  58. try {
  59. logger.info("进客户列表时间:"+DateUtils.getTime());
  60. //1.如果存在保单信息的查询条件,需要先查询保单信息然后通过保单关联出客户信息
  61. //处理保单查询条件
  62. List<String> customerIds = new ArrayList<String>();
  63. if(StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(payS) || StringUtils.isNotEmpty(payE)
  64. || StringUtils.isNotEmpty(insuredAmountS) || StringUtils.isNotEmpty(insuredAmountE)
  65. || StringUtils.isNotEmpty(productname) || StringUtils.isNotEmpty(fadate)){
  66. customerIds = queryInsurancearrangement(policybelong,payS,payE,fadate,productname,insuredAmountS,insuredAmountE);
  67. }
  68. //2.如果没有客户信息以外的查询条件,只需要查询客户信息
  69. // 获取索引的别名,字段,创建时间
  70. String beginBirthDay = "";
  71. String endBirthDay = "";
  72. if(StringUtils.isNotEmpty(ageS)){
  73. String year = DateUtils.getYYYY();
  74. int bYear = Integer.parseInt(year)-Integer.parseInt(ageS);
  75. endBirthDay = bYear+"-"+DateUtils.getMMDD();
  76. }
  77. if(StringUtils.isNotEmpty(ageE)){
  78. String year = DateUtils.getYYYY();
  79. int bYear = Integer.parseInt(year)-Integer.parseInt(ageE);
  80. beginBirthDay = bYear+"-"+DateUtils.getMMDD();
  81. }
  82. //拼装查询条件
  83. StringBuilder builder =new StringBuilder();
  84. builder.append("{");
  85. builder.append("\"query\":{");//query开始
  86. builder.append("\"bool\":{");//boot开始
  87. builder.append("\"must\":[");//must开始
  88. if(StringUtils.isNotEmpty(gender)){
  89. builder.append("{\"prefix\":{\"gender\":"+gender+"}},");
  90. }
  91. if(StringUtils.isNotEmpty(NOVPolicy)){
  92. builder.append("{\"prefix\":{\"label25\":\""+NOVPolicy+"\"}},");
  93. }
  94. if(StringUtils.isNotEmpty(custclass)){
  95. builder.append("{\"term\":{\"custclass\":\""+custclass+"\"}},");
  96. }
  97. if(StringUtils.isNotEmpty(sobirth)){
  98. builder.append("{\"wildcard\":{\"sobirth\":\"*"+sobirth+"*\"}},");//模糊匹配
  99. }
  100. if(StringUtils.isNotEmpty(SCustID)){
  101. builder.append("{\"wildcard\":{\"scustid\":\"*"+SCustID+"*\"}},");//模糊匹配
  102. }
  103. if(StringUtils.isNotEmpty(custtype)){
  104. builder.append("{\"prefix\":{\"custtype\":\""+custtype+"\"}},");
  105. }
  106. if(StringUtils.isNotEmpty(beginBirthDay) && StringUtils.isNotEmpty(endBirthDay)){
  107. builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\",\"lte\":\""+endBirthDay+"\"}}},");
  108. }else{
  109. if(StringUtils.isNotEmpty(beginBirthDay)){
  110. builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\"}}},");
  111. }
  112. if(StringUtils.isNotEmpty(endBirthDay)){
  113. builder.append("{\"range\":{\"birthday\":{\"lte\":\""+endBirthDay+"\"}}},");
  114. }
  115. }
  116. if(StringUtils.isNotEmpty(PIncomeS) && StringUtils.isNotEmpty(PIncomeE)){
  117. builder.append("{\"range\":{\"PIncome\":{\"gte\":\""+PIncomeS+"\",\"lte\":\""+PIncomeE+"\"}}},");
  118. }else{
  119. if(StringUtils.isNotEmpty(PIncomeS)){
  120. builder.append("{\"range\":{\"PIncome\":{\"gte\":\""+PIncomeS+"\"}}},");
  121. }
  122. if(StringUtils.isNotEmpty(PIncomeE)){
  123. builder.append("{\"range\":{\"PIncome\":{\"lte\":\""+PIncomeE+"\"}}},");
  124. }
  125. }
  126. if(StringUtils.isNotEmpty(education)){
  127. String[] edus = education.split("&");
  128. builder.append("{\"terms\":{\"education\":[");
  129. for (String edu:edus) {
  130. builder.append("\""+edu+"\",");
  131. }
  132. builder.delete(builder.length()-1,builder.length());
  133. builder.append ("]}},");
  134. }
  135. if(customerIds.size()>0){
  136. builder.append("{\"terms\":{\"_id\":[");
  137. for (String id:customerIds) {
  138. builder.append("\""+id+"\",");
  139. }
  140. builder.delete(builder.length()-1,builder.length());
  141. builder.append ("]}},");
  142. }
  143. if(StringUtils.isNotEmpty(gzgw)){
  144. builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
  145. }
  146. if(StringUtils.isNotEmpty(zcgw)){
  147. builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
  148. }
  149. if(StringUtils.isNotEmpty(gender) || StringUtils.isNotEmpty(NOVPolicy) || StringUtils.isNotEmpty(custtype)
  150. || StringUtils.isNotEmpty(custclass) || StringUtils.isNotEmpty(sobirth) || StringUtils.isNotEmpty(SCustID)
  151. || StringUtils.isNotEmpty(beginBirthDay) || StringUtils.isNotEmpty(endBirthDay) || StringUtils.isNotEmpty(education)
  152. || StringUtils.isNotEmpty(PIncomeS) || StringUtils.isNotEmpty(PIncomeE) || StringUtils.isNotEmpty(gzgw)
  153. || StringUtils.isNotEmpty(zcgw) || customerIds.size()>0){
  154. builder.delete(builder.length()-1,builder.length());
  155. }
  156. builder.append("],");//must结束
  157. builder.append("\"must_not\":[],");//must_not
  158. builder.append("\"should\":[]");//should
  159. builder.append("}");//boot结束
  160. builder.append("},");//query结束
  161. builder.append("\"from\":"+((pageNum-1)*10)+",");//第几页
  162. builder.append("\"size\":"+pageSize+",");//查询几个
  163. builder.append("\"sort\":[{\"created_time\":{\"order\":\"desc\"}}],");//排序
  164. builder.append("\"aggs\":{}");//
  165. builder.append("}");
  166. HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
  167. Request scriptRequest = new Request("GET", "/shanglifeecif.individual/_search?pretty=true&sort=scustid:asc");
  168. // Request scriptRequest = new Request("GET", "/shanglifeecif.individual/_search?q=%22{%22query%22:{%22bool%22:{%22must%22:[],%22must_not%22:[],%22should%22:[]}},%22from%22:11,%22size%22:10,%22sort%22:[{%22created_time%22:{%22order%22:%22desc%22}}],%22aggs%22:{}}%22");
  169. scriptRequest.setEntity(entity);
  170. Response response = restClient.performRequest(scriptRequest);
  171. // Response response= restClient.performRequest("GET", "/shanglifeecif.individual/_search",Collections.<String, String>emptyMap(),entity);
  172. String result = EntityUtils.toString(response.getEntity());
  173. JSONObject jsonObject = JSON.parseObject(result);
  174. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  175. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  176. List listMap = new ArrayList<>();
  177. Map map = new HashMap();
  178. for (int i = 0; i <array.size() ; i++) {
  179. JSONObject json = (JSONObject)array.get(i);
  180. Map mp = new HashMap();
  181. mp.put("id",json.getString("_id"));
  182. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  183. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  184. if(mp.containsKey("birthday")){
  185. mp.put("birthday", jsonOb.getString("birthday").substring(0,10));
  186. mp.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,jsonOb.getString("birthday"))));
  187. }else{
  188. mp.put("birthday", "");
  189. mp.put("age","");
  190. }
  191. listMap.add(mp);
  192. }
  193. long total = hitsobject.getLong("total");
  194. map.put("list",listMap);
  195. map.put("total",total);
  196. logger.info("出客户列表时间:"+DateUtils.getTime());
  197. return AjaxResult.success(map);
  198. } catch (Exception e) {
  199. logger.info("列表报错时间:"+DateUtils.getTime());
  200. e.printStackTrace();
  201. return AjaxResult.error();
  202. }
  203. }
  204. /**
  205. * 查询保单信息返回客户Id
  206. * @return
  207. */
  208. public List queryInsurancearrangement(String policybelong,String payS,String payE,String fadate,
  209. String productname,String insuredAmountS,String insuredAmountE) throws Exception {
  210. List<String> customerIds = new ArrayList<String>();
  211. //拼装查询条件
  212. StringBuilder builder =new StringBuilder();
  213. builder.append("{");
  214. builder.append("\"query\": {");//query开始
  215. builder.append("\"bool\": {");//boot开始
  216. builder.append("\"must\": [");//must开始
  217. if(StringUtils.isNotEmpty(policybelong)){
  218. builder.append("{\"prefix\": { \"policybelong\": \""+policybelong+"\"}},");
  219. }
  220. if(StringUtils.isNotEmpty(fadate)){
  221. builder.append("{\"prefix\": { \"PADate\": \""+fadate+"\"}},");
  222. }
  223. if(StringUtils.isNotEmpty(productname)){
  224. builder.append("{\"prefix\": { \"risk_categories\": \""+productname+"\"}},");
  225. }
  226. if(StringUtils.isNotEmpty(payS) && StringUtils.isNotEmpty(payE)){
  227. builder.append("{\"range\":{\"Prem\":{\"gt\":\""+payS+"\",\"lt\":\""+payE+"\"}}},");
  228. }else{
  229. if(StringUtils.isNotEmpty(payS)){
  230. builder.append("{\"range\":{\"Prem\":{\"gt\":\""+payS+"\"}}},");
  231. }
  232. if(StringUtils.isNotEmpty(payE)){
  233. builder.append("{\"range\":{\"Prem\":{\"lt\":\""+payE+"\"}}},");
  234. }
  235. }
  236. if(StringUtils.isNotEmpty(insuredAmountS) && StringUtils.isNotEmpty(insuredAmountE)){
  237. builder.append("{\"range\":{\"Risk\":{\"gt\":\""+insuredAmountS+"\",\"lt\":\""+insuredAmountE+"\"}}},");
  238. }else{
  239. if(StringUtils.isNotEmpty(payS)){
  240. builder.append("{\"range\":{\"Risk\":{\"gt\":\""+insuredAmountS+"\"}}},");
  241. }
  242. if(StringUtils.isNotEmpty(payE)){
  243. builder.append("{\"range\":{\"Risk\":{\"lt\":\""+insuredAmountE+"\"}}},");
  244. }
  245. }
  246. if(StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(payS) || StringUtils.isNotEmpty(payE)
  247. || StringUtils.isNotEmpty(insuredAmountS) || StringUtils.isNotEmpty(insuredAmountE)
  248. || StringUtils.isNotEmpty(productname) || StringUtils.isNotEmpty(fadate) ){
  249. builder.delete(builder.length()-1,builder.length());
  250. }
  251. builder.append("],");//must结束
  252. builder.append("\"must_not\": [ ],");//must_not
  253. builder.append("\"should\": [ ]");//should
  254. builder.append("}");//boot结束
  255. builder.append("},");//query结束
  256. //builder.append("\"from\": "+pageNum+",");//第几页
  257. builder.append("\"size\": 1000,");//查询几个
  258. //builder.append(" \"sort\": [{\"created_time\":{\"order\":\"desc\"}}],");//排序
  259. builder.append(" \"aggs\": {}");//
  260. builder.append("}");
  261. HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
  262. Request scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m");
  263. scriptRequest.setEntity(entity);
  264. Response response = restClient.performRequest(scriptRequest);
  265. // Response response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m",Collections.<String, String>emptyMap(),entity);
  266. String result = EntityUtils.toString(response.getEntity());
  267. JSONObject jsonObject = JSON.parseObject(result);
  268. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  269. JSONArray hitsList = JSON.parseArray(hitsobject.get("hits").toString());
  270. String scroll_id = jsonObject.getString("_scroll_id");
  271. JSONObject obj = new JSONObject();
  272. obj.put("scroll_id",scroll_id);
  273. obj.put("scroll","1m");
  274. if (hitsList.size() != 0) {
  275. // 这里填写你的业务逻辑,即对每一条数据的处理
  276. for (int i = 0; i <hitsList.size() ; i++) {
  277. JSONObject json = (JSONObject)hitsList.get(i);
  278. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  279. if(StringUtils.isNotEmpty(jsonOb.getString("applicantid"))){
  280. customerIds.add(jsonOb.getString("applicantid"));
  281. }
  282. }
  283. // 继续向后查询
  284. /* entity = new NStringEntity(JSONUtil.toJsonStr(obj), ContentType.APPLICATION_JSON);
  285. scriptRequest = new Request("GET", "/_search/scroll?");
  286. scriptRequest.setEntity(entity);
  287. response = restClient.performRequest(scriptRequest);
  288. result = EntityUtils.toString(response.getEntity());
  289. jsonObject = JSON.parseObject(result);
  290. hitsobject = (JSONObject) jsonObject.get("hits");
  291. hitsList = JSON.parseArray(hitsobject.get("hits").toString());*/
  292. }
  293. return customerIds;
  294. }
  295. @GetMapping("/getCustomerById")
  296. @ResponseBody
  297. public AjaxResult getCustomerById(String id) {
  298. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  299. try {
  300. logger.info("进客户详情时间:"+DateUtils.getTime());
  301. Map<String, String> paramMap = new HashMap<String, String>();
  302. paramMap.put("pretty", "true");
  303. Request scriptRequest = new Request("GET", "/shanglifeecif.individual/default_type_/"+id+"?pretty=true");
  304. Response response = restClient.performRequest(scriptRequest);
  305. // Response response = restClient.performRequest("GET", "/shanglifeecif.individual/default_type_/"+id, paramMap);
  306. String result = EntityUtils.toString(response.getEntity());
  307. Map map = new HashMap();
  308. JSONObject jsonObject = JSON.parseObject(result);
  309. Map mpInfo = new HashMap();
  310. String indid = jsonObject.getString("_id");
  311. mpInfo.put("id",indid);
  312. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  313. String scustid = source.getString("scustid");
  314. mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
  315. //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday")));
  316. if(mpInfo.containsKey("birthday")){
  317. mpInfo.put("birthday", source.getString("birthday").substring(0,10));
  318. mpInfo.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,source.getString("birthday"))));
  319. }else{
  320. mpInfo.put("birthday","");
  321. mpInfo.put("age","");
  322. }
  323. map.put("custInfo",mpInfo);
  324. Map query =new HashMap();
  325. query.put("indid1",indid);
  326. scriptRequest = new Request("GET", "/shanglifeecif.indrelationship/_search?pretty=true&q=indid1:"+indid);
  327. response = restClient.performRequest(scriptRequest);
  328. result = EntityUtils.toString(response.getEntity());
  329. jsonObject = JSON.parseObject(result);
  330. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  331. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  332. List relationship = new ArrayList<>();
  333. for (int i = 0; i <array.size() ; i++) {
  334. JSONObject json = (JSONObject)array.get(i);
  335. Map mp = new HashMap();
  336. mp.put("id",json.getString("_id"));
  337. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  338. relationship.add(mp);
  339. }
  340. map.put("relationship",relationship);
  341. query =new HashMap();
  342. query.put("applicantid",indid);
  343. scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?pretty=true&q=lpscutid:"+scustid);
  344. response = restClient.performRequest(scriptRequest);
  345. // response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>emptyMap(),entity);
  346. result = EntityUtils.toString(response.getEntity());
  347. jsonObject = JSON.parseObject(result);
  348. hitsobject = (JSONObject) jsonObject.get("hits");
  349. array = JSON.parseArray(hitsobject.get("hits").toString());
  350. List insuranceclaimthread = new ArrayList<>();
  351. for (int i = 0; i <array.size() ; i++) {
  352. JSONObject json = (JSONObject)array.get(i);
  353. Map mp = new HashMap();
  354. mp.put("id",json.getString("_id"));
  355. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  356. insuranceclaimthread.add(mp);
  357. }
  358. map.put("insuranceclaimthread",insuranceclaimthread);
  359. query =new HashMap();
  360. query.put("applicantid",indid);
  361. scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?pretty=true&sort=padate:asc&q=applicantscustid:"+scustid);
  362. response = restClient.performRequest(scriptRequest);
  363. result = EntityUtils.toString(response.getEntity());
  364. jsonObject = JSON.parseObject(result);
  365. hitsobject = (JSONObject) jsonObject.get("hits");
  366. array = JSON.parseArray(hitsobject.get("hits").toString());
  367. List insurancearrangement = new ArrayList<>();
  368. for (int i = 0; i <array.size() ; i++) {
  369. JSONObject json = (JSONObject)array.get(i);
  370. Map mp = new HashMap();
  371. mp.put("id",json.getString("_id"));
  372. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  373. insurancearrangement.add(mp);
  374. }
  375. map.put("insurancearrangement",insurancearrangement);
  376. scriptRequest = new Request("GET", "/shanglifeecif.partytimeline/_search?pretty=true&sort=sdate:asc&q=partyid:"+scustid);
  377. response = restClient.performRequest(scriptRequest);
  378. result = EntityUtils.toString(response.getEntity());
  379. jsonObject = JSON.parseObject(result);
  380. hitsobject = (JSONObject) jsonObject.get("hits");
  381. array = JSON.parseArray(hitsobject.get("hits").toString());
  382. List partytimeline = new ArrayList<>();
  383. for (int i = 0; i <array.size() ; i++) {
  384. JSONObject json = (JSONObject)array.get(i);
  385. Map mp = new HashMap();
  386. mp.put("id",json.getString("_id"));
  387. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  388. partytimeline.add(mp);
  389. }
  390. map.put("partytimeline",partytimeline);
  391. logger.info("出客户详情时间:"+DateUtils.getTime());
  392. return AjaxResult.success(map);
  393. } catch (Exception e) {
  394. logger.info("客户详情报错时间:"+DateUtils.getTime());
  395. e.printStackTrace();
  396. return AjaxResult.error();
  397. }
  398. }
  399. @GetMapping("/getCustomerOverViewById")
  400. @ResponseBody
  401. public AjaxResult getCustomerOverViewById(String id) {
  402. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  403. try {
  404. logger.info("进客户概览时间:"+DateUtils.getTime());
  405. Map<String, String> paramMap = new HashMap<String, String>();
  406. paramMap.put("pretty", "true");
  407. Request scriptRequest = new Request("GET", "shanglifeecif.individual/default_type_/"+id+"?pretty=true");
  408. Response response = restClient.performRequest(scriptRequest);
  409. String result = EntityUtils.toString(response.getEntity());
  410. Map map = new HashMap();
  411. JSONObject jsonObject = JSON.parseObject(result);
  412. Map mpInfo = new HashMap();
  413. String indid = jsonObject.getString("_id");
  414. mpInfo.put("id",indid);
  415. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  416. String scustid = source.getString("scustid");
  417. mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
  418. if(mpInfo.containsKey("birthday")){
  419. mpInfo.put("birthday", source.getString("birthday").substring(0,10));
  420. mpInfo.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,source.getString("birthday"))));
  421. }else{
  422. mpInfo.put("birthday","");
  423. mpInfo.put("age","");
  424. }
  425. scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?pretty=true&sort=padate:asc&q=applicantscustid:"+scustid);
  426. response = restClient.performRequest(scriptRequest);
  427. result = EntityUtils.toString(response.getEntity());
  428. jsonObject = JSON.parseObject(result);
  429. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  430. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  431. DecimalFormat df = new DecimalFormat("######0.00");//保留两位小数
  432. double prem = 0;//标准保费
  433. //概览投保时间和保费折线图
  434. Map expectedData = new HashMap();
  435. String[] edata = new String[12];
  436. expectedData.put("name","");
  437. Map actaulData = new HashMap();
  438. String[] adata = new String[12];
  439. actaulData.put("name","");
  440. List xaxisData = new ArrayList();
  441. xaxisData.add("1");
  442. xaxisData.add("2");
  443. xaxisData.add("3");
  444. xaxisData.add("4");
  445. xaxisData.add("5");
  446. xaxisData.add("6");
  447. xaxisData.add("7");
  448. xaxisData.add("8");
  449. xaxisData.add("9");
  450. xaxisData.add("10");
  451. xaxisData.add("11");
  452. xaxisData.add("12");
  453. long insureDay = 0;//投保时长
  454. int guaranteeDay = 0;//享受保障天数
  455. Map majorCategorie = new HashMap();
  456. Map mpremMap = new HashMap();
  457. for (int i = 0; i <array.size() ; i++) {
  458. JSONObject json = (JSONObject)array.get(i);
  459. JSONObject _source = (JSONObject) json.get("_source");
  460. Date padate = _source.getDate("padate");
  461. //xaxisData.add(DateUtils.parseDateToStr("MM",padate));
  462. if(_source.containsKey("prem")){
  463. prem+=_source.getDouble("prem");
  464. String m = DateUtils.parseDateToStr("M", padate);
  465. if(mpremMap.containsKey(m)){
  466. double tprem = Double.parseDouble(mpremMap.get(m).toString());
  467. tprem+=_source.getDouble("prem");
  468. //mpremMap.put(m,mprem);
  469. mpremMap.put(m,df.format(tprem));
  470. edata[Integer.parseInt(m)-1] = df.format(tprem);
  471. adata[Integer.parseInt(m)-1] = df.format(tprem);
  472. }else{
  473. mpremMap.put(m,df.format(_source.getDouble("prem")));
  474. edata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
  475. adata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
  476. }
  477. //edata.add(_source.getDouble("prem"));
  478. //adata.add(_source.getDouble("prem"));
  479. }
  480. if(i==0){
  481. insureDay = DateUtils.getDateDifDay(new Date(),padate);
  482. }
  483. if("有效".equals(_source.getString("policystate"))){
  484. guaranteeDay+=_source.getInteger("agrmntage");
  485. }
  486. //String risk_categories = _source.getString("risk_categories");
  487. String risk_categories_name = _source.getString("risk_categories_name");
  488. if(majorCategorie.containsKey(risk_categories_name)){
  489. double risk = Double.parseDouble(majorCategorie.get(risk_categories_name).toString());
  490. if(_source.containsKey("risk")){
  491. risk += _source.getDouble("risk");
  492. }
  493. majorCategorie.put(risk_categories_name,risk);
  494. }else{
  495. if(_source.containsKey("risk")){
  496. majorCategorie.put(risk_categories_name,_source.getDouble("risk"));
  497. }
  498. }
  499. }
  500. expectedData.put("data",edata);
  501. actaulData.put("data",adata);
  502. Map lineBarChartData = new HashMap();
  503. lineBarChartData.put("expectedData",expectedData);
  504. lineBarChartData.put("actaulData",actaulData);
  505. lineBarChartData.put("xaxisData",xaxisData);
  506. map.put("lineBarChartData",lineBarChartData);
  507. //查询理赔信息
  508. scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?pretty=true&q=lpscutid:"+scustid);
  509. response = restClient.performRequest(scriptRequest);
  510. result = EntityUtils.toString(response.getEntity());
  511. jsonObject = JSON.parseObject(result);
  512. hitsobject = (JSONObject) jsonObject.get("hits");
  513. array = JSON.parseArray(hitsobject.get("hits").toString());
  514. Map insuranceclaimthread = new HashMap();
  515. List insuranceclaimthreads = new ArrayList<>();
  516. double claimAmount = 0;//理赔总金额
  517. String claimType = "";//理赔类型
  518. for (int i = 0; i <array.size() ; i++) {
  519. JSONObject json = (JSONObject)array.get(i);
  520. JSONObject claimSource = JSON.parseObject(json.getString("_source"));
  521. if(claimSource.containsKey("ccamt")){
  522. claimAmount+=claimSource.getDouble("ccamt");
  523. }
  524. claimType = claimSource.getString("accidenttype");
  525. insuranceclaimthreads.add(claimSource);
  526. }
  527. insuranceclaimthread.put("isClaim",insuranceclaimthreads.size()>0?"是":"否");
  528. insuranceclaimthread.put("claimAmount",df.format(claimAmount));
  529. insuranceclaimthread.put("claimType",claimType);
  530. map.put("insuranceclaimthread",insuranceclaimthread);
  531. mpInfo.put("prem",df.format(prem));
  532. mpInfo.put("insureDay",insureDay);
  533. mpInfo.put("guaranteeDay",guaranteeDay);
  534. map.put("custInfo",mpInfo);
  535. map.put("majorCategorie",majorCategorie);
  536. logger.info("出客户概览时间:"+DateUtils.getTime());
  537. return AjaxResult.success(map);
  538. } catch (Exception e) {
  539. logger.info("客户概览报错时间:"+DateUtils.getTime());
  540. e.printStackTrace();
  541. return AjaxResult.error();
  542. }
  543. }
  544. }