| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967 |
- package com.dgtis.data.api;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.dgtis.common.core.utils.DateUtils;
- import com.dgtis.common.core.utils.StringUtils;
- import com.dgtis.common.core.utils.poi.CsvUtil;
- import com.dgtis.common.core.utils.poi.ExcelUtil;
- import com.dgtis.common.core.web.domain.AjaxResult;
- import com.dgtis.common.security.utils.SecurityUtils;
- import com.dgtis.data.domain.Customer;
- import com.dgtis.data.service.ISysUserService;
- import com.dgtis.data.util.AddressResolutionUtil;
- import com.dgtis.system.api.domain.SysUser;
- import com.mysql.cj.x.protobuf.MysqlxDatatypes;
- import org.apache.http.HttpEntity;
- import org.apache.http.entity.ContentType;
- import org.apache.http.nio.entity.NStringEntity;
- import org.apache.http.util.EntityUtils;
- import org.elasticsearch.client.Request;
- import org.elasticsearch.client.Response;
- import org.elasticsearch.client.RestClient;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * @description:客户信息列表api
- * @author:qxm
- * @date:2021/1/22 10:24
- */
- @Controller
- @RequestMapping("/customer")
- public class CustomerApiController {
- /**
- * SHOW_ALL_LABLES 不分渠道展示所有标签 总部团险展示所有标签
- * HIDE_CHANNELS_LABLES 有不同渠道保单情况下 分渠道标签全不显示 仅显示公共标签 , 总部团险展示所有标签
- * SHOW_DISTINGUISH_CHANNELS_LABLES 分渠道展示标签, 总部团险展示所有标签
- */
- @Value("${dgtis.show-label-code}")
- private String showLabelCode = "SHOW_ALL_LABLES";
- private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class);
- @Autowired
- private RestClient restClient;
- @Autowired
- private ISysUserService userService;
- @GetMapping("/getCustomerList")
- @ResponseBody
- public AjaxResult getCustomerList(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize,
- String education,//学历
- String policybelong,//业绩归属
- String payS,String payE, //年缴费区间
- String fadate,//投保年份
- String productname,//险种类别
- String insuredAmountS,String insuredAmountE,//保额区间
- String ageS,String ageE,//年龄区间
- String gender,//性别
- String sobirth,//省份
- String NOVPolicy,//保单件数
- String custtype,//客户类型 投保人
- String SCustID,// 核心客户号
- String custclass,//客户等级
- String participantsDateS,String participantsDateE,//参与方时间
- String PIncomeS,String PIncomeE,//年收入区间
- String Insured,//投保对象
- String lp,//理赔
- String yx,//有效
- String gzgw,//关注官微
- String zcgw,//注册官微
- String name,//客户姓名
- String idcard,//客户证件号码
- String mobile//客户手机号
- ) {
- try {
- logger.info("进客户列表时间:"+DateUtils.getTime());
- JSONObject jsonObject = getCustomerListData((pageNum - 1) * 10, pageSize, true, null,
- education,//学历
- policybelong,//业绩归属
- payS, payE, //年缴费区间
- fadate,//投保年份
- productname,//险种类别
- insuredAmountS, insuredAmountE,//保额区间
- ageS, ageE,//年龄区间
- gender,//性别
- sobirth,//省份
- NOVPolicy,//保单件数
- custtype,//客户类型 投保人
- SCustID,// 核心客户号
- custclass,//客户等级
- participantsDateS, participantsDateE,//参与方时间
- PIncomeS, PIncomeE,//年收入区间
- Insured,//投保对象
- lp,//理赔
- yx,//有效
- gzgw,//关注官微
- zcgw,//注册官微
- name,//客户姓名
- idcard,//客户证件号码
- mobile//客户手机号
- );
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- List listMap = new ArrayList<>();
- Map map = new HashMap();
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = getSource(json);
- listMap.add(mp);
- }
- long total = hitsobject.getLong("total");
- map.put("list",listMap);
- map.put("total",total);
- logger.info("出客户列表时间:"+DateUtils.getTime());
- return AjaxResult.success(map);
- } catch (Exception e) {
- logger.info("列表报错时间:"+DateUtils.getTime());
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- /**
- * 将hit._source转换成map形式,并在map中添加id字段
- * @param hit hit JSONObject
- * @return
- */
- private Map getSource(JSONObject hit) {
- String idKey = "indid";
- Map mp = JSON.parseObject(hit.getString("_source"), Map.class);
- if (mp.containsKey(idKey)) {
- // 查shanglifeecif.customerno_salecom_relation表id是indid
- mp.put("id", mp.get(idKey));
- } else {
- // 查shanglifeecif.individual表id是_id
- mp.put("id", hit.getString("_id"));
- }
- Object birthday = mp.get("birthday");
- if(birthday != null){
- try {
- mp.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD, birthday.toString())));
- } catch (Exception e) {
- logger.warn(String.format("Failed to calendar age, birthday is [%s], birthday and age reset to empty.", birthday));
- mp.put("birthda", "");
- mp.put("age", "");
- }
- }else{
- mp.put("birthday", "");
- mp.put("age","");
- }
- return mp;
- }
- @GetMapping("/getCustomerById")
- @ResponseBody
- public AjaxResult getCustomerById(String id) {
- // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
- try {
- Long userId = SecurityUtils.getUserId();
- SysUser sysUser = userService.selectUserById(userId);
- String deptCode = "";
- // “上海人寿”部门编号开发环境是null,生产环境是0。不是上海人寿部门的才分渠道
- if(StringUtils.isNotEmpty( sysUser.getDept().getDeptCode()) && ! "0".equals(sysUser.getDept().getDeptCode())){
- deptCode = sysUser.getDept().getDeptCode();
- }
- logger.info("进客户详情时间:"+DateUtils.getTime());
- Map<String, String> paramMap = new HashMap<String, String>();
- paramMap.put("pretty", "true");
- Request scriptRequest = new Request("GET", "/shanglifeecif.individual/default_type_/"+id+"?pretty=true");
- Response response = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(response.getEntity());
- Map map = new HashMap();
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
- String indid = jsonObject.getString("_id");
- String custtype = source.getString("custtype");
- String scustid = source.getString("scustid");
- Map mpInfo = getLables(jsonObject, deptCode);
- map.put("custInfo",mpInfo);
- Map query =new HashMap();
- query.put("indid1",indid);
- // 2022/5/13 陆光晨 关系信息分渠道查询
- String lpqSearch = "indid1:"+ scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- lpqSearch += "%20AND%20salecom:"+deptCode;
- }
- scriptRequest = new Request("GET", "/shanglifeecif.indrelationship/_search?pretty=true&q="+ lpqSearch);
- response = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- Set<Map<String, String>> relationship = new HashSet<>();
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- JSONObject shipSource = JSON.parseObject(json.getString("_source"));
- if (shipSource.containsKey("rstype")
- && shipSource.containsKey("indid1")
- && shipSource.containsKey("name1")
- && shipSource.containsKey("role1")
- && shipSource.containsKey("indid2")
- && shipSource.containsKey("name2")
- && shipSource.containsKey("role2")) {
- Map<String, String> mp = new HashMap<>(8);
- mp.put("rstype", shipSource.getString("rstype"));
- mp.put("indid1", shipSource.getString("indid1"));
- mp.put("name1", shipSource.getString("name1"));
- mp.put("role1", shipSource.getString("role1"));
- mp.put("indid2", shipSource.getString("indid2"));
- mp.put("name2", shipSource.getString("name2"));
- mp.put("role2", shipSource.getString("role2"));
- relationship.add(mp);
- }
- }
- map.put("relationship",relationship);
- query =new HashMap();
- query.put("applicantid",indid);
- //理赔查询
- lpqSearch = "lpscutid:"+scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- lpqSearch = "(lpscutid:"+scustid+"%20AND%20salecom:"+deptCode+")";
- }
- scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?size=100&pretty=true&q="+lpqSearch);
- response = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- List insuranceclaimthread = new ArrayList<>();
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- mp.put("id",json.getString("_id"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- insuranceclaimthread.add(mp);
- }
- map.put("insuranceclaimthread",insuranceclaimthread);
- //合约信息
- if("被保人".equals(custtype.trim())){
- String qSearch = "insuredscustid:"+scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- qSearch = "(insuredscustid:"+scustid+"%20AND%20policybelong:"+deptCode+")";
- }
- scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q="+qSearch);
- }else{
- String qSearch = "applicantscustid:"+scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- qSearch = "(applicantscustid:"+scustid+"%20AND%20policybelong:"+deptCode+")";
- }
- scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q="+qSearch);
- }
- logger.info("合约信息请求参数"+scriptRequest.getEndpoint());
- response = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- List insurancearrangement = new ArrayList<>();
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- mp.put("id",json.getString("_id"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- insurancearrangement.add(mp);
- }
- map.put("insurancearrangement",insurancearrangement);
- //接触信息添加渠道条件
- //接触信息
- String jcqSearch = "partyid:"+scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- jcqSearch = "(partyid:"+scustid+"%20AND%20salecom:"+deptCode+")";
- }
- scriptRequest = new Request("GET", "/shanglifeecif.partytimeline/_search?size=100&pretty=true&sort=sdate:asc&q="+jcqSearch);
- logger.info("接触信息请求参数:",scriptRequest.getEndpoint());
- response = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- List partytimeline = new ArrayList<>();
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- mp.put("id",json.getString("_id"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- partytimeline.add(mp);
- }
- map.put("partytimeline",partytimeline);
- logger.info(scriptRequest.getEndpoint());
- logger.info("出客户详情时间:"+DateUtils.getTime());
- return AjaxResult.success(map);
- } catch (Exception e) {
- logger.info("客户详情报错时间:"+DateUtils.getTime());
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- @GetMapping("/getCustomerOverViewById")
- @ResponseBody
- public AjaxResult getCustomerOverViewById(String id) {
- Long userId = SecurityUtils.getUserId();
- SysUser sysUser = userService.selectUserById(userId);
- String deptCode = null;
- // “上海人寿”部门编号开发环境是null,生产环境是0。不是上海人寿部门的才分渠道
- if (StringUtils.isNotEmpty(sysUser.getDept().getDeptCode()) && ! "0".equals(sysUser.getDept().getDeptCode())) {
- deptCode = sysUser.getDept().getDeptCode();
- }
- // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
- try {
- logger.info("进客户概览时间:"+DateUtils.getTime());
- Request scriptRequest = new Request("GET", "/shanglifeecif.individual/default_type_/"+id+"?pretty=true");
- Response response = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(response.getEntity());
- Map map = new HashMap();
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
- String scustid = source.getString("scustid");
- Map mpInfo = getLables(jsonObject, deptCode);
- String jcqSearch = "applicantscustid:"+scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- jcqSearch = "(applicantscustid:"+scustid+"%20AND%20policybelong:"+deptCode+")";
- }
- scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?size=100&pretty=true&sort=padate:asc&q="+jcqSearch);
- logger.info("insurancearrangement",scriptRequest.getEndpoint());
- response = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- DecimalFormat df = new DecimalFormat("######0.0");//保留两位小数改为保留一位小数
- double prem = 0;//标准保费
- double sumprem = 0;//累计保费
- double handedinprem = 0;//已交保费
- //概览投保时间和保费折线图
- Map expectedData = new HashMap();
- String[] edata = new String[]{"0","0","0","0","0","0","0","0","0","0","0","0"};
- expectedData.put("name","");
- Map actaulData = new HashMap();
- String[] adata = new String[]{"0","0","0","0","0","0","0","0","0","0","0","0"};
- actaulData.put("name","");
- List xaxisData = new ArrayList();
- xaxisData.add("1");
- xaxisData.add("2");
- xaxisData.add("3");
- xaxisData.add("4");
- xaxisData.add("5");
- xaxisData.add("6");
- xaxisData.add("7");
- xaxisData.add("8");
- xaxisData.add("9");
- xaxisData.add("10");
- xaxisData.add("11");
- xaxisData.add("12");
- long insureDay = 0;//投保时长
- int guaranteeDay = 0;//享受保障天数
- Map<String,Object> majorCategorie = new HashMap();
- Map mpremMap = new HashMap();
- int firstDate = 1;//定义第一次长期险获取
- Date date = new Date();
- Calendar cal = Calendar.getInstance();
- cal.setTime(date);
- cal.add(Calendar.YEAR, 1);
- Date nextYearTime = cal.getTime();
- String currentDateTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,date);
- String currentYear = DateUtils.parseDateToStr(DateUtils.YYYY,date);
- Set<String> noivpolicyset= new HashSet<>();//失效保单
- Set<String> novpolicyset= new HashSet<>();//有效保单
- //获取最近年份
- logger.info("getCustomerOverViewById",array.toJSONString());
- List<PolicyDate> policyDates = new ArrayList<>();
- final String contno = "policyno";
- final String startDate = "pindate";
- final String endDate = "pmdate";
- final String padateKey = "padate";
- final String agrmntageKey = "agrmntage";
- final String policystate = "policystate";
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- JSONObject _source = (JSONObject) json.get("_source");
- if (_source.containsKey(contno)
- && _source.containsKey(startDate)
- && _source.containsKey(endDate)
- && _source.containsKey(padateKey)
- && _source.containsKey(agrmntageKey)
- && _source.containsKey(policystate)) {
- try {
- policyDates.add(new PolicyDate(
- _source.getString(contno)
- , _source.getDate(startDate)
- , _source.getDate(endDate)
- , _source.getDate(padateKey)
- , _source.getString(policystate)
- , _source.getInteger(agrmntageKey)));
- } catch (Exception e) {
- logger.warn(String.format(
- "Failed to instance PolicyDate, %s: [%s], %s: [%s], %s: [%s], %s: [%s], %s: [%s], %s: [%s]"
- , contno, _source.get(contno)
- , startDate, _source.get(startDate)
- , endDate, _source.get(endDate)
- , padateKey, _source.get(padateKey)
- , policystate, _source.get(policystate)
- , agrmntageKey, _source.get(agrmntageKey)));
- }
- } else {
- logger.info(String.format("Failed to instance PolicyDate, must be '%s', '%s', '%s', '%s', '%s', '%s', _source: [%s]"
- , contno, startDate, endDate, padateKey, policystate, agrmntageKey, _source.toJSONString()));
- }
- Date padate = _source.getDate("padate");
- if(i==0){
- insureDay = DateUtils.getDateDifDay(new Date(),padate);
- }
- if("有效".equals(_source.getString("policystate"))){
- novpolicyset.add(_source.getString("policyno"));
- if(_source.containsKey("sumprem")){
- sumprem+=_source.getDouble("sumprem");
- }
- /* 2022/5/31 start 陆光晨 享受保障天数放在后面计算
- Integer agrmntage = _source.getInteger("agrmntage");
- //短期险
- if(agrmntage<180){
- Date pindate = _source.getDate("pindate");//起保日期
- Date pmdate = _source.getDate("pmdate");//终保日期
- guaranteeDay+=DateUtils.getDateDifDay(pmdate,pindate);
- }else{
- //获取第一次长期险的投保日期,使用当前日期减去投保日期获取保障天数
- if(firstDate==1){
- guaranteeDay+=DateUtils.getDateDifDay(new Date(),padate);
- firstDate++;
- }
- }
- 2022/5/31 end 陆光晨 享受保障天数放在后面计算
- */
- if(_source.containsKey("prem")){
- //计算年缴保费过滤掉缴费方式趸缴的
- if(!"趸缴".equals(_source.getString("payment"))){
- String norenewal = _source.getString("norenewal")==null?"":_source.getString("norenewal").trim();//续保次数
- String payendyear = _source.getString("payendyear")==null?"":_source.getString("payendyear").trim();//缴费年期
- //String currentPadateStr = DateUtils.parseDateToStr(currentYear+"-MM-dd",padate);
- if(_source.containsKey("npdate")){
- Date npdate = _source.getDate("npdate");
- String npDateStr = DateUtils.parseDateToStr("yyyy-MM-dd", npdate);
- String npDateStrYear = DateUtils.parseDateToStr("yyyy", npdate);
- //缴费期限和缴费次数不一样 或者 当年缴费期限和缴费次数一样时
- if(!norenewal.equals(payendyear) || (norenewal.equals(payendyear) && (Integer.parseInt(npDateStrYear)-1)==Integer.parseInt(currentYear))){
- prem+=_source.getDouble("prem");
- if(norenewal.equals(payendyear) && nextYearTime.getTime()>npdate.getTime() && Integer.parseInt(npDateStrYear)>Integer.parseInt(currentYear)){
- handedinprem+=_source.getDouble("prem");
- }
- }
- if(!norenewal.equals(payendyear) && npDateStr.compareTo(currentDateTime)>0 && !npDateStrYear.equals(currentYear)){
- handedinprem+=_source.getDouble("prem");
- }
- }
- String m = DateUtils.parseDateToStr("M", padate);
- if(mpremMap.containsKey(m)){
- double tprem = Double.parseDouble(mpremMap.get(m).toString());
- tprem+=_source.getDouble("prem");
- mpremMap.put(m,df.format(tprem));
- edata[Integer.parseInt(m)-1] = df.format(tprem);
- adata[Integer.parseInt(m)-1] = df.format(tprem);
- }else{
- mpremMap.put(m,df.format(_source.getDouble("prem")));
- edata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
- adata[Integer.parseInt(m)-1] = df.format(_source.getDouble("prem"));
- }
- }else{
- if("趸缴".equals(_source.getString("payment")) && currentYear.equals(DateUtils.parseDateToStr("yyyy",padate))){
- prem+=_source.getDouble("prem");
- handedinprem+=_source.getDouble("prem");
- }
- }
- }
- String risk_categories_name = _source.getString("risk_categories_name");
- if(majorCategorie.containsKey(risk_categories_name)){
- double risk = Double.parseDouble(majorCategorie.get(risk_categories_name).toString());
- if(_source.containsKey("risk")){
- risk += _source.getDouble("risk");
- }
- majorCategorie.put(risk_categories_name,risk);
- }else{
- if(_source.containsKey("risk") && StringUtils.isNotEmpty(risk_categories_name)){
- majorCategorie.put(risk_categories_name,_source.getDouble("risk"));
- }
- }
- }else{
- //客户的所有保单缴费期满且承保期限已满正常终止的客户,需要加上累计保费
- if("终止".equals(_source.getString("policystate"))){
- String norenewal = _source.getString("norenewal")==null?"":_source.getString("norenewal").trim();//续保次数
- String payendyear = _source.getString("payendyear")==null?"":_source.getString("payendyear").trim();//缴费年期
- Date pmdate = _source.getDate("pmdate");//终保日期
- /*
- 2022/5/13 陆光晨 一期测试环境测试时测试老师要求不计算终止状态的保单,因为页面上显示的是“有效保单累计保费”所以只统计有效的就好
- if(norenewal.equals(payendyear) && currentDateTime.compareTo(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,pmdate))>0){
- if(_source.containsKey("sumprem")){
- sumprem+=_source.getDouble("sumprem");
- }
- }
- */
- Integer agrmntage = _source.getInteger("agrmntage");
- /*
- 2022/5/18 start 陆光晨 根据测试曹老师的要求,终止状态的保单计算保障天数是不需要控制短期险
- 缺陷描述:一期测试,使用健康险权限用户登录时,查看客户号1000573488的客户概览页,有一个终止状态的长期保单(正常到期)但享受保障天数是0
- 测试老师认为终止状态的保单也要算进保障天数中,不管是长期险还是短期险
- */
- //短期险
- // if(agrmntage<180){
- /* 2022/5/31 start 陆光晨 享受保障天数放在后面计算
- Date pindate = _source.getDate("pindate");//起保日期
- guaranteeDay+=DateUtils.getDateDifDay(pmdate,pindate);
- 2022/5/31 end 陆光晨 享受保障天数放在后面计算 */
- // }
- // 2022/5/18 end 陆光晨 根据测试曹老师的要求,终止状态的保单计算保障天数是不需要控制短期险
- }
- if (_source.getString("policystate") != null) {
- noivpolicyset.add(_source.getString("policyno"));
- }
- }
- }
- mpInfo.put("noivpolicy",noivpolicyset.size());
- mpInfo.put("novpolicy",novpolicyset.size());
- expectedData.put("data",edata);
- actaulData.put("data",adata);
- Map lineBarChartData = new HashMap();
- lineBarChartData.put("expectedData",expectedData);
- lineBarChartData.put("actaulData",actaulData);
- lineBarChartData.put("xaxisData",xaxisData);
- map.put("lineBarChartData",lineBarChartData);
- //查询理赔信息
- String lpqSearch = "lpscutid:"+scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- lpqSearch = "(lpscutid:"+scustid+"%20AND%20salecom:"+deptCode+")";
- }
- scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?size=100&pretty=true&q="+lpqSearch);
- response = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- Map insuranceclaimthread = new HashMap();
- List insuranceclaimthreads = new ArrayList<>();
- double claimAmount = 0;//理赔总金额
- Set<String> claimTypeSet = new HashSet<>();//理赔类型
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- JSONObject claimSource = JSON.parseObject(json.getString("_source"));
- if(claimSource.containsKey("ccamt")){
- claimAmount+=claimSource.getDouble("ccamt");
- }
- claimTypeSet.add(claimSource.getString("accidenttype"));
- insuranceclaimthreads.add(claimSource);
- }
- insuranceclaimthread.put("isClaim",insuranceclaimthreads.size()>0?"是":"否");
- insuranceclaimthread.put("claimAmount",df.format(claimAmount));
- insuranceclaimthread.put("claimType",String.join(",",claimTypeSet));
- map.put("insuranceclaimthread",insuranceclaimthread);
- mpInfo.put("prem",df.format(prem));//年缴保费/应交保费
- mpInfo.put("sumprem",df.format(sumprem));//累计保费
- mpInfo.put("handedinprem",df.format(handedinprem));//已交保费
- mpInfo.put("insureDay",(insureDay/365) +"年"+(insureDay%365)+"天");
- //保障天数需要加上退保之前的天数
- String tbcustomerinfoSearch = "scustid:"+scustid;
- if( StringUtils.isNotEmpty(deptCode)){
- tbcustomerinfoSearch = "(scustid:"+scustid+"%20AND%20salecom:"+deptCode+")";
- }
- scriptRequest = new Request("GET", "/shanglifeecif.tbcustomerinfo/_search?pretty=true&sort=sdate:asc&size=100&q="+tbcustomerinfoSearch);
- response = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- List<PolicyDate> cancelPolicyDates = new ArrayList<>();
- Date fSdate = null;//最终起始日期,分段的
- Date fEdate = null;//最终结束日期,分段的
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- JSONObject tbSource = JSON.parseObject(json.getString("_source"));
- if (tbSource.containsKey("contno") && tbSource.containsKey("sdate") && tbSource.containsKey("edate")) {
- try {
- cancelPolicyDates.add(new PolicyDate(tbSource.getString("contno"), tbSource.getDate("sdate"), tbSource.getDate("edate")));
- } catch (Exception e) {
- logger.warn(String.format(
- "Failed to instance PolicyDate, contno: [%s], sdate: [%s], edate: [%s]"
- , tbSource.get("contno"), tbSource.get("sdate"), tbSource.get("edate")));
- }
- } else {
- logger.info("Failed to instance PolicyDate, must be 'contno', 'sdate', 'edate', _source: "+ tbSource.toJSONString());
- }
- /** 2022/5/31 start 陆光晨 享受保障天数放在后面计算
- * 获取该退报客户的所有保单信息,计算天数退保天数加上有效保单的天数
- if(tbSource.containsKey("sdate") && tbSource.containsKey("edate")){
- Date sdate = tbSource.getDate("sdate");
- Date edate = tbSource.getDate("edate");
- //获取第一条数据赋值给最后计算的开始和结束日期
- if(i==0){
- fSdate = sdate;
- fEdate = edate;
- }
- //
- // 逻辑梳理
- // 下一张保单的开始日期小于等于当前的结束日期 ,最终开始日期按照上一张保单的开始日期
- // 下一张保单的开始日期大于当前的结束日期 ,需要计算第一部分的保障天数依次循环
- //
- if(i>0){
- if(sdate.getTime()<=fEdate.getTime()){
- //保单结束日期在最终结束日期之后,需要把保单结束日期赋值给最终结束日期
- if(edate.getTime()>fEdate.getTime()){
- fEdate = edate;
- }
- }else{
- //保单的开始日期在结束日期之后,需要先计算前一段的日期差值加到保障天数
- if(i!=array.size()){
- guaranteeDay+=DateUtils.getDateDifDay(fEdate,fSdate);
- fSdate = sdate;
- fEdate = edate;
- }
- }
- if(i==(array.size()-1)){
- guaranteeDay+=DateUtils.getDateDifDay(fEdate,fSdate);
- }
- }
- }
- 2022/5/31 end 陆光晨 享受保障天数放在后面计算 */
- }
- guaranteeDay = guaranteeDay(policyDates, cancelPolicyDates); // 计算享受保障天数
- mpInfo.put("guaranteeDay",guaranteeDay>insureDay?insureDay+"天":guaranteeDay+"天");
- map.put("custInfo",mpInfo);
- //险种数据准备
- Map riskMap = new HashMap();
- riskMap.put("人寿保险","0");
- riskMap.put("新型寿险","0");
- riskMap.put("意外伤害保险","0");
- riskMap.put("医疗险","0");
- riskMap.put("重疾保险","0");
- riskMap.put("年金保险","0");
- for(String key : majorCategorie.keySet()){
- if(riskMap.containsKey(key)){
- riskMap.put(key,majorCategorie.get(key));
- }
- }
- map.put("majorCategorie",riskMap);
- logger.info("出客户概览时间:"+DateUtils.getTime());
- return AjaxResult.success(map);
- } catch (Exception e) {
- logger.info("客户概览报错时间:"+DateUtils.getTime());
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- @GetMapping("/export")
- public void export(HttpServletResponse response, HttpServletRequest request,
- String education,//学历
- String policybelong,//业绩归属
- String payS,String payE, //年缴费区间
- String fadate,//投保年份
- String productname,//险种类别
- String insuredAmountS,String insuredAmountE,//保额区间
- String ageS,String ageE,//年龄区间
- String gender,//性别
- String sobirth,//省份
- String NOVPolicy,//保单件数
- String custtype,//客户类型 投保人
- String SCustID,// 核心客户号
- String custclass,//客户等级
- String participantsDateS,String participantsDateE,//参与方时间
- String PIncomeS,String PIncomeE,//年收入区间
- String Insured,//投保对象
- String lp,//理赔
- String yx,//有效
- String gzgw,//关注官微
- String zcgw,//注册官微
- String name,//客户姓名
- String idcard,//客户证件号码
- String mobile//客户手机号
- ) {
- try{
- logger.info("导出进时间:"+DateUtils.getTime());
- JSONObject jsonObject = getCustomerListData(0, 10000, false, "5m",
- education,//学历
- policybelong,//业绩归属
- payS, payE, //年缴费区间
- fadate,//投保年份
- productname,//险种类别
- insuredAmountS, insuredAmountE,//保额区间
- ageS, ageE,//年龄区间
- gender,//性别
- sobirth,//省份
- NOVPolicy,//保单件数
- custtype,//客户类型 投保人
- SCustID,// 核心客户号
- custclass,//客户等级
- participantsDateS, participantsDateE,//参与方时间
- PIncomeS, PIncomeE,//年收入区间
- Insured,//投保对象
- lp,//理赔
- yx,//有效
- gzgw,//关注官微
- zcgw,//注册官微
- name,//客户姓名
- idcard,//客户证件号码
- mobile//客户手机号
- );
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- List<Customer> customers = new ArrayList<Customer>();
- String scroll_id = jsonObject.getString("_scroll_id");
- HttpEntity entity = new NStringEntity("{\n" +
- " \"scroll_id\": \""+scroll_id+"\",\n" +
- " \"scroll\": \"5m\"\n" +
- "}", ContentType.APPLICATION_JSON);
- while (array.size() != 0) {
- // 这里填写你的业务逻辑,即对每一条数据的处理
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = getSource(json);
- Customer customer = new Customer();
- JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
- customer.setScustId("\t"+jsonOb.getString("scustid"));
- customer.setCustId(jsonOb.getString("custid"));
- customer.setName(jsonOb.getString("name"));
- customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
- customer.setCustType(jsonOb.getString("custtype"));
- customer.setEducation(jsonOb.getString("education"));
- customer.setVaild(StringUtils.isEmpty(jsonOb.getString("label91"))?"有效":"无效");
- customer.setpIncome(jsonOb.getString("pincome"));
- customer.setNum(jsonOb.getString("label25"));
- String ral = jsonOb.getString("ral");
- if(StringUtils.isNotBlank(ral)){
- List<Map> list = AddressResolutionUtil.addressResolution(ral);
- if(list!=null && list.size()>0){
- customer.setProvince(list.get(0).get("province").toString());
- }
- }
- if(mp.containsKey("birthday")){
- String birthday = jsonOb.getString("birthday");
- mp.put("birthday", birthday);
- mp.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,birthday)));
- customer.setBirthDay("\t"+birthday);
- customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,birthday)));
- }
- //String regex = "(\\w{4})(\\w+)(\\w{0})";
- if(mp.containsKey("idcard")){
- customer.setIdType("身份证");
- String idCard = jsonOb.getString("idcard");
- //customer.setIdCard("\t"+jsonOb.getString("idcard").replaceAll(regex, "$1****$3"));
- if(idCard.length()>6){
- customer.setIdCard("\t"+idCard.replaceAll(idCard.substring(idCard.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("passport")){
- customer.setIdType("护照");
- String passport = jsonOb.getString("passport");
- //customer.setIdCard("\t"+jsonOb.getString("passport").replaceAll(regex, "$1****$3"));
- if(passport.length()>6){
- customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("dlicense")){
- customer.setIdType("驾驶证");
- String dlicense = jsonOb.getString("dlicense");
- //customer.setIdCard("\t"+jsonOb.getString("dlicense").replaceAll(regex, "$1****$3"));
- if(dlicense.length()>6){
- customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("otheridnumber")){
- customer.setIdType("其它证件类型");
- String otheridnumber = jsonOb.getString("otheridnumber");
- //customer.setIdCard("\t"+jsonOb.getString("otheridnumber").replaceAll(regex, "$1****$3"));
- if(otheridnumber.length()>6){
- customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }
- if(mp.containsKey("custclass")){
- String custclazz = jsonOb.getString("custclass");
- switch (custclazz){
- case "1":
- customer.setCustClass("钻石");
- break;
- case "2":
- customer.setCustClass("白金");
- break;
- case "3":
- customer.setCustClass("黄金");
- break;
- case "4":
- customer.setCustClass("普通");
- break;
- default:
- customer.setCustClass("无");
- }
- }else{
- customer.setCustClass("无");
- }
- customers.add(customer);
- }
- // 继续向后查询
- Request scriptRequest = new Request("GET", "/_search/scroll");
- scriptRequest.setEntity(entity);
- Response responseData = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(responseData.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- }
- Map<String, String> header = new LinkedHashMap<>();
- header.put("scustId", "核心客户号");
- header.put("custId", "客户号");
- header.put("name", "姓名");
- header.put("idType", "证件类型");
- header.put("idCard", "证件号码");
- header.put("sex", "性别");
- header.put("age", "年龄");
- header.put("birthDay", "出生日期");
- header.put("custClass", "客户等级");
- header.put("custType", "客户类型");
- header.put("province", "省份");
- header.put("education", "学历");
- header.put("vaild", "是否有效客户");
- /*header.put("policyBelong", "业绩归属");*/
- header.put("pIncome", "年收入(万)");
- header.put("num", "保单件数");
- CsvUtil.export(request, response, "customer", header, customers);
- logger.info("导出出时间:"+DateUtils.getTime());
- }catch (Exception e){
- logger.info("导出出错:"+DateUtils.getTime());
- e.printStackTrace();
- }
- }
- /**
- * 导出四要素疑似相同指姓名、性别、证件类型、手机号一致
- * @param response
- * @param request
- */
- @GetMapping("/exportSameZero")
- public void exportSameZero(HttpServletResponse response, HttpServletRequest request)
- {
- logger.info("导出四要素进时间:"+DateUtils.getTime());
- try{
- Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc&q=sametype:0&size=10000&scroll=5m");
- Response responseData = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(responseData.getEntity());
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- List<Customer> customers = new ArrayList<Customer>();
- String scroll_id = jsonObject.getString("_scroll_id");
- HttpEntity entity = new NStringEntity("{\n" +
- " \"scroll_id\": \""+scroll_id+"\",\n" +
- " \"scroll\": \"5m\"\n" +
- "}", ContentType.APPLICATION_JSON);
- while (array.size() != 0) {
- // 这里填写你的业务逻辑,即对每一条数据的处理
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- Customer customer = new Customer();
- json.getString("_source");
- mp.put("id",json.getString("_id"));
- JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- customer.setScustId("\t"+jsonOb.getString("scustid"));
- customer.setName(jsonOb.getString("name"));
- customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
- if(mp.containsKey("birthday")){
- String birthday = jsonOb.getString("birthday");
- mp.put("birthday", birthday);
- customer.setBirthDay("\t"+birthday);
- customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
- }
- if(mp.containsKey("idcard")){
- customer.setIdType("身份证");
- // customer.setIdCard("\t"+jsonOb.getString("idcard"));
- String idcard = jsonOb.getString("idcard");
- if(idcard.length()>6){
- customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("passport")){
- customer.setIdType("护照");
- // customer.setIdCard("\t"+jsonOb.getString("passport"));
- String passport = jsonOb.getString("passport");
- if(passport.length()>6){
- customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("dlicense")){
- customer.setIdType("驾驶证");
- // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
- String dlicense = jsonOb.getString("dlicense");
- if(dlicense.length()>6){
- customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("otheridnumber")){
- customer.setIdType("其它证件类型");
- // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
- String otheridnumber = jsonOb.getString("otheridnumber");
- if(otheridnumber.length()>6){
- customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }
- customers.add(customer);
- }
- // 继续向后查询
- scriptRequest = new Request("GET", "/_search/scroll");
- scriptRequest.setEntity(entity);
- responseData = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(responseData.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- }
- Map<String, String> header = new LinkedHashMap<>();
- header.put("scustId", "核心客户号");
- header.put("name", "姓名");
- header.put("idType", "证件类型");
- header.put("idCard", "证件号码");
- header.put("sex", "性别");
- header.put("birthDay", "出生日期");
- CsvUtil.export(request, response, "customer", header, customers);
- logger.info("导出四要素出时间:"+DateUtils.getTime());
- }catch (Exception e){
- logger.info("导出四要素出错:"+DateUtils.getTime());
- e.printStackTrace();
- }
- }
- /**
- * 导出三要素疑似相同指姓名、性别、出生日期一致
- * @param response
- * @param request
- */
- @GetMapping("/exportSameOne")
- public void exportSameOne(HttpServletResponse response, HttpServletRequest request)
- {
- logger.info("导出三要素进时间:"+DateUtils.getTime());
- try{
- Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc,gender:asc,birthday:asc&q=sametype:1&size=10000&scroll=5m");
- Response responseData = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(responseData.getEntity());
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- List<Customer> customers = new ArrayList<Customer>();
- String scroll_id = jsonObject.getString("_scroll_id");
- HttpEntity entity = new NStringEntity("{\n" +
- " \"scroll_id\": \""+scroll_id+"\",\n" +
- " \"scroll\": \"5m\"\n" +
- "}", ContentType.APPLICATION_JSON);
- while (array.size() != 0) {
- // 这里填写你的业务逻辑,即对每一条数据的处理
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- Customer customer = new Customer();
- json.getString("_source");
- mp.put("id",json.getString("_id"));
- JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- customer.setScustId("\t"+jsonOb.getString("scustid"));
- customer.setName(jsonOb.getString("name"));
- customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
- if(mp.containsKey("birthday")){
- String birthday = jsonOb.getString("birthday");
- mp.put("birthday", birthday);
- customer.setBirthDay(birthday);
- customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
- }
- if(mp.containsKey("idcard")){
- customer.setIdType("身份证");
- // customer.setIdCard("\t"+jsonOb.getString("idcard"));
- String idcard = jsonOb.getString("idcard");
- if(idcard.length()>6){
- customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("passport")){
- customer.setIdType("护照");
- // customer.setIdCard("\t"+jsonOb.getString("passport"));
- String passport = jsonOb.getString("passport");
- if(passport.length()>6){
- customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("dlicense")){
- customer.setIdType("驾驶证");
- // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
- String dlicense = jsonOb.getString("dlicense");
- if(dlicense.length()>6){
- customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("otheridnumber")){
- customer.setIdType("其它证件类型");
- // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
- String otheridnumber = jsonOb.getString("otheridnumber");
- if(otheridnumber.length()>6){
- customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }
- customers.add(customer);
- }
- // 继续向后查询
- scriptRequest = new Request("GET", "/_search/scroll");
- scriptRequest.setEntity(entity);
- responseData = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(responseData.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- }
- Map<String, String> header = new LinkedHashMap<>();
- header.put("scustId", "核心客户号");
- header.put("name", "姓名");
- header.put("idType", "证件类型");
- header.put("idCard", "证件号码");
- header.put("sex", "性别");
- header.put("birthDay", "出生日期");
- CsvUtil.export(request, response, "customer", header, customers);
- logger.info("导出三要素出时间:"+DateUtils.getTime());
- }catch (Exception e){
- logger.info("导出三要素出错:"+DateUtils.getTime());
- e.printStackTrace();
- }
- }
- /**
- * 导出两要素疑似相同指姓名、证件号码一致
- * @param response
- * @param request
- */
- @GetMapping("/exportSameTwo")
- public void exportSameTwo(HttpServletResponse response, HttpServletRequest request)
- {
- logger.info("导出两要素进时间:"+DateUtils.getTime());
- try{
- Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc&q=sametype:2&size=10000&scroll=5m");
- Response responseData = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(responseData.getEntity());
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- List<Customer> customers = new ArrayList<Customer>();
- String scroll_id = jsonObject.getString("_scroll_id");
- HttpEntity entity = new NStringEntity("{\n" +
- " \"scroll_id\": \""+scroll_id+"\",\n" +
- " \"scroll\": \"5m\"\n" +
- "}", ContentType.APPLICATION_JSON);
- while (array.size() != 0) {
- // 这里填写你的业务逻辑,即对每一条数据的处理
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- Customer customer = new Customer();
- json.getString("_source");
- mp.put("id",json.getString("_id"));
- JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- customer.setScustId("\t"+jsonOb.getString("scustid"));
- customer.setName(jsonOb.getString("name"));
- customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
- if(mp.containsKey("birthday")){
- String birthday = jsonOb.getString("birthday");
- mp.put("birthday", birthday);
- customer.setBirthDay("\t"+birthday);
- customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
- }
- if(mp.containsKey("idcard")){
- customer.setIdType("身份证");
- // customer.setIdCard("\t"+jsonOb.getString("idcard"));
- String idcard = jsonOb.getString("idcard");
- if(idcard.length()>6){
- customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("passport")){
- customer.setIdType("护照");
- // customer.setIdCard("\t"+jsonOb.getString("passport"));
- String passport = jsonOb.getString("passport");
- if(passport.length()>6){
- customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("dlicense")){
- customer.setIdType("驾驶证");
- // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
- String dlicense = jsonOb.getString("dlicense");
- if(dlicense.length()>6){
- customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("otheridnumber")){
- customer.setIdType("其它证件类型");
- // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
- String otheridnumber = jsonOb.getString("otheridnumber");
- if(otheridnumber.length()>6){
- customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }
- customers.add(customer);
- }
- // 继续向后查询
- scriptRequest = new Request("GET", "/_search/scroll");
- scriptRequest.setEntity(entity);
- responseData = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(responseData.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- }
- Map<String, String> header = new LinkedHashMap<>();
- header.put("scustId", "核心客户号");
- header.put("name", "姓名");
- header.put("idType", "证件类型");
- header.put("idCard", "证件号码");
- header.put("sex", "性别");
- header.put("birthDay", "出生日期");
- CsvUtil.export(request, response, "customer", header, customers);
- logger.info("导出两要素出时间:"+DateUtils.getTime());
- }catch (Exception e){
- logger.info("导出两要素出错:"+DateUtils.getTime());
- e.printStackTrace();
- }
- }
- /**
- * 导出数据清洗数据
- * @param response
- * @param request
- */
- @GetMapping("/dataCleaning")
- public void dataCleaning(HttpServletResponse response, HttpServletRequest request,String sameType)
- {
- logger.info("导出数据清洗进时间:"+DateUtils.getTime());
- try{
- Request scriptRequest = new Request("GET", "/shanglifeecif.samecustomer/_search?sort=name:asc&q=sametype:"+sameType+"&size=10000&scroll=5m");
- Response responseData = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(responseData.getEntity());
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- List<Customer> customers = new ArrayList<Customer>();
- String scroll_id = jsonObject.getString("_scroll_id");
- HttpEntity entity = new NStringEntity("{\n" +
- " \"scroll_id\": \""+scroll_id+"\",\n" +
- " \"scroll\": \"5m\"\n" +
- "}", ContentType.APPLICATION_JSON);
- while (array.size() != 0) {
- // 这里填写你的业务逻辑,即对每一条数据的处理
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- Customer customer = new Customer();
- json.getString("_source");
- mp.put("id",json.getString("_id"));
- JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- customer.setScustId("\t"+jsonOb.getString("scustid"));
- customer.setName(jsonOb.getString("name"));
- customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
- if(mp.containsKey("birthday")){
- String birthday = jsonOb.getString("birthday");
- mp.put("birthday", birthday);
- customer.setBirthDay("\t"+birthday);
- customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,jsonOb.getString("birthday"))));
- }
- if(mp.containsKey("idcard")){
- customer.setIdType("身份证");
- // customer.setIdCard("\t"+jsonOb.getString("idcard"));
- String idcard = jsonOb.getString("idcard");
- if(idcard.length()>6){
- customer.setIdCard("\t"+idcard.replaceAll(idcard.substring(idcard.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("passport")){
- customer.setIdType("护照");
- // customer.setIdCard("\t"+jsonOb.getString("passport"));
- String passport = jsonOb.getString("passport");
- if(passport.length()>6){
- customer.setIdCard("\t"+passport.replaceAll(passport.substring(passport.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("dlicense")){
- customer.setIdType("驾驶证");
- // customer.setIdCard("\t"+jsonOb.getString("dlicense"));
- String dlicense = jsonOb.getString("dlicense");
- if(dlicense.length()>6){
- customer.setIdCard("\t"+dlicense.replaceAll(dlicense.substring(dlicense.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }else if(mp.containsKey("otheridnumber")){
- customer.setIdType("其它证件类型");
- // customer.setIdCard("\t"+jsonOb.getString("otheridnumber"));
- String otheridnumber = jsonOb.getString("otheridnumber");
- if(otheridnumber.length()>6){
- customer.setIdCard("\t"+otheridnumber.replaceAll(otheridnumber.substring(otheridnumber.length()-6), "******"));
- }else{
- customer.setIdCard("\t"+"******");
- }
- }
- customer.setZipCode("\t"+jsonOb.getString("zipcode"));
- customer.setMobile("\t"+jsonOb.getString("mobile"));
- customer.setEmail("\t"+jsonOb.getString("email"));
- customer.setPinDate(jsonOb.getString("pindate"));
- customer.setAgentName(jsonOb.getString("agentname"));
- customer.setSalecomName(jsonOb.getString("salecomname"));
- customers.add(customer);
- }
- // 继续向后查询
- scriptRequest = new Request("GET", "/_search/scroll");
- scriptRequest.setEntity(entity);
- responseData = restClient.performRequest(scriptRequest);
- result = EntityUtils.toString(responseData.getEntity());
- jsonObject = JSON.parseObject(result);
- hitsobject = (JSONObject) jsonObject.get("hits");
- array = JSON.parseArray(hitsobject.get("hits").toString());
- }
- Map<String, String> header = new LinkedHashMap<>();
- header.put("scustId", "核心客户号");
- header.put("name", "姓名");
- header.put("idType", "证件类型");
- header.put("idCard", "证件号码");
- header.put("sex", "性别");
- header.put("birthDay", "出生日期");
- if("8".equals(sameType) || "16".equals(sameType)){
- header.put("mobile", "手机号码");
- }else if("9".equals(sameType)){
- header.put("zipCode", "邮政编码");
- }else if("12".equals(sameType)){
- header.put("degree", "学历");
- }else if("14".equals(sameType)){
- header.put("email", "邮箱");
- }else if("15".equals(sameType)){
- header.put("pinDate", "起保日期");
- }else if("18".equals(sameType)){
- header.put("agentName", "业务员名称");
- }else if("19".equals(sameType)){
- header.put("salecomName", "业绩归属");
- }
- CsvUtil.export(request, response, "customer", header, customers);
- logger.info("导出数据清洗出时间:"+DateUtils.getTime());
- }catch (Exception e){
- logger.info("导出数据清洗出错:"+DateUtils.getTime());
- e.printStackTrace();
- }
- }
- public Map getLables(JSONObject jsonObject,String deptCode ) throws Exception {
- Map mpInfo = new HashMap();
- JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
- String indid = jsonObject.getString("_id");
- mpInfo.put("id",indid);
- String salecom = source.getString("salecom"); // 可能会得到用逗号分割的多个标签
- if (salecom == null) {
- salecom = "";
- }
- String[] salecoms = salecom.split(",");
- Arrays.sort(salecoms);
- Map<String, Object> sourceMap = JSON.parseObject(jsonObject.getString("_source"), Map.class);
- if (StringUtils.isEmpty(deptCode)||showLabelCode.equals("SHOW_ALL_LABLES")) {
- // 根渠道,也就是上海人寿,也是admin用户所属的渠道,返回jsonObject中的所有标签(公共标签 + 渠道标签)
- mpInfo.putAll(sourceMap);
- } else if (Arrays.binarySearch(salecoms, deptCode) >= 0) {
- // 登录用户的渠道与客户渠道一致,返回jsonObject中的公共标签 + shanglifeecif.customerno_salecom_relation表中的渠道标签
- mpInfo.putAll(getPublicLabels(sourceMap));
- if(showLabelCode.equals("SHOW_DISTINGUISH_CHANNELS_LABLES")){
- mpInfo.putAll(getSalecomLabels(source.getString("scustid"), deptCode));
- }
- } else {
- // 未找到渠道,不返回渠道标签
- logger.info(String.format("登录渠道和客户所属渠道不匹配,不返回渠道标签,登录渠道 [%s],客户所属渠道 [%s]", deptCode, salecom));
- }
- if(mpInfo.containsKey("birthday")){
- mpInfo.put("birthday", source.getString("birthday"));
- mpInfo.put("age",DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD,source.getString("birthday"))));
- }else{
- mpInfo.put("birthday","");
- mpInfo.put("age","");
- }
- return mpInfo;
- }
- /**
- * 只返回公共标签(以label开头和不以label开头的公共标签都会返回)
- * @param source 包含所有标签的map
- * @return 只包含公共标签的map
- */
- private Map<String, Object> getPublicLabels(Map<String, Object> source) {
- Map<String, Object> rst = new HashMap<>();
- // 一般公共标签的key不以label开头,但也有一部分公共标签是以label开头的,将以label开头的公共标签Key存入list后续使用
- List<String> publicLabels = new ArrayList<>(); // 存放以label开头的公共标签key
- publicLabels.add("label1");
- publicLabels.add("label2");
- publicLabels.add("label3");
- publicLabels.add("label4");
- publicLabels.add("label9");
- publicLabels.add("label10");
- publicLabels.add("label21");
- publicLabels.add("Label67");
- publicLabels.add("Label69");
- publicLabels.add("Label70");
- publicLabels.add("Label71");
- publicLabels.add("Label74");
- publicLabels.add("label77");
- publicLabels.add("Label80");
- publicLabels.add("Label96");
- publicLabels.add("Label97");
- publicLabels.add("Label100");
- publicLabels.add("Label101");
- publicLabels.add("Label103");
- publicLabels.add("Label104");
- publicLabels.add("Label105");
- publicLabels.add("Label106");
- for (Map.Entry<String, Object> entry : source.entrySet()){
- String key = entry.getKey();
- logger.info("getPublicLabels------>"+key);
- if(key.startsWith("label")){
- if(publicLabels.contains(key.toLowerCase())||publicLabels.contains(StringUtils.capitalize(key))){
- // 以label开头的公共标签
- rst.put(key,entry.getValue());
- }
- }else{
- // 不以label开头的公共标签
- rst.put(key,entry.getValue());
- }
- }
- return rst;
- }
- /**
- * 从ES表shanglifeecif.customerno_salecom_relation中获得指定客户指定渠道的渠道标签
- * @param customerno 客户号
- * @param salecom 渠道号
- * @return 指定客户指定渠道的所有渠道标签
- */
- public Map<String, Object> getSalecomLabels(String customerno, String salecom) throws IOException {
- Map<String, Object> rst = new HashMap<>();
- String q = "scustid:"+ customerno +"%20AND%20salecom:"+ salecom;
- Request scriptRequest = new Request("GET", "/shanglifeecif.customerno_salecom_relation/_search?pretty=true&q="+ q);
- Response response = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(response.getEntity());
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map<String, Object> source = JSON.parseObject(json.getString("_source"), Map.class);
- for (Map.Entry<String, Object> entry : source.entrySet()){
- String key = entry.getKey();
- if(key.startsWith("label")){
- rst.put(key, entry.getValue());
- }
- }
- }
- return rst;
- }
- public JSONObject getCustomerListData(int pageNum, int pageSize, boolean isPretty, String scroll,
- String education,//学历
- String policybelong,//业绩归属
- String payS,String payE, //年缴费区间
- String fadate,//投保年份
- String productname,//险种类别
- String insuredAmountS,String insuredAmountE,//保额区间
- String ageS,String ageE,//年龄区间
- String gender,//性别
- String sobirth,//省份
- String NOVPolicy,//保单件数
- String custtype,//客户类型 投保人
- String SCustID,// 核心客户号
- String custclass,//客户等级
- String participantsDateS,String participantsDateE,//参与方时间
- String PIncomeS,String PIncomeE,//年收入区间
- String Insured,//投保对象
- String lp,//理赔
- String yx,//有效
- String gzgw,//关注官微
- String zcgw,//注册官微
- String name,//客户姓名
- String idcard,//客户证件号码
- String mobile//客户手机号
- ) throws IOException {
- //模糊查询渠道
- Long userId = SecurityUtils.getUserId();
- SysUser sysUser = userService.selectUserById(userId);
- String deptCode = null;
- // “上海人寿”部门编号开发环境是null,生产环境是0。不是上海人寿部门的才分渠道
- if (StringUtils.isNotEmpty(sysUser.getDept().getDeptCode()) && ! "0".equals(sysUser.getDept().getDeptCode())) {
- deptCode = sysUser.getDept().getDeptCode();
- }
- /*Long userId = SecurityUtils.getUserId();
- SysUser sysUser = userService.selectUserById(userId);
- String deptCode = sysUser.getDept().getDeptCode();*/
- //2.如果没有客户信息以外的查询条件,只需要查询客户信息
- // 获取索引的别名,字段,创建时间
- String beginBirthDay = "";
- String endBirthDay = "";
- if(StringUtils.isNotEmpty(ageS)){
- String year = DateUtils.getYYYY();
- int bYear = Integer.parseInt(year)-Integer.parseInt(ageS);
- endBirthDay = bYear+"-"+DateUtils.getMMDD();
- }
- if(StringUtils.isNotEmpty(ageE)){
- String year = DateUtils.getYYYY();
- int bYear = Integer.parseInt(year)-Integer.parseInt(ageE);
- beginBirthDay = bYear+"-"+DateUtils.getMMDD();
- }
- //拼装查询条件
- StringBuilder builder =new StringBuilder();
- builder.append("{");
- builder.append("\"query\":{");//query开始
- builder.append("\"bool\":{");//boot开始
- builder.append("\"must\":[");//must开始
- //业绩归属字段
- /*if(StringUtils.isNotEmpty(deptCode)){
- builder.append("{\"prefix\":{\"policybelong\":\""+deptCode+"\"}},");
- }*/
- if(StringUtils.isNotEmpty(policybelong)){
- builder.append("{\"prefix\":{\"policybelong\":\""+policybelong+"\"}},");
- }
- //客户姓名
- if(StringUtils.isNotEmpty(name)){
- builder.append("{\"wildcard\":{\"name\":\"*"+name+"*\"}},");
- }
- //客户手机
- if(StringUtils.isNotEmpty(mobile)){
- builder.append("{\"wildcard\":{\"pmphone\":\"*"+mobile+"*\"}},");
- }
- //投保年份
- if(StringUtils.isNotEmpty(fadate)){
- builder.append("{\"wildcard\":{\"fadate\":\"*"+fadate+"*\"}},");
- }
- if(StringUtils.isNotEmpty(gender)){
- builder.append("{\"prefix\":{\"gender\":"+gender+"}},");
- }
- if(StringUtils.isNotEmpty(NOVPolicy)){
- builder.append("{\"prefix\":{\"label25\":\""+NOVPolicy+"\"}},");
- }
- if(StringUtils.isNotEmpty(custclass)){
- builder.append("{\"term\":{\"custclass\":\""+custclass+"\"}},");
- }
- if(StringUtils.isNotEmpty(sobirth)){
- builder.append("{\"wildcard\":{\"sobirth\":\"*"+sobirth+"*\"}},");//模糊匹配
- }
- if(StringUtils.isNotEmpty(SCustID)){
- builder.append("{\"wildcard\":{\"scustid\":\"*"+SCustID+"*\"}},");//模糊匹配
- }
- if(StringUtils.isNotEmpty(custtype)){
- builder.append("{\"wildcard\":{\"custtype\":\"*"+custtype+"*\"}},");
- }
- if(StringUtils.isNotEmpty(beginBirthDay) && StringUtils.isNotEmpty(endBirthDay)){
- builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\",\"lte\":\""+endBirthDay+"\"}}},");
- }else{
- if(StringUtils.isNotEmpty(beginBirthDay)){
- builder.append("{\"range\":{\"birthday\":{\"gte\":\""+beginBirthDay+"\"}}},");
- }
- if(StringUtils.isNotEmpty(endBirthDay)){
- builder.append("{\"range\":{\"birthday\":{\"lte\":\""+endBirthDay+"\"}}},");
- }
- }
- if(StringUtils.isNotEmpty(participantsDateS) && StringUtils.isNotEmpty(participantsDateE)){
- builder.append("{\"range\":{\"fadate\":{\"gte\":\""+participantsDateS+"\",\"lte\":\""+participantsDateE+"\"}}},");
- }else{
- if(StringUtils.isNotEmpty(participantsDateS)){
- builder.append("{\"range\":{\"fadate\":{\"gte\":\""+participantsDateS+"\"}}},");
- }
- if(StringUtils.isNotEmpty(participantsDateE)){
- builder.append("{\"range\":{\"fadate\":{\"lte\":\""+participantsDateE+"\"}}},");
- }
- }
- if(StringUtils.isNotEmpty(PIncomeS) && StringUtils.isNotEmpty(PIncomeE)){
- builder.append("{\"range\":{\"pincome\":{\"gte\":\""+PIncomeS+"\",\"lte\":\""+PIncomeE+"\"}}},");
- }else{
- if(StringUtils.isNotEmpty(PIncomeS)){
- builder.append("{\"range\":{\"pincome\":{\"gte\":\""+PIncomeS+"\"}}},");
- }
- if(StringUtils.isNotEmpty(PIncomeE)){
- builder.append("{\"range\":{\"pincome\":{\"lte\":\""+PIncomeE+"\"}}},");
- }
- }
- if(StringUtils.isNotEmpty(yx)){
- if (yx.equals("0")){
- builder.append("{\"range\":{\"novpolicy\":{\"gt\":\""+yx+"\"}}},");
- }else
- {
- builder.append("{\"prefix\":{\"label91\":\"失效客户\"}},");
- }
- }
- if(StringUtils.isNotEmpty(education)){
- String[] edus = education.split("&");
- builder.append("{\"terms\":{\"education\":[");
- for (String edu:edus) {
- builder.append("\""+edu+"\",");
- }
- builder.delete(builder.length()-1,builder.length());
- builder.append ("]}},");
- }
- if(StringUtils.isNotEmpty(gzgw) && "0".equals(gzgw)){
- builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
- }
- if(StringUtils.isNotEmpty(zcgw) && "0".equals(zcgw)){
- builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
- }
- if(StringUtils.isNotEmpty(lp) && "0".equals(lp)){
- builder.append("{\"prefix\":{\"label57\":\"最近一次理赔类型\"}},");
- }
- // 渠道不为空的话按渠道筛选
- if(StringUtils.isNotEmpty(deptCode)){
- builder.append("{\"wildcard\":{\"salecom\":\"*"+deptCode+"*\"}},");
- }
- if(StringUtils.isNotEmpty(gender) || StringUtils.isNotEmpty(NOVPolicy) || StringUtils.isNotEmpty(custtype)
- || StringUtils.isNotEmpty(custclass) || StringUtils.isNotEmpty(sobirth) || StringUtils.isNotEmpty(SCustID)
- || StringUtils.isNotEmpty(beginBirthDay) || StringUtils.isNotEmpty(endBirthDay) || StringUtils.isNotEmpty(education)
- || StringUtils.isNotEmpty(PIncomeS) || StringUtils.isNotEmpty(PIncomeE) || (StringUtils.isNotEmpty(gzgw) && "0".equals(gzgw))
- || (StringUtils.isNotEmpty(zcgw) && "0".equals(zcgw)) || StringUtils.isNotEmpty(yx)
- || (StringUtils.isNotEmpty(lp) && "0".equals(lp)) || /*StringUtils.isNotEmpty(deptCode) ||*/
- StringUtils.isNotEmpty(participantsDateS) || StringUtils.isNotEmpty(participantsDateE) ||
- StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(name) || StringUtils.isNotEmpty(mobile)
- || StringUtils.isNotEmpty(fadate) || StringUtils.isNotEmpty(deptCode)){
- builder.delete(builder.length()-1,builder.length());
- }
- builder.append("],");//must结束
- builder.append("\"must_not\":[");//must_not
- if(StringUtils.isNotEmpty(gzgw) && "1".equals(gzgw)){
- builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
- }
- if(StringUtils.isNotEmpty(zcgw) && "1".equals(zcgw)){
- builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
- }
- if(StringUtils.isNotEmpty(lp) && "1".equals(lp)){
- builder.append("{\"prefix\":{\"label57\":\"最近一次理赔类型\"}},");
- }
- if(
- (StringUtils.isNotEmpty(gzgw) && "1".equals(gzgw))
- || (StringUtils.isNotEmpty(zcgw) && "1".equals(zcgw))
- || (StringUtils.isNotEmpty(lp) && "1".equals(lp))
- ){
- builder.delete(builder.length()-1,builder.length());
- }
- builder.append("],");
- builder.append("\"should\":[");
- //客户证件号码
- if(StringUtils.isNotEmpty(idcard)){
- builder.append("{\"wildcard\":{\"idcard\":\"*"+idcard+"*\"}},");
- builder.append("{\"wildcard\":{\"passport\":\"*"+idcard+"*\"}},");
- builder.append("{\"wildcard\":{\"dlicense\":\"*"+idcard+"*\"}},");
- builder.append("{\"wildcard\":{\"otheridnumber\":\"*"+idcard+"*\"}},");
- builder.delete(builder.length()-1,builder.length());
- }
- builder.append("]");//should
- builder.append("}");//boot结束
- builder.append("},");//query结束
- builder.append("\"from\":"+ pageNum +",");//第几页
- builder.append("\"size\":"+ pageSize +",");//查询几个
- builder.append("\"sort\":[{\"scustid\":{\"order\":\"asc\"}}],");//排序
- builder.append("\"aggs\":{}");//
- builder.append("}");
- logger.info(builder.toString());
- HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
- String url;
- /*
- shanglifeecif.individual表中的渠道标签字段值是不分渠道的(也就是全渠道计算),所以像admin这种没有渠道的用户查这个表
- shanglifeecif.customerno_salecom_relation表中渠道标签字段值是分渠道计算的,所以登录用户有渠道时查这个表
- */
- boolean hasDeptCode; // 登录用户是否有渠道 true:有渠道,false:无渠道
- if(StringUtils.isEmpty(deptCode)){
- // 像admin这种无渠道用户
- logger.info("deptCode is empty, search shanglifeecif.individual");
- url = "/shanglifeecif.individual/_search?";
- hasDeptCode = false;
- } else {
- // 有渠道用户
- logger.info(String.format("deptCode is [%s], search shanglifeecif.customerno_salecom_relation", deptCode));
- url = "/shanglifeecif.customerno_salecom_relation/_search?";
- hasDeptCode = true;
- }
- url += isPretty ? "pretty=true" : "pretty=false";
- url += StringUtils.isEmpty(scroll) ? "" : "&scroll="+ scroll;
- Request scriptRequest = new Request("GET", url);
- scriptRequest.setEntity(entity);
- Response response = restClient.performRequest(scriptRequest);
- String result = EntityUtils.toString(response.getEntity());
- JSONObject jsonObject = JSON.parseObject(result);
- return jsonObject;
- }
- /**
- * 计算享受保障天数,所有保单已享受到保障的天数合计(会忽略掉重叠天数),退保的只计算退保前享受到的保障天数
- * @param policyDates 所有保单集合
- * @param cancelPolicyDates 退保保单集合
- * @return
- */
- public int guaranteeDay(List<PolicyDate> policyDates, List<PolicyDate> cancelPolicyDates) {
- modifyDate(policyDates, cancelPolicyDates);
- dateOrder(policyDates);
- List<PolicyDate> merged = dateMerge(policyDates);
- int day = 0;
- if (merged == null || merged.isEmpty()) {
- return day;
- }
- for (PolicyDate i : merged) {
- day += DateUtils.getDateDifDay(i.getEndDate(), i.getStartDate());
- }
- return day;
- }
- /**
- *
- * @param policyDates 所有保单数据
- * @param cancelPolicyDates 退保数据
- */
- public void modifyDate(List<PolicyDate> policyDates, List<PolicyDate> cancelPolicyDates) {
- Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- Date currentDate = c.getTime(); // 当前日期0时(也就是只要当前日期年月日,不要时分秒)
- boolean searchedLongPolicy = false; // 是否找到了第一个有效状态长期险,默认没找到
- List<PolicyDate> removePolicyDates = new ArrayList<>(); //待删除的policyDate
- for (PolicyDate i : policyDates) {
- // 有效状态保单,计算所有短期险 + 第一个长期险
- if ("有效".equals(i.getPolicystate())) {
- if (searchedLongPolicy) {
- // 由于只有第一个有效状态长期险参与计算,所以后续的有效状态长期险都可以标记为不计算
- logger.info("不参与计算,非第一个有效状态长期险, policyDate: "+ i);
- removePolicyDates.add(i);
- } else if (i.getAgrmntage() >= 180) {
- searchedLongPolicy = true;
- logger.info("找到第一个有效状态长期险, policyDate: "+ i);
- i.setStartDate(i.getPadate());
- i.setEndDate(currentDate);
- }
- }
- // 如果该保单已退保,则将开始和结束日期改为退保数据的开始和结束日期
- for (PolicyDate j : cancelPolicyDates) {
- if (i.getContno().equals(j.getContno())) {
- i.setStartDate(j.getStartDate());
- i.setEndDate(j.getEndDate());
- }
- }
- // 如果结束日期大于当前日期,则修改结束日期为当前日期
- if (i.getEndDate().after(currentDate)) {
- i.setEndDate(currentDate);
- }
- }
- policyDates.removeAll(removePolicyDates);
- }
- public void dateOrder(List<PolicyDate> policyDates) {
- Collections.sort(policyDates, new Comparator<PolicyDate>() {
- @Override
- public int compare(PolicyDate o1, PolicyDate o2) {
- int start = o1.getStartDate().compareTo(o2.getStartDate());
- if (start == 0) {
- return o1.getEndDate().compareTo(o2.getEndDate());
- }
- return start;
- }
- });
- }
- public List<PolicyDate> dateMerge(List<PolicyDate> policyDates) {
- List<PolicyDate> rst = new ArrayList<>();
- rst.add(policyDates.get(0));
- for (int i = 1, j = 0; i < policyDates.size(); i++) {
- PolicyDate ip = policyDates.get(i);
- PolicyDate jp = rst.get(j);
- int isje = ip.getStartDate().compareTo(jp.getEndDate());
- if (isje <= 0) {
- // next start 在 last end之前,要判断next end位置
- int ieje = ip.getEndDate().compareTo(jp.getEndDate());
- if (ieje <= 0) {
- //nothing 说明下一个时间范围包含在上一个时间范围内,不做任何操作
- } else {
- // 说明下一个结束时间在上一个结束时间之后,更新结束时间
- jp.setEndDate(ip.getEndDate());
- }
- } else {
- // 下一个开始时间在上一个结束时间之后,说明这又是一个新的时间范围,加入rst
- rst.add(ip);
- j++;
- }
- }
- return rst;
- }
- /**
- * 保单日期类
- */
- public static class PolicyDate {
- /** 保单号 */
- private String contno;
- /** 起保日期 */
- private Date startDate;
- /** 终保日期 */
- private Date endDate;
- /** 投保日期 */
- private Date padate;
- /** 保单状态 */
- private String policystate;
- /** 保险期限 */
- private int agrmntage;
- public PolicyDate(String contno, Date startDate, Date endDate) {
- this.contno = contno;
- this.startDate = startDate;
- this.endDate = endDate;
- }
- public PolicyDate(String contno, Date startDate, Date endDate, Date padate, String policystate, int agrmntage) {
- this.contno = contno;
- this.startDate = startDate;
- this.endDate = endDate;
- this.padate = padate;
- this.policystate = policystate;
- this.agrmntage = agrmntage;
- }
- public String getContno() {
- return contno;
- }
- public void setContno(String contno) {
- this.contno = contno;
- }
- public Date getStartDate() {
- return startDate;
- }
- public void setStartDate(Date startDate) {
- this.startDate = startDate;
- }
- public Date getEndDate() {
- return endDate;
- }
- public void setEndDate(Date endDate) {
- this.endDate = endDate;
- }
- public Date getPadate() {
- return padate;
- }
- public void setPadate(Date padate) {
- this.padate = padate;
- }
- public String getPolicystate() {
- return policystate;
- }
- public void setPolicystate(String policystate) {
- this.policystate = policystate;
- }
- public int getAgrmntage() {
- return agrmntage;
- }
- public void setAgrmntage(int agrmntage) {
- this.agrmntage = agrmntage;
- }
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("PolicyDate{");
- sb.append("contno='").append(contno).append('\'');
- sb.append(", startDate=").append(startDate);
- sb.append(", endDate=").append(endDate);
- sb.append(", padate=").append(padate);
- sb.append(", policystate='").append(policystate).append('\'');
- sb.append(", agrmntage=").append(agrmntage);
- sb.append('}');
- return sb.toString();
- }
- }
- }
|