CustomerApiController.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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.poi.ExcelUtil;
  8. import com.dgtis.common.core.web.domain.AjaxResult;
  9. import com.dgtis.common.security.utils.SecurityUtils;
  10. import com.dgtis.data.domain.Customer;
  11. import org.apache.http.HttpEntity;
  12. import org.apache.http.entity.ContentType;
  13. import org.apache.http.nio.entity.NStringEntity;
  14. import org.apache.http.util.EntityUtils;
  15. import org.elasticsearch.client.Request;
  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.stereotype.Controller;
  22. import org.springframework.web.bind.annotation.*;
  23. import javax.servlet.http.HttpServletResponse;
  24. import java.io.IOException;
  25. import java.text.DecimalFormat;
  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(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize,
  41. String education,//学历
  42. String policybelong,//业绩归属
  43. String payS,String payE, //年缴费区间
  44. String fadate,//投保年份
  45. String productname,//险种类别
  46. String insuredAmountS,String insuredAmountE,//保额区间
  47. String ageS,String ageE,//年龄区间
  48. String gender,//性别
  49. String sobirth,//省份
  50. String NOVPolicy,//保单件数
  51. String custtype,//客户类型 投保人
  52. String SCustID,// 核心客户号
  53. String custclass,//客户等级
  54. String participantsDateS,String participantsDateE,//参与方时间
  55. String PIncomeS,String PIncomeE,//年收入区间
  56. String Insured,//投保对象
  57. String lp,//理赔
  58. String yx,//有效
  59. String gzgw,//关注官微
  60. String zcgw//注册官微
  61. ) {
  62. try {
  63. logger.info("进客户列表时间:"+DateUtils.getTime());
  64. Long userId = SecurityUtils.getUserId();
  65. /*SysUser sysUser = userService.selectUserById(userId);
  66. String deptCode = sysUser.getDept().getDeptCode();*/
  67. //1.如果存在保单信息的查询条件,需要先查询保单信息然后通过保单关联出客户信息
  68. //处理保单查询条件
  69. List<String> customerIds = new ArrayList<String>();
  70. if(StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(payS) || StringUtils.isNotEmpty(payE)
  71. || StringUtils.isNotEmpty(insuredAmountS) || StringUtils.isNotEmpty(insuredAmountE)
  72. || StringUtils.isNotEmpty(productname) || StringUtils.isNotEmpty(fadate)){
  73. customerIds = queryInsurancearrangement(policybelong,payS,payE,fadate,productname,insuredAmountS,insuredAmountE);
  74. }
  75. //2.如果没有客户信息以外的查询条件,只需要查询客户信息
  76. // 获取索引的别名,字段,创建时间
  77. String beginBirthDay = "";
  78. String endBirthDay = "";
  79. if(StringUtils.isNotEmpty(ageS)){
  80. String year = DateUtils.getYYYY();
  81. int bYear = Integer.parseInt(year)-Integer.parseInt(ageS);
  82. endBirthDay = bYear+"-"+DateUtils.getMMDD();
  83. }
  84. if(StringUtils.isNotEmpty(ageE)){
  85. String year = DateUtils.getYYYY();
  86. int bYear = Integer.parseInt(year)-Integer.parseInt(ageE);
  87. beginBirthDay = bYear+"-"+DateUtils.getMMDD();
  88. }
  89. //拼装查询条件
  90. StringBuilder builder =new StringBuilder();
  91. builder.append("{");
  92. builder.append("\"query\":{");//query开始
  93. builder.append("\"bool\":{");//boot开始
  94. builder.append("\"must\":[");//must开始
  95. //业绩归属字段
  96. /*if(StringUtils.isNotEmpty(deptCode)){
  97. builder.append("{\"prefix\":{\"policybelong\":"+deptCode+"}},");
  98. }*/
  99. if(StringUtils.isNotEmpty(gender)){
  100. builder.append("{\"prefix\":{\"gender\":"+gender+"}},");
  101. }
  102. if(StringUtils.isNotEmpty(NOVPolicy)){
  103. builder.append("{\"prefix\":{\"label25\":\""+NOVPolicy+"\"}},");
  104. }
  105. if(StringUtils.isNotEmpty(custclass)){
  106. builder.append("{\"term\":{\"custclass\":\""+custclass+"\"}},");
  107. }
  108. if(StringUtils.isNotEmpty(sobirth)){
  109. builder.append("{\"wildcard\":{\"sobirth\":\"*"+sobirth+"*\"}},");//模糊匹配
  110. }
  111. if(StringUtils.isNotEmpty(SCustID)){
  112. builder.append("{\"wildcard\":{\"scustid\":\"*"+SCustID+"*\"}},");//模糊匹配
  113. }
  114. if(StringUtils.isNotEmpty(custtype)){
  115. builder.append("{\"wildcard\":{\"custtype\":\"*"+custtype+"*\"}},");
  116. }
  117. if(StringUtils.isNotEmpty(beginBirthDay) && StringUtils.isNotEmpty(endBirthDay)){
  118. builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\",\"lte\":\""+endBirthDay+"\"}}},");
  119. }else{
  120. if(StringUtils.isNotEmpty(beginBirthDay)){
  121. builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\"}}},");
  122. }
  123. if(StringUtils.isNotEmpty(endBirthDay)){
  124. builder.append("{\"range\":{\"birthday\":{\"lte\":\""+endBirthDay+"\"}}},");
  125. }
  126. }
  127. if(StringUtils.isNotEmpty(PIncomeS) && StringUtils.isNotEmpty(PIncomeE)){
  128. builder.append("{\"range\":{\"pincome\":{\"gte\":\""+PIncomeS+"\",\"lte\":\""+PIncomeE+"\"}}},");
  129. }else{
  130. if(StringUtils.isNotEmpty(PIncomeS)){
  131. builder.append("{\"range\":{\"pincome\":{\"gte\":\""+PIncomeS+"\"}}},");
  132. }
  133. if(StringUtils.isNotEmpty(PIncomeE)){
  134. builder.append("{\"range\":{\"pincome\":{\"lte\":\""+PIncomeE+"\"}}},");
  135. }
  136. }
  137. if(StringUtils.isNotEmpty(yx)){
  138. if (yx.equals("0")){
  139. builder.append("{\"range\":{\"novpolicy\":{\"gt\":\""+yx+"\"}}},");
  140. }else
  141. {
  142. builder.append("{\"prefix\":{\"label91\":\"失效客户\"}},");
  143. }
  144. }
  145. if(StringUtils.isNotEmpty(education)){
  146. String[] edus = education.split("&");
  147. builder.append("{\"terms\":{\"education\":[");
  148. for (String edu:edus) {
  149. builder.append("\""+edu+"\",");
  150. }
  151. builder.delete(builder.length()-1,builder.length());
  152. builder.append ("]}},");
  153. }
  154. if(customerIds.size()>0){
  155. builder.append("{\"terms\":{\"scustid\":[");
  156. for (String id:customerIds) {
  157. builder.append("\""+id+"\",");
  158. }
  159. builder.delete(builder.length()-1,builder.length());
  160. builder.append ("]}},");
  161. }
  162. if(StringUtils.isNotEmpty(gzgw) && "0".equals(gzgw)){
  163. builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
  164. }
  165. if(StringUtils.isNotEmpty(zcgw) && "0".equals(zcgw)){
  166. builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
  167. }
  168. if(StringUtils.isNotEmpty(lp) && "0".equals(lp)){
  169. builder.append("{\"prefix\":{\"label57\":\"最近一次理赔类型\"}},");
  170. }
  171. if(StringUtils.isNotEmpty(gender) || StringUtils.isNotEmpty(NOVPolicy) || StringUtils.isNotEmpty(custtype)
  172. || StringUtils.isNotEmpty(custclass) || StringUtils.isNotEmpty(sobirth) || StringUtils.isNotEmpty(SCustID)
  173. || StringUtils.isNotEmpty(beginBirthDay) || StringUtils.isNotEmpty(endBirthDay) || StringUtils.isNotEmpty(education)
  174. || StringUtils.isNotEmpty(PIncomeS) || StringUtils.isNotEmpty(PIncomeE) || (StringUtils.isNotEmpty(gzgw) && "0".equals(gzgw))
  175. || (StringUtils.isNotEmpty(zcgw) && "0".equals(zcgw)) || StringUtils.isNotEmpty(yx)
  176. || (StringUtils.isNotEmpty(lp) && "0".equals(lp) || //StringUtils.isNotEmpty(deptCode) ||
  177. customerIds.size()>0)){
  178. builder.delete(builder.length()-1,builder.length());
  179. }
  180. builder.append("],");//must结束
  181. builder.append("\"must_not\":[");//must_not
  182. if(StringUtils.isNotEmpty(gzgw) && "1".equals(gzgw)){
  183. builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
  184. }
  185. if(StringUtils.isNotEmpty(zcgw) && "1".equals(zcgw)){
  186. builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
  187. }
  188. if(StringUtils.isNotEmpty(lp) && "1".equals(lp)){
  189. builder.append("{\"prefix\":{\"label57\":\"最近一次理赔类型\"}},");
  190. }
  191. if(
  192. (StringUtils.isNotEmpty(gzgw) && "1".equals(gzgw))
  193. || (StringUtils.isNotEmpty(zcgw) && "1".equals(zcgw))
  194. || (StringUtils.isNotEmpty(lp) && "1".equals(lp))
  195. ){
  196. builder.delete(builder.length()-1,builder.length());
  197. }
  198. builder.append("],");
  199. builder.append("\"should\":[]");//should
  200. builder.append("}");//boot结束
  201. builder.append("},");//query结束
  202. builder.append("\"from\":"+((pageNum-1)*10)+",");//第几页
  203. builder.append("\"size\":"+pageSize+",");//查询几个
  204. builder.append("\"sort\":[{\"created_time\":{\"order\":\"desc\"}}],");//排序
  205. builder.append("\"aggs\":{}");//
  206. builder.append("}");
  207. HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
  208. Request scriptRequest = new Request("GET", "/shanglifeecif.individual/_search?pretty=true&sort=scustid:asc");
  209. // 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");
  210. scriptRequest.setEntity(entity);
  211. Response response = restClient.performRequest(scriptRequest);
  212. // Response response= restClient.performRequest("GET", "/shanglifeecif.individual/_search",Collections.<String, String>emptyMap(),entity);
  213. String result = EntityUtils.toString(response.getEntity());
  214. JSONObject jsonObject = JSON.parseObject(result);
  215. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  216. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  217. List listMap = new ArrayList<>();
  218. Map map = new HashMap();
  219. for (int i = 0; i <array.size() ; i++) {
  220. JSONObject json = (JSONObject)array.get(i);
  221. Map mp = new HashMap();
  222. mp.put("id",json.getString("_id"));
  223. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  224. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  225. if(mp.containsKey("birthday")){
  226. mp.put("birthday", jsonOb.getString("birthday").substring(0,10));
  227. mp.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,jsonOb.getString("birthday"))));
  228. }else{
  229. mp.put("birthday", "");
  230. mp.put("age","");
  231. }
  232. listMap.add(mp);
  233. }
  234. long total = hitsobject.getLong("total");
  235. map.put("list",listMap);
  236. map.put("total",total);
  237. logger.info("出客户列表时间:"+DateUtils.getTime());
  238. return AjaxResult.success(map);
  239. } catch (Exception e) {
  240. logger.info("列表报错时间:"+DateUtils.getTime());
  241. e.printStackTrace();
  242. return AjaxResult.error();
  243. }
  244. }
  245. /**
  246. * 查询保单信息返回客户Id
  247. * @return
  248. */
  249. public List queryInsurancearrangement(String policybelong,String payS,String payE,String fadate,
  250. String productname,String insuredAmountS,String insuredAmountE) throws Exception {
  251. List<String> customerIds = new ArrayList<String>();
  252. //拼装查询条件
  253. StringBuilder builder =new StringBuilder();
  254. builder.append("{");
  255. builder.append("\"query\": {");//query开始
  256. builder.append("\"bool\": {");//boot开始
  257. builder.append("\"must\": [");//must开始
  258. if(StringUtils.isNotEmpty(policybelong)){
  259. builder.append("{\"prefix\": { \"policybelong\": \""+policybelong+"\"}},");
  260. }
  261. if(StringUtils.isNotEmpty(fadate)){
  262. builder.append("{\"prefix\": { \"padate\": \""+fadate+"\"}},");
  263. }
  264. if(StringUtils.isNotEmpty(productname)){
  265. builder.append("{\"prefix\": { \"risk_categories\": \""+productname+"\"}},");
  266. }
  267. if(StringUtils.isNotEmpty(payS) && StringUtils.isNotEmpty(payE)){
  268. builder.append("{\"range\":{\"prem\":{\"gt\":\""+payS+"\",\"lt\":\""+payE+"\"}}},");
  269. }else{
  270. if(StringUtils.isNotEmpty(payS)){
  271. builder.append("{\"range\":{\"prem\":{\"gt\":\""+payS+"\"}}},");
  272. }
  273. if(StringUtils.isNotEmpty(payE)){
  274. builder.append("{\"range\":{\"prem\":{\"lt\":\""+payE+"\"}}},");
  275. }
  276. }
  277. if(StringUtils.isNotEmpty(insuredAmountS) && StringUtils.isNotEmpty(insuredAmountE)){
  278. builder.append("{\"range\":{\"Risk\":{\"gt\":\""+insuredAmountS+"\",\"lt\":\""+insuredAmountE+"\"}}},");
  279. }else{
  280. if(StringUtils.isNotEmpty(payS)){
  281. builder.append("{\"range\":{\"Risk\":{\"gt\":\""+insuredAmountS+"\"}}},");
  282. }
  283. if(StringUtils.isNotEmpty(payE)){
  284. builder.append("{\"range\":{\"Risk\":{\"lt\":\""+insuredAmountE+"\"}}},");
  285. }
  286. }
  287. if(StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(payS) || StringUtils.isNotEmpty(payE)
  288. || StringUtils.isNotEmpty(insuredAmountS) || StringUtils.isNotEmpty(insuredAmountE)
  289. || StringUtils.isNotEmpty(productname) || StringUtils.isNotEmpty(fadate) ){
  290. builder.delete(builder.length()-1,builder.length());
  291. }
  292. builder.append("],");//must结束
  293. builder.append("\"must_not\": [ ],");//must_not
  294. builder.append("\"should\": [ ]");//should
  295. builder.append("}");//boot结束
  296. builder.append("},");//query结束
  297. //builder.append("\"from\": "+pageNum+",");//第几页
  298. builder.append("\"size\": 1000,");//查询几个
  299. //builder.append(" \"sort\": [{\"created_time\":{\"order\":\"desc\"}}],");//排序
  300. builder.append(" \"aggs\": {}");//
  301. builder.append("}");
  302. HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
  303. Request scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m");
  304. scriptRequest.setEntity(entity);
  305. Response response = restClient.performRequest(scriptRequest);
  306. // Response response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m",Collections.<String, String>emptyMap(),entity);
  307. String result = EntityUtils.toString(response.getEntity());
  308. JSONObject jsonObject = JSON.parseObject(result);
  309. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  310. JSONArray hitsList = JSON.parseArray(hitsobject.get("hits").toString());
  311. String scroll_id = jsonObject.getString("_scroll_id");
  312. JSONObject obj = new JSONObject();
  313. obj.put("scroll_id",scroll_id);
  314. obj.put("scroll","1m");
  315. if (hitsList.size() != 0) {
  316. // 这里填写你的业务逻辑,即对每一条数据的处理
  317. for (int i = 0; i <hitsList.size() ; i++) {
  318. JSONObject json = (JSONObject)hitsList.get(i);
  319. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  320. if(StringUtils.isNotEmpty(jsonOb.getString("applicantscustid"))){
  321. customerIds.add(jsonOb.getString("applicantscustid"));
  322. }
  323. }
  324. // 继续向后查询
  325. /* entity = new NStringEntity(JSONUtil.toJsonStr(obj), ContentType.APPLICATION_JSON);
  326. scriptRequest = new Request("GET", "/_search/scroll?");
  327. scriptRequest.setEntity(entity);
  328. response = restClient.performRequest(scriptRequest);
  329. result = EntityUtils.toString(response.getEntity());
  330. jsonObject = JSON.parseObject(result);
  331. hitsobject = (JSONObject) jsonObject.get("hits");
  332. hitsList = JSON.parseArray(hitsobject.get("hits").toString());*/
  333. }
  334. return customerIds;
  335. }
  336. /**
  337. * 查询保单信息返回客户Id
  338. * @return
  339. */
  340. public List queryInsurancearrangementLp(String ly) throws Exception {
  341. List<String> customerIds = new ArrayList<String>();
  342. //拼装查询条件
  343. StringBuilder builder =new StringBuilder();
  344. builder.append("{");
  345. builder.append("\"query\": {");//query开始
  346. builder.append("\"bool\": {");//boot开始
  347. builder.append("\"must\": [");//must开始
  348. builder.append("],");//must结束
  349. builder.append("\"must_not\": [ ],");//must_not
  350. builder.append("\"should\": [ ]");//should
  351. builder.append("}");//boot结束
  352. builder.append("},");//query结束
  353. //builder.append("\"from\": "+pageNum+",");//第几页
  354. builder.append("\"size\": 1000,");//查询几个
  355. //builder.append(" \"sort\": [{\"created_time\":{\"order\":\"desc\"}}],");//排序
  356. builder.append(" \"aggs\": {}");//
  357. builder.append("}");
  358. HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
  359. Request scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?scroll=1m");
  360. scriptRequest.setEntity(entity);
  361. Response response = restClient.performRequest(scriptRequest);
  362. // Response response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m",Collections.<String, String>emptyMap(),entity);
  363. String result = EntityUtils.toString(response.getEntity());
  364. JSONObject jsonObject = JSON.parseObject(result);
  365. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  366. JSONArray hitsList = JSON.parseArray(hitsobject.get("hits").toString());
  367. String scroll_id = jsonObject.getString("_scroll_id");
  368. JSONObject obj = new JSONObject();
  369. obj.put("scroll_id",scroll_id);
  370. obj.put("scroll","1m");
  371. if (hitsList.size() != 0) {
  372. // 这里填写你的业务逻辑,即对每一条数据的处理
  373. for (int i = 0; i <hitsList.size() ; i++) {
  374. JSONObject json = (JSONObject)hitsList.get(i);
  375. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  376. if(StringUtils.isNotEmpty(jsonOb.getString("lpscutid"))){
  377. customerIds.add(jsonOb.getString("lpscutid"));
  378. }
  379. }
  380. // 继续向后查询
  381. /* entity = new NStringEntity(JSONUtil.toJsonStr(obj), ContentType.APPLICATION_JSON);
  382. scriptRequest = new Request("GET", "/_search/scroll?");
  383. scriptRequest.setEntity(entity);
  384. response = restClient.performRequest(scriptRequest);
  385. result = EntityUtils.toString(response.getEntity());
  386. jsonObject = JSON.parseObject(result);
  387. hitsobject = (JSONObject) jsonObject.get("hits");
  388. hitsList = JSON.parseArray(hitsobject.get("hits").toString());*/
  389. }
  390. return customerIds;
  391. }
  392. @GetMapping("/getCustomerById")
  393. @ResponseBody
  394. public AjaxResult getCustomerById(String id) {
  395. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  396. try {
  397. logger.info("进客户详情时间:"+DateUtils.getTime());
  398. Map<String, String> paramMap = new HashMap<String, String>();
  399. paramMap.put("pretty", "true");
  400. Request scriptRequest = new Request("GET", "/shanglifeecif.individual/default_type_/"+id+"?pretty=true");
  401. Response response = restClient.performRequest(scriptRequest);
  402. // Response response = restClient.performRequest("GET", "/shanglifeecif.individual/default_type_/"+id, paramMap);
  403. String result = EntityUtils.toString(response.getEntity());
  404. Map map = new HashMap();
  405. JSONObject jsonObject = JSON.parseObject(result);
  406. Map mpInfo = new HashMap();
  407. String indid = jsonObject.getString("_id");
  408. mpInfo.put("id",indid);
  409. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  410. String scustid = source.getString("scustid");
  411. mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
  412. //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday")));
  413. if(mpInfo.containsKey("birthday")){
  414. mpInfo.put("birthday", source.getString("birthday").substring(0,10));
  415. mpInfo.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,source.getString("birthday"))));
  416. }else{
  417. mpInfo.put("birthday","");
  418. mpInfo.put("age","");
  419. }
  420. map.put("custInfo",mpInfo);
  421. Map query =new HashMap();
  422. query.put("indid1",indid);
  423. scriptRequest = new Request("GET", "/shanglifeecif.indrelationship/_search?pretty=true&q=indid1:"+indid);
  424. response = restClient.performRequest(scriptRequest);
  425. result = EntityUtils.toString(response.getEntity());
  426. jsonObject = JSON.parseObject(result);
  427. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  428. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  429. List relationship = new ArrayList<>();
  430. for (int i = 0; i <array.size() ; i++) {
  431. JSONObject json = (JSONObject)array.get(i);
  432. Map mp = new HashMap();
  433. mp.put("id",json.getString("_id"));
  434. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  435. relationship.add(mp);
  436. }
  437. map.put("relationship",relationship);
  438. query =new HashMap();
  439. query.put("applicantid",indid);
  440. scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?size=100&pretty=true&q=lpscutid:"+scustid);
  441. response = restClient.performRequest(scriptRequest);
  442. // response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>emptyMap(),entity);
  443. result = EntityUtils.toString(response.getEntity());
  444. jsonObject = JSON.parseObject(result);
  445. hitsobject = (JSONObject) jsonObject.get("hits");
  446. array = JSON.parseArray(hitsobject.get("hits").toString());
  447. List insuranceclaimthread = new ArrayList<>();
  448. for (int i = 0; i <array.size() ; i++) {
  449. JSONObject json = (JSONObject)array.get(i);
  450. Map mp = new HashMap();
  451. mp.put("id",json.getString("_id"));
  452. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  453. insuranceclaimthread.add(mp);
  454. }
  455. map.put("insuranceclaimthread",insuranceclaimthread);
  456. scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q=applicantscustid:"+scustid);
  457. response = restClient.performRequest(scriptRequest);
  458. result = EntityUtils.toString(response.getEntity());
  459. jsonObject = JSON.parseObject(result);
  460. hitsobject = (JSONObject) jsonObject.get("hits");
  461. array = JSON.parseArray(hitsobject.get("hits").toString());
  462. List insurancearrangement = new ArrayList<>();
  463. for (int i = 0; i <array.size() ; i++) {
  464. JSONObject json = (JSONObject)array.get(i);
  465. Map mp = new HashMap();
  466. mp.put("id",json.getString("_id"));
  467. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  468. insurancearrangement.add(mp);
  469. }
  470. map.put("insurancearrangement",insurancearrangement);
  471. scriptRequest = new Request("GET", "/shanglifeecif.partytimeline/_search?pretty=true&sort=sdate:asc&q=partyid:"+scustid);
  472. response = restClient.performRequest(scriptRequest);
  473. result = EntityUtils.toString(response.getEntity());
  474. jsonObject = JSON.parseObject(result);
  475. hitsobject = (JSONObject) jsonObject.get("hits");
  476. array = JSON.parseArray(hitsobject.get("hits").toString());
  477. List partytimeline = new ArrayList<>();
  478. for (int i = 0; i <array.size() ; i++) {
  479. JSONObject json = (JSONObject)array.get(i);
  480. Map mp = new HashMap();
  481. mp.put("id",json.getString("_id"));
  482. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  483. partytimeline.add(mp);
  484. }
  485. map.put("partytimeline",partytimeline);
  486. logger.info("出客户详情时间:"+DateUtils.getTime());
  487. return AjaxResult.success(map);
  488. } catch (Exception e) {
  489. logger.info("客户详情报错时间:"+DateUtils.getTime());
  490. e.printStackTrace();
  491. return AjaxResult.error();
  492. }
  493. }
  494. @GetMapping("/getCustomerOverViewById")
  495. @ResponseBody
  496. public AjaxResult getCustomerOverViewById(String id) {
  497. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  498. try {
  499. logger.info("进客户概览时间:"+DateUtils.getTime());
  500. Map<String, String> paramMap = new HashMap<String, String>();
  501. paramMap.put("pretty", "true");
  502. Request scriptRequest = new Request("GET", "shanglifeecif.individual/default_type_/"+id+"?pretty=true");
  503. Response response = restClient.performRequest(scriptRequest);
  504. String result = EntityUtils.toString(response.getEntity());
  505. Map map = new HashMap();
  506. JSONObject jsonObject = JSON.parseObject(result);
  507. Map mpInfo = new HashMap();
  508. String indid = jsonObject.getString("_id");
  509. mpInfo.put("id",indid);
  510. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  511. String scustid = source.getString("scustid");
  512. mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
  513. if(mpInfo.containsKey("birthday")){
  514. mpInfo.put("birthday", source.getString("birthday").substring(0,10));
  515. mpInfo.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,source.getString("birthday"))));
  516. }else{
  517. mpInfo.put("birthday","");
  518. mpInfo.put("age","");
  519. }
  520. scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?pretty=true&sort=padate:asc&q=applicantscustid:"+scustid);
  521. response = restClient.performRequest(scriptRequest);
  522. result = EntityUtils.toString(response.getEntity());
  523. jsonObject = JSON.parseObject(result);
  524. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  525. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  526. DecimalFormat df = new DecimalFormat("######0.00");//保留两位小数
  527. double prem = 0;//标准保费
  528. //概览投保时间和保费折线图
  529. Map expectedData = new HashMap();
  530. String[] edata = new String[]{"0","0","0","0","0","0","0","0","0","0","0","0"};
  531. expectedData.put("name","");
  532. Map actaulData = new HashMap();
  533. String[] adata = new String[]{"0","0","0","0","0","0","0","0","0","0","0","0"};
  534. actaulData.put("name","");
  535. List xaxisData = new ArrayList();
  536. xaxisData.add("1");
  537. xaxisData.add("2");
  538. xaxisData.add("3");
  539. xaxisData.add("4");
  540. xaxisData.add("5");
  541. xaxisData.add("6");
  542. xaxisData.add("7");
  543. xaxisData.add("8");
  544. xaxisData.add("9");
  545. xaxisData.add("10");
  546. xaxisData.add("11");
  547. xaxisData.add("12");
  548. long insureDay = 0;//投保时长
  549. int guaranteeDay = 0;//享受保障天数
  550. Map majorCategorie = new HashMap();
  551. Map mpremMap = new HashMap();
  552. for (int i = 0; i <array.size() ; i++) {
  553. JSONObject json = (JSONObject)array.get(i);
  554. JSONObject _source = (JSONObject) json.get("_source");
  555. Date padate = _source.getDate("padate");
  556. //xaxisData.add(DateUtils.parseDateToStr("MM",padate));
  557. if(_source.containsKey("prem")){
  558. prem+=_source.getDouble("prem");
  559. String m = DateUtils.parseDateToStr("M", padate);
  560. if(mpremMap.containsKey(m)){
  561. double tprem = Double.parseDouble(mpremMap.get(m).toString());
  562. tprem+=_source.getDouble("prem");
  563. //mpremMap.put(m,mprem);
  564. mpremMap.put(m,df.format(tprem));
  565. edata[Integer.parseInt(m)-1] = df.format(tprem);
  566. adata[Integer.parseInt(m)-1] = df.format(tprem);
  567. }else{
  568. mpremMap.put(m,df.format(_source.getDouble("prem")));
  569. edata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
  570. adata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
  571. }
  572. //edata.add(_source.getDouble("prem"));
  573. //adata.add(_source.getDouble("prem"));
  574. }
  575. if(i==0){
  576. insureDay = DateUtils.getDateDifDay(new Date(),padate);
  577. }
  578. if("有效".equals(_source.getString("policystate"))){
  579. guaranteeDay+=_source.getInteger("agrmntage");
  580. }
  581. //String risk_categories = _source.getString("risk_categories");
  582. String risk_categories_name = _source.getString("risk_categories_name");
  583. if(majorCategorie.containsKey(risk_categories_name)){
  584. double risk = Double.parseDouble(majorCategorie.get(risk_categories_name).toString());
  585. if(_source.containsKey("risk")){
  586. risk += _source.getDouble("risk");
  587. }
  588. majorCategorie.put(risk_categories_name,risk);
  589. }else{
  590. if(_source.containsKey("risk")){
  591. majorCategorie.put(risk_categories_name,_source.getDouble("risk"));
  592. }
  593. }
  594. }
  595. expectedData.put("data",edata);
  596. actaulData.put("data",adata);
  597. Map lineBarChartData = new HashMap();
  598. lineBarChartData.put("expectedData",expectedData);
  599. lineBarChartData.put("actaulData",actaulData);
  600. lineBarChartData.put("xaxisData",xaxisData);
  601. map.put("lineBarChartData",lineBarChartData);
  602. //查询理赔信息
  603. scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?pretty=true&q=lpscutid:"+scustid);
  604. response = restClient.performRequest(scriptRequest);
  605. result = EntityUtils.toString(response.getEntity());
  606. jsonObject = JSON.parseObject(result);
  607. hitsobject = (JSONObject) jsonObject.get("hits");
  608. array = JSON.parseArray(hitsobject.get("hits").toString());
  609. Map insuranceclaimthread = new HashMap();
  610. List insuranceclaimthreads = new ArrayList<>();
  611. double claimAmount = 0;//理赔总金额
  612. String claimType = "";//理赔类型
  613. for (int i = 0; i <array.size() ; i++) {
  614. JSONObject json = (JSONObject)array.get(i);
  615. JSONObject claimSource = JSON.parseObject(json.getString("_source"));
  616. if(claimSource.containsKey("ccamt")){
  617. claimAmount+=claimSource.getDouble("ccamt");
  618. }
  619. claimType = claimSource.getString("accidenttype");
  620. insuranceclaimthreads.add(claimSource);
  621. }
  622. insuranceclaimthread.put("isClaim",insuranceclaimthreads.size()>0?"是":"否");
  623. insuranceclaimthread.put("claimAmount",df.format(claimAmount));
  624. insuranceclaimthread.put("claimType",claimType);
  625. map.put("insuranceclaimthread",insuranceclaimthread);
  626. mpInfo.put("prem",df.format(prem));
  627. mpInfo.put("insureDay",insureDay);
  628. mpInfo.put("guaranteeDay",guaranteeDay>insureDay?insureDay:guaranteeDay);
  629. map.put("custInfo",mpInfo);
  630. map.put("majorCategorie",majorCategorie);
  631. logger.info("出客户概览时间:"+DateUtils.getTime());
  632. return AjaxResult.success(map);
  633. } catch (Exception e) {
  634. logger.info("客户概览报错时间:"+DateUtils.getTime());
  635. e.printStackTrace();
  636. return AjaxResult.error();
  637. }
  638. }
  639. @PostMapping("/export")
  640. public void export(HttpServletResponse response) throws Exception
  641. {
  642. //拼装查询条件
  643. StringBuilder builder =new StringBuilder();
  644. builder.append("{");
  645. builder.append("\"query\":{");//query开始
  646. builder.append("\"bool\":{");//boot开始
  647. builder.append("\"must\":[");//must开始
  648. //业绩归属字段
  649. /*if(StringUtils.isNotEmpty(deptCode)){
  650. builder.append("{\"prefix\":{\"policybelong\":"+deptCode+"}},");
  651. }*/
  652. builder.append("],");//must结束
  653. builder.append("\"must_not\":[");//must_not
  654. builder.append("],");
  655. builder.append("\"should\":[]");//should
  656. builder.append("}");//boot结束
  657. builder.append("},");//query结束
  658. // builder.append("\"from\":"+((pageNum-1)*10)+",");//第几页
  659. //builder.append("\"size\":"+100+",");//查询几个
  660. builder.append("\"sort\":[{\"scustid\":{\"order\":\"asc\"}}],");//排序
  661. builder.append("\"aggs\":{}");//
  662. builder.append("}");
  663. HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
  664. Request scriptRequest = new Request("GET", "/shanglifeecif.individual/_search?size=1000&pretty=true");
  665. scriptRequest.setEntity(entity);
  666. Response responseData = restClient.performRequest(scriptRequest);
  667. String result = EntityUtils.toString(responseData.getEntity());
  668. JSONObject jsonObject = JSON.parseObject(result);
  669. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  670. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  671. List<Customer> customers = new ArrayList<Customer>();
  672. for (int i = 0; i <array.size() ; i++) {
  673. JSONObject json = (JSONObject)array.get(i);
  674. Map mp = new HashMap();
  675. Customer customer = new Customer();
  676. json.getString("_source");
  677. mp.put("id",json.getString("_id"));
  678. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  679. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  680. customer.setScustId(jsonOb.getString("scustid"));
  681. customer.setCustId(jsonOb.getString("custid"));
  682. customer.setName(jsonOb.getString("name"));
  683. customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
  684. if(mp.containsKey("birthday")){
  685. mp.put("birthday", jsonOb.getString("birthday").substring(0,10));
  686. mp.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,jsonOb.getString("birthday"))));
  687. customer.setBirthDay(jsonOb.getString("birthday").substring(0,10));
  688. customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,jsonOb.getString("birthday"))));
  689. }
  690. if(mp.containsKey("idcard")){
  691. customer.setIdType("身份证");
  692. customer.setIdCard(jsonOb.getString("idcard"));
  693. }else if(mp.containsKey("passport")){
  694. customer.setIdType("护照");
  695. customer.setIdCard(jsonOb.getString("passport"));
  696. }else if(mp.containsKey("dlicense")){
  697. customer.setIdType("驾驶证");
  698. customer.setIdCard(jsonOb.getString("dlicense"));
  699. }else if(mp.containsKey("othernumber")){
  700. customer.setIdType("其它证件类型");
  701. customer.setIdCard(jsonOb.getString("othernumber"));
  702. }
  703. if(mp.containsKey("custclass")){
  704. String custclass = jsonOb.getString("custclass");
  705. switch (custclass){
  706. case "1":
  707. customer.setCustClass("钻石");
  708. case "2":
  709. customer.setCustClass("白金");
  710. case "3":
  711. customer.setCustClass("黄金");
  712. case "4":
  713. customer.setCustClass("普通");
  714. default:
  715. customer.setCustClass("无");
  716. }
  717. }else{
  718. customer.setCustClass("无");
  719. }
  720. customers.add(customer);
  721. }
  722. ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer.class);
  723. util.exportExcel(response, customers, "客户数据");
  724. }
  725. }