|
@@ -1,5 +1,6 @@
|
|
|
package com.dgtis.data.api;
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -26,6 +27,7 @@ import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -64,23 +66,42 @@ public class CustomerApiController {
|
|
|
String gzgw,//关注官微
|
|
|
String zcgw//注册官微
|
|
|
) {
|
|
|
- // 获取索引的别名,字段,创建时间
|
|
|
- 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();
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
try {
|
|
|
+
|
|
|
+ //1.如果存在保单信息的查询条件,需要先查询保单信息然后通过保单关联出客户信息
|
|
|
+ //处理保单查询条件
|
|
|
+ List<String> customerIds = new ArrayList<String>();
|
|
|
+ if(StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(payS) || StringUtils.isNotEmpty(payE)
|
|
|
+ || StringUtils.isNotEmpty(insuredAmountS) || StringUtils.isNotEmpty(insuredAmountE)){
|
|
|
+ customerIds = queryInsurancearrangement(policybelong,payS,payE,fadate,productname,insuredAmountS,insuredAmountE);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //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("{");
|
|
@@ -94,7 +115,7 @@ public class CustomerApiController {
|
|
|
builder.append("{\"prefix\": { \"label25\": \""+NOVPolicy+"\"}},");
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(custclass)){
|
|
|
- builder.append("{\"prefix\": { \"custclass\": \""+custclass+"\"}},");
|
|
|
+ builder.append("{\"term\": { \"custclass\": \""+custclass+"\"}},");
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(sobirth)){
|
|
|
builder.append("{\"wildcard\": { \"sobirth\": \"*"+sobirth+"*\"}},");//模糊匹配
|
|
@@ -103,6 +124,9 @@ public class CustomerApiController {
|
|
|
if(StringUtils.isNotEmpty(SCustID)){
|
|
|
builder.append("{\"wildcard\": { \"custid\": \"*"+SCustID+"*\"}},");//模糊匹配
|
|
|
}
|
|
|
+ if(StringUtils.isNotEmpty(custtype)){
|
|
|
+ builder.append("{\"prefix\": { \"custtype\": \""+custtype+"\"}},");
|
|
|
+ }
|
|
|
|
|
|
if(StringUtils.isNotEmpty(beginBirthDay) && StringUtils.isNotEmpty(endBirthDay)){
|
|
|
builder.append("{\"range\":{\"birthday\":{\"gt\":\""+beginBirthDay+"\",\"lt\":\""+endBirthDay+"\"}}},");
|
|
@@ -115,8 +139,53 @@ public class CustomerApiController {
|
|
|
builder.append("{\"range\":{\"birthday\":{\"lt\":\""+endBirthDay+"\"}}},");
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtils.isNotEmpty(gender) || StringUtils.isNotEmpty(NOVPolicy) ||
|
|
|
- StringUtils.isNotEmpty(custclass) || StringUtils.isNotEmpty(sobirth) || StringUtils.isNotEmpty(SCustID)){
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(PIncomeS) && StringUtils.isNotEmpty(PIncomeE)){
|
|
|
+ builder.append("{\"range\":{\"PIncome\":{\"gt\":\""+PIncomeS+"\",\"lt\":\""+PIncomeE+"\"}}},");
|
|
|
+ }else{
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(PIncomeS)){
|
|
|
+ builder.append("{\"range\":{\"PIncome\":{\"gt\":\""+PIncomeS+"\"}}},");
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(PIncomeE)){
|
|
|
+ builder.append("{\"range\":{\"PIncome\":{\"lt\":\""+PIncomeE+"\"}}},");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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(customerIds.size()>0){
|
|
|
+ builder.append("{\"terms\":{\"_id\":[" );
|
|
|
+ for (String id:customerIds) {
|
|
|
+ builder.append("\""+id+"\",");
|
|
|
+ }
|
|
|
+ builder.delete(builder.length()-1,builder.length());
|
|
|
+ builder.append ("]}},");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(gzgw)){
|
|
|
+ builder.append("{\"prefix\": { \"label73\": \"关注官微\"}},");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(zcgw)){
|
|
|
+ builder.append("{\"prefix\": { \"label74\": \"注册官微\"}},");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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)
|
|
|
+ || StringUtils.isNotEmpty(zcgw)){
|
|
|
builder.delete(builder.length()-1,builder.length());
|
|
|
}
|
|
|
|
|
@@ -125,7 +194,7 @@ public class CustomerApiController {
|
|
|
builder.append("\"should\": [ ]");//should
|
|
|
builder.append("}");//boot结束
|
|
|
builder.append("},");//query结束
|
|
|
- builder.append("\"from\": "+pageNum+",");//第几页
|
|
|
+ builder.append("\"from\": "+(pageNum*10+1)+",");//第几页
|
|
|
builder.append("\"size\": "+pageSize+",");//查询几个
|
|
|
builder.append(" \"sort\": [{\"created_time\":{\"order\":\"desc\"}}],");//排序
|
|
|
builder.append(" \"aggs\": {}");//
|
|
@@ -175,6 +244,106 @@ public class CustomerApiController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询保单信息返回客户Id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List queryInsurancearrangement(String policybelong,String payS,String payE,String fadate,
|
|
|
+ String productname,String insuredAmountS,String insuredAmountE) throws Exception {
|
|
|
+
|
|
|
+ List<String> customerIds = new ArrayList<String>();
|
|
|
+
|
|
|
+ //拼装查询条件
|
|
|
+ StringBuilder builder =new StringBuilder();
|
|
|
+ builder.append("{");
|
|
|
+ builder.append("\"query\": {");//query开始
|
|
|
+ builder.append("\"bool\": {");//boot开始
|
|
|
+ builder.append("\"must\": [");//must开始
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(policybelong)){
|
|
|
+ builder.append("{\"prefix\": { \"policybelong\": \""+policybelong+"\"}},");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(fadate)){
|
|
|
+ builder.append("{\"prefix\": { \"PADate\": \""+fadate+"\"}},");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(payS) && StringUtils.isNotEmpty(payE)){
|
|
|
+ builder.append("{\"range\":{\"Prem\":{\"gt\":\""+payS+"\",\"lt\":\""+payE+"\"}}},");
|
|
|
+ }else{
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(payS)){
|
|
|
+ builder.append("{\"range\":{\"Prem\":{\"gt\":\""+payS+"\"}}},");
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(payE)){
|
|
|
+ builder.append("{\"range\":{\"Prem\":{\"lt\":\""+payE+"\"}}},");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(insuredAmountS) && StringUtils.isNotEmpty(insuredAmountE)){
|
|
|
+ builder.append("{\"range\":{\"Risk\":{\"gt\":\""+insuredAmountS+"\",\"lt\":\""+insuredAmountE+"\"}}},");
|
|
|
+ }else{
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(payS)){
|
|
|
+ builder.append("{\"range\":{\"Risk\":{\"gt\":\""+insuredAmountS+"\"}}},");
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(payE)){
|
|
|
+ builder.append("{\"range\":{\"Risk\":{\"lt\":\""+insuredAmountE+"\"}}},");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(policybelong) || StringUtils.isNotEmpty(payS) || StringUtils.isNotEmpty(payE)
|
|
|
+ || StringUtils.isNotEmpty(insuredAmountS) || StringUtils.isNotEmpty(insuredAmountE)){
|
|
|
+ builder.delete(builder.length()-1,builder.length());
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.append("],");//must结束
|
|
|
+ builder.append("\"must_not\": [ ],");//must_not
|
|
|
+ builder.append("\"should\": [ ]");//should
|
|
|
+ builder.append("}");//boot结束
|
|
|
+ builder.append("},");//query结束
|
|
|
+ //builder.append("\"from\": "+pageNum+",");//第几页
|
|
|
+ builder.append("\"size\": 1000,");//查询几个
|
|
|
+ //builder.append(" \"sort\": [{\"created_time\":{\"order\":\"desc\"}}],");//排序
|
|
|
+ builder.append(" \"aggs\": {}");//
|
|
|
+ builder.append("}");
|
|
|
+
|
|
|
+ HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
|
|
|
+
|
|
|
+ Response response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m",Collections.<String, String>emptyMap(),entity);
|
|
|
+
|
|
|
+ String result = EntityUtils.toString(response.getEntity());
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
+ JSONArray hitsList = JSON.parseArray(hitsobject.get("hits").toString());
|
|
|
+ String scroll_id = jsonObject.getString("_scroll_id");
|
|
|
+
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("scroll_id",scroll_id);
|
|
|
+ obj.put("scroll","1m");
|
|
|
+ while (hitsList.size() != 0) {
|
|
|
+
|
|
|
+ // 这里填写你的业务逻辑,即对每一条数据的处理
|
|
|
+ for (int i = 0; i <hitsList.size() ; i++) {
|
|
|
+ JSONObject json = (JSONObject)hitsList.get(i);
|
|
|
+ JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
|
|
|
+ if(StringUtils.isNotEmpty(jsonOb.getString("applicantid"))){
|
|
|
+ customerIds.add(jsonOb.getString("applicantid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // 继续向后查询
|
|
|
+ /* entity = new NStringEntity(JSONUtil.toJsonStr(obj), ContentType.APPLICATION_JSON);
|
|
|
+ response= restClient.performRequest("GET", "/_search/scroll",Collections.<String, String>emptyMap(),entity);
|
|
|
+ result = EntityUtils.toString(response.getEntity());
|
|
|
+ jsonObject = JSON.parseObject(result);
|
|
|
+ hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
+ hitsList = JSON.parseArray(hitsobject.get("hits").toString());*/
|
|
|
+ }
|
|
|
+
|
|
|
+ return customerIds;
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/getCustomerById")
|
|
|
@ResponseBody
|
|
|
public AjaxResult getCustomerById(String id) {
|
|
@@ -240,6 +409,24 @@ public class CustomerApiController {
|
|
|
insuranceclaimthread.add(mp);
|
|
|
}
|
|
|
map.put("insuranceclaimthread",insuranceclaimthread);
|
|
|
+
|
|
|
+ query =new HashMap();
|
|
|
+ query.put("applicantid",indid);
|
|
|
+ entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
|
|
|
+ response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
+ 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);
|
|
|
map.put("custInfo3",null);
|
|
|
map.put("custInfo4",null);
|
|
|
map.put("custInfo5",null);
|