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 paramMap = new HashMap(); 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> relationship = new HashSet<>(); for (int i = 0; i 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 (); for (int i = 0; i (); for (int i = 0; i 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 noivpolicyset= new HashSet<>();//失效保单 Set novpolicyset= new HashSet<>();//有效保单 //获取最近年份 logger.info("getCustomerOverViewById",array.toJSONString()); List 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 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 claimTypeSet = new HashSet<>();//理赔类型 for (int i = 0; i 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 cancelPolicyDates = new ArrayList<>(); Date fSdate = null;//最终起始日期,分段的 Date fEdate = null;//最终结束日期,分段的 for (int i = 0; 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 customers = new ArrayList(); 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 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 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 customers = new ArrayList(); 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 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 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 customers = new ArrayList(); 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 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 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 customers = new ArrayList(); 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 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 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 customers = new ArrayList(); 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 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 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 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 getPublicLabels(Map source) { Map rst = new HashMap<>(); // 一般公共标签的key不以label开头,但也有一部分公共标签是以label开头的,将以label开头的公共标签Key存入list后续使用 List publicLabels =getpublicLabels(); for (Map.Entry entry : source.entrySet()){ String key = entry.getKey(); logger.info("getPublicLabels------>"+key); if(key.startsWith("label")){ if(publicLabels.contains(key)){ // 以label开头的公共标签 logger.info("以label开头的公共标签------>"+key); rst.put(key,entry.getValue()); }else{ logger.info("分渠道标签------>"+key); } }else{ // 不以label开头的公共标签 rst.put(key,entry.getValue()); } } return rst; } /** * 从ES表shanglifeecif.customerno_salecom_relation中获得指定客户指定渠道的渠道标签 * @param customerno 客户号 * @param salecom 渠道号 * @return 指定客户指定渠道的所有渠道标签 */ public Map getSalecomLabels(String customerno, String salecom) throws IOException { Map 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()); List publicLabels = getpublicLabels(); for (int i = 0; i source = JSON.parseObject(json.getString("_source"), Map.class); for (Map.Entry entry : source.entrySet()){ String key = entry.getKey(); if(key.startsWith("label")&&!publicLabels.contains(key)){ logger.info("分渠道标签添加--->"+key+"__"+entry.getValue()); 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\":{\"salecom\":\""+deptCode+"\"}},"); // }else if(StringUtils.isNotEmpty(policybelong)){ // builder.append("{\"prefix\":{\"salecom\":\""+policybelong+"\"}},"); // } // 渠道不为空的话按渠道筛选 if(StringUtils.isNotEmpty(deptCode)){ builder.append("{\"wildcard\":{\"salecom\":\"*"+deptCode+"*\"}},"); }else if(StringUtils.isNotEmpty(policybelong)){ builder.append("{\"wildcard\":{\"salecom\":\"*"+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(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 policyDates, List cancelPolicyDates) { modifyDate(policyDates, cancelPolicyDates); dateOrder(policyDates); List 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 policyDates, List 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 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 policyDates) { Collections.sort(policyDates, new Comparator() { @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 dateMerge(List policyDates) { List 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(); } } //公共标签 private List getpublicLabels(){ List 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"); return publicLabels; } }