CustomerApiController.java 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178
  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.CsvUtil;
  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 com.dgtis.data.service.ISysUserService;
  12. import com.dgtis.data.util.AddressResolutionUtil;
  13. import com.dgtis.system.api.domain.SysUser;
  14. import com.google.common.collect.Lists;
  15. import org.apache.commons.lang3.mutable.Mutable;
  16. import org.apache.commons.lang3.mutable.MutableBoolean;
  17. import org.apache.commons.lang3.mutable.MutableInt;
  18. import org.apache.commons.lang3.mutable.MutableObject;
  19. import org.apache.commons.lang3.tuple.ImmutablePair;
  20. import org.apache.commons.lang3.tuple.ImmutableTriple;
  21. import org.apache.commons.lang3.tuple.Pair;
  22. import org.apache.commons.lang3.tuple.Triple;
  23. import org.apache.http.HttpEntity;
  24. import org.apache.http.entity.ContentType;
  25. import org.apache.http.nio.entity.NStringEntity;
  26. import org.apache.http.util.EntityUtils;
  27. import org.elasticsearch.client.Request;
  28. import org.elasticsearch.client.Response;
  29. import org.elasticsearch.client.RestClient;
  30. import org.slf4j.Logger;
  31. import org.slf4j.LoggerFactory;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.beans.factory.annotation.Value;
  34. import org.springframework.http.HttpMethod;
  35. import org.springframework.stereotype.Controller;
  36. import org.springframework.web.bind.annotation.*;
  37. import javax.servlet.http.HttpServletRequest;
  38. import javax.servlet.http.HttpServletResponse;
  39. import java.io.IOException;
  40. import java.text.DecimalFormat;
  41. import java.util.*;
  42. import java.util.function.BiConsumer;
  43. import java.util.stream.Collectors;
  44. import java.util.stream.Stream;
  45. /**
  46. * @description:客户信息列表api
  47. * @author:qxm
  48. * @date:2021/1/22 10:24
  49. */
  50. @Controller
  51. @RequestMapping("/customer")
  52. public class CustomerApiController {
  53. /**
  54. * SHOW_ALL_LABLES 不分渠道展示所有标签 总部团险展示所有标签
  55. * HIDE_CHANNELS_LABLES 有不同渠道保单情况下 分渠道标签全不显示 仅显示公共标签 , 总部团险展示所有标签
  56. * SHOW_DISTINGUISH_CHANNELS_LABLES 分渠道展示标签, 总部团险展示所有标签
  57. */
  58. @Value("${dgtis.show-label-code}")
  59. private String showLabelCode = "SHOW_ALL_LABLES";
  60. private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class);
  61. @Autowired
  62. private RestClient restClient;
  63. @Autowired
  64. private ISysUserService userService;
  65. @GetMapping("/getCustomerList")
  66. @ResponseBody
  67. public AjaxResult getCustomerList(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize,
  68. String education,//学历
  69. String policybelong,//业绩归属
  70. String payS,String payE, //年缴费区间
  71. String fadate,//投保年份
  72. String productname,//险种类别
  73. String insuredAmountS,String insuredAmountE,//保额区间
  74. String ageS,String ageE,//年龄区间
  75. String gender,//性别
  76. String sobirth,//省份
  77. String NOVPolicy,//保单件数
  78. String custtype,//客户类型 投保人
  79. String SCustID,// 核心客户号
  80. String custclass,//客户等级
  81. String participantsDateS,String participantsDateE,//参与方时间
  82. String PIncomeS,String PIncomeE,//年收入区间
  83. String Insured,//投保对象
  84. String lp,//理赔
  85. String yx,//有效
  86. String gzgw,//关注官微
  87. String zcgw,//注册官微
  88. String name,//客户姓名
  89. String idcard,//客户证件号码
  90. String mobile//客户手机号
  91. ) {
  92. try {
  93. logger.info("进客户列表时间:"+DateUtils.getTime());
  94. JSONObject jsonObject = getCustomerListData((pageNum - 1) * 10, pageSize, true, null,
  95. education,//学历
  96. policybelong,//业绩归属
  97. payS, payE, //年缴费区间
  98. fadate,//投保年份
  99. productname,//险种类别
  100. insuredAmountS, insuredAmountE,//保额区间
  101. ageS, ageE,//年龄区间
  102. gender,//性别
  103. sobirth,//省份
  104. NOVPolicy,//保单件数
  105. custtype,//客户类型 投保人
  106. SCustID,// 核心客户号
  107. custclass,//客户等级
  108. participantsDateS, participantsDateE,//参与方时间
  109. PIncomeS, PIncomeE,//年收入区间
  110. Insured,//投保对象
  111. lp,//理赔
  112. yx,//有效
  113. gzgw,//关注官微
  114. zcgw,//注册官微
  115. name,//客户姓名
  116. idcard,//客户证件号码
  117. mobile//客户手机号
  118. );
  119. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  120. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  121. List listMap = new ArrayList<>();
  122. Map map = new HashMap();
  123. for (int i = 0; i <array.size() ; i++) {
  124. JSONObject json = (JSONObject)array.get(i);
  125. Map mp = getSource(json);
  126. listMap.add(mp);
  127. }
  128. long total = hitsobject.getLong("total");
  129. map.put("list",listMap);
  130. map.put("total",total);
  131. logger.info("出客户列表时间:"+DateUtils.getTime());
  132. return AjaxResult.success(map);
  133. } catch (Exception e) {
  134. logger.info("列表报错时间:"+DateUtils.getTime());
  135. e.printStackTrace();
  136. return AjaxResult.error();
  137. }
  138. }
  139. /**
  140. * 将hit._source转换成map形式,并在map中添加id字段
  141. * @param hit hit JSONObject
  142. * @return
  143. */
  144. private Map getSource(JSONObject hit) {
  145. String idKey = "indid";
  146. Map mp = JSON.parseObject(hit.getString("_source"), Map.class);
  147. if (mp.containsKey(idKey)) {
  148. // 查shanglifeecif.customerno_salecom_relation表id是indid
  149. mp.put("id", mp.get(idKey));
  150. } else {
  151. // 查shanglifeecif.individual表id是_id
  152. mp.put("id", hit.getString("_id"));
  153. }
  154. Object birthday = mp.get("birthday");
  155. if(birthday != null){
  156. try {
  157. mp.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD, birthday.toString())));
  158. } catch (Exception e) {
  159. logger.warn(String.format("Failed to calendar age, birthday is [%s], birthday and age reset to empty.", birthday));
  160. mp.put("birthda", "");
  161. mp.put("age", "");
  162. }
  163. }else{
  164. mp.put("birthday", "");
  165. mp.put("age","");
  166. }
  167. return mp;
  168. }
  169. @GetMapping("/getCustomerById")
  170. @ResponseBody
  171. public AjaxResult getCustomerById(String id) {
  172. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  173. try {
  174. Long userId = SecurityUtils.getUserId();
  175. SysUser sysUser = userService.selectUserById(userId);
  176. String deptCode = "";
  177. // “上海人寿”部门编号开发环境是null,生产环境是0。不是上海人寿部门的才分渠道
  178. if(StringUtils.isNotEmpty( sysUser.getDept().getDeptCode()) && ! "0".equals(sysUser.getDept().getDeptCode())){
  179. deptCode = sysUser.getDept().getDeptCode();
  180. }
  181. logger.info("进客户详情时间:"+DateUtils.getTime());
  182. Map<String, String> paramMap = new HashMap<String, String>();
  183. paramMap.put("pretty", "true");
  184. Request scriptRequest = new Request("GET", "/shanglifeecif.individual/default_type_/"+id+"?pretty=true");
  185. Response response = restClient.performRequest(scriptRequest);
  186. String result = EntityUtils.toString(response.getEntity());
  187. Map map = new HashMap();
  188. JSONObject jsonObject = JSON.parseObject(result);
  189. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  190. String indid = jsonObject.getString("_id");
  191. String custtype = source.getString("custtype");
  192. String scustid = source.getString("scustid");
  193. Map mpInfo = getLables(jsonObject, deptCode);
  194. map.put("custInfo",mpInfo);
  195. Map query =new HashMap();
  196. query.put("indid1",indid);
  197. // 2022/5/13 陆光晨 关系信息分渠道查询
  198. String lpqSearch = "indid1:"+ scustid;
  199. if( StringUtils.isNotEmpty(deptCode)){
  200. lpqSearch += "%20AND%20salecom:"+deptCode;
  201. }
  202. scriptRequest = new Request("GET", "/shanglifeecif.indrelationship/_search?pretty=true&q="+ lpqSearch);
  203. response = restClient.performRequest(scriptRequest);
  204. result = EntityUtils.toString(response.getEntity());
  205. jsonObject = JSON.parseObject(result);
  206. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  207. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  208. Set<Map<String, String>> relationship = new HashSet<>();
  209. for (int i = 0; i <array.size() ; i++) {
  210. JSONObject json = (JSONObject)array.get(i);
  211. JSONObject shipSource = JSON.parseObject(json.getString("_source"));
  212. if (shipSource.containsKey("rstype")
  213. && shipSource.containsKey("indid1")
  214. && shipSource.containsKey("name1")
  215. && shipSource.containsKey("role1")
  216. && shipSource.containsKey("indid2")
  217. && shipSource.containsKey("name2")
  218. && shipSource.containsKey("role2")) {
  219. Map<String, String> mp = new HashMap<>(8);
  220. mp.put("rstype", shipSource.getString("rstype"));
  221. mp.put("indid1", shipSource.getString("indid1"));
  222. mp.put("name1", shipSource.getString("name1"));
  223. mp.put("role1", shipSource.getString("role1"));
  224. mp.put("indid2", shipSource.getString("indid2"));
  225. mp.put("name2", shipSource.getString("name2"));
  226. mp.put("role2", shipSource.getString("role2"));
  227. relationship.add(mp);
  228. }
  229. }
  230. map.put("relationship",relationship);
  231. query =new HashMap();
  232. query.put("applicantid",indid);
  233. //理赔查询
  234. lpqSearch = "lpscutid:"+scustid;
  235. if( StringUtils.isNotEmpty(deptCode)){
  236. lpqSearch = "(lpscutid:"+scustid+"%20AND%20salecom:"+deptCode+")";
  237. }
  238. scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?size=100&pretty=true&q="+lpqSearch);
  239. response = restClient.performRequest(scriptRequest);
  240. result = EntityUtils.toString(response.getEntity());
  241. jsonObject = JSON.parseObject(result);
  242. hitsobject = (JSONObject) jsonObject.get("hits");
  243. array = JSON.parseArray(hitsobject.get("hits").toString());
  244. List insuranceclaimthread = new ArrayList<>();
  245. for (int i = 0; i <array.size() ; i++) {
  246. JSONObject json = (JSONObject)array.get(i);
  247. Map mp = new HashMap();
  248. mp.put("id",json.getString("_id"));
  249. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  250. insuranceclaimthread.add(mp);
  251. }
  252. map.put("insuranceclaimthread",insuranceclaimthread);
  253. //合约信息
  254. logger.info("合约信息 投保人被保人类型:"+custtype);
  255. // if(custtype.trim().indexOf("被保人")!=-1){
  256. // String qSearch = "insuredscustid:"+scustid;
  257. // if( StringUtils.isNotEmpty(deptCode)){
  258. // qSearch = "(insuredscustid:"+scustid+"%20AND%20policybelong:"+deptCode+")";
  259. // }
  260. // scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q="+qSearch);
  261. // }else{
  262. // String qSearch = "applicantscustid:"+scustid;
  263. // if( StringUtils.isNotEmpty(deptCode)){
  264. // qSearch = "(applicantscustid:"+scustid+"%20AND%20policybelong:"+deptCode+")";
  265. // }
  266. // scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q="+qSearch);
  267. // }
  268. //20230426曹老师要求合约查询保险人和被保险人 都查询出合约列表
  269. String qSearch = "(applicantscustid:"+scustid+"%20OR%20insuredscustid:"+scustid+")";
  270. if( StringUtils.isNotEmpty(deptCode)){
  271. qSearch = "(applicantscustid:"+scustid+"%20OR%20insuredscustid:"+scustid+")"+"%20AND%20policybelong:"+deptCode+"";
  272. }
  273. scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q="+qSearch);
  274. logger.info("合约信息请求参数"+scriptRequest.getEndpoint());
  275. response = restClient.performRequest(scriptRequest);
  276. result = EntityUtils.toString(response.getEntity());
  277. jsonObject = JSON.parseObject(result);
  278. hitsobject = (JSONObject) jsonObject.get("hits");
  279. array = JSON.parseArray(hitsobject.get("hits").toString());
  280. List insurancearrangement = new ArrayList<>();
  281. for (int i = 0; i <array.size() ; i++) {
  282. JSONObject json = (JSONObject)array.get(i);
  283. Map mp = new HashMap();
  284. mp.put("id",json.getString("_id"));
  285. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  286. insurancearrangement.add(mp);
  287. }
  288. map.put("insurancearrangement",insurancearrangement);
  289. //接触信息添加渠道条件
  290. //接触信息
  291. String jcqSearch = "partyid:"+scustid;
  292. if( StringUtils.isNotEmpty(deptCode)){
  293. jcqSearch = "(partyid:"+scustid+"%20AND%20salecom:"+deptCode+")";
  294. }
  295. scriptRequest = new Request("GET", "/shanglifeecif.partytimeline/_search?size=100&pretty=true&sort=sdate:asc&q="+jcqSearch);
  296. logger.info("接触信息请求参数:",scriptRequest.getEndpoint());
  297. response = restClient.performRequest(scriptRequest);
  298. result = EntityUtils.toString(response.getEntity());
  299. jsonObject = JSON.parseObject(result);
  300. hitsobject = (JSONObject) jsonObject.get("hits");
  301. array = JSON.parseArray(hitsobject.get("hits").toString());
  302. List partytimeline = new ArrayList<>();
  303. for (int i = 0; i <array.size() ; i++) {
  304. JSONObject json = (JSONObject)array.get(i);
  305. Map mp = new HashMap();
  306. mp.put("id",json.getString("_id"));
  307. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  308. partytimeline.add(mp);
  309. }
  310. map.put("partytimeline",partytimeline);
  311. logger.info(scriptRequest.getEndpoint());
  312. //202508 新增续期标签信息和保单信息
  313. JSONObject renewalNode = (JSONObject) map.computeIfAbsent("renewalNode", k -> new JSONObject(true));
  314. //1.标签信息
  315. List<String> labelDescs = (List<String>) renewalNode.computeIfAbsent("labelDescs", k -> Lists.newArrayList());
  316. Stream.of(mpInfo.get("label130"), mpInfo.get("label131"), mpInfo.get("label132"))
  317. .filter(Objects::nonNull)
  318. .map(Object::toString)
  319. .forEach(labelDescs::add);
  320. Request esRequest = new Request(HttpMethod.GET.name(), "/shanglifeecif.customerno_insurance_policies_info/_search");
  321. esRequest.addParameter("pretty", "true");
  322. esRequest.setJsonEntity(String.format("{\"query\": {\"bool\": {\"filter\": [{\"term\": {\"customer_no\": \"%s\"}}]}}, \"from\": 0, \"size\": 1000}", scustid));
  323. Response esResponse = restClient.performRequest(esRequest);
  324. String responseStr = EntityUtils.toString(esResponse.getEntity());
  325. Optional<List<JSONObject>> optional = Optional.ofNullable(responseStr)
  326. .map(JSON::parseObject)
  327. .map(j -> j.getJSONObject("hits"))
  328. .map(j -> j.getJSONArray("hits"))
  329. .map(hits -> hits.stream()
  330. .filter(o -> o instanceof JSONObject)
  331. .map(o -> (JSONObject) o)
  332. .map(j -> j.getJSONObject("_source"))
  333. .filter(Objects::nonNull)
  334. .collect(Collectors.toList()));
  335. if (optional.isPresent()) {
  336. List<JSONObject> _sources = optional.get();
  337. LinkedList<Triple<Pair<String, String>, MutableInt, Mutable<String>>> triples = Lists.newLinkedList();
  338. //a.交费时间
  339. triples.add(new ImmutableTriple<>(new ImmutablePair<>("a", "30天内交费"), new MutableInt(), new MutableObject<>()));
  340. triples.add(new ImmutableTriple<>(new ImmutablePair<>("b", "31-50天交费"), new MutableInt(), new MutableObject<>()));
  341. triples.add(new ImmutableTriple<>(new ImmutablePair<>("c", "50-60天交费"), new MutableInt(), new MutableObject<>()));
  342. triples.add(new ImmutableTriple<>(new ImmutablePair<>("d", "逾期交费"), new MutableInt(), new MutableObject<>()));
  343. BiConsumer<Triple<Pair<String, String>, MutableInt, Mutable<String>>, JSONObject> consumer = (triple, jsonObj) -> {
  344. String type = triple.getLeft().getKey();
  345. MutableInt num = triple.getMiddle();
  346. Mutable<String> date = triple.getRight();
  347. Optional.of("pay_period_num_".concat(type))
  348. .map(jsonObj::getInteger)
  349. .ifPresent(num::add);
  350. Optional.of("pay_period_date_".concat(type))
  351. .map(jsonObj::getString)
  352. .filter(StringUtils::isNotEmpty)
  353. .map(d -> Optional.ofNullable(date.getValue())
  354. .filter(_d -> _d.compareTo(d) > 0)
  355. .orElse(d))
  356. .ifPresent(date::setValue);
  357. };
  358. //b.是否存在暂停扣费
  359. MutableInt stopFeeNum = new MutableInt();
  360. //c.是否存在收费退费
  361. MutableInt refundFeeNum = new MutableInt();
  362. //d.多次联系不上
  363. MutableBoolean failedContacted = new MutableBoolean();
  364. //e.是否存在多张保单
  365. MutableInt withinPayPeriodNum = new MutableInt();
  366. //f_1.是否存在保单挂起_保全挂起中
  367. MutableInt bqHangupNum = new MutableInt();
  368. //f_2是否存在保单挂起_理赔挂起中
  369. MutableInt lpHangupNum = new MutableInt();
  370. _sources.forEach(_source -> {
  371. triples.forEach(triple -> consumer.accept(triple, _source));
  372. Optional.ofNullable(_source.getString("policy_label_2"))
  373. .filter(StringUtils::isNotEmpty)
  374. .ifPresent(s -> stopFeeNum.increment());
  375. Optional.ofNullable(_source.getString("policy_label_3"))
  376. .filter(StringUtils::isNotEmpty)
  377. .ifPresent(s -> refundFeeNum.increment());
  378. Optional.ofNullable(_source.getString("policy_label_4"))
  379. .filter(StringUtils::isNotEmpty)
  380. .ifPresent(s -> failedContacted.setTrue());
  381. Optional.ofNullable(_source.getString("is_within_pay_period"))
  382. .filter("Y"::equals)
  383. .ifPresent(s -> withinPayPeriodNum.increment());
  384. Optional.ofNullable(_source.getString("policy_label_5"))
  385. .filter(StringUtils::isNotEmpty)
  386. .ifPresent(s -> bqHangupNum.increment());
  387. Optional.ofNullable(_source.getString("policy_label_6"))
  388. .filter(StringUtils::isNotEmpty)
  389. .ifPresent(s -> lpHangupNum.increment());
  390. });
  391. triples.stream()
  392. .max((t1, t2) -> {
  393. int cmp = t1.getMiddle().compareTo(t2.getMiddle());
  394. if (cmp != 0) {
  395. return cmp;
  396. }
  397. String date1 = t1.getRight().getValue();
  398. String date2 = t2.getRight().getValue();
  399. if (date1 == null && date2 == null) {
  400. return 0;
  401. } else if (date1 == null) {
  402. return -1;
  403. } else if (date2 == null) {
  404. return 1;
  405. }
  406. return date1.compareTo(date2);
  407. })
  408. .ifPresent(triple -> {
  409. Pair<String, String> pair = triple.getLeft();
  410. String type = pair.getKey();
  411. String desc = pair.getValue();
  412. Integer num = triple.getMiddle().getValue();
  413. if (num > 0) {
  414. if ("d".equals(type)) {
  415. labelDescs.add(desc.concat("(").concat(num.toString()).concat("次)"));
  416. } else {
  417. labelDescs.add(desc);
  418. triple = triples.getLast();
  419. desc = triple.getLeft().getValue();
  420. num = triple.getMiddle().getValue();
  421. if (num > 0) {
  422. labelDescs.add(desc.concat("(").concat(num.toString()).concat("次)"));
  423. }
  424. }
  425. }
  426. });
  427. Optional.of(stopFeeNum)
  428. .map(MutableInt::getValue)
  429. .filter(num -> num > 0)
  430. .ifPresent(num -> labelDescs.add("有暂停扣费".concat("(").concat(num.toString()).concat("单)")));
  431. Optional.of(refundFeeNum)
  432. .map(MutableInt::getValue)
  433. .filter(num -> num > 0)
  434. .ifPresent(num -> labelDescs.add("有续期收费回退".concat("(").concat(num.toString()).concat("单)")));
  435. if (failedContacted.isTrue()) {
  436. labelDescs.add("多次联系不上");
  437. }
  438. Optional.of(withinPayPeriodNum)
  439. .map(MutableInt::getValue)
  440. .filter(num -> num > 0)
  441. .ifPresent(num -> labelDescs.add("多单交费".concat("(").concat(num.toString()).concat("单)")));
  442. Optional.of(bqHangupNum)
  443. .map(MutableInt::getValue)
  444. .filter(num -> num > 0)
  445. .ifPresent(num -> labelDescs.add("保全挂起中".concat("(").concat(num.toString()).concat("单)")));
  446. Optional.of(lpHangupNum)
  447. .map(MutableInt::getValue)
  448. .filter(num -> num > 0)
  449. .ifPresent(num -> labelDescs.add("理赔挂起中".concat("(").concat(num.toString()).concat("单)")));
  450. }
  451. //2.保单信息 过滤只展示投保人数据
  452. List<Object> policyInfos = (List<Object>) renewalNode.computeIfAbsent("policyInfos",
  453. k -> Lists.newArrayListWithCapacity(insurancearrangement.size()));
  454. ((List<Object>) insurancearrangement).stream()
  455. .filter(o -> {
  456. Map mp = (Map) o;
  457. String applicantscustid = Optional.ofNullable(mp.get("applicantscustid"))
  458. .map(Object::toString)
  459. .orElse(null);
  460. return StringUtils.equals(applicantscustid, scustid);
  461. })
  462. .forEach(policyInfos::add);
  463. logger.info("出客户详情时间:"+DateUtils.getTime());
  464. return AjaxResult.success(map);
  465. } catch (Exception e) {
  466. logger.info("客户详情报错时间:"+DateUtils.getTime());
  467. e.printStackTrace();
  468. return AjaxResult.error();
  469. }
  470. }
  471. @GetMapping("/getCustomerOverViewById")
  472. @ResponseBody
  473. public AjaxResult getCustomerOverViewById(String id) {
  474. Long userId = SecurityUtils.getUserId();
  475. SysUser sysUser = userService.selectUserById(userId);
  476. String deptCode = null;
  477. // “上海人寿” 部门编号开发环境是null,生产环境是0。不是上海人寿部门的才分渠道
  478. if (StringUtils.isNotEmpty(sysUser.getDept().getDeptCode()) && ! "0".equals(sysUser.getDept().getDeptCode())) {
  479. deptCode = sysUser.getDept().getDeptCode();
  480. }
  481. // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
  482. try {
  483. logger.info("进客户概览时间:"+DateUtils.getTime());
  484. Request scriptRequest = new Request("GET", "/shanglifeecif.individual/default_type_/"+id+"?pretty=true");
  485. Response response = restClient.performRequest(scriptRequest);
  486. String result = EntityUtils.toString(response.getEntity());
  487. Map map = new HashMap();
  488. JSONObject jsonObject = JSON.parseObject(result);
  489. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  490. String scustid = source.getString("scustid");
  491. Map mpInfo = getLables(jsonObject, deptCode);
  492. String jcqSearch = "applicantscustid:"+scustid;
  493. if( StringUtils.isNotEmpty(deptCode)){
  494. jcqSearch = "(applicantscustid:"+scustid+"%20AND%20policybelong:"+deptCode+")";
  495. }
  496. scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q="+jcqSearch);
  497. logger.info("insurancearrangement",scriptRequest.getEndpoint());
  498. response = restClient.performRequest(scriptRequest);
  499. result = EntityUtils.toString(response.getEntity());
  500. jsonObject = JSON.parseObject(result);
  501. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  502. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  503. DecimalFormat df = new DecimalFormat("######0.0");//保留两位小数改为保留一位小数
  504. double prem = 0;//标准保费
  505. double sumprem = 0;//累计保费
  506. double handedinprem = 0;//已交保费
  507. //概览投保时间和保费折线图
  508. Map expectedData = new HashMap();
  509. String[] edata = new String[]{"0","0","0","0","0","0","0","0","0","0","0","0"};
  510. expectedData.put("name","");
  511. Map actaulData = new HashMap();
  512. String[] adata = new String[]{"0","0","0","0","0","0","0","0","0","0","0","0"};
  513. actaulData.put("name","");
  514. List xaxisData = new ArrayList();
  515. xaxisData.add("1");
  516. xaxisData.add("2");
  517. xaxisData.add("3");
  518. xaxisData.add("4");
  519. xaxisData.add("5");
  520. xaxisData.add("6");
  521. xaxisData.add("7");
  522. xaxisData.add("8");
  523. xaxisData.add("9");
  524. xaxisData.add("10");
  525. xaxisData.add("11");
  526. xaxisData.add("12");
  527. long insureDay = 0;//投保时长
  528. int guaranteeDay = 0;//享受保障天数
  529. Map<String,Object> majorCategorie = new HashMap();
  530. Map mpremMap = new HashMap();
  531. int firstDate = 1;//定义第一次长期险获取
  532. Date date = new Date();
  533. Calendar cal = Calendar.getInstance();
  534. cal.setTime(date);
  535. cal.add(Calendar.YEAR, 1);
  536. Date nextYearTime = cal.getTime();
  537. String currentDateTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,date);
  538. String currentYear = DateUtils.parseDateToStr(DateUtils.YYYY,date);
  539. Set<String> noivpolicyset= new HashSet<>();//失效保单
  540. Set<String> novpolicyset= new HashSet<>();//有效保单
  541. //获取最近年份
  542. logger.info("getCustomerOverViewById",array.toJSONString());
  543. List<PolicyDate> policyDates = new ArrayList<>();
  544. final String contno = "policyno";
  545. final String startDate = "pindate";
  546. final String endDate = "pmdate";
  547. final String padateKey = "padate";
  548. final String agrmntageKey = "agrmntage";
  549. final String policystate = "policystate";
  550. for (int i = 0; i <array.size() ; i++) {
  551. JSONObject json = (JSONObject)array.get(i);
  552. JSONObject _source = (JSONObject) json.get("_source");
  553. if (_source.containsKey(contno)
  554. && _source.containsKey(startDate)
  555. && _source.containsKey(endDate)
  556. && _source.containsKey(padateKey)
  557. && _source.containsKey(agrmntageKey)
  558. && _source.containsKey(policystate)) {
  559. try {
  560. policyDates.add(new PolicyDate(
  561. _source.getString(contno)
  562. , _source.getDate(startDate)
  563. , _source.getDate(endDate)
  564. , _source.getDate(padateKey)
  565. , _source.getString(policystate)
  566. , _source.getInteger(agrmntageKey)));
  567. } catch (Exception e) {
  568. logger.warn(String.format(
  569. "Failed to instance PolicyDate, %s: [%s], %s: [%s], %s: [%s], %s: [%s], %s: [%s], %s: [%s]"
  570. , contno, _source.get(contno)
  571. , startDate, _source.get(startDate)
  572. , endDate, _source.get(endDate)
  573. , padateKey, _source.get(padateKey)
  574. , policystate, _source.get(policystate)
  575. , agrmntageKey, _source.get(agrmntageKey)));
  576. }
  577. } else {
  578. logger.info(String.format("Failed to instance PolicyDate, must be '%s', '%s', '%s', '%s', '%s', '%s', _source: [%s]"
  579. , contno, startDate, endDate, padateKey, policystate, agrmntageKey, _source.toJSONString()));
  580. }
  581. Date padate = _source.getDate("padate");
  582. if(i==0){
  583. insureDay = DateUtils.getDateDifDay(new Date(),padate);
  584. }
  585. if("有效".equals(_source.getString("policystate"))){
  586. novpolicyset.add(_source.getString("policyno"));
  587. if(_source.containsKey("sumprem")){
  588. sumprem+=_source.getDouble("sumprem");
  589. }
  590. /* 2022/5/31 start 陆光晨 享受保障天数放在后面计算
  591. Integer agrmntage = _source.getInteger("agrmntage");
  592. //短期险
  593. if(agrmntage<180){
  594. Date pindate = _source.getDate("pindate");//起保日期
  595. Date pmdate = _source.getDate("pmdate");//终保日期
  596. guaranteeDay+=DateUtils.getDateDifDay(pmdate,pindate);
  597. }else{
  598. //获取第一次长期险的投保日期,使用当前日期减去投保日期获取保障天数
  599. if(firstDate==1){
  600. guaranteeDay+=DateUtils.getDateDifDay(new Date(),padate);
  601. firstDate++;
  602. }
  603. }
  604. 2022/5/31 end 陆光晨 享受保障天数放在后面计算
  605. */
  606. if(_source.containsKey("prem")){
  607. //计算年缴保费过滤掉缴费方式趸缴的
  608. if(!"趸缴".equals(_source.getString("payment"))){
  609. String norenewal = _source.getString("norenewal")==null?"":_source.getString("norenewal").trim();//续保次数
  610. String payendyear = _source.getString("payendyear")==null?"":_source.getString("payendyear").trim();//缴费年期
  611. //String currentPadateStr = DateUtils.parseDateToStr(currentYear+"-MM-dd",padate);
  612. if(_source.containsKey("npdate")){
  613. Date npdate = _source.getDate("npdate");
  614. String npDateStr = DateUtils.parseDateToStr("yyyy-MM-dd", npdate);
  615. String npDateStrYear = DateUtils.parseDateToStr("yyyy", npdate);
  616. //缴费期限和缴费次数不一样 或者 当年缴费期限和缴费次数一样时
  617. if(!norenewal.equals(payendyear) || (norenewal.equals(payendyear) && (Integer.parseInt(npDateStrYear)-1)==Integer.parseInt(currentYear))){
  618. prem+=_source.getDouble("prem");
  619. if(norenewal.equals(payendyear) && nextYearTime.getTime()>npdate.getTime() && Integer.parseInt(npDateStrYear)>Integer.parseInt(currentYear)){
  620. handedinprem+=_source.getDouble("prem");
  621. }
  622. }
  623. if(!norenewal.equals(payendyear) && npDateStr.compareTo(currentDateTime)>0 && !npDateStrYear.equals(currentYear)){
  624. handedinprem+=_source.getDouble("prem");
  625. }
  626. }
  627. String m = DateUtils.parseDateToStr("M", padate);
  628. if(mpremMap.containsKey(m)){
  629. double tprem = Double.parseDouble(mpremMap.get(m).toString());
  630. tprem+=_source.getDouble("prem");
  631. mpremMap.put(m,df.format(tprem));
  632. edata[Integer.parseInt(m)-1] = df.format(tprem);
  633. adata[Integer.parseInt(m)-1] = df.format(tprem);
  634. }else{
  635. mpremMap.put(m,df.format(_source.getDouble("prem")));
  636. edata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
  637. adata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
  638. }
  639. }else{
  640. if("趸缴".equals(_source.getString("payment")) && currentYear.equals(DateUtils.parseDateToStr("yyyy",padate))){
  641. prem+=_source.getDouble("prem");
  642. handedinprem+=_source.getDouble("prem");
  643. }
  644. }
  645. }
  646. String risk_categories_name = _source.getString("risk_categories_name");
  647. if(majorCategorie.containsKey(risk_categories_name)){
  648. double risk = Double.parseDouble(majorCategorie.get(risk_categories_name).toString());
  649. if(_source.containsKey("risk")){
  650. risk += _source.getDouble("risk");
  651. }
  652. majorCategorie.put(risk_categories_name,risk);
  653. }else{
  654. if(_source.containsKey("risk") && StringUtils.isNotEmpty(risk_categories_name)){
  655. majorCategorie.put(risk_categories_name,_source.getDouble("risk"));
  656. }
  657. }
  658. }else{
  659. //客户的所有保单缴费期满且承保期限已满正常终止的客户,需要加上累计保费
  660. if("终止".equals(_source.getString("policystate"))){
  661. String norenewal = _source.getString("norenewal")==null?"":_source.getString("norenewal").trim();//续保次数
  662. String payendyear = _source.getString("payendyear")==null?"":_source.getString("payendyear").trim();//缴费年期
  663. Date pmdate = _source.getDate("pmdate");//终保日期
  664. /*
  665. 2022/5/13 陆光晨 一期测试环境测试时测试老师要求不计算终止状态的保单,因为页面上显示的是“有效保单累计保费”所以只统计有效的就好
  666. if(norenewal.equals(payendyear) && currentDateTime.compareTo(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,pmdate))>0){
  667. if(_source.containsKey("sumprem")){
  668. sumprem+=_source.getDouble("sumprem");
  669. }
  670. }
  671. */
  672. Integer agrmntage = _source.getInteger("agrmntage");
  673. /*
  674. 2022/5/18 start 陆光晨 根据测试曹老师的要求,终止状态的保单计算保障天数是不需要控制短期险
  675. 缺陷描述:一期测试,使用健康险权限用户登录时,查看客户号1000573488的客户概览页,有一个终止状态的长期保单(正常到期)但享受保障天数是0
  676. 测试老师认为终止状态的保单也要算进保障天数中,不管是长期险还是短期险
  677. */
  678. //短期险
  679. // if(agrmntage<180){
  680. /* 2022/5/31 start 陆光晨 享受保障天数放在后面计算
  681. Date pindate = _source.getDate("pindate");//起保日期
  682. guaranteeDay+=DateUtils.getDateDifDay(pmdate,pindate);
  683. 2022/5/31 end 陆光晨 享受保障天数放在后面计算 */
  684. // }
  685. // 2022/5/18 end 陆光晨 根据测试曹老师的要求,终止状态的保单计算保障天数是不需要控制短期险
  686. }
  687. if (_source.getString("policystate") != null) {
  688. noivpolicyset.add(_source.getString("policyno"));
  689. }
  690. }
  691. }
  692. mpInfo.put("noivpolicy",noivpolicyset.size());
  693. mpInfo.put("novpolicy",novpolicyset.size());
  694. expectedData.put("data",edata);
  695. actaulData.put("data",adata);
  696. Map lineBarChartData = new HashMap();
  697. lineBarChartData.put("expectedData",expectedData);
  698. lineBarChartData.put("actaulData",actaulData);
  699. lineBarChartData.put("xaxisData",xaxisData);
  700. map.put("lineBarChartData",lineBarChartData);
  701. //查询理赔信息
  702. String lpqSearch = "lpscutid:"+scustid;
  703. if( StringUtils.isNotEmpty(deptCode)){
  704. lpqSearch = "(lpscutid:"+scustid+"%20AND%20salecom:"+deptCode+")";
  705. }
  706. scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?size=100&pretty=true&q="+lpqSearch);
  707. response = restClient.performRequest(scriptRequest);
  708. result = EntityUtils.toString(response.getEntity());
  709. jsonObject = JSON.parseObject(result);
  710. hitsobject = (JSONObject) jsonObject.get("hits");
  711. array = JSON.parseArray(hitsobject.get("hits").toString());
  712. Map insuranceclaimthread = new HashMap();
  713. List insuranceclaimthreads = new ArrayList<>();
  714. double claimAmount = 0;//理赔总金额
  715. Set<String> claimTypeSet = new HashSet<>();//理赔类型
  716. for (int i = 0; i <array.size() ; i++) {
  717. JSONObject json = (JSONObject)array.get(i);
  718. JSONObject claimSource = JSON.parseObject(json.getString("_source"));
  719. if(claimSource.containsKey("ccamt")){
  720. claimAmount+=claimSource.getDouble("ccamt");
  721. }
  722. claimTypeSet.add(claimSource.getString("accidenttype"));
  723. insuranceclaimthreads.add(claimSource);
  724. }
  725. insuranceclaimthread.put("isClaim",insuranceclaimthreads.size()>0?"是":"否");
  726. insuranceclaimthread.put("claimAmount",df.format(claimAmount));
  727. insuranceclaimthread.put("claimType",String.join(",",claimTypeSet));
  728. map.put("insuranceclaimthread",insuranceclaimthread);
  729. mpInfo.put("prem",df.format(prem));//年缴保费/应交保费
  730. mpInfo.put("sumprem",df.format(sumprem));//累计保费
  731. mpInfo.put("handedinprem",df.format(handedinprem));//已交保费
  732. mpInfo.put("insureDay",(insureDay/365) +"年"+(insureDay%365)+"天");
  733. //保障天数需要加上退保之前的天数
  734. String tbcustomerinfoSearch = "scustid:"+scustid;
  735. if( StringUtils.isNotEmpty(deptCode)){
  736. tbcustomerinfoSearch = "(scustid:"+scustid+"%20AND%20salecom:"+deptCode+")";
  737. }
  738. scriptRequest = new Request("GET", "/shanglifeecif.tbcustomerinfo/_search?pretty=true&sort=sdate:asc&size=100&q="+tbcustomerinfoSearch);
  739. response = restClient.performRequest(scriptRequest);
  740. result = EntityUtils.toString(response.getEntity());
  741. jsonObject = JSON.parseObject(result);
  742. hitsobject = (JSONObject) jsonObject.get("hits");
  743. array = JSON.parseArray(hitsobject.get("hits").toString());
  744. List<PolicyDate> cancelPolicyDates = new ArrayList<>();
  745. Date fSdate = null;//最终起始日期,分段的
  746. Date fEdate = null;//最终结束日期,分段的
  747. for (int i = 0; i <array.size() ; i++) {
  748. JSONObject json = (JSONObject)array.get(i);
  749. JSONObject tbSource = JSON.parseObject(json.getString("_source"));
  750. if (tbSource.containsKey("contno") && tbSource.containsKey("sdate") && tbSource.containsKey("edate")) {
  751. try {
  752. cancelPolicyDates.add(new PolicyDate(tbSource.getString("contno"), tbSource.getDate("sdate"), tbSource.getDate("edate")));
  753. } catch (Exception e) {
  754. logger.warn(String.format(
  755. "Failed to instance PolicyDate, contno: [%s], sdate: [%s], edate: [%s]"
  756. , tbSource.get("contno"), tbSource.get("sdate"), tbSource.get("edate")));
  757. }
  758. } else {
  759. logger.info("Failed to instance PolicyDate, must be 'contno', 'sdate', 'edate', _source: "+ tbSource.toJSONString());
  760. }
  761. /** 2022/5/31 start 陆光晨 享受保障天数放在后面计算
  762. * 获取该退报客户的所有保单信息,计算天数退保天数加上有效保单的天数
  763. if(tbSource.containsKey("sdate") && tbSource.containsKey("edate")){
  764. Date sdate = tbSource.getDate("sdate");
  765. Date edate = tbSource.getDate("edate");
  766. //获取第一条数据赋值给最后计算的开始和结束日期
  767. if(i==0){
  768. fSdate = sdate;
  769. fEdate = edate;
  770. }
  771. //
  772. // 逻辑梳理
  773. // 下一张保单的开始日期小于等于当前的结束日期 ,最终开始日期按照上一张保单的开始日期
  774. // 下一张保单的开始日期大于当前的结束日期 ,需要计算第一部分的保障天数依次循环
  775. //
  776. if(i>0){
  777. if(sdate.getTime()<=fEdate.getTime()){
  778. //保单结束日期在最终结束日期之后,需要把保单结束日期赋值给最终结束日期
  779. if(edate.getTime()>fEdate.getTime()){
  780. fEdate = edate;
  781. }
  782. }else{
  783. //保单的开始日期在结束日期之后,需要先计算前一段的日期差值加到保障天数
  784. if(i!=array.size()){
  785. guaranteeDay+=DateUtils.getDateDifDay(fEdate,fSdate);
  786. fSdate = sdate;
  787. fEdate = edate;
  788. }
  789. }
  790. if(i==(array.size()-1)){
  791. guaranteeDay+=DateUtils.getDateDifDay(fEdate,fSdate);
  792. }
  793. }
  794. }
  795. 2022/5/31 end 陆光晨 享受保障天数放在后面计算 */
  796. }
  797. guaranteeDay = guaranteeDay(policyDates, cancelPolicyDates); // 计算享受保障天数
  798. mpInfo.put("guaranteeDay",guaranteeDay>insureDay?insureDay+"天":guaranteeDay+"天");
  799. map.put("custInfo",mpInfo);
  800. //险种数据准备
  801. Map riskMap = new HashMap();
  802. riskMap.put("人寿保险","0");
  803. riskMap.put("新型寿险","0");
  804. riskMap.put("意外伤害保险","0");
  805. riskMap.put("医疗险","0");
  806. riskMap.put("重疾保险","0");
  807. riskMap.put("年金保险","0");
  808. for(String key : majorCategorie.keySet()){
  809. if(riskMap.containsKey(key)){
  810. riskMap.put(key,majorCategorie.get(key));
  811. }
  812. }
  813. map.put("majorCategorie",riskMap);
  814. logger.info("出客户概览时间:"+DateUtils.getTime());
  815. return AjaxResult.success(map);
  816. } catch (Exception e) {
  817. logger.info("客户概览报错时间:"+DateUtils.getTime());
  818. e.printStackTrace();
  819. return AjaxResult.error();
  820. }
  821. }
  822. @GetMapping("/export")
  823. public void export(HttpServletResponse response, HttpServletRequest request,
  824. String education,//学历
  825. String policybelong,//业绩归属
  826. String payS,String payE, //年缴费区间
  827. String fadate,//投保年份
  828. String productname,//险种类别
  829. String insuredAmountS,String insuredAmountE,//保额区间
  830. String ageS,String ageE,//年龄区间
  831. String gender,//性别
  832. String sobirth,//省份
  833. String NOVPolicy,//保单件数
  834. String custtype,//客户类型 投保人
  835. String SCustID,// 核心客户号
  836. String custclass,//客户等级
  837. String participantsDateS,String participantsDateE,//参与方时间
  838. String PIncomeS,String PIncomeE,//年收入区间
  839. String Insured,//投保对象
  840. String lp,//理赔
  841. String yx,//有效
  842. String gzgw,//关注官微
  843. String zcgw,//注册官微
  844. String name,//客户姓名
  845. String idcard,//客户证件号码
  846. String mobile//客户手机号
  847. ) {
  848. try{
  849. logger.info("导出进时间:"+DateUtils.getTime());
  850. JSONObject jsonObject = getCustomerListData(0, 10000, false, "5m",
  851. education,//学历
  852. policybelong,//业绩归属
  853. payS, payE, //年缴费区间
  854. fadate,//投保年份
  855. productname,//险种类别
  856. insuredAmountS, insuredAmountE,//保额区间
  857. ageS, ageE,//年龄区间
  858. gender,//性别
  859. sobirth,//省份
  860. NOVPolicy,//保单件数
  861. custtype,//客户类型 投保人
  862. SCustID,// 核心客户号
  863. custclass,//客户等级
  864. participantsDateS, participantsDateE,//参与方时间
  865. PIncomeS, PIncomeE,//年收入区间
  866. Insured,//投保对象
  867. lp,//理赔
  868. yx,//有效
  869. gzgw,//关注官微
  870. zcgw,//注册官微
  871. name,//客户姓名
  872. idcard,//客户证件号码
  873. mobile//客户手机号
  874. );
  875. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  876. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  877. List<Customer> customers = new ArrayList<Customer>();
  878. String scroll_id = jsonObject.getString("_scroll_id");
  879. HttpEntity entity = new NStringEntity("{\n" +
  880. " \"scroll_id\": \""+scroll_id+"\",\n" +
  881. " \"scroll\": \"5m\"\n" +
  882. "}", ContentType.APPLICATION_JSON);
  883. while (array.size() != 0) {
  884. // 这里填写你的业务逻辑,即对每一条数据的处理
  885. for (int i = 0; i <array.size() ; i++) {
  886. JSONObject json = (JSONObject)array.get(i);
  887. Map mp = getSource(json);
  888. Customer customer = new Customer();
  889. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  890. customer.setScustId("\t"+jsonOb.getString("scustid"));
  891. customer.setCustId(jsonOb.getString("custid"));
  892. customer.setName(jsonOb.getString("name"));
  893. customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
  894. customer.setCustType(jsonOb.getString("custtype"));
  895. customer.setEducation(jsonOb.getString("education"));
  896. customer.setVaild(StringUtils.isEmpty(jsonOb.getString("label91"))?"有效":"无效");
  897. customer.setpIncome(jsonOb.getString("pincome"));
  898. customer.setNum(jsonOb.getString("label25"));
  899. String ral = jsonOb.getString("ral");
  900. if(StringUtils.isNotBlank(ral)){
  901. List<Map> list = AddressResolutionUtil.addressResolution(ral);
  902. if(list!=null && list.size()>0){
  903. customer.setProvince(list.get(0).get("province").toString());
  904. }
  905. }
  906. if(mp.containsKey("birthday")){
  907. String birthday = jsonOb.getString("birthday");
  908. mp.put("birthday", birthday);
  909. mp.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,birthday)));
  910. customer.setBirthDay("\t"+birthday);
  911. customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,birthday)));
  912. }
  913. //String regex = "(\\w{4})(\\w+)(\\w{0})";
  914. if(mp.containsKey("idcard")){
  915. customer.setIdType("身份证");
  916. String idCard = jsonOb.getString("idcard");
  917. //customer.setIdCard("\t"+jsonOb.getString("idcard").replaceAll(regex, "$1****$3"));
  918. if(idCard.length()>6){
  919. customer.setIdCard("\t"+idCard.replaceAll(idCard.substring(idCard.length()-6), "******"));
  920. }else{
  921. customer.setIdCard("\t"+"******");
  922. }
  923. }else if(mp.containsKey("passport")){
  924. customer.setIdType("护照");
  925. String passport = jsonOb.getString("passport");
  926. //customer.setIdCard("\t"+jsonOb.getString("passport").replaceAll(regex, "$1****$3"));
  927. if(passport.length()>6){
  928. customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
  929. }else{
  930. customer.setIdCard("\t"+"******");
  931. }
  932. }else if(mp.containsKey("dlicense")){
  933. customer.setIdType("驾驶证");
  934. String dlicense = jsonOb.getString("dlicense");
  935. //customer.setIdCard("\t"+jsonOb.getString("dlicense").replaceAll(regex, "$1****$3"));
  936. if(dlicense.length()>6){
  937. customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
  938. }else{
  939. customer.setIdCard("\t"+"******");
  940. }
  941. }else if(mp.containsKey("otheridnumber")){
  942. customer.setIdType("其它证件类型");
  943. String otheridnumber = jsonOb.getString("otheridnumber");
  944. //customer.setIdCard("\t"+jsonOb.getString("otheridnumber").replaceAll(regex, "$1****$3"));
  945. if(otheridnumber.length()>6){
  946. customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
  947. }else{
  948. customer.setIdCard("\t"+"******");
  949. }
  950. }
  951. if(mp.containsKey("custclass")){
  952. String custclazz = jsonOb.getString("custclass");
  953. switch (custclazz){
  954. case "1":
  955. customer.setCustClass("钻石");
  956. break;
  957. case "2":
  958. customer.setCustClass("白金");
  959. break;
  960. case "3":
  961. customer.setCustClass("黄金");
  962. break;
  963. case "4":
  964. customer.setCustClass("普通");
  965. break;
  966. default:
  967. customer.setCustClass("无");
  968. }
  969. }else{
  970. customer.setCustClass("无");
  971. }
  972. customers.add(customer);
  973. }
  974. // 继续向后查询
  975. Request scriptRequest = new Request("GET", "/_search/scroll");
  976. scriptRequest.setEntity(entity);
  977. Response responseData = restClient.performRequest(scriptRequest);
  978. String result = EntityUtils.toString(responseData.getEntity());
  979. jsonObject = JSON.parseObject(result);
  980. hitsobject = (JSONObject) jsonObject.get("hits");
  981. array = JSON.parseArray(hitsobject.get("hits").toString());
  982. }
  983. Map<String, String> header = new LinkedHashMap<>();
  984. header.put("scustId", "核心客户号");
  985. header.put("custId", "客户号");
  986. header.put("name", "姓名");
  987. header.put("idType", "证件类型");
  988. header.put("idCard", "证件号码");
  989. header.put("sex", "性别");
  990. header.put("age", "年龄");
  991. header.put("birthDay", "出生日期");
  992. header.put("custClass", "客户等级");
  993. header.put("custType", "客户类型");
  994. header.put("province", "省份");
  995. header.put("education", "学历");
  996. header.put("vaild", "是否有效客户");
  997. /*header.put("policyBelong", "业绩归属");*/
  998. header.put("pIncome", "年收入(万)");
  999. header.put("num", "保单件数");
  1000. CsvUtil.export(request, response, "customer", header, customers);
  1001. logger.info("导出出时间:"+DateUtils.getTime());
  1002. }catch (Exception e){
  1003. logger.info("导出出错:"+DateUtils.getTime());
  1004. e.printStackTrace();
  1005. }
  1006. }
  1007. /**
  1008. * 导出四要素疑似相同指姓名、性别、证件类型、手机号一致
  1009. * @param response
  1010. * @param request
  1011. */
  1012. @GetMapping("/exportSameZero")
  1013. public void exportSameZero(HttpServletResponse response, HttpServletRequest request)
  1014. {
  1015. logger.info("导出四要素进时间:"+DateUtils.getTime());
  1016. try{
  1017. Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc&q=sametype:0&size=10000&scroll=5m");
  1018. Response responseData = restClient.performRequest(scriptRequest);
  1019. String result = EntityUtils.toString(responseData.getEntity());
  1020. JSONObject jsonObject = JSON.parseObject(result);
  1021. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  1022. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  1023. List<Customer> customers = new ArrayList<Customer>();
  1024. String scroll_id = jsonObject.getString("_scroll_id");
  1025. HttpEntity entity = new NStringEntity("{\n" +
  1026. " \"scroll_id\": \""+scroll_id+"\",\n" +
  1027. " \"scroll\": \"5m\"\n" +
  1028. "}", ContentType.APPLICATION_JSON);
  1029. while (array.size() != 0) {
  1030. // 这里填写你的业务逻辑,即对每一条数据的处理
  1031. for (int i = 0; i <array.size() ; i++) {
  1032. JSONObject json = (JSONObject)array.get(i);
  1033. Map mp = new HashMap();
  1034. Customer customer = new Customer();
  1035. json.getString("_source");
  1036. mp.put("id",json.getString("_id"));
  1037. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  1038. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  1039. customer.setScustId("\t"+jsonOb.getString("scustid"));
  1040. customer.setName(jsonOb.getString("name"));
  1041. customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
  1042. if(mp.containsKey("birthday")){
  1043. String birthday = jsonOb.getString("birthday");
  1044. mp.put("birthday", birthday);
  1045. customer.setBirthDay("\t"+birthday);
  1046. customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
  1047. }
  1048. if(mp.containsKey("idcard")){
  1049. customer.setIdType("身份证");
  1050. // customer.setIdCard("\t"+jsonOb.getString("idcard"));
  1051. String idcard = jsonOb.getString("idcard");
  1052. if(idcard.length()>6){
  1053. customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
  1054. }else{
  1055. customer.setIdCard("\t"+"******");
  1056. }
  1057. }else if(mp.containsKey("passport")){
  1058. customer.setIdType("护照");
  1059. // customer.setIdCard("\t"+jsonOb.getString("passport"));
  1060. String passport = jsonOb.getString("passport");
  1061. if(passport.length()>6){
  1062. customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
  1063. }else{
  1064. customer.setIdCard("\t"+"******");
  1065. }
  1066. }else if(mp.containsKey("dlicense")){
  1067. customer.setIdType("驾驶证");
  1068. // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
  1069. String dlicense = jsonOb.getString("dlicense");
  1070. if(dlicense.length()>6){
  1071. customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
  1072. }else{
  1073. customer.setIdCard("\t"+"******");
  1074. }
  1075. }else if(mp.containsKey("otheridnumber")){
  1076. customer.setIdType("其它证件类型");
  1077. // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
  1078. String otheridnumber = jsonOb.getString("otheridnumber");
  1079. if(otheridnumber.length()>6){
  1080. customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
  1081. }else{
  1082. customer.setIdCard("\t"+"******");
  1083. }
  1084. }
  1085. customers.add(customer);
  1086. }
  1087. // 继续向后查询
  1088. scriptRequest = new Request("GET", "/_search/scroll");
  1089. scriptRequest.setEntity(entity);
  1090. responseData = restClient.performRequest(scriptRequest);
  1091. result = EntityUtils.toString(responseData.getEntity());
  1092. jsonObject = JSON.parseObject(result);
  1093. hitsobject = (JSONObject) jsonObject.get("hits");
  1094. array = JSON.parseArray(hitsobject.get("hits").toString());
  1095. }
  1096. Map<String, String> header = new LinkedHashMap<>();
  1097. header.put("scustId", "核心客户号");
  1098. header.put("name", "姓名");
  1099. header.put("idType", "证件类型");
  1100. header.put("idCard", "证件号码");
  1101. header.put("sex", "性别");
  1102. header.put("birthDay", "出生日期");
  1103. CsvUtil.export(request, response, "customer", header, customers);
  1104. logger.info("导出四要素出时间:"+DateUtils.getTime());
  1105. }catch (Exception e){
  1106. logger.info("导出四要素出错:"+DateUtils.getTime());
  1107. e.printStackTrace();
  1108. }
  1109. }
  1110. /**
  1111. * 导出三要素疑似相同指姓名、性别、出生日期一致
  1112. * @param response
  1113. * @param request
  1114. */
  1115. @GetMapping("/exportSameOne")
  1116. public void exportSameOne(HttpServletResponse response, HttpServletRequest request)
  1117. {
  1118. logger.info("导出三要素进时间:"+DateUtils.getTime());
  1119. try{
  1120. Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc,gender:asc,birthday:asc&q=sametype:1&size=10000&scroll=5m");
  1121. Response responseData = restClient.performRequest(scriptRequest);
  1122. String result = EntityUtils.toString(responseData.getEntity());
  1123. JSONObject jsonObject = JSON.parseObject(result);
  1124. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  1125. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  1126. List<Customer> customers = new ArrayList<Customer>();
  1127. String scroll_id = jsonObject.getString("_scroll_id");
  1128. HttpEntity entity = new NStringEntity("{\n" +
  1129. " \"scroll_id\": \""+scroll_id+"\",\n" +
  1130. " \"scroll\": \"5m\"\n" +
  1131. "}", ContentType.APPLICATION_JSON);
  1132. while (array.size() != 0) {
  1133. // 这里填写你的业务逻辑,即对每一条数据的处理
  1134. for (int i = 0; i <array.size() ; i++) {
  1135. JSONObject json = (JSONObject)array.get(i);
  1136. Map mp = new HashMap();
  1137. Customer customer = new Customer();
  1138. json.getString("_source");
  1139. mp.put("id",json.getString("_id"));
  1140. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  1141. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  1142. customer.setScustId("\t"+jsonOb.getString("scustid"));
  1143. customer.setName(jsonOb.getString("name"));
  1144. customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
  1145. if(mp.containsKey("birthday")){
  1146. String birthday = jsonOb.getString("birthday");
  1147. mp.put("birthday", birthday);
  1148. customer.setBirthDay(birthday);
  1149. customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
  1150. }
  1151. if(mp.containsKey("idcard")){
  1152. customer.setIdType("身份证");
  1153. // customer.setIdCard("\t"+jsonOb.getString("idcard"));
  1154. String idcard = jsonOb.getString("idcard");
  1155. if(idcard.length()>6){
  1156. customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
  1157. }else{
  1158. customer.setIdCard("\t"+"******");
  1159. }
  1160. }else if(mp.containsKey("passport")){
  1161. customer.setIdType("护照");
  1162. // customer.setIdCard("\t"+jsonOb.getString("passport"));
  1163. String passport = jsonOb.getString("passport");
  1164. if(passport.length()>6){
  1165. customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
  1166. }else{
  1167. customer.setIdCard("\t"+"******");
  1168. }
  1169. }else if(mp.containsKey("dlicense")){
  1170. customer.setIdType("驾驶证");
  1171. // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
  1172. String dlicense = jsonOb.getString("dlicense");
  1173. if(dlicense.length()>6){
  1174. customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
  1175. }else{
  1176. customer.setIdCard("\t"+"******");
  1177. }
  1178. }else if(mp.containsKey("otheridnumber")){
  1179. customer.setIdType("其它证件类型");
  1180. // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
  1181. String otheridnumber = jsonOb.getString("otheridnumber");
  1182. if(otheridnumber.length()>6){
  1183. customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
  1184. }else{
  1185. customer.setIdCard("\t"+"******");
  1186. }
  1187. }
  1188. customers.add(customer);
  1189. }
  1190. // 继续向后查询
  1191. scriptRequest = new Request("GET", "/_search/scroll");
  1192. scriptRequest.setEntity(entity);
  1193. responseData = restClient.performRequest(scriptRequest);
  1194. result = EntityUtils.toString(responseData.getEntity());
  1195. jsonObject = JSON.parseObject(result);
  1196. hitsobject = (JSONObject) jsonObject.get("hits");
  1197. array = JSON.parseArray(hitsobject.get("hits").toString());
  1198. }
  1199. Map<String, String> header = new LinkedHashMap<>();
  1200. header.put("scustId", "核心客户号");
  1201. header.put("name", "姓名");
  1202. header.put("idType", "证件类型");
  1203. header.put("idCard", "证件号码");
  1204. header.put("sex", "性别");
  1205. header.put("birthDay", "出生日期");
  1206. CsvUtil.export(request, response, "customer", header, customers);
  1207. logger.info("导出三要素出时间:"+DateUtils.getTime());
  1208. }catch (Exception e){
  1209. logger.info("导出三要素出错:"+DateUtils.getTime());
  1210. e.printStackTrace();
  1211. }
  1212. }
  1213. /**
  1214. * 导出两要素疑似相同指姓名、证件号码一致
  1215. * @param response
  1216. * @param request
  1217. */
  1218. @GetMapping("/exportSameTwo")
  1219. public void exportSameTwo(HttpServletResponse response, HttpServletRequest request)
  1220. {
  1221. logger.info("导出两要素进时间:"+DateUtils.getTime());
  1222. try{
  1223. Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc&q=sametype:2&size=10000&scroll=5m");
  1224. Response responseData = restClient.performRequest(scriptRequest);
  1225. String result = EntityUtils.toString(responseData.getEntity());
  1226. JSONObject jsonObject = JSON.parseObject(result);
  1227. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  1228. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  1229. List<Customer> customers = new ArrayList<Customer>();
  1230. String scroll_id = jsonObject.getString("_scroll_id");
  1231. HttpEntity entity = new NStringEntity("{\n" +
  1232. " \"scroll_id\": \""+scroll_id+"\",\n" +
  1233. " \"scroll\": \"5m\"\n" +
  1234. "}", ContentType.APPLICATION_JSON);
  1235. while (array.size() != 0) {
  1236. // 这里填写你的业务逻辑,即对每一条数据的处理
  1237. for (int i = 0; i <array.size() ; i++) {
  1238. JSONObject json = (JSONObject)array.get(i);
  1239. Map mp = new HashMap();
  1240. Customer customer = new Customer();
  1241. json.getString("_source");
  1242. mp.put("id",json.getString("_id"));
  1243. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  1244. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  1245. customer.setScustId("\t"+jsonOb.getString("scustid"));
  1246. customer.setName(jsonOb.getString("name"));
  1247. customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
  1248. if(mp.containsKey("birthday")){
  1249. String birthday = jsonOb.getString("birthday");
  1250. mp.put("birthday", birthday);
  1251. customer.setBirthDay("\t"+birthday);
  1252. customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
  1253. }
  1254. if(mp.containsKey("idcard")){
  1255. customer.setIdType("身份证");
  1256. // customer.setIdCard("\t"+jsonOb.getString("idcard"));
  1257. String idcard = jsonOb.getString("idcard");
  1258. if(idcard.length()>6){
  1259. customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
  1260. }else{
  1261. customer.setIdCard("\t"+"******");
  1262. }
  1263. }else if(mp.containsKey("passport")){
  1264. customer.setIdType("护照");
  1265. // customer.setIdCard("\t"+jsonOb.getString("passport"));
  1266. String passport = jsonOb.getString("passport");
  1267. if(passport.length()>6){
  1268. customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
  1269. }else{
  1270. customer.setIdCard("\t"+"******");
  1271. }
  1272. }else if(mp.containsKey("dlicense")){
  1273. customer.setIdType("驾驶证");
  1274. // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
  1275. String dlicense = jsonOb.getString("dlicense");
  1276. if(dlicense.length()>6){
  1277. customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
  1278. }else{
  1279. customer.setIdCard("\t"+"******");
  1280. }
  1281. }else if(mp.containsKey("otheridnumber")){
  1282. customer.setIdType("其它证件类型");
  1283. // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
  1284. String otheridnumber = jsonOb.getString("otheridnumber");
  1285. if(otheridnumber.length()>6){
  1286. customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
  1287. }else{
  1288. customer.setIdCard("\t"+"******");
  1289. }
  1290. }
  1291. customers.add(customer);
  1292. }
  1293. // 继续向后查询
  1294. scriptRequest = new Request("GET", "/_search/scroll");
  1295. scriptRequest.setEntity(entity);
  1296. responseData = restClient.performRequest(scriptRequest);
  1297. result = EntityUtils.toString(responseData.getEntity());
  1298. jsonObject = JSON.parseObject(result);
  1299. hitsobject = (JSONObject) jsonObject.get("hits");
  1300. array = JSON.parseArray(hitsobject.get("hits").toString());
  1301. }
  1302. Map<String, String> header = new LinkedHashMap<>();
  1303. header.put("scustId", "核心客户号");
  1304. header.put("name", "姓名");
  1305. header.put("idType", "证件类型");
  1306. header.put("idCard", "证件号码");
  1307. header.put("sex", "性别");
  1308. header.put("birthDay", "出生日期");
  1309. CsvUtil.export(request, response, "customer", header, customers);
  1310. logger.info("导出两要素出时间:"+DateUtils.getTime());
  1311. }catch (Exception e){
  1312. logger.info("导出两要素出错:"+DateUtils.getTime());
  1313. e.printStackTrace();
  1314. }
  1315. }
  1316. /**
  1317. * 导出数据清洗数据
  1318. * @param response
  1319. * @param request
  1320. */
  1321. @GetMapping("/dataCleaning")
  1322. public void dataCleaning(HttpServletResponse response, HttpServletRequest request,String sameType)
  1323. {
  1324. logger.info("导出数据清洗进时间:"+DateUtils.getTime());
  1325. try{
  1326. Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc&q=sametype:"+sameType+"&size=10000&scroll=5m");
  1327. Response responseData = restClient.performRequest(scriptRequest);
  1328. String result = EntityUtils.toString(responseData.getEntity());
  1329. JSONObject jsonObject = JSON.parseObject(result);
  1330. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  1331. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  1332. List<Customer> customers = new ArrayList<Customer>();
  1333. String scroll_id = jsonObject.getString("_scroll_id");
  1334. HttpEntity entity = new NStringEntity("{\n" +
  1335. " \"scroll_id\": \""+scroll_id+"\",\n" +
  1336. " \"scroll\": \"5m\"\n" +
  1337. "}", ContentType.APPLICATION_JSON);
  1338. while (array.size() != 0) {
  1339. // 这里填写你的业务逻辑,即对每一条数据的处理
  1340. for (int i = 0; i <array.size() ; i++) {
  1341. JSONObject json = (JSONObject)array.get(i);
  1342. Map mp = new HashMap();
  1343. Customer customer = new Customer();
  1344. json.getString("_source");
  1345. mp.put("id",json.getString("_id"));
  1346. JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
  1347. mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
  1348. customer.setScustId("\t"+jsonOb.getString("scustid"));
  1349. customer.setName(jsonOb.getString("name"));
  1350. customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
  1351. if(mp.containsKey("birthday")){
  1352. String birthday = jsonOb.getString("birthday");
  1353. mp.put("birthday", birthday);
  1354. customer.setBirthDay("\t"+birthday);
  1355. customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
  1356. }
  1357. if(mp.containsKey("idcard")){
  1358. customer.setIdType("身份证");
  1359. // customer.setIdCard("\t"+jsonOb.getString("idcard"));
  1360. String idcard = jsonOb.getString("idcard");
  1361. if(idcard.length()>6){
  1362. customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
  1363. }else{
  1364. customer.setIdCard("\t"+"******");
  1365. }
  1366. }else if(mp.containsKey("passport")){
  1367. customer.setIdType("护照");
  1368. // customer.setIdCard("\t"+jsonOb.getString("passport"));
  1369. String passport = jsonOb.getString("passport");
  1370. if(passport.length()>6){
  1371. customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
  1372. }else{
  1373. customer.setIdCard("\t"+"******");
  1374. }
  1375. }else if(mp.containsKey("dlicense")){
  1376. customer.setIdType("驾驶证");
  1377. // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
  1378. String dlicense = jsonOb.getString("dlicense");
  1379. if(dlicense.length()>6){
  1380. customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
  1381. }else{
  1382. customer.setIdCard("\t"+"******");
  1383. }
  1384. }else if(mp.containsKey("otheridnumber")){
  1385. customer.setIdType("其它证件类型");
  1386. // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
  1387. String otheridnumber = jsonOb.getString("otheridnumber");
  1388. if(otheridnumber.length()>6){
  1389. customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
  1390. }else{
  1391. customer.setIdCard("\t"+"******");
  1392. }
  1393. }
  1394. customer.setZipCode("\t"+jsonOb.getString("zipcode"));
  1395. customer.setMobile("\t"+jsonOb.getString("mobile"));
  1396. customer.setEmail("\t"+jsonOb.getString("email"));
  1397. customer.setPinDate(jsonOb.getString("pindate"));
  1398. customer.setAgentName(jsonOb.getString("agentname"));
  1399. customer.setSalecomName(jsonOb.getString("salecomname"));
  1400. customers.add(customer);
  1401. }
  1402. // 继续向后查询
  1403. scriptRequest = new Request("GET", "/_search/scroll");
  1404. scriptRequest.setEntity(entity);
  1405. responseData = restClient.performRequest(scriptRequest);
  1406. result = EntityUtils.toString(responseData.getEntity());
  1407. jsonObject = JSON.parseObject(result);
  1408. hitsobject = (JSONObject) jsonObject.get("hits");
  1409. array = JSON.parseArray(hitsobject.get("hits").toString());
  1410. }
  1411. Map<String, String> header = new LinkedHashMap<>();
  1412. header.put("scustId", "核心客户号");
  1413. header.put("name", "姓名");
  1414. header.put("idType", "证件类型");
  1415. header.put("idCard", "证件号码");
  1416. header.put("sex", "性别");
  1417. header.put("birthDay", "出生日期");
  1418. if("8".equals(sameType) || "16".equals(sameType)){
  1419. header.put("mobile", "手机号码");
  1420. }else if("9".equals(sameType)){
  1421. header.put("zipCode", "邮政编码");
  1422. }else if("12".equals(sameType)){
  1423. header.put("degree", "学历");
  1424. }else if("14".equals(sameType)){
  1425. header.put("email", "邮箱");
  1426. }else if("15".equals(sameType)){
  1427. header.put("pinDate", "起保日期");
  1428. }else if("18".equals(sameType)){
  1429. header.put("agentName", "业务员名称");
  1430. }else if("19".equals(sameType)){
  1431. header.put("salecomName", "业绩归属");
  1432. }
  1433. CsvUtil.export(request, response, "customer", header, customers);
  1434. logger.info("导出数据清洗出时间:"+DateUtils.getTime());
  1435. }catch (Exception e){
  1436. logger.info("导出数据清洗出错:"+DateUtils.getTime());
  1437. e.printStackTrace();
  1438. }
  1439. }
  1440. public Map getLables(JSONObject jsonObject,String deptCode ) throws Exception {
  1441. Map mpInfo = new HashMap();
  1442. JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
  1443. String indid = jsonObject.getString("_id");
  1444. mpInfo.put("id",indid);
  1445. String salecom = source.getString("salecom"); // 可能会得到用逗号分割的多个标签
  1446. if (salecom == null) {
  1447. salecom = "";
  1448. }
  1449. String[] salecoms = salecom.split(",");
  1450. Arrays.sort(salecoms);
  1451. Map<String, Object> sourceMap = JSON.parseObject(jsonObject.getString("_source"), Map.class);
  1452. if (StringUtils.isEmpty(deptCode)||showLabelCode.equals("SHOW_ALL_LABLES")) {
  1453. // 根渠道,也就是上海人寿,也是admin用户所属的渠道,返回jsonObject中的所有标签(公共标签 + 渠道标签)
  1454. mpInfo.putAll(sourceMap);
  1455. } else if (Arrays.binarySearch(salecoms, deptCode) >= 0) {
  1456. // 登录用户的渠道与客户渠道一致,返回jsonObject中的公共标签 + shanglifeecif.customerno_salecom_relation表中的渠道标签
  1457. mpInfo.putAll(getPublicLabels(sourceMap));
  1458. if(showLabelCode.equals("SHOW_DISTINGUISH_CHANNELS_LABLES")){
  1459. mpInfo.putAll(getSalecomLabels(source.getString("scustid"), deptCode));
  1460. }
  1461. } else {
  1462. // 未找到渠道,不返回渠道标签
  1463. logger.info(String.format("登录渠道和客户所属渠道不匹配,不返回渠道标签,登录渠道 [%s],客户所属渠道 [%s]", deptCode, salecom));
  1464. }
  1465. if(mpInfo.containsKey("birthday")){
  1466. mpInfo.put("birthday", source.getString("birthday"));
  1467. mpInfo.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,source.getString("birthday"))));
  1468. }else{
  1469. mpInfo.put("birthday","");
  1470. mpInfo.put("age","");
  1471. }
  1472. return mpInfo;
  1473. }
  1474. /**
  1475. * 只返回公共标签(以label开头和不以label开头的公共标签都会返回)
  1476. * @param source 包含所有标签的map
  1477. * @return 只包含公共标签的map
  1478. */
  1479. private Map<String, Object> getPublicLabels(Map<String, Object> source) {
  1480. Map<String, Object> rst = new HashMap<>();
  1481. // 一般公共标签的key不以label开头,但也有一部分公共标签是以label开头的,将以label开头的公共标签Key存入list后续使用
  1482. List<String> publicLabels =getpublicLabels();
  1483. for (Map.Entry<String, Object> entry : source.entrySet()){
  1484. String key = entry.getKey();
  1485. logger.info("getPublicLabels------>"+key);
  1486. if(key.startsWith("label")){
  1487. if(publicLabels.contains(key)){
  1488. // 以label开头的公共标签
  1489. logger.info("以label开头的公共标签------>"+key);
  1490. rst.put(key,entry.getValue());
  1491. }else{
  1492. logger.info("分渠道标签------>"+key);
  1493. }
  1494. }else{
  1495. // 不以label开头的公共标签
  1496. rst.put(key,entry.getValue());
  1497. }
  1498. }
  1499. return rst;
  1500. }
  1501. /**
  1502. * 从ES表shanglifeecif.customerno_salecom_relation中获得指定客户指定渠道的渠道标签
  1503. * @param customerno 客户号
  1504. * @param salecom 渠道号
  1505. * @return 指定客户指定渠道的所有渠道标签
  1506. */
  1507. public Map<String, Object> getSalecomLabels(String customerno, String salecom) throws IOException {
  1508. Map<String, Object> rst = new HashMap<>();
  1509. String q = "scustid:"+ customerno +"%20AND%20salecom:"+ salecom;
  1510. Request scriptRequest = new Request("GET", "/shanglifeecif.customerno_salecom_relation/_search?pretty=true&q="+ q);
  1511. Response response = restClient.performRequest(scriptRequest);
  1512. String result = EntityUtils.toString(response.getEntity());
  1513. JSONObject jsonObject = JSON.parseObject(result);
  1514. JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
  1515. JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
  1516. List<String> publicLabels = getpublicLabels();
  1517. for (int i = 0; i <array.size() ; i++) {
  1518. JSONObject json = (JSONObject)array.get(i);
  1519. Map<String, Object> source = JSON.parseObject(json.getString("_source"), Map.class);
  1520. for (Map.Entry<String, Object> entry : source.entrySet()){
  1521. String key = entry.getKey();
  1522. if(key.startsWith("label")&&!publicLabels.contains(key)){
  1523. logger.info("分渠道标签添加--->"+key+"__"+entry.getValue());
  1524. rst.put(key, entry.getValue());
  1525. }
  1526. }
  1527. }
  1528. return rst;
  1529. }
  1530. public JSONObject getCustomerListData(int pageNum, int pageSize, boolean isPretty, String scroll,
  1531. String education,//学历
  1532. String policybelong,//业绩归属
  1533. String payS,String payE, //年缴费区间
  1534. String fadate,//投保年份
  1535. String productname,//险种类别
  1536. String insuredAmountS,String insuredAmountE,//保额区间
  1537. String ageS,String ageE,//年龄区间
  1538. String gender,//性别
  1539. String sobirth,//省份
  1540. String NOVPolicy,//保单件数
  1541. String custtype,//客户类型 投保人
  1542. String SCustID,// 核心客户号
  1543. String custclass,//客户等级
  1544. String participantsDateS,String participantsDateE,//参与方时间
  1545. String PIncomeS,String PIncomeE,//年收入区间
  1546. String Insured,//投保对象
  1547. String lp,//理赔
  1548. String yx,//有效
  1549. String gzgw,//关注官微
  1550. String zcgw,//注册官微
  1551. String name,//客户姓名
  1552. String idcard,//客户证件号码
  1553. String mobile//客户手机号
  1554. ) throws IOException {
  1555. //模糊查询渠道
  1556. Long userId = SecurityUtils.getUserId();
  1557. SysUser sysUser = userService.selectUserById(userId);
  1558. String deptCode = null;
  1559. // “上海人寿”部门编号开发环境是null,生产环境是0。不是上海人寿部门的才分渠道
  1560. if (StringUtils.isNotEmpty(sysUser.getDept().getDeptCode()) && ! "0".equals(sysUser.getDept().getDeptCode())) {
  1561. deptCode = sysUser.getDept().getDeptCode();
  1562. }
  1563. /*Long userId = SecurityUtils.getUserId();
  1564. SysUser sysUser = userService.selectUserById(userId);
  1565. String deptCode = sysUser.getDept().getDeptCode();*/
  1566. //2.如果没有客户信息以外的查询条件,只需要查询客户信息
  1567. // 获取索引的别名,字段,创建时间
  1568. String beginBirthDay = "";
  1569. String endBirthDay = "";
  1570. if(StringUtils.isNotEmpty(ageS)){
  1571. String year = DateUtils.getYYYY();
  1572. int bYear = Integer.parseInt(year)-Integer.parseInt(ageS);
  1573. endBirthDay = bYear+"-"+DateUtils.getMMDD();
  1574. }
  1575. if(StringUtils.isNotEmpty(ageE)){
  1576. String year = DateUtils.getYYYY();
  1577. int bYear = Integer.parseInt(year)-Integer.parseInt(ageE);
  1578. beginBirthDay = bYear+"-"+DateUtils.getMMDD();
  1579. }
  1580. //拼装查询条件
  1581. StringBuilder builder =new StringBuilder();
  1582. builder.append("{");
  1583. builder.append("\"query\":{");//query开始
  1584. builder.append("\"bool\":{");//boot开始
  1585. builder.append("\"must\":[");//must开始
  1586. //业绩归属字段
  1587. // if(StringUtils.isNotEmpty(deptCode)){
  1588. // builder.append("{\"prefix\":{\"salecom\":\""+deptCode+"\"}},");
  1589. // }else if(StringUtils.isNotEmpty(policybelong)){
  1590. // builder.append("{\"prefix\":{\"salecom\":\""+policybelong+"\"}},");
  1591. // }
  1592. // 渠道不为空的话按渠道筛选
  1593. if(StringUtils.isNotEmpty(deptCode)){
  1594. builder.append("{\"wildcard\":{\"salecom\":\"*"+deptCode+"*\"}},");
  1595. }else if(StringUtils.isNotEmpty(policybelong)){
  1596. builder.append("{\"wildcard\":{\"salecom\":\"*"+policybelong+"*\"}},");
  1597. }
  1598. //客户姓名
  1599. if(StringUtils.isNotEmpty(name)){
  1600. builder.append("{\"wildcard\":{\"name\":\"*"+name+"*\"}},");
  1601. }
  1602. //客户手机
  1603. if(StringUtils.isNotEmpty(mobile)){
  1604. builder.append("{\"wildcard\":{\"pmphone\":\"*"+mobile+"*\"}},");
  1605. }
  1606. //投保年份
  1607. if(StringUtils.isNotEmpty(fadate)){
  1608. builder.append("{\"wildcard\":{\"fadate\":\"*"+fadate+"*\"}},");
  1609. }
  1610. if(StringUtils.isNotEmpty(gender)){
  1611. builder.append("{\"prefix\":{\"gender\":"+gender+"}},");
  1612. }
  1613. if(StringUtils.isNotEmpty(NOVPolicy)){
  1614. builder.append("{\"prefix\":{\"label25\":\""+NOVPolicy+"\"}},");
  1615. }
  1616. if(StringUtils.isNotEmpty(custclass)){
  1617. builder.append("{\"term\":{\"custclass\":\""+custclass+"\"}},");
  1618. }
  1619. if(StringUtils.isNotEmpty(sobirth)){
  1620. builder.append("{\"wildcard\":{\"sobirth\":\"*"+sobirth+"*\"}},");//模糊匹配
  1621. }
  1622. if(StringUtils.isNotEmpty(SCustID)){
  1623. builder.append("{\"wildcard\":{\"scustid\":\"*"+SCustID+"*\"}},");//模糊匹配
  1624. }
  1625. if(StringUtils.isNotEmpty(custtype)){
  1626. builder.append("{\"wildcard\":{\"custtype\":\"*"+custtype+"*\"}},");
  1627. }
  1628. if(StringUtils.isNotEmpty(beginBirthDay) && StringUtils.isNotEmpty(endBirthDay)){
  1629. builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\",\"lte\":\""+endBirthDay+"\"}}},");
  1630. }else{
  1631. if(StringUtils.isNotEmpty(beginBirthDay)){
  1632. builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\"}}},");
  1633. }
  1634. if(StringUtils.isNotEmpty(endBirthDay)){
  1635. builder.append("{\"range\":{\"birthday\":{\"lte\":\""+endBirthDay+"\"}}},");
  1636. }
  1637. }
  1638. if(StringUtils.isNotEmpty(participantsDateS) && StringUtils.isNotEmpty(participantsDateE)){
  1639. builder.append("{\"range\":{\"fadate\":{\"gte\":\""+participantsDateS+"\",\"lte\":\""+participantsDateE+"\"}}},");
  1640. }else{
  1641. if(StringUtils.isNotEmpty(participantsDateS)){
  1642. builder.append("{\"range\":{\"fadate\":{\"gte\":\""+participantsDateS+"\"}}},");
  1643. }
  1644. if(StringUtils.isNotEmpty(participantsDateE)){
  1645. builder.append("{\"range\":{\"fadate\":{\"lte\":\""+participantsDateE+"\"}}},");
  1646. }
  1647. }
  1648. if(StringUtils.isNotEmpty(PIncomeS) && StringUtils.isNotEmpty(PIncomeE)){
  1649. builder.append("{\"range\":{\"pincome\":{\"gte\":\""+PIncomeS+"\",\"lte\":\""+PIncomeE+"\"}}},");
  1650. }else{
  1651. if(StringUtils.isNotEmpty(PIncomeS)){
  1652. builder.append("{\"range\":{\"pincome\":{\"gte\":\""+PIncomeS+"\"}}},");
  1653. }
  1654. if(StringUtils.isNotEmpty(PIncomeE)){
  1655. builder.append("{\"range\":{\"pincome\":{\"lte\":\""+PIncomeE+"\"}}},");
  1656. }
  1657. }
  1658. if(StringUtils.isNotEmpty(yx)){
  1659. if (yx.equals("0")){
  1660. builder.append("{\"range\":{\"novpolicy\":{\"gt\":\""+yx+"\"}}},");
  1661. }else
  1662. {
  1663. builder.append("{\"prefix\":{\"label91\":\"失效客户\"}},");
  1664. }
  1665. }
  1666. if(StringUtils.isNotEmpty(education)){
  1667. String[] edus = education.split("&");
  1668. builder.append("{\"terms\":{\"education\":[");
  1669. for (String edu:edus) {
  1670. builder.append("\""+edu+"\",");
  1671. }
  1672. builder.delete(builder.length()-1,builder.length());
  1673. builder.append ("]}},");
  1674. }
  1675. if(StringUtils.isNotEmpty(gzgw) && "0".equals(gzgw)){
  1676. builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
  1677. }
  1678. if(StringUtils.isNotEmpty(zcgw) && "0".equals(zcgw)){
  1679. builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
  1680. }
  1681. if(StringUtils.isNotEmpty(lp) && "0".equals(lp)){
  1682. builder.append("{\"prefix\":{\"label57\":\"最近一次理赔类型\"}},");
  1683. }
  1684. if(StringUtils.isNotEmpty(gender) || StringUtils.isNotEmpty(NOVPolicy) || StringUtils.isNotEmpty(custtype)
  1685. || StringUtils.isNotEmpty(custclass) || StringUtils.isNotEmpty(sobirth) || StringUtils.isNotEmpty(SCustID)
  1686. || StringUtils.isNotEmpty(beginBirthDay) || StringUtils.isNotEmpty(endBirthDay) || StringUtils.isNotEmpty(education)
  1687. || StringUtils.isNotEmpty(PIncomeS) || StringUtils.isNotEmpty(PIncomeE) || (StringUtils.isNotEmpty(gzgw) && "0".equals(gzgw))
  1688. || (StringUtils.isNotEmpty(zcgw) && "0".equals(zcgw)) || StringUtils.isNotEmpty(yx)
  1689. || (StringUtils.isNotEmpty(lp) && "0".equals(lp)) || /*StringUtils.isNotEmpty(deptCode) ||*/
  1690. StringUtils.isNotEmpty(participantsDateS) || StringUtils.isNotEmpty(participantsDateE) ||
  1691. StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(name) || StringUtils.isNotEmpty(mobile)
  1692. || StringUtils.isNotEmpty(fadate) || StringUtils.isNotEmpty(deptCode)){
  1693. builder.delete(builder.length()-1,builder.length());
  1694. }
  1695. builder.append("],");//must结束
  1696. builder.append("\"must_not\":[");//must_not
  1697. if(StringUtils.isNotEmpty(gzgw) && "1".equals(gzgw)){
  1698. builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
  1699. }
  1700. if(StringUtils.isNotEmpty(zcgw) && "1".equals(zcgw)){
  1701. builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
  1702. }
  1703. if(StringUtils.isNotEmpty(lp) && "1".equals(lp)){
  1704. builder.append("{\"prefix\":{\"label57\":\"最近一次理赔类型\"}},");
  1705. }
  1706. if(
  1707. (StringUtils.isNotEmpty(gzgw) && "1".equals(gzgw))
  1708. || (StringUtils.isNotEmpty(zcgw) && "1".equals(zcgw))
  1709. || (StringUtils.isNotEmpty(lp) && "1".equals(lp))
  1710. ){
  1711. builder.delete(builder.length()-1,builder.length());
  1712. }
  1713. builder.append("],");
  1714. builder.append("\"should\":[");
  1715. //客户证件号码
  1716. if(StringUtils.isNotEmpty(idcard)){
  1717. builder.append("{\"wildcard\":{\"idcard\":\"*"+idcard+"*\"}},");
  1718. builder.append("{\"wildcard\":{\"passport\":\"*"+idcard+"*\"}},");
  1719. builder.append("{\"wildcard\":{\"dlicense\":\"*"+idcard+"*\"}},");
  1720. builder.append("{\"wildcard\":{\"otheridnumber\":\"*"+idcard+"*\"}},");
  1721. builder.delete(builder.length()-1,builder.length());
  1722. }
  1723. builder.append("]");//should
  1724. builder.append("}");//boot结束
  1725. builder.append("},");//query结束
  1726. builder.append("\"from\":"+ pageNum +",");//第几页
  1727. builder.append("\"size\":"+ pageSize +",");//查询几个
  1728. builder.append("\"sort\":[{\"scustid\":{\"order\":\"asc\"}}],");//排序
  1729. builder.append("\"aggs\":{}");//
  1730. builder.append("}");
  1731. logger.info(builder.toString());
  1732. HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
  1733. String url;
  1734. /*
  1735. shanglifeecif.individual表中的渠道标签字段值是不分渠道的(也就是全渠道计算),所以像admin这种没有渠道的用户查这个表
  1736. shanglifeecif.customerno_salecom_relation表中渠道标签字段值是分渠道计算的,所以登录用户有渠道时查这个表
  1737. */
  1738. boolean hasDeptCode; // 登录用户是否有渠道 true:有渠道,false:无渠道
  1739. if(StringUtils.isEmpty(deptCode)){
  1740. // 像admin这种无渠道用户
  1741. logger.info("deptCode is empty, search shanglifeecif.individual");
  1742. url = "/shanglifeecif.individual/_search?";
  1743. hasDeptCode = false;
  1744. } else {
  1745. // 有渠道用户
  1746. logger.info(String.format("deptCode is [%s], search shanglifeecif.customerno_salecom_relation", deptCode));
  1747. url = "/shanglifeecif.customerno_salecom_relation/_search?";
  1748. hasDeptCode = true;
  1749. }
  1750. url += isPretty ? "pretty=true" : "pretty=false";
  1751. url += StringUtils.isEmpty(scroll) ? "" : "&scroll="+ scroll;
  1752. Request scriptRequest = new Request("GET", url);
  1753. scriptRequest.setEntity(entity);
  1754. Response response = restClient.performRequest(scriptRequest);
  1755. String result = EntityUtils.toString(response.getEntity());
  1756. JSONObject jsonObject = JSON.parseObject(result);
  1757. return jsonObject;
  1758. }
  1759. /**
  1760. * 计算享受保障天数,所有保单已享受到保障的天数合计(会忽略掉重叠天数),退保的只计算退保前享受到的保障天数
  1761. * @param policyDates 所有保单集合
  1762. * @param cancelPolicyDates 退保保单集合
  1763. * @return
  1764. */
  1765. public int guaranteeDay(List<PolicyDate> policyDates, List<PolicyDate> cancelPolicyDates) {
  1766. modifyDate(policyDates, cancelPolicyDates);
  1767. dateOrder(policyDates);
  1768. List<PolicyDate> merged = dateMerge(policyDates);
  1769. int day = 0;
  1770. if (merged == null || merged.isEmpty()) {
  1771. return day;
  1772. }
  1773. for (PolicyDate i : merged) {
  1774. day += DateUtils.getDateDifDay(i.getEndDate(), i.getStartDate());
  1775. }
  1776. return day;
  1777. }
  1778. /**
  1779. *
  1780. * @param policyDates 所有保单数据
  1781. * @param cancelPolicyDates 退保数据
  1782. */
  1783. public void modifyDate(List<PolicyDate> policyDates, List<PolicyDate> cancelPolicyDates) {
  1784. Calendar c = Calendar.getInstance();
  1785. c.set(Calendar.HOUR_OF_DAY, 0);
  1786. c.set(Calendar.MINUTE, 0);
  1787. c.set(Calendar.SECOND, 0);
  1788. c.set(Calendar.MILLISECOND, 0);
  1789. Date currentDate = c.getTime(); // 当前日期0时(也就是只要当前日期年月日,不要时分秒)
  1790. boolean searchedLongPolicy = false; // 是否找到了第一个有效状态长期险,默认没找到
  1791. List<PolicyDate> removePolicyDates = new ArrayList<>(); //待删除的policyDate
  1792. for (PolicyDate i : policyDates) {
  1793. // 有效状态保单,计算所有短期险 + 第一个长期险
  1794. if ("有效".equals(i.getPolicystate())) {
  1795. if (searchedLongPolicy) {
  1796. // 由于只有第一个有效状态长期险参与计算,所以后续的有效状态长期险都可以标记为不计算
  1797. logger.info("不参与计算,非第一个有效状态长期险, policyDate: "+ i);
  1798. removePolicyDates.add(i);
  1799. } else if (i.getAgrmntage() >= 180) {
  1800. searchedLongPolicy = true;
  1801. logger.info("找到第一个有效状态长期险, policyDate: "+ i);
  1802. i.setStartDate(i.getPadate());
  1803. i.setEndDate(currentDate);
  1804. }
  1805. }
  1806. // 如果该保单已退保,则将开始和结束日期改为退保数据的开始和结束日期
  1807. for (PolicyDate j : cancelPolicyDates) {
  1808. if (i.getContno().equals(j.getContno())) {
  1809. i.setStartDate(j.getStartDate());
  1810. i.setEndDate(j.getEndDate());
  1811. }
  1812. }
  1813. // 如果结束日期大于当前日期,则修改结束日期为当前日期
  1814. if (i.getEndDate().after(currentDate)) {
  1815. i.setEndDate(currentDate);
  1816. }
  1817. }
  1818. policyDates.removeAll(removePolicyDates);
  1819. }
  1820. public void dateOrder(List<PolicyDate> policyDates) {
  1821. Collections.sort(policyDates, new Comparator<PolicyDate>() {
  1822. @Override
  1823. public int compare(PolicyDate o1, PolicyDate o2) {
  1824. int start = o1.getStartDate().compareTo(o2.getStartDate());
  1825. if (start == 0) {
  1826. return o1.getEndDate().compareTo(o2.getEndDate());
  1827. }
  1828. return start;
  1829. }
  1830. });
  1831. }
  1832. public List<PolicyDate> dateMerge(List<PolicyDate> policyDates) {
  1833. List<PolicyDate> rst = new ArrayList<>();
  1834. if(null!=policyDates&&policyDates.size()>0){
  1835. rst.add(policyDates.get(0));
  1836. for (int i = 1, j = 0; i < policyDates.size(); i++) {
  1837. PolicyDate ip = policyDates.get(i);
  1838. PolicyDate jp = rst.get(j);
  1839. int isje = ip.getStartDate().compareTo(jp.getEndDate());
  1840. if (isje <= 0) {
  1841. // next start 在 last end之前,要判断next end位置
  1842. int ieje = ip.getEndDate().compareTo(jp.getEndDate());
  1843. if (ieje <= 0) {
  1844. //nothing 说明下一个时间范围包含在上一个时间范围内,不做任何操作
  1845. } else {
  1846. // 说明下一个结束时间在上一个结束时间之后,更新结束时间
  1847. jp.setEndDate(ip.getEndDate());
  1848. }
  1849. } else {
  1850. // 下一个开始时间在上一个结束时间之后,说明这又是一个新的时间范围,加入rst
  1851. rst.add(ip);
  1852. j++;
  1853. }
  1854. }
  1855. }
  1856. return rst;
  1857. }
  1858. /**
  1859. * 保单日期类
  1860. */
  1861. public static class PolicyDate {
  1862. /** 保单号 */
  1863. private String contno;
  1864. /** 起保日期 */
  1865. private Date startDate;
  1866. /** 终保日期 */
  1867. private Date endDate;
  1868. /** 投保日期 */
  1869. private Date padate;
  1870. /** 保单状态 */
  1871. private String policystate;
  1872. /** 保险期限 */
  1873. private int agrmntage;
  1874. public PolicyDate(String contno, Date startDate, Date endDate) {
  1875. this.contno = contno;
  1876. this.startDate = startDate;
  1877. this.endDate = endDate;
  1878. }
  1879. public PolicyDate(String contno, Date startDate, Date endDate, Date padate, String policystate, int agrmntage) {
  1880. this.contno = contno;
  1881. this.startDate = startDate;
  1882. this.endDate = endDate;
  1883. this.padate = padate;
  1884. this.policystate = policystate;
  1885. this.agrmntage = agrmntage;
  1886. }
  1887. public String getContno() {
  1888. return contno;
  1889. }
  1890. public void setContno(String contno) {
  1891. this.contno = contno;
  1892. }
  1893. public Date getStartDate() {
  1894. return startDate;
  1895. }
  1896. public void setStartDate(Date startDate) {
  1897. this.startDate = startDate;
  1898. }
  1899. public Date getEndDate() {
  1900. return endDate;
  1901. }
  1902. public void setEndDate(Date endDate) {
  1903. this.endDate = endDate;
  1904. }
  1905. public Date getPadate() {
  1906. return padate;
  1907. }
  1908. public void setPadate(Date padate) {
  1909. this.padate = padate;
  1910. }
  1911. public String getPolicystate() {
  1912. return policystate;
  1913. }
  1914. public void setPolicystate(String policystate) {
  1915. this.policystate = policystate;
  1916. }
  1917. public int getAgrmntage() {
  1918. return agrmntage;
  1919. }
  1920. public void setAgrmntage(int agrmntage) {
  1921. this.agrmntage = agrmntage;
  1922. }
  1923. @Override
  1924. public String toString() {
  1925. final StringBuilder sb = new StringBuilder("PolicyDate{");
  1926. sb.append("contno='").append(contno).append('\'');
  1927. sb.append(", startDate=").append(startDate);
  1928. sb.append(", endDate=").append(endDate);
  1929. sb.append(", padate=").append(padate);
  1930. sb.append(", policystate='").append(policystate).append('\'');
  1931. sb.append(", agrmntage=").append(agrmntage);
  1932. sb.append('}');
  1933. return sb.toString();
  1934. }
  1935. }
  1936. //公共标签
  1937. private List<String> getpublicLabels(){
  1938. List<String> publicLabels = new ArrayList<>(); // 存放以label开头的公共标签key
  1939. publicLabels.add("label1");
  1940. publicLabels.add("label2");
  1941. publicLabels.add("label3");
  1942. publicLabels.add("label4");
  1943. publicLabels.add("label9");
  1944. publicLabels.add("label10");
  1945. publicLabels.add("label21");
  1946. publicLabels.add("label67");
  1947. publicLabels.add("label69");
  1948. publicLabels.add("label70");
  1949. publicLabels.add("label71");
  1950. publicLabels.add("label74");
  1951. publicLabels.add("label77");
  1952. publicLabels.add("label80");
  1953. publicLabels.add("label96");
  1954. publicLabels.add("label97");
  1955. publicLabels.add("label100");
  1956. publicLabels.add("label101");
  1957. publicLabels.add("label103");
  1958. publicLabels.add("label104");
  1959. publicLabels.add("label105");
  1960. publicLabels.add("label106");
  1961. return publicLabels;
  1962. }
  1963. }