wangbo 3 tahun lalu
induk
melakukan
9ecdc7cf00

+ 91 - 86
operation_manager/src/main/java/com/huaxu/order/controller/WorkOrderStatisticsController.java

@@ -32,35 +32,33 @@ public class WorkOrderStatisticsController {
 
     @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(chainEndDate, 1);
+        } else if (type == 2) {
             startDate = String.format("%s-01", startDate);
             endDate = String.format("%s-01", endDate);
         }
@@ -73,58 +71,70 @@ 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");
 
-        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,
+    public AjaxMessage<List<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;
+        List<Map<String, Object>> statistics = null;
         //根据用户编号,获取用户的权限
         LoginUser loginUser = UserUtil.getCurrentUser();
         WorkOrderManageDto workOrderManageDto = new WorkOrderManageDto();
@@ -133,14 +143,14 @@ 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);
+                startDate = String.format("%s-01", startDate);
+                endDate = subMonth(startDate, 1);
                 break;
             case 1:
-                startDate = String.format("%s-01-01",startDate);
-                endDate = subYear(startDate,1);
+                startDate = String.format("%s-01-01", startDate);
+                endDate = subYear(startDate, 1);
                 break;
             case 2:
                 startDate = String.format("%s-01", startDate);
@@ -150,24 +160,23 @@ 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);
         }
 
-        return new AjaxMessage<>(ResultStatus.OK,  statistics);
+        return new AjaxMessage<>(ResultStatus.OK, statistics);
     }
 
 
     @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,
+    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<>();
+        Map<String, Object> result = new HashMap<>();
         //根据用户编号,获取用户的权限
         LoginUser loginUser = UserUtil.getCurrentUser();
         WorkOrderManageDto workOrderManageDto = new WorkOrderManageDto();
@@ -176,34 +185,32 @@ 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);
+        if (type == 0) {
+            startDate = String.format("%s-01", startDate);
             workOrderManageDto.setStartDate(startDate);
-        }
-        else if(type == 1){
-            startDate = String.format("%s-01-01",startDate);
+        } else if (type == 1) {
+            startDate = String.format("%s-01-01", startDate);
             workOrderManageDto.setStartDate(startDate);
-        }
-        else if(type == 2){
+        } else if (type == 2) {
             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);
+        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;
+    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();
-           }
+        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 +220,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 +232,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 +246,4 @@ public class WorkOrderStatisticsController {
     }
 
 
-
-
 }