Kaynağa Gözat

pms 瑞鹰看板调整 总设备利用率 NPT生产异常

zhangcl 3 gün önce
ebeveyn
işleme
0c05df6425

+ 321 - 9
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java

@@ -26,10 +26,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDai
 import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportTaskCountVO;
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
-import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.OrderVo;
-import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.ProjectUtilizationRateVo;
-import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.TeamUtilizationRateVo;
-import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.YearTotalGas;
+import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.*;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotProductClassifyListReqVO;
@@ -596,12 +593,13 @@ public class IotStaticController {
      * @return
      */
     @GetMapping("/home/ry/count/zjxj")
-    public CommonResult<ImmutableMap<Object, Object>> getHomeZjXjStat() {
+    public CommonResult<ImmutableMap<Object, Object>> getHomeZjXjStat(IotRyDailyReportPageReqVO reqVO) {
         // 查询所有钻井进尺
-        IotRyDailyReportPageReqVO reqVO = new IotRyDailyReportPageReqVO();
-        reqVO.setProjectClassification("1");
+        IotRyDailyReportPageReqVO zjReqVO = new IotRyDailyReportPageReqVO();
+        zjReqVO.setProjectClassification("1");
+        zjReqVO.setCreateTime(reqVO.getCreateTime());
         BigDecimal totalFootage = BigDecimal.ZERO;
-        List<IotRyDailyReportDO> dailyReports = iotRyDailyReportMapper.dailyReports(reqVO);
+        List<IotRyDailyReportDO> dailyReports = iotRyDailyReportMapper.dailyReports(zjReqVO);
         // 使用Stream API计算总进尺
         if (CollUtil.isNotEmpty(dailyReports)) {
             totalFootage = dailyReports.stream()
@@ -612,7 +610,7 @@ public class IotStaticController {
 
         // 查询所有完工井数
         IotRyDailyReportPageReqVO xjReqVO = new IotRyDailyReportPageReqVO();
-
+        xjReqVO.setCreateTime(reqVO.getCreateTime());
         List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportMapper.countRepairTasksByDept(xjReqVO);
         // Java8 Stream 简洁累加(核心优化)
         Integer completeWellCount = repairDeptTasks.stream()
@@ -2259,6 +2257,320 @@ public class IotStaticController {
         return success(rates);
     }
 
+    /**
+     * 瑞鹰 公司总的设备利用率
+     * @return
+     */
+    @GetMapping("/ry/device/totalUtilizationRate")
+    @PermitAll
+    public CommonResult<BigDecimal> totalUtilizationRate(IotRyDailyReportPageReqVO reqVO) {
+        if (ObjUtil.isEmpty(reqVO.getCreateTime())) {
+            throw exception(IOT_DAILY_REPORT_TIME_NOT_EXISTS);
+        }
+        if (reqVO.getCreateTime().length < 2) {
+            throw exception(IOT_DAILY_REPORT_TIME_NOT_EXISTS);
+        }
+        // 计算公司整体的设备利用率
+        BigDecimal totalDeviceUtilization = BigDecimal.ZERO;
+        // 查询瑞鹰 158l 所有项目部
+        Set<Long> childDeptIds = deptService.getChildDeptIdListFromCache(158l);
+        Map<Long, DeptDO> allDeptPair = deptService.getDeptMap(childDeptIds);
+        Set<String> projectDeptNames = new HashSet<>();
+        Set<Long> projectDeptIds = new HashSet<>();
+        // key项目部id   value项目部名称
+        Map<Long, String> projectPair = new HashMap<>();
+        // key项目部id   value项目部包含的队伍id集合
+        Map<Long, Set<Long>> projectTeamPair = new HashMap<>();
+        // 队伍id 集合
+        Set<Long> crewIds = new HashSet<>();
+        if (CollUtil.isNotEmpty(allDeptPair)) {
+            allDeptPair.forEach((deptId, dept) -> {
+                if ("2".equals(dept.getType())) {
+                    projectDeptIds.add(deptId);
+                    projectDeptNames.add(dept.getName());
+                    projectPair.put(deptId, dept.getName());
+                }
+                if ("3".equals(dept.getType())) {
+                    // 队伍
+                    crewIds.add(dept.getId());
+                }
+            });
+            // 遍历所有部门
+            allDeptPair.forEach((deptId, dept) -> {
+                // 找出每个项目部下的队伍
+                if (projectPair.containsKey(dept.getParentId()) && 0==dept.getStatus()) {
+                    // 获得当前部门的上级项目部
+                    projectPair.forEach((projectDeptId, projectDept) -> {
+                        if (projectDeptId.equals(dept.getParentId())) {
+                            if (projectTeamPair.containsKey(projectDeptId)) {
+                                Set<Long> teamIds = projectTeamPair.get(projectDeptId);
+                                teamIds.add(deptId);
+                                projectTeamPair.put(projectDeptId, teamIds);
+                            } else {
+                                Set<Long> teamIds = new HashSet<>();
+                                teamIds.add(deptId);
+                                projectTeamPair.put(projectDeptId, teamIds);
+                            }
+                        }
+                    });
+                }
+            });
+        }
+        // 查询出指定时间区间内 已经填写的日报数量
+        // 瑞鹰区分 钻井 修井 日报
+        // 钻井:日报状态 过滤掉 ‘等停dt’    修井:日报状态过滤掉 ‘等停dt’、‘整修zx’
+        List<String> statuses = new ArrayList<>();
+        statuses.add("dt");
+        statuses.add("zx");
+        reqVO.setStatuses(statuses);
+        List<IotRyDailyReportDO> dailyReports = iotRyDailyReportMapper.dailyReports(reqVO);
+        // key项目部id     value项目部包含的队伍指定时间区域内日报数量
+        Map<Long, Integer> projectReportPair = new HashMap<>();
+        if (CollUtil.isNotEmpty(dailyReports)) {
+            // 整理出每个项目部下的队伍填报的日报数量
+            dailyReports.forEach(report -> {
+                if (CollUtil.isNotEmpty(projectTeamPair)) {
+                    projectTeamPair.forEach((projectDeptId, teamDeptIds) -> {
+                        if (teamDeptIds.contains(report.getDeptId())) {
+                            if (projectReportPair.containsKey(projectDeptId)) {
+                                Integer tempCount = projectReportPair.get(projectDeptId);
+                                projectReportPair.put(projectDeptId, ++tempCount);
+                            } else {
+                                projectReportPair.put(projectDeptId, 1);
+                            }
+                        }
+                    });
+                }
+
+            });
+            // 计算指定时间区间内包含的天数
+            long daysCount;
+            if (ObjUtil.isNotEmpty(reqVO.getCreateTime()) && reqVO.getCreateTime().length >= 2) {
+                LocalDateTime start = reqVO.getCreateTime()[0];
+                LocalDateTime end = reqVO.getCreateTime()[1];
+                if (ObjUtil.isNotEmpty(start) && ObjUtil.isNotEmpty(end) && !end.isBefore(start)) {
+                    // 使用ChronoUnit.DAYS.between计算天数差,并+1包含首尾两天
+                    daysCount = ChronoUnit.DAYS.between(
+                            start.toLocalDate(),
+                            end.toLocalDate()
+                    ) + 1;
+                } else {
+                    daysCount = 0L;
+                }
+            } else {
+                daysCount = 0L;
+            }
+
+            //时间查询区间内 公司总的日报数量
+            Integer totalReportCount = 0;
+            // 时间查询区间内 公司总的队伍数量
+            Integer totalTeamNum = 0;
+            if (CollUtil.isNotEmpty(projectTeamPair)) {
+                for (Map.Entry<Long, Set<Long>> longSetEntry : projectTeamPair.entrySet()) {
+                    Long projectDeptId = longSetEntry.getKey();
+                    Set<Long> teamIds = longSetEntry.getValue();
+                    Integer currentTeamNum = teamIds.size();
+                    totalTeamNum = totalTeamNum + currentTeamNum;
+                    if (projectReportPair.containsKey(projectDeptId)) {
+                        Integer reportCount = projectReportPair.getOrDefault(projectDeptId, 0);
+                        totalReportCount = totalReportCount + reportCount;
+                        // 公司总的 设备利用率 公式 totalReportCount/(totalTeamNum*daysCount)
+                    }
+                }
+                // 计算公司总的设备利用率
+                if (totalTeamNum > 0 && daysCount > 0) {
+                    totalDeviceUtilization = new BigDecimal((double) totalReportCount / (totalTeamNum * daysCount))
+                            .setScale(4, RoundingMode.HALF_UP);
+                }
+            }
+        }
+        return success(totalDeviceUtilization);
+    }
+
+    /**
+     * 瑞鹰 NPT 队伍数量
+     * @return
+     */
+    @GetMapping("/ry/device/nptCount")
+    @PermitAll
+    public CommonResult<List<NptCountVo>> nptCount(IotRyDailyReportPageReqVO reqVO) {
+        if (ObjUtil.isEmpty(reqVO.getCreateTime())) {
+            throw exception(IOT_DAILY_REPORT_TIME_NOT_EXISTS);
+        }
+        if (reqVO.getCreateTime().length < 2) {
+            throw exception(IOT_DAILY_REPORT_TIME_NOT_EXISTS);
+        }
+        // 计算公司整体的设备利用率
+        BigDecimal totalDeviceUtilization = BigDecimal.ZERO;
+        // 查询瑞鹰 158l 所有项目部
+        Set<Long> childDeptIds = deptService.getChildDeptIdListFromCache(158l);
+        Map<Long, DeptDO> allDeptPair = deptService.getDeptMap(childDeptIds);
+        Set<String> projectDeptNames = new HashSet<>();
+        Set<Long> projectDeptIds = new HashSet<>();
+        // key项目部id   value项目部名称
+        Map<Long, String> projectPair = new HashMap<>();
+        // key项目部id   value项目部包含的队伍id集合
+        Map<Long, Set<Long>> projectTeamPair = new HashMap<>();
+        // 队伍id 集合
+        Set<Long> crewIds = new HashSet<>();
+        if (CollUtil.isNotEmpty(allDeptPair)) {
+            allDeptPair.forEach((deptId, dept) -> {
+                if ("2".equals(dept.getType())) {
+                    projectDeptIds.add(deptId);
+                    projectDeptNames.add(dept.getName());
+                    projectPair.put(deptId, dept.getName());
+                }
+                if ("3".equals(dept.getType())) {
+                    // 队伍
+                    crewIds.add(dept.getId());
+                }
+            });
+            // 遍历所有部门
+            allDeptPair.forEach((deptId, dept) -> {
+                // 找出每个项目部下的队伍
+                if (projectPair.containsKey(dept.getParentId()) && 0==dept.getStatus()) {
+                    // 获得当前部门的上级项目部
+                    projectPair.forEach((projectDeptId, projectDept) -> {
+                        if (projectDeptId.equals(dept.getParentId())) {
+                            if (projectTeamPair.containsKey(projectDeptId)) {
+                                Set<Long> teamIds = projectTeamPair.get(projectDeptId);
+                                teamIds.add(deptId);
+                                projectTeamPair.put(projectDeptId, teamIds);
+                            } else {
+                                Set<Long> teamIds = new HashSet<>();
+                                teamIds.add(deptId);
+                                projectTeamPair.put(projectDeptId, teamIds);
+                            }
+                        }
+                    });
+                }
+            });
+        }
+        // 查询出指定时间区间内 已经填写的日报数量
+        // 瑞鹰区分 钻井 修井 日报
+        List<String> statuses = new ArrayList<>();
+        // statuses.add("dt");
+        // statuses.add("zx");
+        reqVO.setStatuses(statuses);
+        List<IotRyDailyReportDO> dailyReports = iotRyDailyReportMapper.dailyReports(reqVO);
+        // key项目部id     value项目部包含的队伍指定时间区域内日报数量
+        Map<Long, Integer> projectReportPair = new HashMap<>();
+        // 过滤掉 ‘设备保养、生产配合、待命’ 之外的非生产时间集合
+        Map<String, Integer> nptTeamPair = new HashMap<>();
+        List<NptCountVo> resultNptCounts = new ArrayList<>();
+        if (CollUtil.isNotEmpty(dailyReports)) {
+            // 整理出每个项目部下的队伍填报的日报数量
+            dailyReports.forEach(report -> {
+                if (CollUtil.isNotEmpty(projectTeamPair)) {
+                    projectTeamPair.forEach((projectDeptId, teamDeptIds) -> {
+                        if (teamDeptIds.contains(report.getDeptId())) {
+                            /* if (projectReportPair.containsKey(projectDeptId)) {
+                                Integer tempCount = projectReportPair.get(projectDeptId);
+                                projectReportPair.put(projectDeptId, ++tempCount);
+                            } else {
+                                projectReportPair.put(projectDeptId, 1);
+                            } */
+                            // 统计日报下的非生产时间集合
+                            BigDecimal accidentTime = report.getAccidentTime();
+                            if (ObjUtil.isNotEmpty(accidentTime) && accidentTime.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("工程质量")) {
+                                    Integer tempCount = nptTeamPair.get("工程质量");
+                                    nptTeamPair.put("工程质量", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("工程质量", 1);
+                                }
+                            }
+                            BigDecimal repairTime = report.getRepairTime();
+                            if (ObjUtil.isNotEmpty(repairTime) && repairTime.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("设备故障")) {
+                                    Integer tempCount = nptTeamPair.get("设备故障");
+                                    nptTeamPair.put("设备故障", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("设备故障", 1);
+                                }
+                            }
+                            BigDecimal complexityTime = report.getComplexityTime();
+                            if (ObjUtil.isNotEmpty(complexityTime) && complexityTime.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("技术受限")) {
+                                    Integer tempCount = nptTeamPair.get("技术受限");
+                                    nptTeamPair.put("技术受限", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("技术受限", 1);
+                                }
+                            }
+                            BigDecimal rectificationTime = report.getRectificationTime();
+                            if (ObjUtil.isNotEmpty(rectificationTime) && rectificationTime.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("生产组织")) {
+                                    Integer tempCount = nptTeamPair.get("生产组织");
+                                    nptTeamPair.put("生产组织", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("生产组织", 1);
+                                }
+                            }
+                            BigDecimal waitingStopTime = report.getWaitingStopTime();
+                            if (ObjUtil.isNotEmpty(waitingStopTime) && waitingStopTime.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("不可抗力")) {
+                                    Integer tempCount = nptTeamPair.get("不可抗力");
+                                    nptTeamPair.put("不可抗力", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("不可抗力", 1);
+                                }
+                            }
+                            BigDecimal partyaDesign = report.getPartyaDesign();
+                            if (ObjUtil.isNotEmpty(partyaDesign) && partyaDesign.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("甲方设计")) {
+                                    Integer tempCount = nptTeamPair.get("甲方设计");
+                                    nptTeamPair.put("甲方设计", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("甲方设计", 1);
+                                }
+                            }
+                            BigDecimal partyaPrepare = report.getPartyaPrepare();
+                            if (ObjUtil.isNotEmpty(partyaPrepare) && partyaPrepare.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("甲方准备")) {
+                                    Integer tempCount = nptTeamPair.get("甲方准备");
+                                    nptTeamPair.put("甲方准备", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("甲方准备", 1);
+                                }
+                            }
+                            BigDecimal partyaResource = report.getPartyaResource();
+                            if (ObjUtil.isNotEmpty(partyaResource) && partyaResource.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("甲方资源")) {
+                                    Integer tempCount = nptTeamPair.get("甲方资源");
+                                    nptTeamPair.put("甲方资源", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("甲方资源", 1);
+                                }
+                            }
+                            BigDecimal otherNptTime = report.getOtherNptTime();
+                            if (ObjUtil.isNotEmpty(otherNptTime) && otherNptTime.compareTo(BigDecimal.ZERO)>0) {
+                                if (nptTeamPair.containsKey("其它非生产时间")) {
+                                    Integer tempCount = nptTeamPair.get("其它非生产时间");
+                                    nptTeamPair.put("其它非生产时间", ++tempCount);
+                                } else {
+                                    nptTeamPair.put("其它非生产时间", 1);
+                                }
+                            }
+                        }
+                    });
+                }
+            });
+
+            if (CollUtil.isNotEmpty(nptTeamPair)) {
+                nptTeamPair.forEach((nptName, teamCount) -> {
+                    NptCountVo countVo = new NptCountVo();
+                    countVo.setNptName(nptName);
+                    countVo.setTeamCount(teamCount);
+                    resultNptCounts.add(countVo);
+                });
+            }
+        }
+        // 按照每种非生产时间队伍数量 降序排列
+        resultNptCounts.sort(Comparator.comparingInt(NptCountVo::getTeamCount).reversed());
+        return success(resultNptCounts);
+    }
+
     /**
      * 瑞鹰 设备利用率 按 队伍 统计
      * @return

+ 21 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/vo/NptCountVo.java

@@ -0,0 +1,21 @@
+package cn.iocoder.yudao.module.pms.controller.admin.stat.vo;
+
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * 生产异常 日报非生产时间 返回对象
+ */
+@Data
+@ToString(callSuper = true)
+public class NptCountVo {
+
+    /**
+     * 非生产时间名称
+     */
+    private String nptName;
+    /**
+     * 非生产时间队伍数量
+     */
+    private Integer teamCount;
+}