CustomerApiController.java 96 KB

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