Bladeren bron

数据统计-电梯,收款

黄远 5 jaren geleden
bovenliggende
commit
dbb75c8b1e

+ 11 - 11
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/constants/DataStatisticsConstants.java

@@ -40,34 +40,34 @@ public class DataStatisticsConstants {
      */
     public static final String PAYMENT_DATA_FIELD = "paymentData";
 
-    /**
-     * 电梯状态->电梯数量
-     */
-    public static final Map<Integer, Integer> LIFT_STATUS_TO_LIFT_NUM = new HashMap<>();
-
     /**
      * 年检状态->数量
      */
     public static final Map<Integer, Long> ANNUAL_STATUS_TO_NUM = new HashMap<>();
 
     /**
-     * 电梯状态数组 1:新增 2:在保 3:丢失
+     * 收款状态->数量
      */
-    public static final int [] LIFT_STATUS_ARRAY = {1,2,3};
+    public static final Map<Integer, Double> PAYMENT_STATUS_TO_MONEY = new HashMap<>();
 
     /**
      * 年检状态数组 1:计划年检 2:实际完成 3:超期未检
      */
     public static final int [] ANNUAL_STATUS_ARRAY = {1,2,3};
 
+    /**
+     * 收款状态 1:计划应收 2:时间收款 3:超期未收
+     */
+    public static final int [] PAYMENT_STATUS_ARRAY = {1,2,3};
+
     static{
-        //初始化电梯状态对应数量
-        for(int status: LIFT_STATUS_ARRAY){
-            LIFT_STATUS_TO_LIFT_NUM.put(status, 0);
-        }
         //初始化年检状态对应数量
         for(int status: ANNUAL_STATUS_ARRAY){
             ANNUAL_STATUS_TO_NUM.put(status, 0L);
         }
+        //初始化收款数据
+        for(int status: PAYMENT_STATUS_ARRAY){
+            PAYMENT_STATUS_TO_MONEY.put(status, 0d);
+        }
     }
 }

+ 1 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/controller/PaymentDataStatisticsController.java

@@ -52,4 +52,5 @@ public class PaymentDataStatisticsController {
     public RestResponse dueToProject(PaymentDataRequest paymentDataRequest) {
         return paymentDataService.dueToProject(paymentDataRequest);
     }
+
 }

+ 42 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/PaymentDataModel.java

@@ -2,6 +2,9 @@ package cn.com.ty.lift.batch.applet.dao.model;
 
 import lombok.Data;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
+
 /**
  * @author huangyuan
  * @date 2020/2/3
@@ -9,4 +12,43 @@ import lombok.Data;
  */
 @Data
 public class PaymentDataModel extends BaseDataModel{
+    /**
+     * 应收金额
+     */
+    private BigDecimal planMoney;
+
+    /**
+     * 已收金额
+     */
+    private BigDecimal workMoney;
+
+    /**
+     * 收款类型 1:保养 2:急修 3:大修
+     */
+    private Integer paymentType;
+
+    /**
+     * 应收时间
+     */
+    private LocalDate planDate;
+
+    /**
+     * 已收时间
+     */
+    private LocalDate workDate;
+
+    /**
+     * 项目名称
+     */
+    private String projectName;
+
+    /**
+     * 区域名称
+     */
+    private String regionName;
+
+    /**
+     * 合同金额
+     */
+    private BigDecimal contractAmount;
 }

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

@@ -1,9 +1,37 @@
 package cn.com.ty.lift.batch.applet.dao.model.request;
 
+import lombok.Data;
+
+import java.time.LocalDate;
+
 /**
  * @author huangyuan
  * @date 2020/2/4
  * @description 收款请求数据
  */
-public class PaymentDataRequest extends CommonRequest {
+@Data
+public class PaymentDataRequest {
+    /**
+     * 公司id
+     */
+    private Long mtCompanyId;
+    /**
+     * 起始时间
+     */
+    private LocalDate startDate;
+
+    /**
+     * 终止时间
+     */
+    private LocalDate endDate;
+
+    /**
+     * 收款类型
+     */
+    private Integer paymentType;
+
+    /**
+     * 项目取值范围 top5 表示前5 all 表示全部
+     */
+    private String projectScope;
 }

+ 31 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/response/ProjectPaymentResponse.java

@@ -0,0 +1,31 @@
+package cn.com.ty.lift.batch.applet.dao.model.response;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2020/2/7
+ * @description
+ */
+@Data
+public class ProjectPaymentResponse {
+    /**
+     * 项目名称
+     */
+    private String projectName;
+
+    /**
+     * 合同金额
+     */
+    private Double contractAmount;
+
+    /**
+     * 超期时长
+     */
+    private Long dueToDays;
+
+    /**
+     * 超期收款金额
+     */
+    private Double beyondAmount;
+}

+ 28 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/response/RegionLiftResponse.java

@@ -0,0 +1,28 @@
+package cn.com.ty.lift.batch.applet.dao.model.response;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2020/2/7
+ * @description 区域电梯
+ */
+@Data
+public class RegionLiftResponse {
+    /**
+     *  区域名称
+     */
+    private String regionName;
+    /**
+     * 总台量
+     */
+    private Long totalLiftNums;
+    /**
+     * 新增电梯台量
+     */
+    private Long newLiftNums;
+    /**
+     * 丢失电梯台量
+     */
+    private Long lostLiftNums;
+}

+ 32 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/response/RegionPaymentResponse.java

@@ -0,0 +1,32 @@
+package cn.com.ty.lift.batch.applet.dao.model.response;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2020/2/7
+ * @description
+ */
+@Data
+public class RegionPaymentResponse {
+    /**
+     * 站点名称
+     */
+    private String regionName;
+
+    /**
+     * 计划应收
+     */
+    private Double planMoney;
+
+    /**
+     * 时间收款
+     */
+    private Double workMoney;
+
+    /**
+     * 超期收款
+     */
+    private Double beyondMoney;
+
+}

+ 2 - 3
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/EmergencyRepairDataService.java

@@ -14,7 +14,6 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.time.LocalDateTime;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
@@ -98,8 +97,8 @@ public class EmergencyRepairDataService {
      */
     public RestResponse getEachMonthUnits(EmergencyRepairDataRequest emergencyRepairDataRequest) {
         Map<String, Long> monthToUnits = DataStatisticsUtil.initDateMap();
-        emergencyRepairDataRequest.setStartTimeDate(DataStatisticsUtil.getYearFirstTime());
-        emergencyRepairDataRequest.setEndTimeDate(LocalDateTime.now());
+        //设置时间段
+        DataStatisticsUtil.setBeginYearToNow(emergencyRepairDataRequest);
         //从redis中获取时间段内的急修数据
         List<EmergencyRepairDataModel> emergencyRepairDataModelList =
                 getEmergencyRepairDataListFromRedis(emergencyRepairDataRequest);

+ 163 - 8
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/LiftDataService.java

@@ -5,6 +5,7 @@ import cn.com.ty.lift.batch.applet.dao.mapper.LiftDataMapper;
 import cn.com.ty.lift.batch.applet.dao.model.LiftDataModel;
 import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
 import cn.com.ty.lift.batch.applet.dao.model.request.LiftDataRequest;
+import cn.com.ty.lift.batch.applet.dao.model.response.RegionLiftResponse;
 import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.xwy.boot.web.dto.RestResponse;
@@ -12,8 +13,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -30,6 +30,18 @@ public class LiftDataService {
     @Resource
     private RedisTemplate redisTemplate;
 
+    /**
+     * @param
+     * @return
+     * @description 从redis中获取电梯数据
+     * @date 2020/2/7 12:01 下午
+     */
+    private List<LiftDataModel> getLiftDataModels(LiftDataRequest liftDataRequest) {
+        return (List<LiftDataModel>)
+                DataStatisticsUtil.getStatisticsDataFromRedis(redisTemplate,
+                        DataStatisticsConstants.LIFT_DATA_FIELD, liftDataRequest.getMtCompanyId());
+    }
+
     /**
      * @param commonRequest 起始时间 终止时间
      * @return
@@ -51,19 +63,19 @@ public class LiftDataService {
      */
     public List<LiftDataModel> getLiftDataListFromRedis(LiftDataRequest liftDataRequest) {
         //从redis中获取当前公司电梯信息
-        List<LiftDataModel> liftDataModelList = (List<LiftDataModel>)
-                DataStatisticsUtil.getStatisticsDataFromRedis(redisTemplate,
-                        DataStatisticsConstants.LIFT_DATA_FIELD, liftDataRequest.getMtCompanyId());
+        List<LiftDataModel> liftDataModelList = getLiftDataModels(liftDataRequest);
         if (liftDataModelList != null) {
             //过滤起始时间之前的数据
             if (liftDataRequest.getStartTimeDate() != null) {
                 liftDataModelList = liftDataModelList.stream()
+                        //新增电梯的时间
                         .filter(a -> a.getConnectTime().isAfter(liftDataRequest.getStartTimeDate()))
                         .collect(Collectors.toList());
             }
             //过滤终止时间之后的数据
             if (liftDataRequest.getEndTimeDate() != null) {
                 liftDataModelList = liftDataModelList.stream()
+                        //新增电梯的时间
                         .filter(a -> a.getConnectTime().isBefore(liftDataRequest.getEndTimeDate()))
                         .collect(Collectors.toList());
             }
@@ -71,6 +83,38 @@ public class LiftDataService {
         return liftDataModelList;
     }
 
+    /**
+     * @param
+     * @return
+     * @description 区域电梯数据:从redis中获取,并通过新增电梯时间和丢失电梯时间过滤
+     * @date 2020/2/7 11:57 上午
+     */
+    public List<LiftDataModel> getRegionListFromRedis(LiftDataRequest liftDataRequest) {
+        //从redis中获取当前公司电梯信息
+        List<LiftDataModel> liftDataModelList = getLiftDataModels(liftDataRequest);
+        if (liftDataModelList != null) {
+            //过滤起始时间之前的数据:过滤条件,新增电梯的时间或者丢失电梯的时间
+            if (liftDataRequest.getStartTimeDate() != null) {
+                liftDataModelList = liftDataModelList.stream()
+                        //新增电梯的时间
+                        .filter(a -> a.getConnectTime().isAfter(liftDataRequest.getStartTimeDate())
+                                //丢失电梯的时间
+                                || a.getLostTime().isAfter(liftDataRequest.getStartTimeDate()))
+                        .collect(Collectors.toList());
+            }
+            //过滤终止时间之后的数据:过滤条件,新增电梯的时间或者丢失电梯的时间
+            if (liftDataRequest.getEndTimeDate() != null) {
+                liftDataModelList = liftDataModelList.stream()
+                        //新增电梯的时间
+                        .filter(a -> a.getConnectTime().isBefore(liftDataRequest.getEndTimeDate())
+                                //丢失电梯的时间
+                                || a.getLostTime().isBefore(liftDataRequest.getEndTimeDate()))
+                        .collect(Collectors.toList());
+            }
+        }
+        return liftDataModelList;
+    }
+
     /**
      * @param
      * @return
@@ -78,7 +122,67 @@ public class LiftDataService {
      * @date 2020/2/5 12:28 下午
      */
     public RestResponse liftOverView(LiftDataRequest liftDataRequest) {
-        Map<Integer, Integer> liftStatusToNums = DataStatisticsConstants.LIFT_STATUS_TO_LIFT_NUM;
+        //获取时间段内按月份统计的丢失电梯数量
+        Map<Integer, List<Long>> liftStatusToNums = new HashMap<>();
+
+        //从redis中获取当前公司总的电梯信息
+        List<LiftDataModel> companyTotalLiftDataList = getLiftDataModels(liftDataRequest);
+        //设置时间段
+        DataStatisticsUtil.setBeginYearToNow(liftDataRequest);
+        //从redis中获取当前公司时间段之内的电梯信息
+        List<LiftDataModel> liftDataModelList = getLiftDataListFromRedis(liftDataRequest);
+
+        if ((companyTotalLiftDataList != null && companyTotalLiftDataList.size() > 0) &&
+                liftDataModelList != null && liftDataModelList.size() > 0) {
+            //获取传递起始时间之前的电梯信息
+            List<LiftDataModel> beforeLiftDataList = companyTotalLiftDataList.stream()
+                    //新建时间在起始时间之前的
+                    .filter(a -> a.getConnectTime().isBefore(liftDataRequest.getStartTimeDate()))
+                    .collect(Collectors.toList());
+            //时间段之前的电梯台数,去掉丢失的电梯
+            long beforeLiftTotalNum = 0L;
+            if (beforeLiftDataList != null && beforeLiftDataList.size() > 0) {
+                beforeLiftTotalNum = beforeLiftDataList.stream()
+                        .filter(a -> a.getLiftStatus() != 3).count();
+            }
+
+            //获取时间段内按月份统计的新增电梯数量
+            Map<Integer, Long> monthToNewLiftNums = liftDataModelList.stream()
+                    //获取电梯状态是新增的电梯数据
+                    .filter(a -> a.getLiftStatus() == 1)
+                    //通过新增时间顺序排列
+                    .sorted(Comparator.comparing(LiftDataModel::getConnectTime))
+                    .collect(Collectors.groupingBy(liftDataModel ->
+                            DataStatisticsUtil.getMonth(liftDataModel.getConnectTime()), Collectors.counting()));
+
+            //获取时间段内按月份统计的丢失电梯数量
+            Map<Integer, Long> monthToLostLiftNums = liftDataModelList.stream()
+                    //获取电梯状态是丢失的电梯数据
+                    .filter(a -> a.getLiftStatus() == 3)
+                    //通过丢失时间顺序排列
+                    .sorted(Comparator.comparing(LiftDataModel::getLostTime))
+                    .collect(Collectors.groupingBy(liftDataModel ->
+                            DataStatisticsUtil.getMonth(liftDataModel.getLostTime()), Collectors.counting()));
+            //获取截止时间的月份值
+            int nowMonthValue = liftDataRequest.getEndTimeDate().getMonthValue();
+
+            //设置不同状态对应的电梯台量
+            List<Long> newLiftNums = new ArrayList<>();
+            List<Long> onMaintenanceLiftNums = new ArrayList<>();
+            List<Long> lostLiftNums = new ArrayList<>();
+            for (int i = 1; i <= nowMonthValue; i++) {
+                long newLiftNum = monthToNewLiftNums.get(i) != null ? monthToNewLiftNums.get(i) : 0L;
+                long lostLiftNum = monthToLostLiftNums.get(i) != null ? monthToLostLiftNums.get(i) : 0L;
+                //计算在保电梯台量:原有电梯台量 + 新增电梯台量 - 丢失电梯台量
+                long onMaintenanceLiftNum = beforeLiftTotalNum + newLiftNum - lostLiftNum;
+                newLiftNums.add(newLiftNum);
+                onMaintenanceLiftNums.add(onMaintenanceLiftNum);
+                lostLiftNums.add(lostLiftNum);
+            }
+            liftStatusToNums.put(1, newLiftNums);
+            liftStatusToNums.put(2, onMaintenanceLiftNums);
+            liftStatusToNums.put(3, lostLiftNums);
+        }
         return RestResponse.success(liftStatusToNums, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 
@@ -89,7 +193,36 @@ public class LiftDataService {
      * @date 2020/2/5 2:43 下午
      */
     public RestResponse regionRank(LiftDataRequest liftDataRequest) {
-        return RestResponse.success(ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
+        //区域电梯数据
+        List<RegionLiftResponse> regionLiftResponseList = new ArrayList<>();
+        List<LiftDataModel> liftDataModelList = getRegionListFromRedis(liftDataRequest);
+        if (liftDataModelList != null && liftDataModelList.size() > 0) {
+            //将数据转化为 区域名称->电梯数据列表
+            Map<String, List<LiftDataModel>> regionNameToLiftData = liftDataModelList.stream()
+                    .collect(Collectors.groupingBy(LiftDataModel::getRegionName));
+            //封装区域电梯信息
+            regionNameToLiftData.forEach((key, value) -> {
+                RegionLiftResponse regionLiftResponse = new RegionLiftResponse();
+                //总电梯数
+                long totalLiftNums = value.stream().count();
+                //计算新增电梯的数量
+                long newLiftNums = value.stream()
+                        .filter(a -> a.getLiftStatus() == 1).count();
+                regionLiftResponse.setNewLiftNums(newLiftNums);
+                //丢失电梯台量
+                long lostLiftNums = value.stream()
+                        .filter(a -> a.getLiftStatus() == 3).count();
+                regionLiftResponse.setLostLiftNums(lostLiftNums);
+                //实际总台量
+                regionLiftResponse.setTotalLiftNums(totalLiftNums - lostLiftNums);
+            });
+            //通过丢失台量排序并获取前五的数据
+            regionLiftResponseList = regionLiftResponseList.stream()
+                    .sorted(Comparator.comparing(RegionLiftResponse::getLostLiftNums)).limit(5)
+                    .collect(Collectors.toList());
+        }
+        //通过丢失台量排序获取前五的台量
+        return RestResponse.success(regionLiftResponseList, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 
     /**
@@ -99,6 +232,28 @@ public class LiftDataService {
      * @date 2020/2/5 4:46 下午
      */
     public RestResponse projectLiftNums(LiftDataRequest liftDataRequest) {
-        return RestResponse.success(ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
+        Map<String, Long> projectNameToLiftNums = new HashMap<>();
+        //获取时间段内的电梯数量
+        List<LiftDataModel> liftDataModelList = getLiftDataListFromRedis(liftDataRequest);
+        if (liftDataModelList != null && liftDataModelList.size() > 0) {
+            //过滤掉丢失的电梯
+            liftDataModelList = liftDataModelList.stream()
+                    .filter(a -> a.getLiftStatus() != 3).collect(Collectors.toList());
+            //通过项目名称给电梯数据分组
+            projectNameToLiftNums = liftDataModelList.stream()
+                    .collect(Collectors.groupingBy(LiftDataModel::getProjectName, Collectors.counting()));
+        }
+        //通过电梯台量给map排序
+        projectNameToLiftNums.entrySet().stream()
+                .sorted(Comparator.comparing(entry -> entry.getValue()));
+        //获取前5的数据
+        Map<String, Long> topFive = new HashMap<>();
+        projectNameToLiftNums.forEach((key, value) -> {
+                    if (topFive.size() < 5) {
+                        topFive.put(key, value);
+                    }
+                }
+        );
+        return RestResponse.success(topFive, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 }

+ 106 - 7
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/PaymentDataService.java

@@ -5,6 +5,8 @@ import cn.com.ty.lift.batch.applet.dao.mapper.PaymentDataMapper;
 import cn.com.ty.lift.batch.applet.dao.model.PaymentDataModel;
 import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
 import cn.com.ty.lift.batch.applet.dao.model.request.PaymentDataRequest;
+import cn.com.ty.lift.batch.applet.dao.model.response.ProjectPaymentResponse;
+import cn.com.ty.lift.batch.applet.dao.model.response.RegionPaymentResponse;
 import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.xwy.boot.web.dto.RestResponse;
@@ -12,7 +14,12 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -54,10 +61,18 @@ public class PaymentDataService {
                 DataStatisticsUtil.getStatisticsDataFromRedis(redisTemplate,
                         DataStatisticsConstants.PAYMENT_DATA_FIELD, paymentDataRequest.getMtCompanyId());
         if (paymentDataModelList != null && paymentDataModelList.size() > 0) {
-            //通过公司id过滤
-            paymentDataModelList = paymentDataModelList.stream()
-                    .filter(a -> a.getMtCompanyId().equals(paymentDataRequest.getMtCompanyId()))
-                    .collect(Collectors.toList());
+            //通过起始时间过滤
+            if (paymentDataRequest.getStartDate() != null) {
+                paymentDataModelList = paymentDataModelList.stream()
+                        .filter(a -> a.getPlanDate().isAfter(paymentDataRequest.getStartDate()))
+                        .collect(Collectors.toList());
+            }
+            //通过终止时间过滤
+            if (paymentDataRequest.getEndDate() != null) {
+                paymentDataModelList = paymentDataModelList.stream()
+                        .filter(a -> a.getPlanDate().isBefore(paymentDataRequest.getEndDate()))
+                        .collect(Collectors.toList());
+            }
         }
         return paymentDataModelList;
     }
@@ -69,7 +84,24 @@ public class PaymentDataService {
      * @date 2020/2/5 4:55 下午
      */
     public RestResponse paymentOverView(PaymentDataRequest paymentDataRequest) {
-        return RestResponse.success(ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
+        Map<Integer, Double> paymentStatusToMoney = DataStatisticsConstants.PAYMENT_STATUS_TO_MONEY;
+        List<PaymentDataModel> paymentDataModelList = getPaymentDataListFromRedis(paymentDataRequest);
+        if (paymentDataModelList != null && paymentDataModelList.size() > 0) {
+            //计划收款总和
+            double totalPlanMoney = paymentDataModelList.stream().mapToDouble(
+                    paymentDataModel -> DataStatisticsUtil.getDoubleValue(paymentDataModel.getPlanMoney())
+            ).sum();
+            //实际收款总和
+            double totalWorkMoney = paymentDataModelList.stream().mapToDouble(
+                    paymentDataModel -> DataStatisticsUtil.getDoubleValue(paymentDataModel.getWorkMoney())
+            ).sum();
+            //超期未收总和
+            double totalBeyondMoney = totalPlanMoney - totalWorkMoney;
+            paymentStatusToMoney.put(1, totalPlanMoney);
+            paymentStatusToMoney.put(2, totalWorkMoney);
+            paymentStatusToMoney.put(3, totalBeyondMoney);
+        }
+        return RestResponse.success(paymentStatusToMoney, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 
     /**
@@ -79,7 +111,35 @@ public class PaymentDataService {
      * @date 2020/2/5 5:00 下午
      */
     public RestResponse regionRank(PaymentDataRequest paymentDataRequest) {
-        return RestResponse.success(ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
+        List<RegionPaymentResponse> regionPaymentResponseList = new ArrayList<>();
+        //从redis中获取收款数据
+        List<PaymentDataModel> paymentDataModelList = getPaymentDataListFromRedis(paymentDataRequest);
+        if (paymentDataModelList != null && paymentDataModelList.size() > 0) {
+            //区域名称对应付款数据
+            Map<String, List<PaymentDataModel>> regionNameToPaymentData = paymentDataModelList.stream()
+                    .collect(Collectors.groupingBy(PaymentDataModel::getRegionName));
+            regionNameToPaymentData.forEach((key, value) -> {
+                RegionPaymentResponse regionPaymentResponse = new RegionPaymentResponse();
+                //计划收款总和
+                double planMoney = paymentDataModelList.stream().mapToDouble(
+                        paymentDataModel -> DataStatisticsUtil.getDoubleValue(paymentDataModel.getPlanMoney())
+                ).sum();
+                //实际收款总和
+                double workMoney = paymentDataModelList.stream().mapToDouble(
+                        paymentDataModel -> DataStatisticsUtil.getDoubleValue(paymentDataModel.getWorkMoney())
+                ).sum();
+                //超期未收总和
+                double beyondMoney = planMoney - workMoney;
+                regionPaymentResponse.setRegionName(key);
+                regionPaymentResponse.setPlanMoney(planMoney);
+                regionPaymentResponse.setBeyondMoney(beyondMoney);
+            });
+            //通过超期款排名,并取前5的数据
+            regionPaymentResponseList = regionPaymentResponseList.stream()
+                    .sorted(Comparator.comparing(RegionPaymentResponse::getBeyondMoney)).limit(5)
+                    .collect(Collectors.toList());
+        }
+        return RestResponse.success(regionPaymentResponseList, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 
     /**
@@ -89,6 +149,45 @@ public class PaymentDataService {
      * @date 2020/2/5 5:02 下午
      */
     public RestResponse dueToProject(PaymentDataRequest paymentDataRequest) {
-        return RestResponse.success(ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
+        List<ProjectPaymentResponse> projectPaymentResponseList = new ArrayList<>();
+        //从redis中获取收款数据
+        List<PaymentDataModel> paymentDataModelList = getPaymentDataListFromRedis(paymentDataRequest);
+        if (paymentDataModelList != null && paymentDataModelList.size() > 0) {
+            //将数据转化为项目名->付款数据
+            Map<String, List<PaymentDataModel>> projectNameToPaymentData = paymentDataModelList.stream()
+                    .collect(Collectors.groupingBy(PaymentDataModel::getProjectName));
+            projectNameToPaymentData.forEach((key, value) -> {
+                if (value != null && value.size() > 0) {
+                    PaymentDataModel paymentDataModel = value.get(0);
+                    ProjectPaymentResponse projectPaymentResponse = new ProjectPaymentResponse();
+                    projectPaymentResponse.setProjectName(key);
+                    //计划收款总和
+                    double planMoney = paymentDataModel.getPlanMoney() != null
+                            ? paymentDataModel.getPlanMoney().doubleValue() : 0d;
+                    //实际收款总和
+                    double workMoney = paymentDataModel.getWorkMoney() != null
+                            ? paymentDataModel.getWorkMoney().doubleValue() : 0d;
+                    //超期未收总和
+                    double beyondMoney = planMoney - workMoney;
+                    projectPaymentResponse.setBeyondAmount(beyondMoney);
+                    //超期天数 计划收款和实际收款日期差值
+                    LocalDate afterDate = LocalDate.now();
+                    if(paymentDataModel.getWorkDate() != null){
+                        afterDate = paymentDataModel.getWorkDate();
+                    }
+                    Duration duration = Duration.between(afterDate, paymentDataModel.getPlanDate());
+                    projectPaymentResponse.setDueToDays(duration.toDays());
+                }
+            });
+            //通过超期款倒序
+            projectPaymentResponseList = projectPaymentResponseList.stream()
+                    .sorted(Comparator.comparing(ProjectPaymentResponse::getBeyondAmount).reversed())
+                    .collect(Collectors.toList());
+            //判断获取的是前5的数据 还是所有数据
+            if(projectPaymentResponseList.size() > 5 && "top5".equals(paymentDataRequest.getProjectScope())){
+                projectPaymentResponseList = projectPaymentResponseList.stream().limit(5).collect(Collectors.toList());
+            }
+        }
+        return RestResponse.success(projectPaymentResponseList, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
 }

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

@@ -1,8 +1,10 @@
 package cn.com.ty.lift.batch.applet.util;
 
 import cn.com.ty.lift.batch.applet.dao.model.BaseDataModel;
+import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
 import org.springframework.data.redis.core.RedisTemplate;
 
+import java.math.BigDecimal;
 import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.HashMap;
@@ -38,7 +40,7 @@ public class DataStatisticsUtil {
      * @date 2020/2/5 3:26 下午
      */
     public static List<? extends BaseDataModel> getStatisticsDataFromRedis(RedisTemplate redisTemplate, String dataKey,
-                                                                    Long mtCompanyId) {
+                                                                           Long mtCompanyId) {
         Map<Long, ? extends List<? extends BaseDataModel>> mtCompanyIdToData =
                 (Map<Long, ? extends List<? extends BaseDataModel>>) redisTemplate.opsForValue().get(dataKey);
         return mtCompanyIdToData.get(mtCompanyId);
@@ -76,10 +78,14 @@ public class DataStatisticsUtil {
     /**
      * @param localDateTime 时间数据
      * @return
-     * @description 获取时间的月份数据
+     * @description 获取时间的月份值(字符串)
      * @date 2020/2/4 4:31 下午
      */
     public static String getMonthStr(LocalDateTime localDateTime) {
+        //为空返回0
+        if (localDateTime == null) {
+            return "0";
+        }
         int month = localDateTime.getMonthValue();
         if (month < 10) {
             return "0" + month;
@@ -87,6 +93,20 @@ public class DataStatisticsUtil {
         return month + "";
     }
 
+    /**
+     * @param localDateTime 时间数据
+     * @return
+     * @description 获取时间的月份值(数字)
+     * @date 2020/2/7 3:06 下午
+     */
+    public static int getMonth(LocalDateTime localDateTime) {
+        //为空返回0
+        if (localDateTime == null) {
+            return 0;
+        }
+        return localDateTime.getMonthValue();
+    }
+
     /**
      * @param afterTime  较大时间
      * @param beforeTime 较小时间
@@ -101,4 +121,27 @@ public class DataStatisticsUtil {
         }
         return 0L;
     }
+
+    /**
+     * @param
+     * @return
+     * @description 给请求类设置年初到现在的时间
+     * @date 2020/2/7 3:51 下午
+     */
+    public static void setBeginYearToNow(CommonRequest commonRequest) {
+        //年初时间
+        commonRequest.setStartTimeDate(getYearFirstTime());
+        //当前时间
+        commonRequest.setEndTimeDate(LocalDateTime.now());
+    }
+
+    /**
+     * @param bigDecimalValue
+     * @return
+     * @description 获取 BigDecimal的值
+     * @date 2020/2/7 8:11 下午
+     */
+    public static double getDoubleValue(BigDecimal bigDecimalValue) {
+        return bigDecimalValue != null ? bigDecimalValue.doubleValue() : 0d;
+    }
 }