Bläddra i källkod

数据统计-接口调试程序完善

黄远 5 år sedan
förälder
incheckning
31319c6ed7
16 ändrade filer med 344 tillägg och 66 borttagningar
  1. 22 3
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/CommonRequest.java
  2. 25 0
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/ContractDataRequest.java
  3. 24 1
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/MaintenanceDataRequest.java
  4. 23 0
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/PaymentDataRequest.java
  5. 12 2
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/AnnualInspectionDataService.java
  6. 36 6
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/ContractDataService.java
  7. 49 15
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/EmergencyRepairDataService.java
  8. 55 7
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/LiftDataService.java
  9. 13 3
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/MaintenanceDataService.java
  10. 25 10
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/PaymentDataService.java
  11. 47 11
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/util/DataStatisticsUtil.java
  12. 5 0
      lift-batch-service/src/main/java/cn/com/ty/lift/batch/config/RedisConfig.java
  13. 2 2
      lift-batch-service/src/main/resources/mapper/AnnualInspectionDataMapper.xml
  14. 2 2
      lift-batch-service/src/main/resources/mapper/ContractDataMapper.xml
  15. 2 2
      lift-batch-service/src/main/resources/mapper/EmergencyRepairDataMapper.xml
  16. 2 2
      lift-batch-service/src/main/resources/mapper/MaintenanceDataMapper.xml

+ 22 - 3
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/CommonRequest.java

@@ -1,7 +1,10 @@
 package cn.com.ty.lift.batch.applet.dao.model.request;
 
+import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
+import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import lombok.Data;
 
+import java.io.Serializable;
 import java.time.LocalDateTime;
 
 /**
@@ -10,7 +13,7 @@ import java.time.LocalDateTime;
  * @description
  */
 @Data
-public class CommonRequest {
+public class CommonRequest implements Serializable {
     /**
      * 起始时间-日期格式
      */
@@ -18,7 +21,7 @@ public class CommonRequest {
     /**
      * 起始时间-字符串格式
      */
-    private String startTimeStr;
+    private String startTimeDateStr;
     /**
      * 终止时间-日期格式
      */
@@ -26,10 +29,26 @@ public class CommonRequest {
     /**
      * 结束时间-字符串形式
      */
-    private String endTimeStr;
+    private String endTimeDateStr;
 
     /**
      * 公司id
      */
     private Long mtCompanyId;
+
+    public LocalDateTime getStartTimeDate(){
+        if(startTimeDate != null){
+            return startTimeDate;
+        }
+        return DataStatisticsUtil.getLocalDateTimeFromStr(startTimeDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
+
+    public LocalDateTime getEndTimeDate(){
+        if(endTimeDate != null){
+            return endTimeDate;
+        }
+        return DataStatisticsUtil.getLocalDateTimeFromStr(endTimeDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
 }

+ 25 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/ContractDataRequest.java

@@ -1,5 +1,7 @@
 package cn.com.ty.lift.batch.applet.dao.model.request;
 
+import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
+import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import lombok.Data;
 
 import java.time.LocalDate;
@@ -15,12 +17,35 @@ public class ContractDataRequest extends CommonRequest{
      * 起始时间
      */
     private LocalDate startDate;
+
+    /**
+     * 起始时间字符串
+     */
+    private String startDateStr;
+
     /**
      * 结束时间
      */
     private LocalDate endDate;
+
+    /**
+     * 结束时间字符串
+     */
+    private String endDateStr;
+
     /**
      * 合同取值范围 top5 表示前5 all 表示全部
      */
     private String contractScope;
+
+    public LocalDate getStartDate(){
+        return DataStatisticsUtil.getLocalDateFromStr(startDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
+
+    public LocalDate getEndDate(){
+        return DataStatisticsUtil.getLocalDateFromStr(endDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
+
 }

+ 24 - 1
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/MaintenanceDataRequest.java

@@ -1,5 +1,7 @@
 package cn.com.ty.lift.batch.applet.dao.model.request;
 
+import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
+import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import lombok.Data;
 
 import java.time.LocalDate;
@@ -15,8 +17,29 @@ public class MaintenanceDataRequest extends CommonRequest {
      * 起始时间
      */
     private LocalDate startDate;
+
     /**
-     * 终止时间
+     * 起始时间字符串
+     */
+    private String startDateStr;
+
+    /**
+     * 结束时间
      */
     private LocalDate endDate;
+
+    /**
+     * 结束时间字符串
+     */
+    private String endDateStr;
+
+    public LocalDate getStartDate(){
+        return DataStatisticsUtil.getLocalDateFromStr(startDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
+
+    public LocalDate getEndDate(){
+        return DataStatisticsUtil.getLocalDateFromStr(endDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
 }

+ 23 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/PaymentDataRequest.java

@@ -1,5 +1,7 @@
 package cn.com.ty.lift.batch.applet.dao.model.request;
 
+import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
+import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import lombok.Data;
 
 import java.time.LocalDate;
@@ -15,16 +17,27 @@ public class PaymentDataRequest {
      * 公司id
      */
     private Long mtCompanyId;
+
     /**
      * 起始时间
      */
     private LocalDate startDate;
 
+    /**
+     * 起始时间字符串
+     */
+    private String startDateStr;
+
     /**
      * 终止时间
      */
     private LocalDate endDate;
 
+    /**
+     * 结束时间字符串
+     */
+    private String endDateStr;
+
     /**
      * 收款类型
      */
@@ -34,4 +47,14 @@ public class PaymentDataRequest {
      * 项目取值范围 top5 表示前5 all 表示全部
      */
     private String projectScope;
+
+    public LocalDate getStartDate(){
+        return DataStatisticsUtil.getLocalDateFromStr(startDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
+
+    public LocalDate getEndDate(){
+        return DataStatisticsUtil.getLocalDateFromStr(endDateStr,
+                DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
+    }
 }

+ 12 - 2
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/AnnualInspectionDataService.java

@@ -62,13 +62,23 @@ public class AnnualInspectionDataService {
             if (annualInspectionDataRequest.getStartTimeDate() != null) {
                 //通过起始时间过滤数据
                 annualInspectionDataModelList = annualInspectionDataModelList.stream()
-                        .filter(a -> a.getPlanDate().isAfter(annualInspectionDataRequest.getStartTimeDate()))
+                        .filter(a -> {
+                            if (a.getPlanDate() != null) {
+                                return a.getPlanDate().isAfter(annualInspectionDataRequest.getStartTimeDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
             if (annualInspectionDataRequest.getEndTimeDate() != null) {
                 //通过终止时间过滤数据
                 annualInspectionDataModelList = annualInspectionDataModelList.stream()
-                        .filter(a -> a.getPlanDate().isBefore(annualInspectionDataRequest.getEndTimeDate()))
+                        .filter(a -> {
+                            if (a.getPlanDate() != null) {
+                                a.getPlanDate().isBefore(annualInspectionDataRequest.getEndTimeDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
         }

+ 36 - 6
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/ContractDataService.java

@@ -83,13 +83,23 @@ public class ContractDataService {
             //通过起始时间过滤合同信息
             if (contractDataRequest.getStartTimeDate() != null) {
                 contractDataModelList = contractDataModelList.stream()
-                        .filter(a -> a.getGivenDate().isAfter(contractDataRequest.getStartDate()))
+                        .filter(a -> {
+                            if (a.getGivenDate() != null) {
+                                return a.getGivenDate().isAfter(contractDataRequest.getStartDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
             //通过终止时间过滤
             if (contractDataRequest.getEndTimeDate() != null) {
                 contractDataModelList = contractDataModelList.stream()
-                        .filter(a -> a.getGivenDate().isBefore(contractDataRequest.getEndDate()))
+                        .filter(a -> {
+                            if (a.getGivenDate() != null) {
+                                return a.getGivenDate().isBefore(contractDataRequest.getEndDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
         }
@@ -111,11 +121,21 @@ public class ContractDataService {
             contractTypeToNum.put(1, contractDataModelList.stream().count());
             //设置计划合同数量
             long planContractNum = contractDataModelList.stream()
-                    .filter(a -> a.getContractType() == 2).count();
+                    .filter(a -> {
+                        if (a.getContractType() != null) {
+                            return a.getContractType() == 2;
+                        }
+                        return false;
+                    }).count();
             contractTypeToNum.put(2, planContractNum);
             //设置丢失合同数量
             long lostContractNum = contractDataModelList.stream()
-                    .filter(a -> a.getContractType() == 3).count();
+                    .filter(a -> {
+                        if (a.getContractType() != null) {
+                            return a.getContractType() == 3;
+                        }
+                        return false;
+                    }).count();
             contractTypeToNum.put(3, lostContractNum);
         }
         return RestResponse.success(contractTypeToNum, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
@@ -134,7 +154,12 @@ public class ContractDataService {
             //定义一个临时变量
             final List<LostContractResponse> finalLostContractResponseList = new ArrayList<>();
             contractDataModelList = contractDataModelList.stream()
-                    .filter(a -> a.getContractType() == 3)
+                    .filter(a -> {
+                        if (a.getContractType() != null) {
+                            return a.getContractType() == 3;
+                        }
+                        return false;
+                    })
                     .collect(Collectors.toList());
             //循环设置丢失合同信息
             contractDataModelList.forEach(a -> {
@@ -176,7 +201,12 @@ public class ContractDataService {
             final List<DueToContractResponse> finalDueToContractResponseList = new ArrayList<>();
             //获取在执行中的合同
             contractDataModelList = contractDataModelList.stream()
-                    .filter(a -> a.getContractType() == 2)
+                    .filter(a -> {
+                        if (a.getContractType() != null) {
+                            return a.getContractType() == 2;
+                        }
+                        return true;
+                    })
                     .collect(Collectors.toList());
             contractDataModelList.forEach(a -> {
                 DueToContractResponse dueToContractResponse = new DueToContractResponse();

+ 49 - 15
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/EmergencyRepairDataService.java

@@ -8,7 +8,6 @@ import cn.com.ty.lift.batch.applet.dao.model.request.EmergencyRepairDataRequest;
 import cn.com.ty.lift.batch.applet.dao.model.response.EmergencyTimeStatisticsResponse;
 import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import cn.com.ty.lift.common.constants.ApiConstants;
-import cn.com.ty.lift.common.judge.Judge;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
@@ -43,6 +42,22 @@ public class EmergencyRepairDataService {
         //获取时间段内的急修数据
         List<EmergencyRepairDataModel> emergencyRepairDataModelList = emergencyRepairDataMapper
                 .getEmergencyRepairDataList(commonRequest);
+        if (emergencyRepairDataModelList != null && emergencyRepairDataModelList.size() > 0) {
+            emergencyRepairDataModelList.forEach(a -> {
+                //计算接单时长
+                if (a.getAssignTime() != null && a.getTakingTime() != null) {
+                    a.setTakingTimeLength(DataStatisticsUtil.getDiffMinute(a.getTakingTime(), a.getAssignTime()));
+                }
+                //计算到达时长
+                if (a.getTakingTime() != null && a.getArriveTime() != null) {
+                    a.setArriveTimeLength(DataStatisticsUtil.getDiffMinute(a.getArriveTime(), a.getTakingTime()));
+                }
+                //计算修理时长
+                if (a.getArriveTime() != null && a.getRecoveryDate() != null) {
+                    a.setFixTimeLength(DataStatisticsUtil.getDiffMinute(a.getRecoveryDate(), a.getTakingTime()));
+                }
+            });
+        }
         //通过公司id给数据分组,并将数据放入redis中
         DataStatisticsUtil.putStatisticsDataToRedis(emergencyRepairDataModelList, redisTemplate,
                 DataStatisticsConstants.EMERGENCY_REPAIR_DATA_FIELD);
@@ -64,13 +79,23 @@ public class EmergencyRepairDataService {
             //过滤起始时间之前的数据
             if (emergencyRepairDataRequest.getStartTimeDate() != null) {
                 emergencyRepairDataModelList = emergencyRepairDataModelList.stream()
-                        .filter(a -> a.getCallerDate().isAfter(emergencyRepairDataRequest.getStartTimeDate()))
+                        .filter(a -> {
+                            if (a.getCallerDate() != null) {
+                                return a.getCallerDate().isAfter(emergencyRepairDataRequest.getStartTimeDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
             //过滤终止时间之后的数据
             if (emergencyRepairDataRequest.getEndTimeDate() != null) {
                 emergencyRepairDataModelList = emergencyRepairDataModelList.stream()
-                        .filter(a -> a.getCallerDate().isBefore(emergencyRepairDataRequest.getEndTimeDate()))
+                        .filter(a -> {
+                            if (a.getCallerDate() != null) {
+                                return a.getCallerDate().isBefore(emergencyRepairDataRequest.getEndTimeDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
             //通过区域id过滤数据
@@ -82,7 +107,12 @@ public class EmergencyRepairDataService {
             //通过状态过滤数据
             if (emergencyRepairDataRequest.getStatus() != null) {
                 emergencyRepairDataModelList = emergencyRepairDataModelList.stream()
-                        .filter(a -> a.getStatus() == emergencyRepairDataRequest.getStatus())
+                        .filter(a -> {
+                            if (a.getStatus() != null) {
+                                return a.getStatus() == emergencyRepairDataRequest.getStatus();
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
         }
@@ -102,12 +132,14 @@ public class EmergencyRepairDataService {
         //从redis中获取时间段内的急修数据
         List<EmergencyRepairDataModel> emergencyRepairDataModelList =
                 getEmergencyRepairDataListFromRedis(emergencyRepairDataRequest);
-        //将数据组合成月->台量的map
-        Map<String, Long> monthToUnitsRow = emergencyRepairDataModelList.stream()
-                .collect(Collectors.groupingBy(emergencyRepairDataModel ->
-                        DataStatisticsUtil.getMonthStr(emergencyRepairDataModel.getCallerDate()), Collectors.counting()));
-        //将monthToUnitsRow月份对应台量的值放入monthToUnits中
-        monthToUnitsRow.forEach((key, value) -> monthToUnits.put(key, value));
+        if (emergencyRepairDataModelList != null && emergencyRepairDataModelList.size() > 0) {
+            //将数据组合成月->台量的map
+            Map<String, Long> monthToUnitsRow = emergencyRepairDataModelList.stream()
+                    .collect(Collectors.groupingBy(emergencyRepairDataModel ->
+                            DataStatisticsUtil.getMonthStr(emergencyRepairDataModel.getCallerDate()), Collectors.counting()));
+            //将monthToUnitsRow月份对应台量的值放入monthToUnits中
+            monthToUnitsRow.forEach((key, value) -> monthToUnits.put(key, value));
+        }
         return RestResponse.success(monthToUnits, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 
@@ -119,7 +151,7 @@ public class EmergencyRepairDataService {
      */
     public RestResponse emergencyTimeStatistics(EmergencyRepairDataRequest emergencyRepairDataRequest) {
         //获取急修完成的急修信息
-        emergencyRepairDataRequest.setStatus(Judge.Repair.STATUS_FINISH);
+        //emergencyRepairDataRequest.setStatus(Judge.Repair.STATUS_FINISH);
         List<EmergencyRepairDataModel> emergencyRepairDataModelList =
                 getEmergencyRepairDataListFromRedis(emergencyRepairDataRequest);
         EmergencyTimeStatisticsResponse emergencyTimeStatisticsResponse = new EmergencyTimeStatisticsResponse();
@@ -164,10 +196,12 @@ public class EmergencyRepairDataService {
     public RestResponse emergencyStatus(EmergencyRepairDataRequest emergencyRepairDataRequest) {
         List<EmergencyRepairDataModel> emergencyRepairDataModelList =
                 getEmergencyRepairDataListFromRedis(emergencyRepairDataRequest);
-        //通过发起急修时间降序排列,并获取前5条数据
-        emergencyRepairDataModelList = emergencyRepairDataModelList.stream()
-                .sorted(Comparator.comparing(EmergencyRepairDataModel::getCallerDate).reversed()).limit(5)
-                .collect(Collectors.toList());
+        if(emergencyRepairDataModelList != null && emergencyRepairDataModelList.size() > 0){
+            //通过发起急修时间降序排列,并获取前5条数据
+            emergencyRepairDataModelList = emergencyRepairDataModelList.stream()
+                    .sorted(Comparator.comparing(EmergencyRepairDataModel::getCallerDate).reversed()).limit(5)
+                    .collect(Collectors.toList());
+        }
         return RestResponse.success(emergencyRepairDataModelList, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 }

+ 55 - 7
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/LiftDataService.java

@@ -14,6 +14,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -79,19 +80,29 @@ public class LiftDataService {
     public List<LiftDataModel> getLiftDataListFromRedis(LiftDataRequest liftDataRequest) {
         //从redis中获取当前公司电梯信息
         List<LiftDataModel> liftDataModelList = getLiftDataModels(liftDataRequest);
-        if (liftDataModelList != null) {
+        if (liftDataModelList != null && liftDataModelList.size() > 0) {
             //过滤起始时间之前的数据
             if (liftDataRequest.getStartTimeDate() != null) {
                 liftDataModelList = liftDataModelList.stream()
                         //新增电梯的时间
-                        .filter(a -> a.getConnectTime().isAfter(liftDataRequest.getStartTimeDate()))
+                        .filter(a -> {
+                            if (a.getConnectTime() != null) {
+                                return a.getConnectTime().isAfter(liftDataRequest.getStartTimeDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
             //过滤终止时间之后的数据
             if (liftDataRequest.getEndTimeDate() != null) {
                 liftDataModelList = liftDataModelList.stream()
                         //新增电梯的时间
-                        .filter(a -> a.getConnectTime().isBefore(liftDataRequest.getEndTimeDate()))
+                        .filter(a -> {
+                            if (a.getConnectTime() != null) {
+                                return a.getConnectTime().isBefore(liftDataRequest.getEndTimeDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
         }
@@ -106,7 +117,7 @@ public class LiftDataService {
      */
     public RestResponse liftOverView(LiftDataRequest liftDataRequest) {
         //获取时间段内按月份统计的丢失电梯数量
-        Map<Integer, List<Long>> liftStatusToNums = new HashMap<>();
+        Map<Integer, List<Long>> liftStatusToNums = initLiftStatusToNums(liftDataRequest);
 
         //从redis中获取当前公司总的电梯信息
         List<LiftDataModel> companyTotalLiftDataList = getLiftDataModels(liftDataRequest);
@@ -163,12 +174,14 @@ public class LiftDataService {
         List<RegionLiftResponse> regionLiftResponseList = new ArrayList<>();
         List<LiftDataModel> liftDataModelList = getLiftDataListFromRedis(liftDataRequest);
         if (liftDataModelList != null && liftDataModelList.size() > 0) {
+            final List<RegionLiftResponse> finalRegionLiftResponseList = new ArrayList<>();
             //将数据转化为 区域名称->电梯数据列表
             Map<String, List<LiftDataModel>> regionNameToLiftData = liftDataModelList.stream()
                     .collect(Collectors.groupingBy(LiftDataModel::getRegionName));
             //封装区域电梯信息
             regionNameToLiftData.forEach((key, value) -> {
                 RegionLiftResponse regionLiftResponse = new RegionLiftResponse();
+                regionLiftResponse.setRegionName(key);
                 //总电梯数
                 long totalLiftNums = value.stream().count();
                 //计算新增电梯的数量
@@ -181,9 +194,10 @@ public class LiftDataService {
                 regionLiftResponse.setLostLiftNums(lostLiftNums);
                 //实际总台量
                 regionLiftResponse.setTotalLiftNums(totalLiftNums - lostLiftNums);
+                finalRegionLiftResponseList.add(regionLiftResponse);
             });
             //通过丢失台量排序并获取前五的数据
-            regionLiftResponseList = regionLiftResponseList.stream()
+            regionLiftResponseList = finalRegionLiftResponseList.stream()
                     .sorted(Comparator.comparing(RegionLiftResponse::getLostLiftNums)).limit(5)
                     .collect(Collectors.toList());
         }
@@ -227,9 +241,14 @@ public class LiftDataService {
      * @description 设置电梯总览情况
      * @date 2020/2/10 11:36 上午
      */
-    private void setLiftOverViewNum(LiftDataRequest liftDataRequest, Map<Integer, List<Long>> liftStatusToNums, long beforeLiftTotalNum, Map<Integer, Long> monthToNewLiftNums, Map<Integer, Long> monthToLostLiftNums) {
+    private void setLiftOverViewNum(LiftDataRequest liftDataRequest, Map<Integer,
+            List<Long>> liftStatusToNums, long beforeLiftTotalNum, Map<Integer, Long> monthToNewLiftNums,
+                                    Map<Integer, Long> monthToLostLiftNums) {
+        int nowMonthValue = LocalDateTime.now().getMonthValue();
         //获取截止时间的月份值
-        int nowMonthValue = liftDataRequest.getEndTimeDate().getMonthValue();
+        if(liftDataRequest != null) {
+            nowMonthValue = liftDataRequest.getEndTimeDate().getMonthValue();
+        }
         //设置不同状态对应的电梯台量
         List<Long> newLiftNums = new ArrayList<>();
         List<Long> onMaintenanceLiftNums = new ArrayList<>();
@@ -247,4 +266,33 @@ public class LiftDataService {
         liftStatusToNums.put(2, onMaintenanceLiftNums);
         liftStatusToNums.put(3, lostLiftNums);
     }
+
+    /**
+     * @param liftDataRequest 请求数据
+     * @return
+     * @description 初始化电梯总览数据
+     * @date 2020/2/11 7:15 下午
+     */
+    private static Map<Integer, List<Long>> initLiftStatusToNums(LiftDataRequest liftDataRequest) {
+        Map<Integer, List<Long>> liftStatusToNums = new HashMap<>();
+        //时间初始化 默认时间为当前时间
+        LocalDateTime time = LocalDateTime.now();
+        if(liftDataRequest.getEndTimeDate() != null) {
+            time = liftDataRequest.getEndTimeDate();
+        }
+        //设置不同状态对应的电梯台量
+        List<Long> newLiftNums = new ArrayList<>();
+        List<Long> onMaintenanceLiftNums = new ArrayList<>();
+        List<Long> lostLiftNums = new ArrayList<>();
+        for (int i = 1; i <= time.getMonthValue(); i++) {
+            newLiftNums.add(0L);
+            onMaintenanceLiftNums.add(0L);
+            lostLiftNums.add(0L);
+        }
+        //设置初始值
+        liftStatusToNums.put(1, newLiftNums);
+        liftStatusToNums.put(2, onMaintenanceLiftNums);
+        liftStatusToNums.put(3, lostLiftNums);
+        return liftStatusToNums;
+    }
 }

+ 13 - 3
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/MaintenanceDataService.java

@@ -62,13 +62,23 @@ public class MaintenanceDataService {
             //通过起始时间过滤
             if (maintenanceDataRequest.getStartDate() != null) {
                 maintenanceDataModelList = maintenanceDataModelList.stream()
-                        .filter(a -> a.getPlanDate().isAfter(maintenanceDataRequest.getStartDate()))
+                        .filter(a -> {
+                            if (a.getPlanDate() != null) {
+                                return a.getPlanDate().isAfter(maintenanceDataRequest.getStartDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
             //通过终止时间过滤
             if (maintenanceDataRequest.getEndDate() != null) {
                 maintenanceDataModelList = maintenanceDataModelList.stream()
-                        .filter(a -> a.getPlanDate().isBefore(maintenanceDataRequest.getEndDate()))
+                        .filter(a -> {
+                            if (a.getPlanDate() != null) {
+                                return a.getPlanDate().isBefore(maintenanceDataRequest.getEndDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
         }
@@ -120,7 +130,7 @@ public class MaintenanceDataService {
             allProjectNameToBeyondNum = DataStatisticsUtil.sortByValue(allProjectNameToBeyondNum, true);
             //获取前5的数据
             allProjectNameToBeyondNum.forEach((key, value) -> {
-                if(projectNameToBeyondNum.size() < 5) {
+                if (projectNameToBeyondNum.size() < 5) {
                     projectNameToBeyondNum.put(key, value);
                 }
             });

+ 25 - 10
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/PaymentDataService.java

@@ -61,22 +61,37 @@ public class PaymentDataService {
                 DataStatisticsUtil.getStatisticsDataFromRedis(redisTemplate,
                         DataStatisticsConstants.PAYMENT_DATA_FIELD, paymentDataRequest.getMtCompanyId());
         if (paymentDataModelList != null && paymentDataModelList.size() > 0) {
-            //通过起始时间过滤
-            if (paymentDataRequest.getStartDate() != null) {
+            //通过终止时间过滤
+            if (paymentDataRequest.getEndDate() != null) {
                 paymentDataModelList = paymentDataModelList.stream()
-                        .filter(a -> a.getPlanDate().isAfter(paymentDataRequest.getStartDate()))
+                        .filter(a -> {
+                            if (a.getPlanDate() != null) {
+                                return a.getPlanDate().isBefore(paymentDataRequest.getEndDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
-            //通过终止时间过滤
-            if (paymentDataRequest.getEndDate() != null) {
+            //通过起始时间过滤
+            if (paymentDataRequest.getStartDate() != null) {
                 paymentDataModelList = paymentDataModelList.stream()
-                        .filter(a -> a.getPlanDate().isBefore(paymentDataRequest.getEndDate()))
+                        .filter(a -> {
+                            if (a.getPlanDate() != null) {
+                                return a.getPlanDate().isAfter(paymentDataRequest.getStartDate());
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
             //通过合同类型过滤
-            if(paymentDataRequest.getPaymentType() != null){
+            if (paymentDataRequest.getPaymentType() != null) {
                 paymentDataModelList = paymentDataModelList.stream()
-                        .filter(a -> a.getPaymentType() == paymentDataRequest.getPaymentType())
+                        .filter(a -> {
+                            if (a.getPaymentType() != null) {
+                                return a.getPaymentType() == paymentDataRequest.getPaymentType();
+                            }
+                            return false;
+                        })
                         .collect(Collectors.toList());
             }
         }
@@ -183,7 +198,7 @@ public class PaymentDataService {
                     projectPaymentResponse.setBeyondAmount(beyondMoney);
                     //超期天数 计划收款和实际收款日期差值
                     LocalDate afterDate = LocalDate.now();
-                    if(paymentDataModel.getWorkDate() != null){
+                    if (paymentDataModel.getWorkDate() != null) {
                         afterDate = paymentDataModel.getWorkDate();
                     }
                     Duration duration = Duration.between(afterDate, paymentDataModel.getPlanDate());
@@ -200,7 +215,7 @@ public class PaymentDataService {
                     .sorted(Comparator.comparing(ProjectPaymentResponse::getBeyondAmount).reversed())
                     .collect(Collectors.toList());
             //判断获取的是前5的数据 还是所有数据
-            if(projectPaymentResponseList.size() > 5 && "top5".equals(paymentDataRequest.getProjectScope())){
+            if (projectPaymentResponseList.size() > 5 && "top5".equals(paymentDataRequest.getProjectScope())) {
                 projectPaymentResponseList = projectPaymentResponseList.stream().limit(5).collect(Collectors.toList());
             }
         }

+ 47 - 11
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/util/DataStatisticsUtil.java

@@ -9,11 +9,13 @@ import org.springframework.data.redis.core.RedisTemplate;
 
 import java.math.BigDecimal;
 import java.time.Duration;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
@@ -35,7 +37,8 @@ public class DataStatisticsUtil {
         //通过公司id给数组分组
         Map<Long, ? extends List<? extends BaseDataModel>> mtCompanyIdToData = dataList.stream()
                 .collect(Collectors.groupingBy(BaseDataModel::getMtCompanyId));
-        redisTemplate.opsForValue().set(dataKey, mtCompanyIdToData);
+        //存放缓存时间为1天
+        redisTemplate.opsForValue().set(dataKey, mtCompanyIdToData, 1L, TimeUnit.DAYS);
     }
 
     /**
@@ -48,7 +51,10 @@ public class DataStatisticsUtil {
                                                                            Long mtCompanyId) {
         Map<Long, ? extends List<? extends BaseDataModel>> mtCompanyIdToData =
                 (Map<Long, ? extends List<? extends BaseDataModel>>) redisTemplate.opsForValue().get(dataKey);
-        return mtCompanyIdToData.get(mtCompanyId);
+        if (mtCompanyIdToData != null) {
+            return mtCompanyIdToData.get(mtCompanyId.toString());
+        }
+        return null;
     }
 
     /**
@@ -59,12 +65,13 @@ public class DataStatisticsUtil {
      */
     public static Map<String, Long> initDateMap() {
         Map<String, Long> monthToCount = new HashMap<>();
-        for (int i = 1; i <= LocalDateTime.now().getMonthValue(); i++) {
+        int month = LocalDateTime.now().getMonthValue();
+        for (int i = 1; i <= month; i++) {
             //小于10的月份前面加0
             if (i < 10) {
-                initDateMap().put("0" + i, 0L);
+                monthToCount.put("0" + i, 0L);
             } else {
-                initDateMap().put(i + "", 0L);
+                monthToCount.put(i + "", 0L);
             }
         }
         return monthToCount;
@@ -190,15 +197,15 @@ public class DataStatisticsUtil {
 
     /**
      * @param subField 模糊查询字段
-     * @param field 字段
+     * @param field    字段
      * @return
      * @description 查看字符串是否包含子字符串
      * @date 2020/2/10 6:43 下午
      */
     public static boolean strMatch(String subField, String field) {
-        if(StringUtils.isNotBlank(subField) && StringUtils.isNotBlank(field)){
-           Pattern pattern = Pattern.compile(".*" + subField + ".*");
-           return pattern.matcher(field).find();
+        if (StringUtils.isNotBlank(subField) && StringUtils.isNotBlank(field)) {
+            Pattern pattern = Pattern.compile(".*" + subField + ".*");
+            return pattern.matcher(field).find();
         }
         return false;
     }
@@ -217,15 +224,44 @@ public class DataStatisticsUtil {
         //获取格式化后的时间字符串
         //起始时间
         commonRequest.setStartTimeDate(beforeTime);
-        commonRequest.setStartTimeStr(beforeTime.format(
+        commonRequest.setStartTimeDateStr(beforeTime.format(
                 DateTimeFormatter.ofPattern(DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT)
         ));
         //终止时间
         commonRequest.setEndTimeDate(now);
-        commonRequest.setEndTimeStr(now.format(
+        commonRequest.setEndTimeDateStr(now.format(
                 DateTimeFormatter.ofPattern(DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT)
         ));
         return commonRequest;
     }
 
+    /**
+     * @param timeStr       时间字符串
+     * @param formatPattern 格式
+     * @return
+     * @description 将指定格式的时间字符串转化为 LocalDateTime对象
+     * @date 2020/2/11 11:14 上午
+     */
+    public static LocalDateTime getLocalDateTimeFromStr(String timeStr, String formatPattern) {
+        if (StringUtils.isNotBlank(timeStr)) {
+            return LocalDateTime.parse(timeStr,
+                    DateTimeFormatter.ofPattern(formatPattern));
+        }
+        return null;
+    }
+
+    /**
+     * @param timeStr       时间字符串
+     * @param formatPattern 格式
+     * @return
+     * @description 将指定格式的时间字符串转化为 LocalDate对象
+     * @date 2020/2/11 11:14 上午
+     */
+    public static LocalDate getLocalDateFromStr(String timeStr, String formatPattern) {
+        if (StringUtils.isNotBlank(timeStr)) {
+            return LocalDate.parse(timeStr,
+                    DateTimeFormatter.ofPattern(formatPattern));
+        }
+        return null;
+    }
 }

+ 5 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/config/RedisConfig.java

@@ -3,6 +3,8 @@ package cn.com.ty.lift.batch.config;
 import com.fasterxml.jackson.annotation.JsonAutoDetect;
 import com.fasterxml.jackson.annotation.PropertyAccessor;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 import org.springframework.cache.CacheManager;
 import org.springframework.cache.annotation.CachingConfigurerSupport;
 import org.springframework.cache.annotation.EnableCaching;
@@ -82,6 +84,9 @@ public class RedisConfig extends CachingConfigurerSupport {
         om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
         om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
         jackson2JsonRedisSerializer.setObjectMapper(om);
+        //解决jackson2无法反序列化LocalDateTime的问题
+        om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+        om.registerModule(new JavaTimeModule());
         // 配置redisTemplate
         RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
         redisTemplate.setConnectionFactory(jedisConnectionFactory);

+ 2 - 2
lift-batch-service/src/main/resources/mapper/AnnualInspectionDataMapper.xml

@@ -22,9 +22,9 @@
         on
             plr.project_id = p.id
         where
-            ai.plan_date <![CDATA[ >= ]]> #{startTimeStr}
+            ai.plan_date <![CDATA[ >= ]]> #{startTimeDateStr}
         and
-            ai.plan_date <![CDATA[ <= ]]> #{endTimeStr}
+            ai.plan_date <![CDATA[ <= ]]> #{endTimeDateStr}
     </select>
 
 </mapper>

+ 2 - 2
lift-batch-service/src/main/resources/mapper/ContractDataMapper.xml

@@ -30,9 +30,9 @@
             on
                 c.id = pay.contracts_id
             where
-                c.given_date <![CDATA[ >= ]]> #{startTimeStr}
+                c.given_date <![CDATA[ >= ]]> #{startTimeDateStr}
             and
-                c.given_date <![CDATA[ <= ]]> #{endTimeStr}
+                c.given_date <![CDATA[ <= ]]> #{endTimeDateStr}
     </select>
 
 </mapper>

+ 2 - 2
lift-batch-service/src/main/resources/mapper/EmergencyRepairDataMapper.xml

@@ -22,9 +22,9 @@
         on
             er.project_id = p.id
         where
-            er.caller_date <![CDATA[ >= ]]> #{startTimeStr}
+            er.caller_date <![CDATA[ >= ]]> #{startTimeDateStr}
         and
-            er.caller_date <![CDATA[ <= ]]> #{endTimeStr}
+            er.caller_date <![CDATA[ <= ]]> #{endTimeDateStr}
     </select>
 
 </mapper>

+ 2 - 2
lift-batch-service/src/main/resources/mapper/MaintenanceDataMapper.xml

@@ -30,9 +30,9 @@
         on
             mp.project_id = p.id
         where
-            mp.plan_date <![CDATA[ >= ]]> #{startTimeStr}
+            mp.plan_date <![CDATA[ >= ]]> #{startTimeDateStr}
         and
-            mp.plan_date <![CDATA[ <= ]]> #{endTimeStr}
+            mp.plan_date <![CDATA[ <= ]]> #{endTimeDateStr}
     </select>
 
 </mapper>