123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- package com.dgtis.data.api;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.arronlong.httpclientutil.HttpClientUtil;
- import com.arronlong.httpclientutil.common.HttpConfig;
- import com.arronlong.httpclientutil.exception.HttpProcessException;
- import com.dgtis.common.core.utils.DateUtils;
- import com.dgtis.common.core.utils.StringUtils;
- import com.dgtis.common.core.utils.sql.EsJsonUtil;
- import com.dgtis.common.core.web.domain.AjaxResult;
- import com.dgtis.common.security.annotation.PreAuthorize;
- 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.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.Qualifier;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.util.*;
- /**
- * @description:客户信息列表api
- * @author:qxm
- * @date:2021/1/22 10:24
- */
- @Controller
- @RequestMapping("/customer")
- public class CustomerApiController {
- private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class);
- @Autowired
- private RestClient restClient;
- @GetMapping("/getCustomerList")
- @ResponseBody
- public AjaxResult getCustomerList(@RequestParam(defaultValue = "0") 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 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 {
- //拼装查询条件
- StringBuilder builder =new StringBuilder();
- builder.append("{");
- builder.append("\"query\": {");//query开始
- builder.append("\"bool\": {");//boot开始
- builder.append("\"must\": [");//must开始
- if(StringUtils.isNotEmpty(gender)){
- builder.append("{\"prefix\": { \"gender\": "+gender+"}},");
- }
- if(StringUtils.isNotEmpty(NOVPolicy)){
- builder.append("{\"prefix\": { \"label25\": \""+NOVPolicy+"\"}},");
- }
- if(StringUtils.isNotEmpty(custclass)){
- builder.append("{\"prefix\": { \"custclass\": \""+custclass+"\"}},");
- }
- if(StringUtils.isNotEmpty(sobirth)){
- builder.append("{\"wildcard\": { \"sobirth\": \"*"+sobirth+"*\"}},");//模糊匹配
- }
- if(StringUtils.isNotEmpty(SCustID)){
- builder.append("{\"wildcard\": { \"custid\": \"*"+SCustID+"*\"}},");//模糊匹配
- }
- if(StringUtils.isNotEmpty(beginBirthDay) && StringUtils.isNotEmpty(endBirthDay)){
- builder.append("{\"range\":{\"birthday\":{\"gt\":\""+beginBirthDay+"\",\"lt\":\""+endBirthDay+"\"}}},");
- }else{
- if(StringUtils.isNotEmpty(beginBirthDay)){
- builder.append("{\"range\":{\"birthday\":{\"gt\":\""+beginBirthDay+"\"}}},");
- }
- if(StringUtils.isNotEmpty(endBirthDay)){
- builder.append("{\"range\":{\"birthday\":{\"lt\":\""+endBirthDay+"\"}}},");
- }
- }
- if(StringUtils.isNotEmpty(gender) || StringUtils.isNotEmpty(NOVPolicy) ||
- StringUtils.isNotEmpty(custclass) || StringUtils.isNotEmpty(sobirth) || StringUtils.isNotEmpty(SCustID)){
- 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\": "+pageSize+",");//查询几个
- 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.individual/_search",Collections.<String, String>emptyMap(),entity);
- 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 listMap = new ArrayList<>();
- Map map = new HashMap();
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- Map mp = new HashMap();
- mp.put("id",json.getString("_id"));
- JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
- mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
- if(mp.containsKey("birthday")){
- Date date = jsonOb.getDate("birthday");
- if(date!=null){
- mp.put("birthday", DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date));
- mp.put("age",DateUtils.getAge(date));
- }else{
- mp.put("birthday", "");
- mp.put("age","");
- }
- }else{
- mp.put("birthday", "");
- mp.put("age","");
- }
- listMap.add(mp);
- }
- long total = hitsobject.getLong("total");
- map.put("list",listMap);
- map.put("total",total);
- return AjaxResult.success(map);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- @GetMapping("/getCustomerById")
- @ResponseBody
- public AjaxResult getCustomerById(String id) {
- // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
- try {
- Map<String, String> paramMap = new HashMap<String, String>();
- paramMap.put("pretty", "true");
- Response response = restClient.performRequest("GET", "/shanglifeecif.individual/default_type_/"+id, paramMap);
- String result = EntityUtils.toString(response.getEntity());
- Map map = new HashMap();
- JSONObject jsonObject = JSON.parseObject(result);
- Map mpInfo = new HashMap();
- String indid = jsonObject.getString("_id");
- mpInfo.put("id",indid);
- JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
- mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
- //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday")));
- if(mpInfo.containsKey("birthday")){
- Date date = source.getDate("birthday");
- if(date!=null){
- mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",date));
- mpInfo.put("age",DateUtils.getAge(date));
- }
- }else{
- mpInfo.put("birthday","");
- mpInfo.put("age","");
- }
- map.put("custInfo",mpInfo);
- Map query =new HashMap();
- query.put("indid1",indid);
- HttpEntity entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
- response= restClient.performRequest("GET", "/shanglifeecif.indrelationship/_search",Collections.<String, String>emptyMap(),entity);
- result = EntityUtils.toString(response.getEntity());
- jsonObject = JSON.parseObject(result);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- List relationship = 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));
- relationship.add(mp);
- }
- map.put("relationship",relationship);
- query =new HashMap();
- query.put("applicantid",indid);
- entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
- response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_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 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);
- map.put("custInfo3",null);
- map.put("custInfo4",null);
- map.put("custInfo5",null);
- map.put("custInfo6",null);
- map.put("custInfo7",null);
- map.put("custInfo8",null);
- return AjaxResult.success(map);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- @GetMapping("/getCustomerOverViewById")
- @ResponseBody
- public AjaxResult getCustomerOverViewById(String id) {
- // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
- try {
- Map<String, String> paramMap = new HashMap<String, String>();
- paramMap.put("pretty", "true");
- Response response = restClient.performRequest("GET", "shanglifeecif.individual/default_type_/"+id, paramMap);
- String result = EntityUtils.toString(response.getEntity());
- Map map = new HashMap();
- JSONObject jsonObject = JSON.parseObject(result);
- Map mpInfo = new HashMap();
- String indid = jsonObject.getString("_id");
- mpInfo.put("id",indid);
- JSONObject source = JSON.parseObject(jsonObject.getString("_source"));
- mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
- //mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",JSON.parseObject(jsonObject.getString("_source")).getDate("birthday")));
- if(mpInfo.containsKey("birthday")){
- Date date = source.getDate("birthday");
- if(date!=null){
- mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",date));
- mpInfo.put("age",DateUtils.getAge(date));
- }
- }else{
- mpInfo.put("birthday","");
- mpInfo.put("age","");
- }
- Map query =new HashMap();
- query.put("applicantid",indid);
- HttpEntity 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);
- JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
- JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
- long prem = 0;//总保费
- Map expectedData = new HashMap();
- List edata = new ArrayList();
- expectedData.put("name","");
- Map actaulData = new HashMap();
- List adata = new ArrayList();
- actaulData.put("name","");
- List xaxisData = new ArrayList();
- long insureDay = 0;
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = (JSONObject)array.get(i);
- JSONObject _source = (JSONObject) json.get("_source");
- if(_source.containsKey("prem")){
- prem+=_source.getLong("prem");
- edata.add(_source.getLong("prem"));
- adata.add(_source.getLong("prem"));
- }
-
- if(_source.containsKey("padate")){
- Date padate = _source.getDate("padate");
- xaxisData.add(DateUtils.parseDateToStr("MM",padate));
- insureDay = DateUtils.getDateDifDay(new Date(),padate);
- }
- }
- 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);
- query =new HashMap();
- query.put("applicantid",indid);
- entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
- response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_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 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);
- mpInfo.put("prem",prem);
- mpInfo.put("insureDay",insureDay);
- map.put("custInfo",mpInfo);
- return AjaxResult.success(map);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error();
- }
- }
- }
|