Browse Source

客户概览接口完善

kouchengxing 4 years ago
parent
commit
9abdb5cdc6

+ 126 - 44
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/api/CustomerApiController.java

@@ -585,6 +585,7 @@ public class CustomerApiController {
             DecimalFormat   df  = new DecimalFormat("######0.00");//保留两位小数
             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"};
@@ -608,49 +609,19 @@ public class CustomerApiController {
             xaxisData.add("12");
             long insureDay = 0;//投保时长
             int guaranteeDay = 0;//享受保障天数
-
-
             Map majorCategorie = new HashMap();
-
             Map mpremMap = new HashMap();
             int firstDate = 1;//定义第一次长期险获取
-            String yyyy = "";
+            Date date = new Date();
+            String currentDateTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,date);
+            String currentYear = DateUtils.parseDateToStr(DateUtils.YYYY,date);
             //获取最近年份
-            if(array!=null && array.size()>0){
-                JSONObject json = (JSONObject) array.get(array.size()-1);
-                JSONObject _source = (JSONObject) json.get("_source");
-                Date padate = _source.getDate("padate");
-                yyyy = DateUtils.parseDateToStr(DateUtils.YYYY, padate);
-            }
             for (int i = 0; i <array.size() ; i++) {
                 JSONObject json = (JSONObject)array.get(i);
                 JSONObject _source = (JSONObject) json.get("_source");
-                String padateStr = _source.getString("padate");
+//                String padateStr = _source.getString("padate");
                 Date padate = _source.getDate("padate");
 
-                //xaxisData.add(DateUtils.parseDateToStr("MM",padate));
-
-                if(_source.containsKey("prem") && padateStr.contains(yyyy)){
-                    prem+=_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,mprem);
-                        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"));
-                    }
-
-                    //edata.add(_source.getDouble("prem"));
-                    //adata.add(_source.getDouble("prem"));
-                }
 
                 if(_source.containsKey("sumprem")){
                     sumprem+=_source.getDouble("sumprem");
@@ -675,6 +646,31 @@ public class CustomerApiController {
                         }
                     }
 
+
+                    if(_source.containsKey("prem")){
+                        prem+=_source.getDouble("prem");
+                        String m = DateUtils.parseDateToStr("M", padate);
+                        String currentPadateStr = DateUtils.parseDateToStr(currentYear+"-MM-dd",padate);
+                        if(currentDateTime.compareTo(currentPadateStr)>0){
+                            handedinprem+=_source.getDouble("prem");
+                        }
+
+
+                        if(mpremMap.containsKey(m)){
+                            double tprem = Double.parseDouble(mpremMap.get(m).toString());
+                            tprem+=_source.getDouble("prem");
+                            //mpremMap.put(m,mprem);
+                            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"));
+                        }
+
+                    }
+
                 }
 
                 //String risk_categories = _source.getString("risk_categories");
@@ -712,7 +708,8 @@ public class CustomerApiController {
             Map insuranceclaimthread = new HashMap();
             List insuranceclaimthreads = new ArrayList<>();
             double claimAmount = 0;//理赔总金额
-            String claimType = "";//理赔类型
+            //String claimType = "";//理赔类型
+            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"));
@@ -720,15 +717,17 @@ public class CustomerApiController {
                 if(claimSource.containsKey("ccamt")){
                     claimAmount+=claimSource.getDouble("ccamt");
                 }
-                claimType = claimSource.getString("accidenttype");
+                //claimType +="," + claimSource.getString("accidenttype");
+                claimTypeSet.add(claimSource.getString("accidenttype"));
                 insuranceclaimthreads.add(claimSource);
             }
             insuranceclaimthread.put("isClaim",insuranceclaimthreads.size()>0?"是":"否");
             insuranceclaimthread.put("claimAmount",df.format(claimAmount));
-            insuranceclaimthread.put("claimType",claimType);
+            insuranceclaimthread.put("claimType",String.join(",",claimTypeSet));
             map.put("insuranceclaimthread",insuranceclaimthread);
-            mpInfo.put("prem",df.format(prem));
-            mpInfo.put("sumprem",df.format(sumprem));
+            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)+"天");
             mpInfo.put("guaranteeDay",guaranteeDay>insureDay?insureDay+"天":guaranteeDay+"天");
             map.put("custInfo",mpInfo);
@@ -1110,7 +1109,7 @@ public class CustomerApiController {
             header.put("province", "省份");
             header.put("education", "学历");
             header.put("vaild", "是否有效客户");
-            header.put("policyBelong", "业绩归属");
+            /*header.put("policyBelong", "业绩归属");*/
             header.put("pIncome", "年收入(万)");
             header.put("num", "保单件数");
             CsvUtil.export(request, response, "customer", header, customers);
@@ -1122,6 +1121,93 @@ public class CustomerApiController {
 
     }
 
+    /**
+     * 导出四要素疑似相同指姓名、性别、证件类型、手机号一致
+     * @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(jsonOb.getString("scustid"));
+                    customer.setName(jsonOb.getString("name"));
+                    customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
+                    if(mp.containsKey("birthday")){
+                        String birthday = jsonOb.getString("birthday").length()>10?jsonOb.getString("birthday").substring(0,10):jsonOb.getString("birthday");
+                        mp.put("birthday", birthday);
+                        customer.setBirthDay(birthday);
+                        customer.setAge(DateUtils.getAge(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,jsonOb.getString("birthday"))));
+                    }
+
+                    if(mp.containsKey("idcard")){
+                        customer.setIdType("身份证");
+                        customer.setIdCard(jsonOb.getString("idcard"));
+                    }else if(mp.containsKey("passport")){
+                        customer.setIdType("护照");
+                        customer.setIdCard(jsonOb.getString("passport"));
+                    }else if(mp.containsKey("dlicense")){
+                        customer.setIdType("驾驶证");
+                        customer.setIdCard(jsonOb.getString("dlicense"));
+                    }else if(mp.containsKey("othernumber")){
+                        customer.setIdType("其它证件类型");
+                        customer.setIdCard(jsonOb.getString("othernumber"));
+                    }
+
+                    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();
+        }
+
+    }
 
     /**
      * 导出三要素疑似相同指姓名、性别、出生日期一致
@@ -1160,7 +1246,6 @@ public class CustomerApiController {
                     JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
                     mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
                     customer.setScustId(jsonOb.getString("scustid"));
-                    customer.setCustId(jsonOb.getString("custid"));
                     customer.setName(jsonOb.getString("name"));
                     customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
                     if(mp.containsKey("birthday")){
@@ -1198,7 +1283,6 @@ public class CustomerApiController {
             }
             Map<String, String> header = new LinkedHashMap<>();
             header.put("scustId", "核心客户号");
-            header.put("custId", "客户号");
             header.put("name", "姓名");
             header.put("idType", "证件类型");
             header.put("idCard", "证件号码");
@@ -1250,7 +1334,6 @@ public class CustomerApiController {
                     JSONObject jsonOb = JSON.parseObject(json.getString("_source"));
                     mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
                     customer.setScustId(jsonOb.getString("scustid"));
-                    customer.setCustId(jsonOb.getString("custid"));
                     customer.setName(jsonOb.getString("name"));
                     customer.setSex("0".equals(jsonOb.getString("gender"))?"男":"女");
                     if(mp.containsKey("birthday")){
@@ -1288,7 +1371,6 @@ public class CustomerApiController {
             }
             Map<String, String> header = new LinkedHashMap<>();
             header.put("scustId", "核心客户号");
-            header.put("custId", "客户号");
             header.put("name", "姓名");
             header.put("idType", "证件类型");
             header.put("idCard", "证件号码");