From 2f0009c750de4d47a18cce4a5a403fa83ba0c209 Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期三, 02 七月 2025 08:58:27 +0800
Subject: [PATCH] feat(report): 新增设备稼动率统计功能

---
 eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/service/impl/ReportServiceImpl.java |   90 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/service/impl/ReportServiceImpl.java b/eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/service/impl/ReportServiceImpl.java
index ce7d9a2..d103bce 100644
--- a/eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/service/impl/ReportServiceImpl.java
+++ b/eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/service/impl/ReportServiceImpl.java
@@ -1,9 +1,11 @@
 package org.dromara.eims.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
+import org.dromara.common.core.utils.DateUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -274,12 +276,23 @@
                 order -> String.valueOf(order.getPlanTime().toInstant()
                     .atZone(ZoneId.systemDefault())
                     .toLocalDate().getMonthValue()),
-                // 鎸夋湀浠藉垎缁勫悗锛屽垽鏂鏈堟槸鍚﹀叏閮╯tatus=3
                 Collectors.collectingAndThen(
                     Collectors.toList(),
-                    orders -> orders.stream().allMatch(o -> o.getStatus().equals("3"))
-                        ? "宸插畬鎴�"
-                        : "鏈畬鎴�"
+                    orders -> {
+                        boolean allZero = orders.stream().allMatch(o -> o.getStatus().equals("0"));
+                        if (allZero) {
+                            return MAINT_0; // 寰呬繚鍏�
+                        }
+                        boolean allGtOne = orders.stream().allMatch(o -> Integer.parseInt(o.getStatus()) > 1);
+                        if (allGtOne) {
+                            return MAINT_2; // 寰呴獙璇�
+                        }
+                        boolean allGtTwo = orders.stream().allMatch(o -> Integer.parseInt(o.getStatus()) > 2);
+                        if (allGtTwo) {
+                            return MAINT_3; // 宸插畬鎴�
+                        }
+                        return "淇濆吇涓�";
+                    }
                 )
             ));
         Map<String, EimsMaintPlan> planMap = equMaintPlanList.stream()
@@ -295,7 +308,7 @@
         for (int month = 1; month <= monthInYear; month++) {
             String monthKey = "month_" + month;
             if (planMap.containsKey(String.valueOf(month))) {
-                item.put(monthKey, UNCHECKED);
+                item.put(monthKey, MAINT_0);
             } else if (orderMap.containsKey(String.valueOf(month))) {
                 String result  = orderMap.get(String.valueOf(month));
                 item.put(monthKey, result);
@@ -307,4 +320,71 @@
 
         return item;
     }
+
+    @Override
+    public TableDataInfo<Map<String, Object>> queryEquEfficiencyList(Map<String, Object> queryParams, PageQuery pageQuery) {
+        Integer selectYear = getYearFromParams(queryParams);
+        String start = Year.of(selectYear).atDay(1).toString(); // yyyy-MM-dd
+        String end = Year.of(selectYear).atDay(Year.of(selectYear).length()).toString();
+
+        List<Map<String, Object>> statList = inspectStMapper.statEquEfficiency(start, end);
+
+        // 缁勮缁熻缁撴灉
+        Map<Integer, Integer> runTimes = new HashMap<>();
+        Map<Integer, Integer> faultTimes = new HashMap<>();
+        Map<Integer, Integer> totalTimes = new HashMap<>();
+        int runTotal = 0, faultTotal = 0, totalTotal = 0;
+
+        for (Map<String, Object> row : statList) {
+            int month = Integer.parseInt(row.get("month").toString());
+            int run = row.get("runTimes") == null ? 0 : Integer.parseInt(row.get("runTimes").toString());
+            int fault = row.get("faultTimes") == null ? 0 : Integer.parseInt(row.get("faultTimes").toString());
+            int total = run + fault;
+            runTimes.put(month, run);
+            faultTimes.put(month, fault);
+            totalTimes.put(month, total);
+            runTotal += run;
+            faultTotal += fault;
+            totalTotal += total;
+        }
+
+        // 缁勮杩斿洖鏁版嵁锛堝悓鍓嶏級
+        String targetValue = "98.00%";
+        List<Map<String, Object>> resultList = new ArrayList<>();
+        Map<String, Object> row1 = new LinkedHashMap<>(); // 姝e父杩愯浆鏃堕棿
+        Map<String, Object> row2 = new LinkedHashMap<>(); // 鎬昏繍杞椂闂�
+        Map<String, Object> row3 = new LinkedHashMap<>(); // 鏁呴殰鏃堕棿
+        Map<String, Object> row4 = new LinkedHashMap<>(); // 鐩爣鍊�
+        Map<String, Object> row5 = new LinkedHashMap<>(); // 姝e父杩愯浆鐜囷紙绋煎姩鐜囷級
+
+        row1.put("item", "姝e父杩愯浆鏃堕棿");
+        row2.put("item", "鎬昏繍杞椂闂�");
+        row3.put("item", "鏁呴殰鏃堕棿");
+        row4.put("item", "鐩爣鍊�");
+        row5.put("item", "姝e父杩愯浆鐜囷紙绋煎姩鐜囷級");
+
+        for (int m = 1; m <= 12; m++) {
+            row1.put(m + "鏈�", runTimes.getOrDefault(m, 0));
+            row2.put(m + "鏈�", totalTimes.getOrDefault(m, 0));
+            row3.put(m + "鏈�", faultTimes.getOrDefault(m, 0));
+            row4.put(m + "鏈�", targetValue);
+            int run = runTimes.getOrDefault(m, 0);
+            int total = totalTimes.getOrDefault(m, 0);
+            String eff = total > 0 ? String.format("%.2f%%", run * 100.0 / total) : "-";
+            row5.put(m + "鏈�", eff);
+        }
+        row1.put("total", runTotal);
+        row2.put("total", totalTotal);
+        row3.put("total", faultTotal);
+        row4.put("total", targetValue);
+        row5.put("total", totalTotal > 0 ? String.format("%.2f%%", runTotal * 100.0 / totalTotal) : "-");
+
+        resultList.add(row1);
+        resultList.add(row2);
+        resultList.add(row3);
+        resultList.add(row4);
+        resultList.add(row5);
+
+        return TableDataInfo.build(resultList);
+    }
 }

--
Gitblit v1.9.3