xiongchao 3 years ago
parent
commit
91f7c8978b

+ 40 - 0
platform-dao/src/main/java/com/platform/dao/vo/report/RepairReportMttr.java

@@ -0,0 +1,40 @@
+package com.platform.dao.vo.report;
+
+import com.platform.office.annotation.Excel;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ *
+ * 平均修复时间(Mean time to repair,MTTR)
+ *
+ * @author cyz
+ */
+@Data
+@Accessors(chain = true)
+public class RepairReportMttr implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 月份
+     */
+    @Excel(name = "月份", orderNum = "1")
+    private String month;
+
+    /**
+     * 次数
+     */
+    @Excel(name = "故障次数", orderNum = "2")
+    private Integer num;
+    /**
+     * 次数
+     */
+    @Excel(name = "总修复时间(小时)", orderNum = "3")
+    private Double totalHours;
+    /**
+     * 平均修复时间(Mean time to repair,MTTR)
+     */
+    @Excel(name = "平均修复时间(小时)", orderNum = "4")
+    private Double mttr;
+}

+ 5 - 2
platform-dao/src/main/resources/mapper/repair/RepairApplicationFormMapper.xml

@@ -36,8 +36,11 @@
             <if test="category != null and category != ''">
                 and application.category = #{category}
             </if>
-            <if test="category != null and category != ''">
-                and application.category = #{category}
+            <if test="categoryList != null and categoryList.size > 0">
+                AND application.category  in
+                <foreach item="item" index="index" collection="categoryList" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
             </if>
             <if test="zbh != null and zbh != ''">
                 and sb.zbh = #{zbh}

+ 40 - 7
platform-rest/src/main/java/com/platform/rest/controller/report/RepairReportController.java

@@ -9,6 +9,7 @@ import com.platform.dao.util.ExcelUtil;
 import com.platform.dao.vo.export.repair.ExportRepairApplicationFormVO;
 import com.platform.dao.vo.report.CheckJobReportVO;
 import com.platform.dao.vo.report.RepairReport24VO;
+import com.platform.dao.vo.report.RepairReportMttr;
 import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.check.CheckJobService;
 import com.platform.service.repair.RepairApplicationFormService;
@@ -43,12 +44,13 @@ public class RepairReportController {
    */
   @GetMapping("")
   @SysLog(">24小时停机次数按月统计")
-  public R getMonthReportBig24(RepairApplicationFormDTO dto, @RequestParam(defaultValue = "2021") Integer year){
-      return new R(repairApplicationFormService.getMonthReportBig24(dto, year));
+  public R getMonthReportBig24(RepairApplicationFormDTO dto, @RequestParam(defaultValue = "2021") Integer year, @RequestParam(defaultValue = "1") Integer searchType){
+      return new R(repairApplicationFormService.getMonthReportBig24(dto, year, searchType));
   }
 
     /**
-     * >24小时停机次数按月统计
+     * 1: >24小时停机次数按月统计
+     * 2: 设备故障次数按月统计
      * 统计规则:
      *    1:非计划性维修
      *    2:报修和维修结束的时间大于24小时,即设备停机修复时间
@@ -58,9 +60,40 @@ public class RepairReportController {
      */
     @GetMapping("/export")
     @SysLog("24小时停机次数按月统计导出")
-    @PreAuthorize("@pms.hasPermission('repair-application-forms-export')")
-    public void export(HttpServletResponse response, RepairApplicationFormDTO dto, @RequestParam(defaultValue = "2021") Integer year) {
-        List<RepairReport24VO> list = repairApplicationFormService.getMonthReportBig24(dto, year);
-        ExcelUtil.exportResponseDict(response, RepairReport24VO.class, list, year + "年-24小时停机次数按月统计表");
+    public void export(HttpServletResponse response, RepairApplicationFormDTO dto, @RequestParam(defaultValue = "2021") Integer year, @RequestParam(defaultValue = "1") Integer searchType) {
+        List<RepairReport24VO> list = repairApplicationFormService.getMonthReportBig24(dto, year, searchType);
+        ExcelUtil.exportResponseDict(response, RepairReport24VO.class, list, year + (searchType==1?"年-24小时停机次数按月统计表":"年-设备故障次数按月统计"));
+    }
+
+    /**
+     * MTTR月统计报表
+     * 统计规则:
+     *    1:所有非计划性维修
+     *    2:所有维修时间累加除以每月的次数
+     * @param dto 查询条件
+     * @param year 查询年份
+     * @return R
+     */
+    @GetMapping("mttr")
+    @SysLog("MTTR月统计报表")
+    public R getMonthReportMttr(RepairApplicationFormDTO dto, @RequestParam(defaultValue = "2021") Integer year, @RequestParam(defaultValue = "1") Integer searchType){
+        return new R(repairApplicationFormService.getMonthReportMtrr(dto, year));
+    }
+
+    /**
+     * 1: >24小时停机次数按月统计
+     * 2: 设备故障次数按月统计
+     * 统计规则:
+     *    1:非计划性维修
+     *    2:报修和维修结束的时间大于24小时,即设备停机修复时间
+     * @param dto 查询条件
+     * @param year 查询年份
+     * @return R
+     */
+    @GetMapping("/mttr/export")
+    @SysLog("MTTR月统计报表")
+    public void exportMttr(HttpServletResponse response, RepairApplicationFormDTO dto, @RequestParam(defaultValue = "2021") Integer year) {
+        List<RepairReportMttr> list = repairApplicationFormService.getMonthReportMtrr(dto, year);
+        ExcelUtil.exportResponseDict(response, RepairReportMttr.class, list, year + "年-MTTR月统计报表");
     }
 }

+ 5 - 1
platform-service/src/main/java/com/platform/service/repair/RepairApplicationFormService.java

@@ -10,6 +10,7 @@ import com.platform.dao.entity.repair.RepairForm;
 import com.platform.dao.vo.repair.RepairApplicationFormVO;
 import com.platform.dao.vo.repair.RepairFormVO;
 import com.platform.dao.vo.report.RepairReport24VO;
+import com.platform.dao.vo.report.RepairReportMttr;
 import com.platform.service.base.IBaseService;
 
 import java.util.List;
@@ -105,5 +106,8 @@ public interface RepairApplicationFormService extends IBaseService<RepairApplica
 
     void examine(String id);
 
-    List<RepairReport24VO> getMonthReportBig24(RepairApplicationFormDTO repairApplicationFormDTO, Integer year);
+    List<RepairReport24VO> getMonthReportBig24(RepairApplicationFormDTO repairApplicationFormDTO, Integer year, Integer type);
+
+    List<RepairReportMttr> getMonthReportMtrr(RepairApplicationFormDTO repairApplicationFormDTO, Integer year);
+
 }

+ 89 - 6
platform-service/src/main/java/com/platform/service/repair/impl/RepairApplicationFormServiceImpl.java

@@ -41,6 +41,7 @@ import com.platform.dao.vo.repair.RepairApplicationFormVO;
 import com.platform.dao.vo.repair.RepairCheckVO;
 import com.platform.dao.vo.repair.RepairFormVO;
 import com.platform.dao.vo.report.RepairReport24VO;
+import com.platform.dao.vo.report.RepairReportMttr;
 import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.office.annotation.Excel;
 import com.platform.service.base.impl.BaseServiceImpl;
@@ -685,11 +686,13 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
      * 2:如果不是当前年份,则统计全年的
      *
      * @param repairApplicationFormDTO
-     * @param searchYear
+     * @param searchYear 查询年份
+     * @param type  1:大于24的非计划性维修
+     *              2:所有类型维修,不限维修时间,包括计划性和非计划性,单不包括其他(如:布线等完善性维修)
      * @return
      */
     @Override
-    public List<RepairReport24VO> getMonthReportBig24(RepairApplicationFormDTO repairApplicationFormDTO, Integer searchYear) {
+    public List<RepairReport24VO> getMonthReportBig24(RepairApplicationFormDTO repairApplicationFormDTO, Integer searchYear, Integer type) {
         LocalDate localDate = LocalDate.now();
         int year = localDate.getYear();
 
@@ -707,7 +710,14 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
             searchEndTime = DateUtils.getLastDayOfThisYear(searchYear);
         }
         // 选择非计划性的订单
-        repairApplicationFormDTO.setCategory(RepairApplicationFormCategoryEnum.PLAN_NOT.getValue());
+        if(type == 1){
+            repairApplicationFormDTO.setCategory(RepairApplicationFormCategoryEnum.PLAN_NOT.getValue());
+        }else if(type == 2){
+            List<Integer> categoryList = new ArrayList<Integer>();
+            categoryList.add(RepairApplicationFormCategoryEnum.PLAN_NOT.getValue());
+            categoryList.add(RepairApplicationFormCategoryEnum.PLAN.getValue());
+            repairApplicationFormDTO.setCategoryList(categoryList);
+        }
         repairApplicationFormDTO.setSearchStartTime(searchStartTime);
         repairApplicationFormDTO.setSearchEndTime(searchEndTime);
         List<RepairApplicationFormVO> list = mapper.selectPageList(repairApplicationFormDTO);
@@ -721,18 +731,91 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
                 if(repairApplicationForm.getDealMinutes() == null){
                     continue;
                 }
-                double minites = repairApplicationForm.getDealMinutes();
-                if(minites/60.0<24.0){
+                if(type == 1){
+                    double minites = repairApplicationForm.getDealMinutes();
+                    if(minites/60.0<24.0){
+                        continue;
+                    }
+                }
+                if(repairApplicationForm.getApplyTime().isAfter(map.get("searchStartTimeMonth")) && repairApplicationForm.getApplyTime().isBefore(map.get("searchEndTimeMonth"))){
+                    i++;
+                }
+            }
+            vo.setNum(i);
+            result.add(vo);
+        }
+  /*      for(RepairReport24VO r: result){
+            System.out.println(r.toString());
+        }*/
+        return result;
+    }
+
+    /**
+     * 1: 如果年份是当前年份,则统计到当前月份
+     * 2:如果不是当前年份,则统计全年的
+     *
+     * @param repairApplicationFormDTO
+     * @param searchYear 查询年份
+     * @param type  1:大于24的非计划性维修
+     *              2:所有类型维修,不限维修时间,包括计划性和非计划性,单不包括其他(如:布线等完善性维修)
+     * @return
+     */
+    @Override
+    public List<RepairReportMttr> getMonthReportMtrr(RepairApplicationFormDTO repairApplicationFormDTO, Integer searchYear ) {
+        LocalDate localDate = LocalDate.now();
+        int year = localDate.getYear();
+
+        // 如2021-10-15号码,则month=10,需要计算到11月份,需要加1
+        int month = localDate.getMonthValue() + 1;
+        List<Map<String, LocalDateTime>> monthStartAndEndList = DateUtils.getMonthStartAndEndByYear(year, month);
+        LocalDateTime searchStartTime = null;
+        LocalDateTime searchEndTime = null;
+        // 当前年份只统计到当前月,历史年份统计全年
+        if(year == searchYear){
+            searchStartTime = DateUtils.getFirstDayOfThisYear(year);
+            searchEndTime = DateUtils.getLastDayOfMonth(month);
+        }else{
+            searchStartTime = DateUtils.getFirstDayOfThisYear(searchYear);
+            searchEndTime = DateUtils.getLastDayOfThisYear(searchYear);
+        }
+        // 选择非计划性的订单
+        List<Integer> categoryList = new ArrayList<Integer>();
+        categoryList.add(RepairApplicationFormCategoryEnum.PLAN_NOT.getValue());
+        categoryList.add(RepairApplicationFormCategoryEnum.PLAN.getValue());
+        repairApplicationFormDTO.setCategoryList(categoryList);
+
+        repairApplicationFormDTO.setSearchStartTime(searchStartTime);
+        repairApplicationFormDTO.setSearchEndTime(searchEndTime);
+        List<RepairApplicationFormVO> list = mapper.selectPageList(repairApplicationFormDTO);
+
+        List<RepairReportMttr> result = new ArrayList<RepairReportMttr>();
+        for(Map<String, LocalDateTime> map: monthStartAndEndList){
+            RepairReportMttr vo = new RepairReportMttr();
+            vo.setMonth(searchStartTime.getYear() + "-" + map.get("searchStartTimeMonth").getMonthValue() + "月");
+            double totalMinuties = 0.0;
+            double meanMinuties = 0.0;
+            int i = 0;
+            for(RepairApplicationFormVO repairApplicationForm: list){
+                if(repairApplicationForm.getDealMinutes() == null){
                     continue;
                 }
                 if(repairApplicationForm.getApplyTime().isAfter(map.get("searchStartTimeMonth")) && repairApplicationForm.getApplyTime().isBefore(map.get("searchEndTimeMonth"))){
                     i++;
+                    totalMinuties = totalMinuties + repairApplicationForm.getDealMinutes();
                 }
             }
+            if(totalMinuties == 0.0){
+                meanMinuties = 0.0;
+            }else{
+                totalMinuties = BigDecimalUtil.decimal(totalMinuties/60, 2);
+                meanMinuties = BigDecimalUtil.decimal(totalMinuties/i, 2);
+            }
+            vo.setTotalHours(totalMinuties);
+            vo.setMttr(meanMinuties);
             vo.setNum(i);
             result.add(vo);
         }
-        for(RepairReport24VO r: result){
+        for(RepairReportMttr r: result){
             System.out.println(r.toString());
         }
         return result;