Browse Source

首页数据

黄远 5 years ago
parent
commit
ac621fb499

+ 1 - 1
lift-common/src/main/java/cn.com.ty.lift.common/constants/ApiConstants.java

@@ -115,7 +115,7 @@ public class ApiConstants {
     /**
      * 平台公司id
      */
-    public static final Long PLATFORM_COMPANY_ID = 10000L;
+    public static final Long PLATFORM_COMPANY_ID = 10086L;
 
     /**
      * 直梯

+ 33 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/homepage/controller/EnterpriseDataStatisticsController.java

@@ -0,0 +1,33 @@
+package cn.com.ty.lift.system.homepage.controller;
+
+import cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest;
+import cn.com.ty.lift.system.homepage.service.EnterpriseDataStatisticsService;
+import cn.com.xwy.boot.web.dto.RestResponse;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * @author huangyuan
+ * @date 2020/4/24
+ * @description 企业数据统计
+ */
+@RestController
+@RequestMapping("/home/enterprise/statistics")
+public class EnterpriseDataStatisticsController {
+
+    @Resource
+    private EnterpriseDataStatisticsService enterpriseDataStatisticsService;
+
+    /**
+     * @param dataStatisticsRequest 请求数据 公司id
+     * @return 年份对应业务数据
+     * @description 获取年度业务统计数据
+     * @date 2020/4/24 10:27 上午
+     */
+    @RequestMapping("/yearBusinessData")
+    public RestResponse yearBusinessData(DataStatisticsRequest dataStatisticsRequest) {
+        return enterpriseDataStatisticsService.yearBusinessData(dataStatisticsRequest);
+    }
+}

+ 26 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/homepage/dao/dto/request/DataStatisticsRequest.java

@@ -0,0 +1,26 @@
+package cn.com.ty.lift.system.homepage.dao.dto.request;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2020/4/24
+ * @description 统计图请求体
+ */
+@Data
+public class DataStatisticsRequest {
+    /**
+     * 当前公司id
+     */
+    private Long companyId;
+
+    /**
+     * 之前时间
+     */
+    private String beforeDateStr;
+
+    /**
+     * 当前公司
+     */
+    private String nowDateStr;
+}

+ 36 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/homepage/dao/dto/response/EnterpriseDataStatisticsResponse.java

@@ -0,0 +1,36 @@
+package cn.com.ty.lift.system.homepage.dao.dto.response;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2020/4/24
+ * @description 企业统计数据相应
+ */
+@Data
+public class EnterpriseDataStatisticsResponse {
+    /**
+     * 年份
+     */
+    private Integer year;
+    /**
+     * 项目数量
+     */
+    private Long projectNum;
+    /**
+     * 维保数量
+     */
+    private Long maintenanceNum;
+    /**
+     * 急修数量
+     */
+    private Long emergencyNum;
+    /**
+     * 年检数量
+     */
+    private Long annualNum;
+    /**
+     * 大修数量
+     */
+    private Long capitalNum;
+}

+ 41 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/homepage/dao/mapper/CommonDataMapper.java

@@ -1,5 +1,6 @@
 package cn.com.ty.lift.system.homepage.dao.mapper;
 
+import cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest;
 import cn.com.ty.lift.system.homepage.dao.dto.request.LiftDataRequest;
 import cn.com.ty.lift.system.homepage.dao.dto.request.PlatformCalendarRequest;
 import cn.com.ty.lift.system.homepage.dao.model.*;
@@ -94,4 +95,44 @@ public interface CommonDataMapper {
      * @date 2020/2/20 5:57 下午
      */
     List<AnnualInspectionDataModel> getMonthBeginToEndAnnualInspectionRecord(PlatformCalendarRequest platformCalendarRequest);
+
+    /**
+     * @param dataStatisticsRequest 请求数据
+     * @return 年份-数量
+     * @description 获取 年份-项目数量
+     * @date 2020/4/24 3:52 下午
+     */
+    List<CountDataModel> getEveryYearProjectCount(DataStatisticsRequest dataStatisticsRequest);
+
+    /**
+     * @param dataStatisticsRequest 请求数据
+     * @return 年份-数量
+     * @description 获取 年份-维保次数
+     * @date 2020/4/24 3:52 下午
+     */
+    List<CountDataModel> getEveryYearMaintenanceCount(DataStatisticsRequest dataStatisticsRequest);
+
+    /**
+     * @param dataStatisticsRequest 请求数据
+     * @return 年份-数量
+     * @description 获取 年份-急修次数
+     * @date 2020/4/24 3:52 下午
+     */
+    List<CountDataModel> getEveryYearEmergencyCount(DataStatisticsRequest dataStatisticsRequest);
+
+    /**
+     * @param dataStatisticsRequest 请求数据
+     * @return 年份-数量
+     * @description 获取 年份-年检次数
+     * @date 2020/4/24 3:52 下午
+     */
+    List<CountDataModel> getEveryYearAnnualCount(DataStatisticsRequest dataStatisticsRequest);
+
+    /**
+     * @param dataStatisticsRequest 请求数据
+     * @return 年份-数量
+     * @description 获取 年份-大修次数
+     * @date 2020/4/24 3:52 下午
+     */
+    List<CountDataModel> getEveryYearCapitalCount(DataStatisticsRequest dataStatisticsRequest);
 }

+ 5 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/homepage/dao/model/CountDataModel.java

@@ -14,6 +14,11 @@ public class CountDataModel {
      */
     private Long mtCompanyId;
 
+    /**
+     * 年份
+     */
+    private Integer year;
+
     /**
      * 数据条数
      */

+ 116 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/homepage/service/EnterpriseDataStatisticsService.java

@@ -0,0 +1,116 @@
+package cn.com.ty.lift.system.homepage.service;
+
+import cn.com.ty.lift.common.constants.ApiConstants;
+import cn.com.ty.lift.system.constants.CommonConstants;
+import cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest;
+import cn.com.ty.lift.system.homepage.dao.dto.response.EnterpriseDataStatisticsResponse;
+import cn.com.ty.lift.system.homepage.dao.mapper.CommonDataMapper;
+import cn.com.ty.lift.system.homepage.dao.model.CountDataModel;
+import cn.com.xwy.boot.web.dto.RestResponse;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+
+/**
+ * @author huangyuan
+ * @date 2020/4/24
+ * @description
+ */
+@Service
+public class EnterpriseDataStatisticsService {
+
+    @Resource
+    private CommonDataMapper commonDataMapper;
+
+    /**
+     * 时间间隔
+     */
+    private static final int YEAR_INTERVAL = 3;
+
+    /**
+     * @param dataStatisticsRequest 请求数据 公司id
+     * @return 年份对应业务数据
+     * @description 获取年度业务统计数据
+     * @date 2020/4/24 10:27 上午
+     */
+    public RestResponse yearBusinessData(DataStatisticsRequest dataStatisticsRequest) {
+        initDataStatisticsRequest(dataStatisticsRequest);
+        List<EnterpriseDataStatisticsResponse> enterpriseDataStatisticsResponseList = new LinkedList<>();
+        //年份-项目数量
+        Map<Integer, Long> projectYearToNum = yearToNum(commonDataMapper
+                .getEveryYearProjectCount(dataStatisticsRequest));
+        //年份-维保次数
+        Map<Integer, Long> maintenanceYearToNum = yearToNum(commonDataMapper
+                .getEveryYearMaintenanceCount(dataStatisticsRequest));
+        //年份-急修次数
+        Map<Integer, Long> emergencyYearToNum = yearToNum(commonDataMapper
+                .getEveryYearEmergencyCount(dataStatisticsRequest));
+        //年份-年检次数
+        Map<Integer, Long> annualYearToNum = yearToNum(commonDataMapper
+                .getEveryYearProjectCount(dataStatisticsRequest));
+        //年份-大修次数
+        Map<Integer, Long> capitalYearToNum = yearToNum(commonDataMapper
+                .getEveryYearCapitalCount(dataStatisticsRequest));
+        int before = Integer.parseInt(dataStatisticsRequest.getBeforeDateStr().substring(0, 4));
+        int nowYear = Integer.parseInt(dataStatisticsRequest.getNowDateStr().substring(0, 4));
+        while (before <= nowYear) {
+            EnterpriseDataStatisticsResponse enterpriseDataStatisticsResponse = new EnterpriseDataStatisticsResponse();
+            enterpriseDataStatisticsResponse.setYear(before);
+            enterpriseDataStatisticsResponse.setProjectNum(getLongValue(projectYearToNum.get(before)));
+            enterpriseDataStatisticsResponse.setMaintenanceNum(getLongValue(maintenanceYearToNum.get(before)));
+            enterpriseDataStatisticsResponse.setEmergencyNum(getLongValue(emergencyYearToNum.get(before)));
+            enterpriseDataStatisticsResponse.setAnnualNum(getLongValue(annualYearToNum.get(before)));
+            enterpriseDataStatisticsResponse.setCapitalNum(getLongValue(capitalYearToNum.get(before)));
+            enterpriseDataStatisticsResponseList.add(enterpriseDataStatisticsResponse);
+            before++;
+        }
+        return RestResponse.success(enterpriseDataStatisticsResponseList, ApiConstants.RESULT_SUCCESS,
+                "获取统计信息成功");
+    }
+
+    /**
+     * @param dataStatisticsRequest 初始化时间数据
+     * @description 设置请求的时间数据
+     * @date 2020/4/24 11:03 上午
+     */
+    private void initDataStatisticsRequest(DataStatisticsRequest dataStatisticsRequest) {
+        LocalDate now = LocalDate.now();
+        LocalDate beforeYear = now.plusDays(-YEAR_INTERVAL);
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(CommonConstants.PLAN_DATE_FORMAT);
+        dataStatisticsRequest.setNowDateStr(now.format(dateTimeFormatter));
+        dataStatisticsRequest.setBeforeDateStr(beforeYear.format(dateTimeFormatter));
+    }
+
+    /**
+     * @param countDataModelList 年份-数量
+     * @return 年份-数量map
+     * @description 获取年份-数量map
+     * @date 2020/4/24 4:55 下午
+     */
+    private Map<Integer, Long> yearToNum(List<CountDataModel> countDataModelList) {
+        Map<Integer, Long> yearToNum = new HashMap<>();
+        if (countDataModelList != null && countDataModelList.size() > 0) {
+            countDataModelList.forEach(countDataModel -> {
+                yearToNum.put(countDataModel.getYear(), countDataModel.getDataCount());
+            });
+        }
+        return yearToNum;
+    }
+
+    /**
+     * @param value 值
+     * @return long 值
+     * @description 去除空值的情况
+     * @date 2020/4/24 5:18 下午
+     */
+    public long getLongValue(Long value) {
+        if (value != null) {
+            return value;
+        }
+        return 0L;
+    }
+
+}

+ 146 - 59
lift-system-service/src/main/resources/mapper/CommonDataMapper.xml

@@ -93,15 +93,15 @@
             parameterType="cn.com.ty.lift.system.settings.dao.entity.model.MaintenanceCompanyRequest"
             resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
         select
-            <include refid="companyIdToCountSql"/>
+        <include refid="companyIdToCountSql"/>
         from
-            project
+        project
         group by
-            mt_company_id
+        mt_company_id
         having
-            1=1
-            <!-- 判断公司id是否在集合中 -->
-            <include refid="setCompanyId"/>
+        1=1
+        <!-- 判断公司id是否在集合中 -->
+        <include refid="setCompanyId"/>
 
     </select>
 
@@ -110,15 +110,15 @@
             parameterType="cn.com.ty.lift.system.settings.dao.entity.model.MaintenanceCompanyRequest"
             resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
         select
-            <include refid="companyIdToCountSql"/>
+        <include refid="companyIdToCountSql"/>
         from
-            maintenance_record
+        maintenance_record
         group by
-            mt_company_id
+        mt_company_id
         having
-            1=1
-            <!-- 判断公司id是否在集合中 -->
-            <include refid="setCompanyId"/>
+        1=1
+        <!-- 判断公司id是否在集合中 -->
+        <include refid="setCompanyId"/>
     </select>
 
     <!-- 获取公司急修记录 -->
@@ -126,15 +126,15 @@
             parameterType="cn.com.ty.lift.system.settings.dao.entity.model.MaintenanceCompanyRequest"
             resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
         select
-            <include refid="companyIdToCountSql"/>
+        <include refid="companyIdToCountSql"/>
         from
-            emergency_repair
+        emergency_repair
         group by
-            mt_company_id
+        mt_company_id
         having
-            1=1
-            <!-- 判断公司id是否在集合中 -->
-            <include refid="setCompanyId"/>
+        1=1
+        <!-- 判断公司id是否在集合中 -->
+        <include refid="setCompanyId"/>
     </select>
 
     <!--################################################################################-->
@@ -146,22 +146,22 @@
             parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.PlatformCalendarRequest"
             resultType="cn.com.ty.lift.system.homepage.dao.model.MtPlanDataModel">
         select
-            <include refid="liftInfoSql"/>
-            mp.plan_date as planDate,
-            mp.status as status
+        <include refid="liftInfoSql"/>
+        mp.plan_date as planDate,
+        mp.status as status
         from
-            maintenance_plan mp
+        maintenance_plan mp
         left join
-            lift l
+        lift l
         on
-            mp.lift_id = l.id
-            <include refid="liftInfoJoinSql"/>
+        mp.lift_id = l.id
+        <include refid="liftInfoJoinSql"/>
         where
-            mp.mt_company_id = #{mtCompanyId}
+        mp.mt_company_id = #{mtCompanyId}
         and
-            mp.plan_date <![CDATA[ >= ]]> #{monthEndStr}
+        mp.plan_date <![CDATA[ >= ]]> #{monthEndStr}
         and
-            mp.plan_date <![CDATA[ <= ]]> #{monthEndStr}
+        mp.plan_date <![CDATA[ <= ]]> #{monthEndStr}
 
     </select>
 
@@ -170,22 +170,22 @@
             parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.PlatformCalendarRequest"
             resultType="cn.com.ty.lift.system.homepage.dao.model.MtRecordDataModel">
         select
-            <include refid="liftInfoSql"/>
-            mr.work_date as workDate,
-            mr.status as status
+        <include refid="liftInfoSql"/>
+        mr.work_date as workDate,
+        mr.status as status
         from
-            maintenance_record mr
+        maintenance_record mr
         left join
-            lift l
+        lift l
         on
-            mr.lift_id = l.id
-            <include refid="liftInfoJoinSql"/>
+        mr.lift_id = l.id
+        <include refid="liftInfoJoinSql"/>
         where
-            mr.mt_company_id = #{mtCompanyId}
+        mr.mt_company_id = #{mtCompanyId}
         and
-            mr.work_date <![CDATA[ >= ]]> #{monthBeginStr}
+        mr.work_date <![CDATA[ >= ]]> #{monthBeginStr}
         and
-            mr.work_date <![CDATA[ <= ]]> #{monthEndStr}
+        mr.work_date <![CDATA[ <= ]]> #{monthEndStr}
 
     </select>
 
@@ -194,23 +194,23 @@
             parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.PlatformCalendarRequest"
             resultType="cn.com.ty.lift.system.homepage.dao.model.EmergencyRecordDataModel">
         select
-            <include refid="liftInfoSql"/>
-            er.caller_date as callerDate,
-            er.recovery_date as recoveryDate,
-            er.status as status
+        <include refid="liftInfoSql"/>
+        er.caller_date as callerDate,
+        er.recovery_date as recoveryDate,
+        er.status as status
         from
-            emergency_repair er
+        emergency_repair er
         left join
-            lift l
+        lift l
         on
-            er.lift_id = l.id
-            <include refid="liftInfoJoinSql"/>
+        er.lift_id = l.id
+        <include refid="liftInfoJoinSql"/>
         where
-            er.mt_company_id = #{mtCompanyId}
+        er.mt_company_id = #{mtCompanyId}
         and
-            er.caller_date <![CDATA[ >= ]]> #{monthBeginStr}
+        er.caller_date <![CDATA[ >= ]]> #{monthBeginStr}
         and
-            er.caller_date <![CDATA[ <= ]]> #{monthEndStr}
+        er.caller_date <![CDATA[ <= ]]> #{monthEndStr}
 
     </select>
 
@@ -219,22 +219,109 @@
             parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.PlatformCalendarRequest"
             resultType="cn.com.ty.lift.system.homepage.dao.model.AnnualInspectionDataModel">
         select
-            <include refid="liftInfoSql"/>
-            ai.finish_time as finishTime,
-            ai.status as status
+        <include refid="liftInfoSql"/>
+        ai.finish_time as finishTime,
+        ai.status as status
         from
-            annual_inspection ai
+        annual_inspection ai
         left join
-            lift l
+        lift l
         on
-            ai.lift_id = l.id
-            <include refid="liftInfoJoinSql"/>
+        ai.lift_id = l.id
+        <include refid="liftInfoJoinSql"/>
+        where
+        ai.mt_company_id = #{mtCompanyId}
+        and
+        ai.finish_time <![CDATA[ >= ]]> #{monthBeginStr}
+        and
+        ai.finish_time <![CDATA[ <= ]]> #{monthEndStr}
+    </select>
+
+    <!-- 获取 年份-项目总数 -->
+    <select id="getEveryYearProjectCount"
+            parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest"
+            resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
+        select
+            SUBSTR(create_date, 1, 4) as year,
+            count(create_date) as dataCount
+        from project
+        group by
+            SUBSTR(create_date, 1, 4)
+        where
+            mt_company_id = #{companyId}
+        and
+            create_date <![CDATA[ >= ]]> #{beforeDateStr}
+        and
+            create_date <![CDATA[ <= ]]> #{nowDateStr}
+    </select>
+
+    <!--获取 年份-维保次数 -->
+    <select id="getEveryYearMaintenanceCount"
+            parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest"
+            resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
+        select
+            SUBSTR(create_date, 1, 4) as year,
+            count(create_date) as dataCount
+        from maintenance_record
+        group by
+            SUBSTR(create_date, 1, 4)
+        where
+            mt_company_id = #{companyId}
+        and
+            create_date <![CDATA[ >= ]]> #{beforeDateStr}
+        and
+            create_date <![CDATA[ <= ]]> #{nowDateStr}
+    </select>
+    <!--获取 年份-急修次数 -->
+    <select id="getEveryYearEmergencyCount"
+            parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest"
+            resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
+        select
+            SUBSTR(create_date, 1, 4) as year,
+            count(create_date) as dataCount
+        from emergency_repair
+        group by
+            SUBSTR(create_date, 1, 4)
+        where
+            mt_company_id = #{companyId}
+        and
+            create_date <![CDATA[ >= ]]> #{beforeDateStr}
+        and
+            create_date <![CDATA[ <= ]]> #{nowDateStr}
+    </select>
+    <!--获取 年份-年检次数 -->
+    <select id="getEveryYearAnnualCount"
+            parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest"
+            resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
+        select
+            SUBSTR(create_date, 1, 4) as year,
+            count(create_date) as dataCount
+        from annual_inspection
+        group by
+            SUBSTR(create_date, 1, 4)
+        where
+            mt_company_id = #{companyId}
+        and
+            create_date <![CDATA[ >= ]]> #{beforeDateStr}
+        and
+            create_date <![CDATA[ <= ]]> #{nowDateStr}
+    </select>
+    <!--获取 年份-大修次数 -->
+    <select id="getEveryYearCapitalCount"
+            parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.DataStatisticsRequest"
+            resultType="cn.com.ty.lift.system.homepage.dao.model.CountDataModel">
+        select
+            SUBSTR(create_date, 1, 4) as year,
+            count(create_date) as dataCount
+        from capital_repair
+        group by
+            SUBSTR(create_date, 1, 4)
         where
-            ai.mt_company_id = #{mtCompanyId}
+            mt_company_id = #{companyId}
         and
-            ai.finish_time <![CDATA[ >= ]]> #{monthBeginStr}
+            create_date <![CDATA[ >= ]]> #{beforeDateStr}
         and
-            ai.finish_time <![CDATA[ <= ]]> #{monthEndStr}
+            create_date <![CDATA[ <= ]]> #{nowDateStr}
     </select>
 
 </mapper>