From 75d26035001d85c12dc3ca93455b0fee477c3f77 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期一, 03 三月 2025 16:47:58 +0800
Subject: [PATCH] 看板设备状态概况及月利用路趋势接口

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/impl/MdcLargeScreenServiceImpl.java           |  119 ++++++++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml                        |   36 +++-
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentStatisticalInfoMapper.xml         |   27 +++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/MdcLargeScreenService.java                    |   14 +
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java |   21 ++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/controller/MdcLargeScreenController.java              |   19 +-
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java                                      |   40 +++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonth.java                             |   23 +++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonthDto.java                          |   35 +++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentStatisticalInfoMapper.java            |    6 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentStatisticalInfoService.java         |   20 ++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java                |    6 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java                           |    4 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java                        |    4 
 14 files changed, 337 insertions(+), 37 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java
index 9be2447..dda4d65 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java
@@ -127,8 +127,8 @@
 
     /**
      * 鏍规嵁浜х嚎id鑾峰彇璁惧鐘舵�佸垪琛�
-     * @param workshopId
+     * @param productionId
      * @return
      */
-    List<MdcEquipmentMonitor> getEquipmentMonitorList(@Param("workshopId") String workshopId);
+    List<MdcEquipmentMonitor> getEquipmentMonitorList(@Param("productionId") String productionId);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentStatisticalInfoMapper.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentStatisticalInfoMapper.java
index c63deec..ccdc298 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentStatisticalInfoMapper.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentStatisticalInfoMapper.java
@@ -4,6 +4,8 @@
 import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo;
 
+import java.math.BigDecimal;
+
 /**
  * @Description: 璁惧鍗曟棩杩愯鏁版嵁琛�
  * @Author: jeecg-boot
@@ -27,4 +29,8 @@
     Integer selectProcessLong(@Param("equipmentId") String equipmentId, @Param("validDate") String validDate);
 
     MdcEquipmentStatisticalInfo findMdcEquipmentStatisticalInfo(@Param("equipmentId") String equipmentId, @Param("data") String data);
+
+    BigDecimal computeUtilizationMonth(@Param("productionId") String productionId, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    BigDecimal computeUtilizationMonthTotal(@Param("productionId") String productionId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
index 58aaf78..05d4b7d 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
@@ -281,19 +281,29 @@
 
     <!--鏍规嵁浜х嚎id鑾峰彇璁惧鐘舵�佸垪琛�-->
     <select id="getEquipmentMonitorList" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentMonitor">
-        SELECT e.equipment_id,
-               et.CollectTime,
-               e.equipment_name,
-               et.Oporation,
-               e.id,
-               e.equipment_status,
-               e.equipment_type AS equipmentType,
-               etp.equipment_type_pictures
-        FROM mdc_equipment e
-                 LEFT JOIN Equipment et ON e.equipment_id = et.EquipmentID
-                 LEFT JOIN mdc_equipment_type etp ON e.equipment_type = etp.equipment_type_name
-                 JOIN mdc_workshop_equipment we ON e.equipment_id = we.equipment_id
-        WHERE we.workshop_id = #{workshopId}
+        SELECT
+            t1.equipment_id,
+            t2.CollectTime,
+            t1.equipment_name,
+            t2.Oporation,
+            t1.id,
+            t1.equipment_status,
+            t1.equipment_type AS equipmentType,
+            t3.equipment_type_pictures
+        FROM
+            mdc_equipment t1
+                JOIN
+            mdc_workshop_equipment t4
+            ON t1.equipment_id = t4.equipment_id
+                JOIN
+            mdc_workshop_info t5
+            ON t4.workshop_id = t5.id AND t5.production_id = #{productionId}
+                LEFT JOIN
+            Equipment t2
+            ON t1.equipment_id = t2.EquipmentID
+                LEFT JOIN
+            mdc_equipment_type t3
+            ON t1.equipment_type = t3.equipment_type_name
     </select>
 
 </mapper>
\ No newline at end of file
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentStatisticalInfoMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentStatisticalInfoMapper.xml
index dc24767..0f53f20 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentStatisticalInfoMapper.xml
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentStatisticalInfoMapper.xml
@@ -16,4 +16,31 @@
     <select id="findMdcEquipmentStatisticalInfo" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo">
         SELECT TOP 1 * FROM mdc_equipment_statistical_info WHERE equipment_id = #{equipmentId} AND the_date = #{data}
     </select>
+
+    <select id="computeUtilizationMonth" resultType="java.math.BigDecimal">
+        SELECT
+            AVG(t1.process_long) AS processLong
+        FROM
+            mdc_equipment_statistical_info t1
+                INNER JOIN mdc_equipment t2
+                           ON t1.equipment_id = t2.equipment_id
+                INNER JOIN mdc_production_equipment t3
+                           ON t2.id = t3.equipment_id
+                               AND t3.production_id = #{productionId}
+        WHERE
+            t1.the_date BETWEEN #{startDate} AND #{endDate}
+    </select>
+
+    <select id="computeUtilizationMonthTotal" resultType="java.math.BigDecimal">
+        SELECT AVG
+               ( t1.process_long ) AS processLong
+        FROM
+            mdc_equipment_statistical_info t1
+                INNER JOIN mdc_equipment t2 ON t1.equipment_id = t2.equipment_id
+                INNER JOIN mdc_production_equipment t3 ON t2.id = t3.equipment_id
+                INNER JOIN mdc_production t4 ON t3.production_id = t4.id
+        WHERE
+            t4.parent_id = #{productionId}
+          AND t1.the_date BETWEEN #{startDate} AND #{endDate}
+    </select>
 </mapper>
\ No newline at end of file
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java
index 87a1a43..d6775c8 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java
@@ -213,8 +213,8 @@
     /**
      * 鏍规嵁浜х嚎id鑾峰彇璁惧鐘舵�佸垪琛�
      *
-     * @param workshopId
+     * @param productionId
      * @return
      */
-    List<MdcEquipmentMonitor> getEquipmentMonitorList(String workshopId);
+    List<MdcEquipmentMonitor> getEquipmentMonitorList(String productionId);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentStatisticalInfoService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentStatisticalInfoService.java
index 953b23f..9e5116a 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentStatisticalInfoService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentStatisticalInfoService.java
@@ -3,6 +3,8 @@
 import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.math.BigDecimal;
+
 /**
  * @Description: 璁惧鍗曟棩杩愯鏁版嵁琛�
  * @Author: lius
@@ -35,4 +37,22 @@
      * @return
      */
     MdcEquipmentStatisticalInfo findMdcEquipmentStatisticalInfo(String equipmentId, String date);
+
+    /**
+     * 璁$畻宸ユ鏈堝埄鐢ㄧ巼
+     * @param productionId
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    BigDecimal computeUtilizationMonth(String productionId, String startDate, String endDate);
+
+    /**
+     *
+     * @param productionId
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    BigDecimal computeUtilizationMonthTotal(String productionId, String startDate, String endDate);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
index 6c195c4..ee12d77 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -908,12 +908,12 @@
     /**
      * 鏍规嵁浜х嚎id鑾峰彇璁惧鐘舵�佸垪琛�
      *
-     * @param workshopId
+     * @param productionId
      * @return
      */
     @Override
-    public List<MdcEquipmentMonitor> getEquipmentMonitorList(String workshopId) {
-        return this.baseMapper.getEquipmentMonitorList(workshopId);
+    public List<MdcEquipmentMonitor> getEquipmentMonitorList(String productionId) {
+        return this.baseMapper.getEquipmentMonitorList(productionId);
     }
 
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
index 267b539..994ec9e 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
@@ -2,7 +2,6 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import io.swagger.models.auth.In;
 import org.apache.commons.lang.StringUtils;
 import org.jeecg.common.system.vo.DictModel;
 import org.jeecg.modules.mdc.entity.*;
@@ -99,6 +98,26 @@
         return this.baseMapper.findMdcEquipmentStatisticalInfo(equipmentId, date.replaceAll("-", ""));
     }
 
+    @Override
+    public BigDecimal computeUtilizationMonth(String productionId, String startDate, String endDate) {
+        BigDecimal processLong = this.baseMapper.computeUtilizationMonth(productionId, startDate, endDate);
+        if (processLong != null && processLong.compareTo(BigDecimal.ZERO) > 0) {
+            return processLong.divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP);
+        } else {
+            return BigDecimal.ZERO;
+        }
+    }
+
+    @Override
+    public BigDecimal computeUtilizationMonthTotal(String productionId, String startDate, String endDate) {
+        BigDecimal processLong = this.baseMapper.computeUtilizationMonthTotal(productionId, startDate, endDate);
+        if (processLong != null && processLong.compareTo(BigDecimal.ZERO) > 0) {
+            return processLong.divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP);
+        } else {
+            return BigDecimal.ZERO;
+        }
+    }
+
     private List<EquipmentStatisticalInfo> dataHandle(List<MdcEquipmentStatisticalInfo> list) {
         List<EquipmentStatisticalInfo> result = new ArrayList<>();
         list.forEach(item -> {
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
index 2c31126..0129bd6 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
@@ -1,8 +1,6 @@
 package org.jeecg.modules.mdc.util;
 
 
-import io.swagger.models.auth.In;
-
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
 import java.text.ParseException;
@@ -10,6 +8,8 @@
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.TextStyle;
 import java.time.temporal.ChronoField;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
@@ -1098,4 +1098,40 @@
 
         return formattedHours + "灏忔椂" + formattedMinutes + "鍒�" + formattedSeconds + "绉�";
     }
+
+
+    public static List<String[]> generateMonthlyDateRanges(String inputDate) {
+        List<String[]> dateRanges = new ArrayList<>();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
+
+        // 瑙f瀽浼犲叆鐨勬棩鏈�
+        LocalDate date = LocalDate.parse(inputDate, formatter);
+
+        // 濡傛灉褰撳墠鏃ユ湡鏄�18鍙锋垨涔嬪墠锛岀粨鏉熸棩鏈熸槸涓婁釜鏈堢殑18鍙�
+        LocalDate endDate = date.getDayOfMonth() <= 18
+                ? date.minusMonths(1).withDayOfMonth(18)
+                : date.withDayOfMonth(18);
+
+        // 寰幆鐢熸垚12涓湀鐨勬棩鏈熻寖鍥�
+        for (int i = 0; i < 12; i++) {
+            // 寮�濮嬫棩鏈燂細涓婁笂涓湀鐨�19鍙�
+            LocalDate startDate = endDate.minusMonths(1).withDayOfMonth(19);
+            String startDateStr = startDate.format(formatter);
+            String endDateStr = endDate.format(formatter);
+
+            // 鑾峰彇鏈堜唤鍚嶇О锛堝锛�2鏈堬級
+            String monthName = endDate.getMonth().getDisplayName(TextStyle.FULL, Locale.CHINA);
+
+            // 灏嗘棩鏈熻寖鍥村拰鏈堜唤鍚嶇О娣诲姞鍒伴泦鍚堜腑锛堝�掑簭鎻掑叆锛�
+            dateRanges.add(0, new String[]{startDateStr, endDateStr, monthName});
+
+            // 鍥為��鍒颁笂涓湀鐨�18鍙�
+            endDate = endDate.minusMonths(1).withDayOfMonth(18);
+        }
+
+        return dateRanges;
+    }
+
+
+
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/controller/MdcLargeScreenController.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/controller/MdcLargeScreenController.java
index 31b0207..d075732 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/controller/MdcLargeScreenController.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/controller/MdcLargeScreenController.java
@@ -11,6 +11,7 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.Map;
 
 /**
  * @Author: Lius
@@ -28,16 +29,18 @@
 
     @ApiOperation(value = "澶у睆鐪嬫澘-璁惧鎯呭喌", notes = "澶у睆鐪嬫澘-璁惧鎯呭喌")
     @GetMapping("/equipmentStatusOverview")
-    public Result<EquipmentStatusOverview> equipmentStatusOverview(String workshopId) {
-        EquipmentStatusOverview equipmentStatusOverview = mdcLargeScreenService.equipmentStatusOverview(workshopId);
+    public Result<EquipmentStatusOverview> equipmentStatusOverview(String productionId) {
+        EquipmentStatusOverview equipmentStatusOverview = mdcLargeScreenService.equipmentStatusOverview(productionId);
         return Result.OK(equipmentStatusOverview);
     }
 
-//    @ApiOperation(value = "澶у睆鐪嬫澘-鏈堝埄鐢ㄧ巼瓒嬪娍", notes = "澶у睆鐪嬫澘-鏈堝埄鐢ㄧ巼瓒嬪娍")
-//    @GetMapping("/monthUtilizationTendency")
-//    public Result<EquipmentStatusOverview> monthUtilizationTendency(String workshopId) {
-//
-//        return Result.OK(equipmentStatusOverview);
-//    }
+    @ApiOperation(value = "澶у睆鐪嬫澘-鏈堝埄鐢ㄧ巼瓒嬪娍", notes = "澶у睆鐪嬫澘-鏈堝埄鐢ㄧ巼瓒嬪娍")
+    @GetMapping("/monthUtilizationTendency")
+    public Result<Map<String, Object>> monthUtilizationTendency(String productionId) {
+        Map<String, Object> result = mdcLargeScreenService.monthUtilizationTendency(productionId);
+        return Result.OK(result);
+    }
+
+//    public Result<?> monthUtilizationTendency(String)
 
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonth.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonth.java
new file mode 100644
index 0000000..3cccda3
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonth.java
@@ -0,0 +1,23 @@
+package org.jeecg.modules.screen.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @Author: Lius
+ * @CreateTime: 2025-03-03
+ * @Description:
+ */
+@Data
+@ApiModel(value = "鏈堝埄鐢ㄧ巼resp", description = "鏈堝埄鐢ㄧ巼resp")
+public class UtilizationMonth {
+
+    @ApiModelProperty(value = "鏈堜唤")
+    private String month;
+
+    @ApiModelProperty(value = "鍒╃敤鐜�")
+    private BigDecimal utilizationRate = BigDecimal.ZERO;
+}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonthDto.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonthDto.java
new file mode 100644
index 0000000..bb52b5e
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/dto/UtilizationMonthDto.java
@@ -0,0 +1,35 @@
+package org.jeecg.modules.screen.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @Author: Lius
+ * @CreateTime: 2025-03-03
+ * @Description:
+ */
+@Data
+@ApiModel(value = "鏈堝埄鐢ㄧ巼resp", description = "鏈堝埄鐢ㄧ巼resp")
+public class UtilizationMonthDto {
+
+    /**
+     * 宸ユid
+     */
+    @ApiModelProperty(value = "宸ユid")
+    private String productionId = UUID.randomUUID().toString().replace("-", "");
+    /**
+     * 宸ユ鍚嶇О
+     */
+    @ApiModelProperty(value = "宸ユ鍚嶇О")
+    private String productionName;
+    /**
+     * 鏈堝埄鐢ㄧ巼
+     */
+    @ApiModelProperty(value = "鏈堝埄鐢ㄧ巼")
+    private List<UtilizationMonth> utilizationMonthList;
+
+}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/MdcLargeScreenService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/MdcLargeScreenService.java
index c09ee64..bf5a962 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/MdcLargeScreenService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/MdcLargeScreenService.java
@@ -2,6 +2,8 @@
 
 import org.jeecg.modules.screen.dto.EquipmentStatusOverview;
 
+import java.util.Map;
+
 /**
  * @Author: Lius
  * @CreateTime: 2025-02-28
@@ -12,8 +14,16 @@
     /**
      * 璁惧鎯呭喌
      *
-     * @param workshopId
+     * @param productionId
      * @return
      */
-    EquipmentStatusOverview equipmentStatusOverview(String workshopId);
+    EquipmentStatusOverview equipmentStatusOverview(String productionId);
+
+    /**
+     * 璁惧鏈堝埄鐢ㄧ巼瓒嬪娍
+     *
+     * @param productionId
+     * @return
+     */
+    Map<String, Object> monthUtilizationTendency(String productionId);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/impl/MdcLargeScreenServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/impl/MdcLargeScreenServiceImpl.java
index 5bb85fa..b33f90f 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/impl/MdcLargeScreenServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/screen/service/impl/MdcLargeScreenServiceImpl.java
@@ -1,16 +1,25 @@
 package org.jeecg.modules.screen.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.system.vo.DictModel;
 import org.jeecg.modules.mdc.entity.MdcEquipmentMonitor;
 import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.mdc.service.IMdcEquipmentStatisticalInfoService;
+import org.jeecg.modules.mdc.util.DateUtils;
 import org.jeecg.modules.screen.dto.EquipmentStatusOverview;
+import org.jeecg.modules.screen.dto.UtilizationMonth;
+import org.jeecg.modules.screen.dto.UtilizationMonthDto;
 import org.jeecg.modules.screen.service.MdcLargeScreenService;
+import org.jeecg.modules.system.entity.MdcProduction;
+import org.jeecg.modules.system.service.IMdcProductionService;
 import org.jeecg.modules.system.service.ISysDictService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @Author: Lius
@@ -26,16 +35,22 @@
     @Resource
     private ISysDictService sysDictService;
 
+    @Resource
+    private IMdcProductionService mdcProductionService;
+
+    @Resource
+    private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService;
+
     /**
      * 璁惧鐘舵�佹儏鍐�
      *
-     * @param workshopId
+     * @param productionId
      * @return
      */
     @Override
-    public EquipmentStatusOverview equipmentStatusOverview(String workshopId) {
+    public EquipmentStatusOverview equipmentStatusOverview(String productionId) {
         EquipmentStatusOverview equipmentStatusOverview = new EquipmentStatusOverview();
-        List<MdcEquipmentMonitor> equipmentMonitorList = mdcEquipmentService.getEquipmentMonitorList(workshopId);
+        List<MdcEquipmentMonitor> equipmentMonitorList = mdcEquipmentService.getEquipmentMonitorList(productionId);
         if (equipmentMonitorList != null && !equipmentMonitorList.isEmpty()) {
             equipmentStatusOverview.setEquipmentCount(equipmentMonitorList.size());
             for (MdcEquipmentMonitor mdcEquipmentMonitor : equipmentMonitorList) {
@@ -72,4 +87,100 @@
         }
         return equipmentStatusOverview;
     }
+
+    /**
+     * 璁惧鏈堝埄鐢ㄧ巼瓒嬪娍
+     *
+     * @param productionId
+     * @return
+     */
+    @Override
+    public Map<String, Object> monthUtilizationTendency(String productionId) {
+        Map<String, Object> result = new HashMap<>();
+
+        // 鑾峰彇瀛愮敓浜у垪琛�
+        List<MdcProduction> mdcProductionList = mdcProductionService.list(
+                new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, productionId)
+        );
+
+        if (mdcProductionList == null || mdcProductionList.isEmpty()) {
+            return result;
+        }
+
+        // 鐢熸垚鏈堝害鏃ユ湡鑼冨洿
+        List<String[]> dateLists = DateUtils.generateMonthlyDateRanges(DateUtils.format(new Date(), DateUtils.STRDATE));
+        List<String> dateList = dateLists.stream()
+                .map(array -> array[2]) // 鎻愬彇鏈堜唤鍚嶇О
+                .collect(Collectors.toList());
+        result.put("dateList", dateList);
+
+        // 璁$畻姣忎釜瀛愮敓浜х殑鏈堝害鍒╃敤鐜�
+        List<UtilizationMonthDto> utilizationMonthDtoList = mdcProductionList.stream()
+                .map(mdcProduction -> createUtilizationMonthDto(mdcProduction, dateLists))
+                .collect(Collectors.toList());
+
+        // 璁$畻鎬诲巶鐨勬湀搴﹀埄鐢ㄧ巼
+        UtilizationMonthDto totalUtilizationMonthDto = createTotalUtilizationMonthDto(productionId, dateLists);
+        utilizationMonthDtoList.add(totalUtilizationMonthDto);
+
+        result.put("dataList", utilizationMonthDtoList);
+        return result;
+    }
+
+    /**
+     * 鍒涘缓瀛愮敓浜х殑鏈堝害鍒╃敤鐜� DTO
+     */
+    private UtilizationMonthDto createUtilizationMonthDto(MdcProduction mdcProduction, List<String[]> dateLists) {
+        UtilizationMonthDto utilizationMonthDto = new UtilizationMonthDto();
+        utilizationMonthDto.setProductionId(mdcProduction.getId());
+        utilizationMonthDto.setProductionName(mdcProduction.getProductionName());
+
+        List<UtilizationMonth> utilizationMonthList = calculateUtilizationRates(mdcProduction.getId(), dateLists);
+        utilizationMonthDto.setUtilizationMonthList(utilizationMonthList);
+
+        return utilizationMonthDto;
+    }
+
+    /**
+     * 鍒涘缓鎬诲巶鐨勬湀搴﹀埄鐢ㄧ巼 DTO
+     */
+    private UtilizationMonthDto createTotalUtilizationMonthDto(String productionId, List<String[]> dateLists) {
+        UtilizationMonthDto utilizationMonthDto = new UtilizationMonthDto();
+        utilizationMonthDto.setProductionName("鎬诲巶");
+
+        List<UtilizationMonth> utilizationMonthList = calculateUtilizationRatesTotal(productionId, dateLists);
+        utilizationMonthDto.setUtilizationMonthList(utilizationMonthList);
+
+        return utilizationMonthDto;
+    }
+
+    /**
+     * 璁$畻瀛愮敓浜х殑鏈堝害鍒╃敤鐜�
+     */
+    private List<UtilizationMonth> calculateUtilizationRates(String productionId, List<String[]> dateLists) {
+        return dateLists.stream()
+                .map(dates -> {
+                    UtilizationMonth utilizationMonth = new UtilizationMonth();
+                    utilizationMonth.setMonth(dates[2]);
+                    BigDecimal utilizationRate = mdcEquipmentStatisticalInfoService.computeUtilizationMonth(productionId, dates[0], dates[1]);
+                    utilizationMonth.setUtilizationRate(utilizationRate);
+                    return utilizationMonth;
+                })
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * 璁$畻鎬诲巶鐨勬湀搴﹀埄鐢ㄧ巼
+     */
+    private List<UtilizationMonth> calculateUtilizationRatesTotal(String productionId, List<String[]> dateLists) {
+        return dateLists.stream()
+                .map(dates -> {
+                    UtilizationMonth utilizationMonth = new UtilizationMonth();
+                    utilizationMonth.setMonth(dates[2]);
+                    BigDecimal utilizationRate = mdcEquipmentStatisticalInfoService.computeUtilizationMonthTotal(productionId, dates[0], dates[1]);
+                    utilizationMonth.setUtilizationRate(utilizationRate);
+                    return utilizationMonth;
+                })
+                .collect(Collectors.toList());
+    }
 }

--
Gitblit v1.9.3