From 9363b7a09744b3003ad6163ac42591fe40c59c5e Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 14 三月 2024 15:50:06 +0800
Subject: [PATCH] 首页设备利用率和oee接口

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcHomeMapper.java                 |   55 +++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml         |   16 -
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcCommonVo.java                       |    3 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IEquipmentLogService.java         |    2 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcHomeMapper.xml              |   64 ++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcHomeController.java         |   85 ++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcHomeService.java              |   33 +++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/EquipmentLogServiceImpl.java |    5 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/EquipmentLogMapper.java            |    3 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/EquipmentLogMapper.xml         |   16 +
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java |   71 -------
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java     |  231 +++++++++++++++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java            |    2 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java         |    5 
 14 files changed, 495 insertions(+), 96 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcHomeController.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcHomeController.java
index 901b846..970da2f 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcHomeController.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcHomeController.java
@@ -11,6 +11,7 @@
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.mdc.constant.MdcConstant;
 import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.mdc.service.IMdcHomeService;
 import org.jeecg.modules.mdc.vo.MdcCommonVo;
 import org.jeecg.modules.system.entity.MdcProduction;
 import org.jeecg.modules.system.service.IMdcProductionService;
@@ -20,6 +21,7 @@
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Lius
@@ -37,6 +39,9 @@
 
     @Resource
     private IMdcProductionService mdcProductionService;
+
+    @Resource
+    private IMdcHomeService mdcHomeService;
 
     @ApiOperation(value = "MDC棣栭〉鎺ュ彛-璁惧杩愯鐘舵�佺粺璁�", notes = "MDC棣栭〉鎺ュ彛-璁惧杩愯鐘舵�佺粺璁�")
     @GetMapping("/equipmentStatusStatistics")
@@ -60,7 +65,85 @@
                 key = mdcProductionService.findFirstProduction(userId, mdcProduction.getId());
             }
         }
-        List<MdcCommonVo> resultMap = mdcEquipmentService.getEquipmentStatusStatistics(userId, key);
+        List<MdcCommonVo> resultMap = mdcHomeService.getEquipmentStatusStatistics(userId, key);
         return Result.OK(resultMap);
     }
+
+    @ApiOperation(value = "MDC棣栭〉鎺ュ彛-璁惧鍒╃敤鐜囩粺璁�(鏄ㄦ棩)", notes = "MDC棣栭〉鎺ュ彛-璁惧杩愯鐘舵�佺粺璁�(鏄ㄦ棩)")
+    @GetMapping("/equipmentUtilizationStatistics")
+    public Result<?> equipmentUtilizationStatistics(String productionCode) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        Integer userType = user.getUserType();
+        String userId = user.getId();
+        String key = "";
+        if (StringUtils.isNotBlank(productionCode)) {
+            //鍘傚尯
+            MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getProductionCode, productionCode).eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()));
+            key = mdcProduction.getId();
+        } else {
+            //鍒ゆ柇鏄叕鍙哥骇杩樻槸鍘傚尯
+            MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, ""));
+            if (userType.equals(MdcConstant.USER_TYPE_4)) {
+                //鍏徃
+                key = mdcProduction.getId();
+            } else if (userType.equals(MdcConstant.USER_TYPE_3)) {
+                //鍘傚尯
+                key = mdcProductionService.findFirstProduction(userId, mdcProduction.getId());
+            }
+        }
+        List<MdcCommonVo> result = mdcHomeService.getEquipmentUtilizationStatistics(userId, key);
+        return Result.OK(result);
+    }
+
+    @ApiOperation(value = "MDC棣栭〉鎺ュ彛-璁惧OEE缁熻(涓婃湀)", notes = "MDC棣栭〉鎺ュ彛-璁惧OEE缁熻(涓婃湀)")
+    @GetMapping("/equipmentOEEStatistics")
+    public Result<?> equipmentOEEStatistics(String productionCode) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        Integer userType = user.getUserType();
+        String userId = user.getId();
+        String key = "";
+        if (StringUtils.isNotBlank(productionCode)) {
+            //鍘傚尯
+            MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getProductionCode, productionCode).eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()));
+            key = mdcProduction.getId();
+        } else {
+            //鍒ゆ柇鏄叕鍙哥骇杩樻槸鍘傚尯
+            MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, ""));
+            if (userType.equals(MdcConstant.USER_TYPE_4)) {
+                //鍏徃
+                key = mdcProduction.getId();
+            } else if (userType.equals(MdcConstant.USER_TYPE_3)) {
+                //鍘傚尯
+                key = mdcProductionService.findFirstProduction(userId, mdcProduction.getId());
+            }
+        }
+        List<MdcCommonVo> result = mdcHomeService.getEquipmentOeeStatistics(userId, key);
+        return Result.OK(result);
+    }
+
+    @ApiOperation(value = "MDC棣栭〉鎺ュ彛-璁惧OEE鍜屽埄鐢ㄧ巼缁熻鏌辩姸鍥�", notes = "MDC棣栭〉鎺ュ彛-璁惧OEE鍜屽埄鐢ㄧ巼缁熻鏌辩姸鍥�")
+    @GetMapping("/equipmentMonthStatistics")
+    public Result<?> equipmentMonthStatistics(String productionCode) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        Integer userType = user.getUserType();
+        String userId = user.getId();
+        String key = "";
+        if (StringUtils.isNotBlank(productionCode)) {
+            //鍘傚尯
+            MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getProductionCode, productionCode).eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()));
+            key = mdcProduction.getId();
+        } else {
+            //鍒ゆ柇鏄叕鍙哥骇杩樻槸鍘傚尯
+            MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, ""));
+            if (userType.equals(MdcConstant.USER_TYPE_4)) {
+                //鍏徃
+                key = mdcProduction.getId();
+            } else if (userType.equals(MdcConstant.USER_TYPE_3)) {
+                //鍘傚尯
+                key = mdcProductionService.findFirstProduction(userId, mdcProduction.getId());
+            }
+        }
+        Map<String, Object> result = mdcHomeService.getEquipmentMonthStatistics(userId, key);
+        return Result.OK(result);
+    }
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/EquipmentLogMapper.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/EquipmentLogMapper.java
index cfa1ba1..69d4c80 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/EquipmentLogMapper.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/EquipmentLogMapper.java
@@ -5,6 +5,7 @@
 import org.jeecg.modules.mdc.entity.EquipmentLog;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * @author: LiuS
@@ -16,4 +17,6 @@
     EquipmentLog getRow(@Param("equipmentid") String equipmentid, @Param("startTime") Date startTime);
 
     EquipmentLog selectEquipmentOporation(@Param("equipmentId") String equipmentId);
+
+    List<EquipmentLog> getEquipmentStatusList(@Param("equipmentIdList") List<String> equipmentIdList);
 }
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 2c844a6..80991e7 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
@@ -9,7 +9,6 @@
 import org.jeecg.modules.mdc.dto.MdcEquDepDto;
 import org.jeecg.modules.mdc.dto.MdcEquProDto;
 import org.jeecg.modules.mdc.dto.MdcEquipmentDto;
-import org.jeecg.modules.mdc.entity.EquipmentLog;
 import org.jeecg.modules.mdc.entity.MdcEquipment;
 import org.jeecg.modules.mdc.entity.MdcEquipmentMonitor;
 import org.jeecg.modules.mdc.vo.MdcEquipmentDepVo;
@@ -118,5 +117,4 @@
     @InterceptorIgnore(tenantLine = "1")
     MdcEquipmentDto findWorkLineLast(@Param("tableName") String tableName);
 
-    List<EquipmentLog> getEquipmentStatusList(@Param("equipmentIdList") List<String> equipmentIdList);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcHomeMapper.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcHomeMapper.java
new file mode 100644
index 0000000..bae0b19
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcHomeMapper.java
@@ -0,0 +1,55 @@
+package org.jeecg.modules.mdc.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.system.entity.MdcProduction;
+import org.springframework.stereotype.Repository;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Lius
+ * @date 2024/3/14 10:27
+ */
+@Mapper
+@Repository
+public interface MdcHomeMapper {
+
+    /**
+     * 鏍规嵁鐢ㄦ埛id鍜屼笂绾т骇绾縤d鑾峰彇浜х嚎淇℃伅
+     *
+     * @param userId
+     * @param productionId
+     * @return
+     */
+    List<MdcProduction> getProductionByPid(@Param("userId") String userId, @Param("productionId") String productionId);
+
+    /**
+     * 鏍规嵁璁惧闆嗗悎鍜屾棩鏈熻幏鍙栧姞宸ユ椂闂�
+     *
+     * @param equipmentIdList
+     * @param date
+     * @return
+     */
+    BigDecimal getProcessCount(@Param("equipmentIdList") List<String> equipmentIdList, @Param("date") String date);
+
+    /**
+     * 鏍规嵁璁惧闆嗗悎鍜屾棩鏈熻幏鍙杘ee
+     *
+     * @param equipmentIdList
+     * @param date
+     * @return
+     */
+    BigDecimal getOeeByDate(@Param("equipmentIdList") List<String> equipmentIdList, @Param("date") String date);
+
+    /**
+     * 鏍规嵁璁惧id闆嗗悎鍜屾湀浠借幏鍙栧埄鐢ㄧ巼鏁版嵁
+     *
+     * @param equipmentIdList
+     * @param date
+     * @return
+     */
+    Map<String, Object> getUtilizationByMonth(@Param("equipmentIdList") List<String> equipmentIdList, @Param("date") String date);
+}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/EquipmentLogMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/EquipmentLogMapper.xml
index d31b630..42fffcd 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/EquipmentLogMapper.xml
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/EquipmentLogMapper.xml
@@ -9,4 +9,20 @@
     <select id="selectEquipmentOporation" resultType="org.jeecg.modules.mdc.entity.EquipmentLog">
         SELECT TOP 1 * FROM EquipmentLog WHERE EquipmentID = #{ equipmentId } ORDER BY CollectTime DESC
     </select>
+
+    <!--鏌ヨ璁惧鏈�鏂颁竴鏉℃暟鎹�-->
+    <select id="getEquipmentStatusList" resultType="org.jeecg.modules.mdc.entity.EquipmentLog">
+        SELECT
+        t1.*
+        FROM
+        EquipmentLog t1
+        INNER JOIN ( SELECT MAX ( CollectTime ) AS CollectTime, EquipmentID FROM EquipmentLog GROUP BY EquipmentID ) t2 ON t1.CollectTime= t2.CollectTime
+        AND t1.EquipmentID= t2.EquipmentID
+        <if test="equipmentIdList != null and equipmentIdList.size() > 0">
+            AND t1.EquipmentID IN
+            <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+    </select>
 </mapper>
\ No newline at end of file
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 480d71e..4e0ace6 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
@@ -286,20 +286,4 @@
         select top 1 spindlespeed, actualspindlespeed from [${tableName}] order by CollectTime  desc
     </select>
 
-    <!--鏌ヨ璁惧鏈�鏂颁竴鏉℃暟鎹�-->
-    <select id="getEquipmentStatusList" resultType="org.jeecg.modules.mdc.entity.EquipmentLog">
-        SELECT
-            t1.*
-        FROM
-            EquipmentLog t1
-            INNER JOIN ( SELECT MAX ( CollectTime ) AS CollectTime, EquipmentID FROM EquipmentLog GROUP BY EquipmentID ) t2 ON t1.CollectTime= t2.CollectTime
-            AND t1.EquipmentID= t2.EquipmentID
-        <if test="equipmentIdList != null and equipmentIdList.size() > 0">
-            AND t1.EquipmentID IN
-            <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")">
-                #{id}
-            </foreach>
-        </if>
-    </select>
-
 </mapper>
\ No newline at end of file
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcHomeMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcHomeMapper.xml
new file mode 100644
index 0000000..b358a64
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcHomeMapper.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.mdc.mapper.MdcHomeMapper">
+
+    <select id="getProductionByPid" resultType="org.jeecg.modules.system.entity.MdcProduction">
+        SELECT
+            t1.*
+        FROM
+            mdc_production t1
+                LEFT JOIN mdc_user_production t2 ON t1.id = t2.pro_id
+        WHERE
+            t1.parent_id = #{ productionId } AND t2.user_id = #{ userId }
+    </select>
+
+    <select id="getProcessCount" resultType="java.math.BigDecimal">
+        SELECT
+            SUM(process_long)
+        FROM
+            mdc_equipment_statistical_info
+        <where>
+            <if test="equipmentIdList != null and equipmentIdList.size() > 0 ">
+                AND equipment_id IN
+                <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")">
+                    #{id}
+                </foreach>
+            </if>
+            AND the_date = #{ date }
+        </where>
+    </select>
+
+    <select id="getOeeByDate" resultType="java.math.BigDecimal">
+        SELECT
+            SUM(overall_equipment_efficiency)
+        FROM
+            mdc_overall_equipment_efficiency
+        <where>
+            <if test="equipmentIdList != null and equipmentIdList.size() > 0 ">
+                AND equipment_id IN
+                <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")">
+                    #{id}
+                </foreach>
+            </if>
+            AND valid_date = #{ date }
+        </where>
+    </select>
+
+    <select id="getUtilizationByMonth" resultType="java.util.Map">
+        SELECT
+            SUM(process_long) processLong,
+            COUNT(*) processDay
+        FROM
+            mdc_equipment_statistical_info
+        <where>
+            <if test="equipmentIdList != null and equipmentIdList.size() > 0 ">
+                AND equipment_id IN
+                <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")">
+                    #{id}
+                </foreach>
+            </if>
+            AND the_date LIKE CONCAT('%', #{ date } ,'%')
+        </where>
+    </select>
+
+</mapper>
\ No newline at end of file
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IEquipmentLogService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IEquipmentLogService.java
index c98f2b1..805e454 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IEquipmentLogService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IEquipmentLogService.java
@@ -28,4 +28,6 @@
     EquipmentLog getRow(String equipmentid, Date startTime);
 
     EquipmentLog selectEquipmentOporation(String equipmentId);
+
+    List<EquipmentLog> getEquipmentStatusList(List<String> equipmentIdList);
 }
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 198b5fe..c523148 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
@@ -9,7 +9,6 @@
 import org.jeecg.modules.mdc.entity.MdcEquipment;
 import org.jeecg.modules.mdc.entity.MdcEquipmentMonitor;
 import org.jeecg.modules.mdc.model.MdcEquipmentTree;
-import org.jeecg.modules.mdc.vo.MdcCommonVo;
 import org.jeecg.modules.mdc.vo.MdcEquipmentVo;
 import org.jeecg.modules.mdc.vo.WorkshopEquipmentVo;
 
@@ -204,8 +203,4 @@
      */
     MdcEquipmentDto getWorkLineLast(String tableName);
 
-    /**
-     * 璁惧杩愯鐘舵�佺粺璁�
-     */
-    List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcHomeService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcHomeService.java
new file mode 100644
index 0000000..41759d8
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcHomeService.java
@@ -0,0 +1,33 @@
+package org.jeecg.modules.mdc.service;
+
+import org.jeecg.modules.mdc.vo.MdcCommonVo;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Lius
+ * @date 2024/3/14 9:51
+ */
+public interface IMdcHomeService {
+
+    /**
+     * 璁惧杩愯鐘舵�佺粺璁�
+     */
+    List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key);
+
+    /**
+     * 璁惧鍒╃敤鐜囩粺璁�
+     */
+    List<MdcCommonVo> getEquipmentUtilizationStatistics(String userId, String key);
+
+    /**
+     * 璁惧OEE缁熻
+     */
+    List<MdcCommonVo> getEquipmentOeeStatistics(String userId, String key);
+
+    /**
+     * 璁惧OEE鍜屽埄鐢ㄧ巼缁熻鏌辩姸鍥�
+     */
+    Map<String, Object> getEquipmentMonthStatistics(String userId, String key);
+}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/EquipmentLogServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/EquipmentLogServiceImpl.java
index 76de098..7a2da87 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/EquipmentLogServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/EquipmentLogServiceImpl.java
@@ -53,4 +53,9 @@
     public EquipmentLog selectEquipmentOporation(String equipmentId) {
         return this.baseMapper.selectEquipmentOporation(equipmentId);
     }
+
+    @Override
+    public List<EquipmentLog> getEquipmentStatusList(List<String> equipmentIdList) {
+        return this.baseMapper.getEquipmentStatusList(equipmentIdList);
+    }
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java
new file mode 100644
index 0000000..df3abeb
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java
@@ -0,0 +1,231 @@
+package org.jeecg.modules.mdc.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import org.jeecg.modules.mdc.entity.EquipmentLog;
+import org.jeecg.modules.mdc.mapper.MdcHomeMapper;
+import org.jeecg.modules.mdc.service.IEquipmentLogService;
+import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.mdc.service.IMdcHomeService;
+import org.jeecg.modules.mdc.util.DateUtils;
+import org.jeecg.modules.mdc.vo.MdcCommonVo;
+import org.jeecg.modules.mdc.vo.MdcEquipmentStatusVo;
+import org.jeecg.modules.system.entity.MdcProduction;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.util.*;
+
+/**
+ * @author Lius
+ * @date 2024/3/14 9:52
+ */
+@Service
+public class IMdcHomeServiceImpl implements IMdcHomeService {
+
+    @Resource
+    private IMdcEquipmentService mdcEquipmentService;
+
+    @Resource
+    private IEquipmentLogService equipmentLogService;
+
+    @Resource
+    private MdcHomeMapper mdcHomeMapper;
+
+    /**
+     * 璁惧杩愯鐘舵�佺粺璁�
+     */
+    @Override
+    public List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key) {
+        List<MdcCommonVo> result = new ArrayList<>();
+        MdcCommonVo mdcCommonVo1 = new MdcCommonVo();
+        mdcCommonVo1.setName("鍏虫満");
+        mdcCommonVo1.setValue("0");
+        result.add(mdcCommonVo1);
+        MdcCommonVo mdcCommonVo2 = new MdcCommonVo();
+        mdcCommonVo2.setName("鎶ヨ");
+        mdcCommonVo2.setValue("0");
+        result.add(mdcCommonVo2);
+        MdcCommonVo mdcCommonVo3 = new MdcCommonVo();
+        mdcCommonVo3.setName("寰呮満");
+        mdcCommonVo3.setValue("0");
+        result.add(mdcCommonVo3);
+        MdcCommonVo mdcCommonVo4 = new MdcCommonVo();
+        mdcCommonVo4.setName("杩愯");
+        mdcCommonVo4.setValue("0");
+        result.add(mdcCommonVo4);
+        MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo();
+        if (StringUtils.isBlank(key)) {
+            return result;
+        }
+        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
+        if (equipmentIdList == null || equipmentIdList.isEmpty()) {
+            return result;
+        }
+        List<EquipmentLog> logList = equipmentLogService.getEquipmentStatusList(equipmentIdList);
+        if (logList != null && !logList.isEmpty()) {
+            for (EquipmentLog equipmentLog : logList) {
+                if (equipmentLog.getOporation() != null) {
+                    switch (equipmentLog.getOporation()) {
+                        case 1:
+                        case 2:
+                            mdcEquipmentStatusVo.setWaitCount(mdcEquipmentStatusVo.getWaitCount() + 1);
+                            break;
+                        case 3:
+                            mdcEquipmentStatusVo.setRunCount(mdcEquipmentStatusVo.getRunCount() + 1);
+                            break;
+                        case 22:
+                            mdcEquipmentStatusVo.setAlarmCount(mdcEquipmentStatusVo.getAlarmCount() + 1);
+                            break;
+                        default:
+                            mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
+                            break;
+                    }
+                } else {
+                    mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
+                }
+            }
+        }
+        result.clear();
+        MdcCommonVo mdcCommonVo5 = new MdcCommonVo();
+        mdcCommonVo5.setName("鍏虫満");
+        mdcCommonVo5.setValue(mdcEquipmentStatusVo.getCloseCount().toString());
+        result.add(mdcCommonVo5);
+        MdcCommonVo mdcCommonVo6 = new MdcCommonVo();
+        mdcCommonVo6.setName("鎶ヨ");
+        mdcCommonVo6.setValue(mdcEquipmentStatusVo.getAlarmCount().toString());
+        result.add(mdcCommonVo6);
+        MdcCommonVo mdcCommonVo7 = new MdcCommonVo();
+        mdcCommonVo7.setName("寰呮満");
+        mdcCommonVo7.setValue(mdcEquipmentStatusVo.getWaitCount().toString());
+        result.add(mdcCommonVo7);
+        MdcCommonVo mdcCommonVo8 = new MdcCommonVo();
+        mdcCommonVo8.setName("杩愯");
+        mdcCommonVo8.setValue(mdcEquipmentStatusVo.getRunCount().toString());
+        result.add(mdcCommonVo8);
+        return result;
+    }
+
+    /**
+     * 璁惧鍒╃敤鐜囩粺璁�
+     */
+    @Override
+    public List<MdcCommonVo> getEquipmentUtilizationStatistics(String userId, String key) {
+        List<MdcCommonVo> result = new ArrayList<>();
+        //鑾峰彇鍏徃鎴栧巶鍖轰簩绾т俊鎭�
+        List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key);
+        if (mdcProductionList != null && !mdcProductionList.isEmpty()) {
+            for (MdcProduction mdcProduction : mdcProductionList) {
+                MdcCommonVo mdcCommonVo = new MdcCommonVo();
+                mdcCommonVo.setName(mdcProduction.getProductionName());
+                mdcCommonVo.setProductionCode(mdcProduction.getProductionCode());
+                //鑾峰彇姝ゅ眰绾т笅璁惧
+                List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId());
+                if (equipmentIdList == null || equipmentIdList.isEmpty()) {
+                    mdcCommonVo.setValue("0");
+                } else {
+                    String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
+                    BigDecimal processCount = mdcHomeMapper.getProcessCount(equipmentIdList, date);
+                    if (processCount == null || processCount.compareTo(BigDecimal.ZERO) == 0) {
+                        mdcCommonVo.setValue("0");
+                    } else {
+                        mdcCommonVo.setValue(processCount.divide(new BigDecimal(86400).multiply(new BigDecimal(equipmentIdList.size())), 4, RoundingMode.HALF_UP).toString());
+                    }
+                }
+                result.add(mdcCommonVo);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 璁惧OEE缁熻
+     */
+    @Override
+    public List<MdcCommonVo> getEquipmentOeeStatistics(String userId, String key) {
+        List<MdcCommonVo> result = new ArrayList<>();
+        //鑾峰彇鍏徃鎴栧巶鍖轰簩绾т俊鎭�
+        List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key);
+        if (mdcProductionList != null && !mdcProductionList.isEmpty()) {
+            for (MdcProduction mdcProduction : mdcProductionList) {
+                MdcCommonVo mdcCommonVo = new MdcCommonVo();
+                mdcCommonVo.setName(mdcProduction.getProductionName());
+                mdcCommonVo.setProductionCode(mdcProduction.getProductionCode());
+                //鑾峰彇姝ゅ眰绾т笅璁惧
+                List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId());
+                if (equipmentIdList == null || equipmentIdList.isEmpty()) {
+                    mdcCommonVo.setValue("0");
+                } else {
+                    String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH);
+                    BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, date);
+                    if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
+                        mdcCommonVo.setValue("0");
+                    } else {
+                        mdcCommonVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).toString());
+                    }
+                }
+                result.add(mdcCommonVo);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 璁惧OEE鍜屽埄鐢ㄧ巼缁熻鏌辩姸鍥�
+     */
+    @Override
+    public Map<String, Object> getEquipmentMonthStatistics(String userId, String key) {
+        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
+        Map<String, Object> result = new HashMap<>();
+        Date end = DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE);
+        Date start = DateUtils.toDate(LocalDate.now().plusMonths(-12).toString(), DateUtils.STR_DATE);
+        List<String> monthBetween = DateUtils.getMonthBetween(start, end);
+        List<String> dateList = new ArrayList<>();
+        List<MdcCommonVo> utilizationList = new ArrayList<>();
+        List<MdcCommonVo> oeeList = new ArrayList<>();
+        for (String month : monthBetween) {
+            //鏃ユ湡闆嗗悎
+            String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�";
+            dateList.add(name);
+            //鍒╃敤鐜囧拰oee
+            MdcCommonVo mdcCommonUtilizationVo = new MdcCommonVo();
+            mdcCommonUtilizationVo.setName(name);
+            MdcCommonVo mdcCommonOeeVo = new MdcCommonVo();
+            mdcCommonOeeVo.setName(name);
+            if (equipmentIdList == null || equipmentIdList.isEmpty()) {
+                mdcCommonUtilizationVo.setValue("0");
+                mdcCommonOeeVo.setValue("0");
+            } else {
+                //鍒╃敤鐜�
+                Map<String, Object> resultMap = mdcHomeMapper.getUtilizationByMonth(equipmentIdList, month.replace("-", ""));
+                if (resultMap != null && resultMap.get("processLong") != null) {
+                    BigDecimal processLong = BigDecimal.valueOf((Double) resultMap.get("processLong"));
+                    BigDecimal processDay = new BigDecimal((Integer) resultMap.get("processDay"));
+                    if (processLong.compareTo(BigDecimal.ZERO) == 0) {
+                        mdcCommonUtilizationVo.setValue("0");
+                    } else {
+                        mdcCommonUtilizationVo.setValue(processLong.divide(processDay, 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).toString());
+                    }
+                } else {
+                    mdcCommonUtilizationVo.setValue("0");
+                }
+
+                //OEE
+                BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, month);
+                if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
+                    mdcCommonOeeVo.setValue("0");
+                } else {
+                    mdcCommonOeeVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).toString());
+                }
+            }
+            utilizationList.add(mdcCommonUtilizationVo);
+            oeeList.add(mdcCommonOeeVo);
+        }
+        result.put("dateList", dateList);
+        result.put("utilizationList", utilizationList);
+        result.put("oeeList", oeeList);
+        return result;
+    }
+}
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 1e21981..33e6449 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
@@ -849,75 +849,4 @@
         return this.baseMapper.findWorkLineLast(tableName);
     }
 
-    /**
-     * 璁惧杩愯鐘舵�佺粺璁�
-     */
-    @Override
-    public List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key) {
-        List<MdcCommonVo> result = new ArrayList<>();
-        MdcCommonVo mdcCommonVo1 = new MdcCommonVo();
-        mdcCommonVo1.setName("鍏虫満");
-        mdcCommonVo1.setValue(0);
-        result.add(mdcCommonVo1);
-        MdcCommonVo mdcCommonVo2 = new MdcCommonVo();
-        mdcCommonVo2.setName("鎶ヨ");
-        mdcCommonVo2.setValue(0);
-        result.add(mdcCommonVo2);
-        MdcCommonVo mdcCommonVo3 = new MdcCommonVo();
-        mdcCommonVo3.setName("寰呮満");
-        mdcCommonVo3.setValue(0);
-        result.add(mdcCommonVo3);
-        MdcCommonVo mdcCommonVo4 = new MdcCommonVo();
-        mdcCommonVo4.setName("杩愯");
-        mdcCommonVo4.setValue(0);
-        result.add(mdcCommonVo4);
-        MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo();
-        List<String> equipmentIdList = this.getEquipmentIdsProduction(userId, key);
-        if (equipmentIdList == null || equipmentIdList.isEmpty()) {
-            return result;
-        }
-        List<EquipmentLog> logList = this.baseMapper.getEquipmentStatusList(equipmentIdList);
-        if (logList != null && !logList.isEmpty()) {
-            for (EquipmentLog equipmentLog : logList) {
-                if (equipmentLog.getOporation() != null) {
-                    switch (equipmentLog.getOporation()) {
-                        case 1:
-                        case 2:
-                            mdcEquipmentStatusVo.setWaitCount(mdcEquipmentStatusVo.getWaitCount() + 1);
-                            break;
-                        case 3:
-                            mdcEquipmentStatusVo.setRunCount(mdcEquipmentStatusVo.getRunCount() + 1);
-                            break;
-                        case 22:
-                            mdcEquipmentStatusVo.setAlarmCount(mdcEquipmentStatusVo.getAlarmCount() + 1);
-                            break;
-                        default:
-                            mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
-                            break;
-                    }
-                } else {
-                    mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
-                }
-            }
-        }
-        result.clear();
-        MdcCommonVo mdcCommonVo5 = new MdcCommonVo();
-        mdcCommonVo5.setName("鍏虫満");
-        mdcCommonVo5.setValue(mdcEquipmentStatusVo.getCloseCount());
-        result.add(mdcCommonVo5);
-        MdcCommonVo mdcCommonVo6 = new MdcCommonVo();
-        mdcCommonVo6.setName("鎶ヨ");
-        mdcCommonVo6.setValue(mdcEquipmentStatusVo.getAlarmCount());
-        result.add(mdcCommonVo6);
-        MdcCommonVo mdcCommonVo7 = new MdcCommonVo();
-        mdcCommonVo7.setName("寰呮満");
-        mdcCommonVo7.setValue(mdcEquipmentStatusVo.getWaitCount());
-        result.add(mdcCommonVo7);
-        MdcCommonVo mdcCommonVo8 = new MdcCommonVo();
-        mdcCommonVo8.setName("杩愯");
-        mdcCommonVo8.setValue(mdcEquipmentStatusVo.getRunCount());
-        result.add(mdcCommonVo8);
-        return result;
-    }
-
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcCommonVo.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcCommonVo.java
index d37ef5f..1f504c3 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcCommonVo.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcCommonVo.java
@@ -8,6 +8,7 @@
  */
 @Data
 public class MdcCommonVo {
-    private Integer value;
+    private String value;
     private String name;
+    private String productionCode;
 }

--
Gitblit v1.9.3