Ver código fonte

首页查询条件完善

kouchengxing 4 anos atrás
pai
commit
99665cc52c

+ 29 - 0
dgtis-common/dgtis-common-core/src/main/java/com/dgtis/common/core/utils/DateUtils.java

@@ -18,6 +18,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
 
     public static String YYYY_MM = "yyyy-MM";
 
+    public static String MM_DD = "MM-dd";
+
     public static String YYYY_MM_DD = "yyyy-MM-dd";
 
     public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
@@ -39,6 +41,16 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         return new Date();
     }
 
+    public static String getYYYY()
+    {
+        return dateTimeNow(YYYY);
+    }
+
+    public static String getMMDD()
+    {
+        return dateTimeNow(MM_DD);
+    }
+
     /**
      * 获取当前日期, 默认格式为yyyy-MM-dd
      * 
@@ -158,6 +170,23 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     }
 
 
+    /**
+     * 计算两个时间相差天数
+     */
+    public static long getDateDifDay(Date endDate, Date nowDate)
+    {
+        long nd = 1000 * 24 * 60 * 60;
+        long nh = 1000 * 60 * 60;
+        long nm = 1000 * 60;
+        // long ns = 1000;
+        // 获得两个时间的毫秒时间差异
+        long diff = endDate.getTime() - nowDate.getTime();
+        // 计算差多少天
+        long day = diff / nd;
+        return day ;
+    }
+
+
     /**
      *根据出生日期计算年龄
      * @param birthDay

+ 125 - 11
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/api/CustomerApiController.java

@@ -20,12 +20,12 @@ 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.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.util.*;
 
 /**
@@ -42,14 +42,99 @@ public class CustomerApiController {
     private RestClient restClient;
     @GetMapping("/getCustomerList")
     @ResponseBody
-    public AjaxResult getCustomerList(int pageNum,int pageSize) {
+    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 {
-            Map<String, String> paramMap = new HashMap<String, String>();
-            paramMap.put("pretty", "true");
-            paramMap.put("from", pageNum+"");
-            paramMap.put("size", pageSize+"");
-            Response response = restClient.performRequest("GET", "shanglifeecif.individual/_search?", paramMap);
+            //拼装查询条件
+            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");
@@ -204,14 +289,41 @@ public class CustomerApiController {
             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);
-                if(json.containsKey("prem")){
-                    prem+=json.getLong("prem");
+                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);
@@ -230,6 +342,7 @@ public class CustomerApiController {
             }
             map.put("insuranceclaimthread",insuranceclaimthread);
             mpInfo.put("prem",prem);
+            mpInfo.put("insureDay",insureDay);
             map.put("custInfo",mpInfo);
             return AjaxResult.success(map);
         } catch (Exception e) {
@@ -239,4 +352,5 @@ public class CustomerApiController {
     }
 
 
+
 }

+ 21 - 1
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/config/ElasticSearchConfig.java

@@ -3,11 +3,14 @@ package com.dgtis.data.config;
 
 
 import org.apache.http.HttpHost;
+import org.apache.http.client.config.RequestConfig;
 import org.elasticsearch.client.RestClient;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import static org.elasticsearch.client.RestClientBuilder.DEFAULT_CONNECTION_REQUEST_TIMEOUT_MILLIS;
+
 /**
  * @author koucx
  * @version 1.0
@@ -30,11 +33,28 @@ public class ElasticSearchConfig {
     @Value("${elasticsearch.cluster.name}")
     private String esName;
 
+    /**
+     * 超时时间设为5分钟
+     */
+    private static final int TIME_OUT = 5 * 60 * 1000;
+
+
     @Bean
     public RestClient esClient() {
         RestClient restClient = null;
         try {
-            restClient = RestClient.builder(httpHost()).build();
+            restClient = RestClient.builder(httpHost()).setMaxRetryTimeoutMillis(TIME_OUT)
+                    .setHttpClientConfigCallback(httpClientBuilder -> {
+                        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
+                                //超时时间5分钟
+                                .setConnectTimeout(TIME_OUT)
+                                //这就是Socket超时时间设置
+                                .setSocketTimeout(TIME_OUT)
+                                .setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT_MILLIS);
+                        httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
+                        return httpClientBuilder;
+                    })
+                    .build();
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 1 - 1
dgtis-ui/src/utils/request.js

@@ -11,7 +11,7 @@ const service = axios.create({
   // axios中请求配置有baseURL选项,表示请求URL公共部分
   baseURL: process.env.VUE_APP_BASE_API,
   // 超时
-  timeout: 10000
+  timeout: 300000
 })
 
 // request拦截器