Browse Source

Merge remote-tracking branch 'origin/20210223' into 20210223

yuejiaying 3 years ago
parent
commit
b60f9352ac

+ 124 - 95
operation_manager/src/main/java/com/huaxu/order/controller/WorkOrderStatisticsController.java

@@ -1,5 +1,6 @@
 package com.huaxu.order.controller;
 
+import com.huaxu.client.UserCenterClient;
 import com.huaxu.model.AjaxMessage;
 import com.huaxu.model.LoginUser;
 import com.huaxu.model.ResultStatus;
@@ -30,37 +31,38 @@ public class WorkOrderStatisticsController {
     @Autowired
     WorkOrderManageService workOrderManageService;
 
+    @Autowired
+    UserCenterClient userCenterClient;
+
     @RequestMapping(value = "completionStatistics", method = RequestMethod.GET)
     @ApiOperation(value = "工单完成情况统计")
-    public AjaxMessage<Map<String,Object>> completionStatistics(
-            @ApiParam(value="统计类型:0-按月统计,1-按年统计,2-自定义统计",required =true) @RequestParam(required = true) int type,
+    public AjaxMessage<Map<String, Object>> completionStatistics(
+            @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int type,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
         //同比日期
         String sameStartDate = null, sameEndDate = null;
         //环比日期
-        String chainStartDate =null, chainEndDate = null;
-        if(type==0){
-            startDate = String.format("%s-01",startDate);
-            endDate = subMonth(startDate,1);
+        String chainStartDate = null, chainEndDate = null;
+        if (type == 0) {
+            startDate = String.format("%s-01", startDate);
+            endDate = subMonth(startDate, 1);
 
-            sameStartDate = subYear(startDate,-1);
-            sameEndDate =subYear(sameStartDate, 1);
+            sameStartDate = subYear(startDate, -1);
+            sameEndDate = subYear(sameStartDate, 1);
 
-            chainStartDate = subMonth(startDate,-1);
+            chainStartDate = subMonth(startDate, -1);
             chainEndDate = subMonth(chainStartDate, 1);
-        }
-        else if(type==1){
-            startDate = String.format("%s-01-01",startDate);
-            endDate = subMonth(startDate,1);
+        } else if (type == 1) {
+            startDate = String.format("%s-01-01", startDate);
+            endDate = subMonth(startDate, 1);
 
             sameStartDate = subYear(startDate, -1);
-            sameEndDate = subYear(sameStartDate,1);
+            sameEndDate = subYear(sameStartDate, 1);
 
-            chainStartDate = subYear(startDate,-1);
-            chainEndDate = subYear(chainEndDate,1);
-        }
-        else if(type == 2) {
+            chainStartDate = subYear(startDate, -1);
+            chainEndDate = subYear(chainStartDate, 1);
+        } else if (type == 2) {
             startDate = String.format("%s-01", startDate);
             endDate = String.format("%s-01", endDate);
         }
@@ -73,58 +75,72 @@ public class WorkOrderStatisticsController {
         workOrderManageDto.setUserType(loginUser.getType());
         //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
         workOrderManageDto.setPermissonType(loginUser.getPermissonType());
-        Map<String,Object> statistics=workOrderManageService.workOrderStatistics(workOrderManageDto);
+        Map<String, Object> statistics = workOrderManageService.workOrderStatistics(workOrderManageDto);
         workOrderManageDto.setStartDate(sameStartDate);
         workOrderManageDto.setEndDate(sameEndDate);
         //同比
-        Map<String,Object> sameStatistic = workOrderManageService.workOrderStatistics(workOrderManageDto);
+        Map<String, Object> sameStatistic = workOrderManageService.workOrderStatistics(workOrderManageDto);
         //环比
         workOrderManageDto.setStartDate(chainStartDate);
         workOrderManageDto.setEndDate(chainEndDate);
-        Map<String,Object> chainStatistic = workOrderManageService.workOrderStatistics(workOrderManageDto);
+        Map<String, Object> chainStatistic = workOrderManageService.workOrderStatistics(workOrderManageDto);
 
-        DecimalFormat df = new DecimalFormat("#.00");
+        DecimalFormat df = new DecimalFormat("#0.00");
 
-        if(statistics.get("工单完成率") == null || statistics.get("工单完成率").toString().equals("0")){
-            statistics.put("工单完成率同比",0);
-            statistics.put("工单完成率环比",0);
+        if (sameStatistic.get("工单完成率") == null || sameStatistic.get("工单完成率").toString().equals("0")) {
+            statistics.put("工单完成率同比", 0);
+        } else {
+            Double finishedSameRate = (Double.parseDouble(statistics.get("工单完成率").toString()) - Double.parseDouble(sameStatistic.get("工单完成率").toString())) * 100 / Double.parseDouble(sameStatistic.get("工单完成率").toString());
+            statistics.put("工单完成率同比", df.format(finishedSameRate));
         }
-        else {
-            Double finishedSameRate = (Double.parseDouble(statistics.get("工单完成率").toString())-Double.parseDouble(sameStatistic.get("工单完成率").toString()))*100/Double.parseDouble(statistics.get("工单完成率").toString());
-            statistics.put("工单完成率同比",df.format(finishedSameRate));
-            Double finishedChainRate = (Double.parseDouble(statistics.get("工单完成率").toString())-Double.parseDouble(chainStatistic.get("工单完成率").toString()))*100/Double.parseDouble(statistics.get("工单完成率").toString());
-            statistics.put("工单完成率环比",df.format(finishedChainRate));
+
+        if (chainStatistic.get("工单完成率") == null || chainStatistic.get("工单完成率").toString().equals("0")) {
+            statistics.put("工单完成率环比", 0);
+        } else {
+            Double finishedChainRate = (Double.parseDouble(statistics.get("工单完成率").toString()) - Double.parseDouble(chainStatistic.get("工单完成率").toString())) * 100 / Double.parseDouble(chainStatistic.get("工单完成率").toString());
+            statistics.put("工单完成率环比", df.format(finishedChainRate));
         }
-        if(statistics.get("工单总数") == null || statistics.get("工单总数").toString().equals("0")){
-            statistics.put("工单总数同比",0);
-            statistics.put("工单总数环比",0);
+        
+        if (sameStatistic.get("工单总数") == null || sameStatistic.get("工单总数").toString().equals("0")) {
+            statistics.put("工单总数同比", 0);
+        } else {
+            Double orderSameTotalNumberRate = (Double.parseDouble(statistics.get("工单总数").toString()) - Double.parseDouble(sameStatistic.get("工单总数").toString())) * 100 / Double.parseDouble(sameStatistic.get("工单总数").toString());
+            statistics.put("工单总数同比", df.format(orderSameTotalNumberRate));
         }
-        else {
-            Double orderSameTotalNumberRate = (Double.parseDouble(statistics.get("工单总数").toString())-Double.parseDouble(sameStatistic.get("工单总数").toString()))*100/Double.parseDouble(statistics.get("工单总数").toString());
-            statistics.put("工单总数同比",df.format(orderSameTotalNumberRate));
-            Double orderChainTotalNumberRate = (Double.parseDouble(statistics.get("工单总数").toString())-Double.parseDouble(chainStatistic.get("工单总数").toString()))*100/Double.parseDouble(statistics.get("工单总数").toString());
-            statistics.put("工单总数环比",df.format(orderChainTotalNumberRate));
+        if (chainStatistic.get("工单总数") == null || chainStatistic.get("工单总数").toString().equals("0")) {
+            statistics.put("工单总数环比", 0);
+        } else {
+            Double orderChainTotalNumberRate = (Double.parseDouble(statistics.get("工单总数").toString()) - Double.parseDouble(chainStatistic.get("工单总数").toString())) * 100 / Double.parseDouble(chainStatistic.get("工单总数").toString());
+            statistics.put("工单总数环比", df.format(orderChainTotalNumberRate));
         }
-        if(statistics.get("工单完成数") == null || statistics.get("工单完成数").toString().equals("0")){
-            statistics.put("工单完成数同比",0);
-            statistics.put("工单完成数环比",0);
+
+        if (sameStatistic.get("工单完成数") == null || sameStatistic.get("工单完成数").toString().equals("0")) {
+            statistics.put("工单完成数同比", 0);
+
+        } else {
+            Double finishedSameNumber = (Double.parseDouble(statistics.get("工单完成数").toString()) - Double.parseDouble(sameStatistic.get("工单完成数").toString())) * 100 / Double.parseDouble(sameStatistic.get("工单完成数").toString());
+            statistics.put("工单完成数同比", df.format(finishedSameNumber));
         }
-        else {
-            Double finishedSameNumber = (Double.parseDouble(statistics.get("工单完成数").toString())-Double.parseDouble(sameStatistic.get("工单完成数").toString()))*100/Double.parseDouble(statistics.get("工单完成数").toString());
-            statistics.put("工单完成数同比",df.format(finishedSameNumber));
-            Double finishedChainNumber = (Double.parseDouble(statistics.get("工单完成数").toString())-Double.parseDouble(chainStatistic.get("工单完成数").toString()))*100/Double.parseDouble(statistics.get("工单完成数").toString());
-            statistics.put("工单完成数环比",df.format(finishedChainNumber));
+
+        if (chainStatistic.get("工单完成数") == null || chainStatistic.get("工单完成数").toString().equals("0")) {
+            statistics.put("工单完成数环比", 0);
+        } else {
+            Double finishedChainNumber = (Double.parseDouble(statistics.get("工单完成数").toString()) - Double.parseDouble(chainStatistic.get("工单完成数").toString())) * 100 / Double.parseDouble(chainStatistic.get("工单完成数").toString());
+            statistics.put("工单完成数环比", df.format(finishedChainNumber));
         }
 
-        return new AjaxMessage<>(ResultStatus.OK,  statistics);
+        return new AjaxMessage<>(ResultStatus.OK, statistics);
     }
+
     @RequestMapping(value = "eventStatistics", method = RequestMethod.GET)
-    @ApiOperation(value = "事件曲线数据统计展示")
-    public AjaxMessage<List<Map<String,Object>>> eventStatistics(
-            @ApiParam(value="统计类型:0-按月统计,1-按年统计,2-自定义统计",required =true) @RequestParam(required = true) int type,
+    @ApiOperation(value = "事件曲线数据统计展示、人均工单数据统计展示")
+    public AjaxMessage<Map<String,Object>> eventStatistics(
+            @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int type,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
-        List<Map<String,Object>> statistics = null;
+        int maintainerCount = 0;
+        Map<String,Object> result = new HashMap<>();
+        List<Map<String, Object>> statistics = new ArrayList<>(), average =new ArrayList<>();
         //根据用户编号,获取用户的权限
         LoginUser loginUser = UserUtil.getCurrentUser();
         WorkOrderManageDto workOrderManageDto = new WorkOrderManageDto();
@@ -133,16 +149,19 @@ public class WorkOrderStatisticsController {
         workOrderManageDto.setUserType(loginUser.getType());
         //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
         workOrderManageDto.setPermissonType(loginUser.getPermissonType());
-        switch (type){
+        switch (type) {
             case 0:
-                startDate = String.format("%s-01",startDate);
-                endDate = subMonth(startDate,1);
+                maintainerCount = userCenterClient.findMaintainerCount(startDate);
+                startDate = String.format("%s-01", startDate);
+                endDate = subMonth(startDate, 1);
                 break;
             case 1:
-                startDate = String.format("%s-01-01",startDate);
-                endDate = subYear(startDate,1);
+                maintainerCount = userCenterClient.findMaintainerCount(String.format("%s-12",startDate));
+                startDate = String.format("%s-01-01", startDate);
+                endDate = subYear(startDate, 1);
                 break;
             case 2:
+                maintainerCount = userCenterClient.findMaintainerCount(endDate);
                 startDate = String.format("%s-01", startDate);
                 endDate = String.format("%s-01", endDate);
                 break;
@@ -150,24 +169,35 @@ public class WorkOrderStatisticsController {
         workOrderManageDto.setStartDate(startDate);
         workOrderManageDto.setEndDate(endDate);
 
-        if(type==0 || type ==2){
+        if (type == 0 || type == 2) {
             statistics = workOrderManageService.eventMonthStatistics(workOrderManageDto);
+        } else if (type == 1) {
+            statistics = workOrderManageService.eventYearStatistics(workOrderManageDto);
         }
-        else if(type==1){
-            statistics =workOrderManageService.eventYearStatistics(workOrderManageDto);
+        DecimalFormat df = new DecimalFormat("#0.00");
+        for(Map<String,Object> map : statistics){
+            double number = 0;
+            if(maintainerCount > 0){
+                number = Double.parseDouble(map.get("数量").toString())/maintainerCount;
+            }
+            Map<String,Object> data = new HashMap<>();
+            data.put("日期",map.get("日期"));
+            data.put("数量",df.format(number));
+            average.add(data);
         }
-
-        return new AjaxMessage<>(ResultStatus.OK,  statistics);
+        result.put("事件数量",statistics);
+        result.put("人均工单",average);
+        return new AjaxMessage<>(ResultStatus.OK, result);
     }
 
 
     @RequestMapping(value = "distributionStatistics", method = RequestMethod.GET)
-    @ApiOperation(value = "分布统计")
-    public AjaxMessage<Map<String,Object>> distributionStatistics(
-            @ApiParam(value="统计类型:0-按月统计,1-按年统计,2-自定义统计",required =true) @RequestParam(required = true) int type,
+    @ApiOperation(value = "上报类型、工单类型、工单状态统计")
+    public AjaxMessage<Map<String, Object>> distributionStatistics(
+            @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int type,
             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate,
-            @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) {
-        Map<String,Object> result = new HashMap<>();
+            @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException {
+        Map<String, Object> result = new HashMap<>();
         //根据用户编号,获取用户的权限
         LoginUser loginUser = UserUtil.getCurrentUser();
         WorkOrderManageDto workOrderManageDto = new WorkOrderManageDto();
@@ -176,34 +206,35 @@ public class WorkOrderStatisticsController {
         workOrderManageDto.setUserType(loginUser.getType());
         //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
         workOrderManageDto.setPermissonType(loginUser.getPermissonType());
-        if(type == 0){
-            startDate = String.format("%s-01",startDate);
-            workOrderManageDto.setStartDate(startDate);
-        }
-        else if(type == 1){
-            startDate = String.format("%s-01-01",startDate);
-            workOrderManageDto.setStartDate(startDate);
-        }
-        else if(type == 2){
-            workOrderManageDto.setStartDate(startDate);
-            workOrderManageDto.setEndDate(endDate);
+        if (type == 0) {
+            startDate = String.format("%s-01", startDate);
+            endDate = subMonth(startDate, 1);
+
+        } else if (type == 1) {
+            startDate = String.format("%s-01-01", startDate);
+            endDate = subYear(startDate, 1);
+        } else if (type == 2) {
+            startDate = String.format("%s-01", startDate);
+            endDate = String.format("%s-01", endDate);
         }
-        result.put("上报类型",CalculatePercentage(workOrderManageService.reportStatistics(workOrderManageDto)));
-        result.put("工单状态",CalculatePercentage(workOrderManageService.orderStatusStatistics(workOrderManageDto)));
-        result.put("工单类型",CalculatePercentage(workOrderManageService.orderTypeStatistics(workOrderManageDto)));
-        return new AjaxMessage<>(ResultStatus.OK,  result);
+        workOrderManageDto.setStartDate(startDate);
+        workOrderManageDto.setEndDate(endDate);
+        result.put("上报类型", CalculatePercentage(workOrderManageService.reportStatistics(workOrderManageDto)));
+        result.put("工单状态", CalculatePercentage(workOrderManageService.orderStatusStatistics(workOrderManageDto)));
+        result.put("工单类型", CalculatePercentage(workOrderManageService.orderTypeStatistics(workOrderManageDto)));
+        return new AjaxMessage<>(ResultStatus.OK, result);
     }
 
-    private List<StatisticsDto> CalculatePercentage(List<StatisticsDto> list){
-        double total= 0;
-        DecimalFormat df = new DecimalFormat("#.00");
-        for(StatisticsDto statisticsDto: list){
-           if(statisticsDto.getStatisticsValue()!= null) {
-               total += statisticsDto.getStatisticsValue();
-           }
+    private List<StatisticsDto> CalculatePercentage(List<StatisticsDto> list) {
+        double total = 0;
+        DecimalFormat df = new DecimalFormat("#0.00");
+        for (StatisticsDto statisticsDto : list) {
+            if (statisticsDto.getStatisticsValue() != null) {
+                total += statisticsDto.getStatisticsValue();
+            }
         }
-        for(StatisticsDto statisticsDto: list){
-            double d = statisticsDto.getStatisticsValue()*100/total;
+        for (StatisticsDto statisticsDto : list) {
+            double d = statisticsDto.getStatisticsValue() * 100 / total;
             BigDecimal b = new BigDecimal(d);
             statisticsDto.setStatisticsValue(b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
         }
@@ -213,7 +244,7 @@ public class WorkOrderStatisticsController {
     /**
      * 日期增加一年
      */
-    private  String subYear(String date,int n) throws ParseException {
+    private String subYear(String date, int n) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Date dt = sdf.parse(date);
         Calendar rightNow = Calendar.getInstance();
@@ -225,9 +256,9 @@ public class WorkOrderStatisticsController {
     }
 
     /**
-     *日期增加一月
+     * 日期增加一月
      */
-    private  String subMonth(String date,int n) throws ParseException {
+    private String subMonth(String date, int n) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Date dt = sdf.parse(date);
         Calendar rightNow = Calendar.getInstance();
@@ -239,6 +270,4 @@ public class WorkOrderStatisticsController {
     }
 
 
-
-
 }

+ 2 - 2
operation_manager/src/main/java/com/huaxu/order/service/impl/WorkOrderManageServiceImpl.java

@@ -174,7 +174,7 @@ public class WorkOrderManageServiceImpl implements WorkOrderManageService {
         for(int i=0;i<list.size();i++){
             Map<String,Object> map =list.get(i);
             int day = Integer.parseInt(map.get("日期").toString().substring(8,10));
-            list.get(day-1).put("数量",map.get("数量"));
+            result.get(day-1).put("数量",map.get("数量"));
         }
         return result;
     }
@@ -193,7 +193,7 @@ public class WorkOrderManageServiceImpl implements WorkOrderManageService {
         for(int i=0;i<list.size();i++){
             Map<String,Object> map =list.get(i);
             int month = Integer.parseInt(map.get("日期").toString().substring(5,7));
-            list.get(month-1).put("数量",map.get("数量"));
+            result.get(month-1).put("数量",map.get("数量"));
         }
         return result;
     }

+ 4 - 10
operation_manager/src/main/resources/mapper/order/WorkOrderManageMapper.xml

@@ -915,8 +915,6 @@
 
   <!--事件数据月统计-->
   <select id="eventMonthStatistics" resultType="map">
-    select 数量,日期 from
-    (
     select count(1) 数量,date_format(date_create,'%Y-%m-%d') 日期
     from sc_work_order_manage t1
     <where>
@@ -954,15 +952,12 @@
       </if>
     </where>
     group by date_format(date_create,'%Y-%m-%d')
-    ) a
-    order by 日期
+    order by date_format(date_create,'%Y-%m-%d')
   </select>
 
   <!--事件数据年统计-->
   <select id="eventYearStatistics" resultType="map">
-    select 数量,日期 from
-    (
-    select count(1) 数量,date_format(date_create,'%Y-%c') 日期
+    select count(1) 数量,date_format(date_create,'%Y-%m') 日期
     from sc_work_order_manage t1
     <where>
       t1.date_create &gt;= date_format(#{order.startDate,jdbcType=VARCHAR},'%Y-%m-%d')
@@ -998,9 +993,8 @@
         </if>
       </if>
     </where>
-    group by date_format(date_create,'%Y-%c')
-    ) a
-    order by 日期
+    group by date_format(date_create,'%Y-%m')
+    order by date_format(date_create,'%Y-%m')
   </select>
 
   <!--上报类型统计-->