From db0cd1d60268811918f38a165052f94911f18e1e Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 11 四月 2024 15:26:06 +0800
Subject: [PATCH] 更新

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcHomeEfficiencyVo.java           |   32 ++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcHomeMapper.java             |   14 ++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcHomeMapper.xml          |   41 +++++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquipmentDayUtilizationVo.java     |    4 
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java |   61 ++++++++++++++++++--
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcHomeController.java     |   21 ++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcHomeService.java          |    6 ++
 7 files changed, 170 insertions(+), 9 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 65d39c8..2b64c30 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
@@ -14,6 +14,7 @@
 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.mdc.vo.MdcHomeEfficiencyVo;
 import org.jeecg.modules.system.entity.MdcProduction;
 import org.jeecg.modules.system.service.IMdcProductionService;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -73,7 +74,7 @@
         List<MdcCommonVo> resultMap = mdcHomeService.getEquipmentStatusStatistics(userId, key);
         Map<String, Object> map = new HashMap<>();
         map.put("list", resultMap);
-        map.put("producitonId", key);
+        map.put("productionId", key);
         return Result.OK(map);
     }
 
@@ -191,5 +192,23 @@
         return Result.OK(result);
     }
 
+    @ApiOperation(value = "MDC棣栭〉鎺ュ彛-宸ユ绾ц澶囨晥鐜囩粺璁�", notes = "MDC棣栭〉鎺ュ彛-宸ユ绾ц澶囨晥鐜囩粺璁�")
+    @GetMapping("/equipmentEfficiencyStatistics")
+    public Result<?> equipmentEfficiencyStatistics(String productionCode) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        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 {
+            //宸ユ 鏌ヨ鐢ㄦ埛鎷ユ湁鐨勫伐娈垫潈闄�
+            key = mdcProductionService.findThreeProductionId(userId);
+        }
+        MdcHomeEfficiencyVo result = mdcHomeService.getEquipmentEfficiencyStatistics(userId, key);
+        return Result.OK(result);
+    }
+
 
 }
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
index 79e3ebd..2f87dcb 100644
--- 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
@@ -73,4 +73,18 @@
      */
     List<MdcOverallEquipmentEfficiency> getEquipmentOEEMonthStatistics(@Param("validDate") String validDate, @Param("equipmentIdList") List<String> equipmentIdList);
 
+    /**
+     * 鑾峰彇鏄ㄥぉ鐨勫埄鐢ㄧ巼
+     *
+     * @param equipmentIdList
+     * @param date
+     * @return
+     */
+    MdcEquipmentStatisticalInfo getUtilizationByDay(@Param("equipmentIdList") List<String> equipmentIdList, @Param("date") String date);
+
+    /**
+     * 鏌ヨ鍓嶄竷澶╁埄鐢ㄧ巼
+     */
+    List<MdcEquipmentStatisticalInfo> getEquipmentSevenUtilizationStatistics(@Param("equipmentIdList") List<String> equipmentIdList, @Param("start") String start, @Param("end") String end);
+
 }
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
index ad5cadb..25e3308 100644
--- 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
@@ -102,4 +102,45 @@
         </where>
     </select>
 
+    <select id="getUtilizationByDay" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo">
+        SELECT
+            the_date,
+            SUM ( process_long ) processLong,
+            SUM ( open_long ) openLong
+        FROM
+            mdc_equipment_statistical_info
+        <where>
+            AND the_date = #{date}
+            <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>
+        </where>
+        GROUP BY
+            the_date
+    </select>
+
+    <select id="getEquipmentSevenUtilizationStatistics" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo">
+        SELECT
+            equipment_id,
+            SUM ( process_long ) processLong,
+            SUM ( open_long ) openLong
+        FROM
+            mdc_equipment_statistical_info
+        <where>
+            AND the_date BETWEEN #{start} AND #{end}
+            <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>
+        </where>
+        GROUP BY
+            equipment_id
+    </select>
+
+
 </mapper>
\ No newline at end of file
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
index aa3a799..9b52a4c 100644
--- 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
@@ -2,6 +2,7 @@
 
 import org.jeecg.modules.mdc.entity.MdcOverallEquipmentEfficiency;
 import org.jeecg.modules.mdc.vo.MdcCommonVo;
+import org.jeecg.modules.mdc.vo.MdcHomeEfficiencyVo;
 
 import java.util.List;
 import java.util.Map;
@@ -41,4 +42,9 @@
      * 鏌ヨ璁惧涓婃湀OEE
      */
     List<MdcOverallEquipmentEfficiency> getEquipmentOEEMonthStatistics(String userId, String key);
+
+    /**
+     * 宸ユ绾ц澶囨晥鐜�
+     */
+    MdcHomeEfficiencyVo getEquipmentEfficiencyStatistics(String userId, String key);
 }
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
index 9a9fe09..4507893 100644
--- 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
@@ -12,6 +12,7 @@
 import org.jeecg.modules.mdc.vo.EquipmentDayUtilizationVo;
 import org.jeecg.modules.mdc.vo.MdcCommonVo;
 import org.jeecg.modules.mdc.vo.MdcEquipmentStatusVo;
+import org.jeecg.modules.mdc.vo.MdcHomeEfficiencyVo;
 import org.jeecg.modules.system.entity.MdcProduction;
 import org.springframework.stereotype.Service;
 
@@ -241,9 +242,27 @@
         Map<String, Object> result = new HashMap<>();
         List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
         //鑾峰彇鍓嶄竷澶╂棩鏈熼泦鍚�
-        Date start = DateUtils.toDate(LocalDate.now().plusDays(-7).toString(), DateUtils.STR_DATE);
-        Date end = DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE);
-        List<String> dayBetween = DateUtils.getDatesStringList2(start, end);
+        String start = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-7).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
+        String end = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
+        if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
+            result.put("equipmentIdList", equipmentIdList);
+            List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfoList = mdcHomeMapper.getEquipmentSevenUtilizationStatistics(equipmentIdList, start, end);
+            List<EquipmentDayUtilizationVo> dataList = new ArrayList<>();
+            if (mdcEquipmentStatisticalInfoList != null && !mdcEquipmentStatisticalInfoList.isEmpty()) {
+                for (MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo : mdcEquipmentStatisticalInfoList) {
+                    EquipmentDayUtilizationVo equipmentDayUtilizationVo = new EquipmentDayUtilizationVo();
+                    equipmentDayUtilizationVo.setEquipmentId(mdcEquipmentStatisticalInfo.getEquipmentId());
+                    equipmentDayUtilizationVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(mdcEquipmentStatisticalInfoList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
+                    if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) {
+                        equipmentDayUtilizationVo.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
+                        equipmentDayUtilizationVo.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(mdcEquipmentStatisticalInfoList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
+                    }
+                    dataList.add(equipmentDayUtilizationVo);
+                }
+            }
+            result.put("dataList", dataList);
+        }
+        /*List<String> dayBetween = DateUtils.getDatesStringList2(start, end);
         List<String> dateList = new ArrayList<>();
         List<EquipmentDayUtilizationVo> dataList = new ArrayList<>();
         for (String date : dayBetween) {
@@ -260,9 +279,9 @@
             } else {
                 String sub = item.substring(2);
                 if (sub.startsWith("0")) {
-                    item = item.substring(0, 2) +  "鏈�" + sub.substring(2) + "鏃�";
+                    item = item.substring(0, 2) + "鏈�" + sub.substring(2) + "鏃�";
                 } else {
-                    item = item.substring(0, 2) +  "鏈�" + item.substring(2) + "鏃�";
+                    item = item.substring(0, 2) + "鏈�" + item.substring(2) + "鏃�";
                 }
             }
             dateList.add(item);
@@ -288,7 +307,7 @@
             }
         }
         result.put("dateList", dateList);
-        result.put("dataList", dataList);
+        result.put("dataList", dataList);*/
         return result;
     }
 
@@ -305,4 +324,34 @@
         }
         return result;
     }
+
+    /**
+     * 宸ユ绾ц澶囨晥鐜�
+     */
+    @Override
+    public MdcHomeEfficiencyVo getEquipmentEfficiencyStatistics(String userId, String key) {
+        MdcHomeEfficiencyVo result = new MdcHomeEfficiencyVo();
+        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
+        if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
+            // 鑾峰彇鍒╃敤鐜囨暟鎹�
+            String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
+            MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcHomeMapper.getUtilizationByDay(equipmentIdList, date);
+            if (mdcEquipmentStatisticalInfo != null) {
+                result.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
+                if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) {
+                    result.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
+                    result.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
+                }
+            }
+            //鑾峰彇OEE鏁版嵁
+            String month = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH);
+            BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, month);
+            if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
+                result.setOverallEquipmentEfficiency(BigDecimal.ZERO);
+            } else {
+                result.setOverallEquipmentEfficiency(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
+            }
+        }
+        return result;
+    }
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquipmentDayUtilizationVo.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquipmentDayUtilizationVo.java
index e3e18fb..c634d10 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquipmentDayUtilizationVo.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquipmentDayUtilizationVo.java
@@ -11,9 +11,9 @@
 @Data
 public class EquipmentDayUtilizationVo {
     /**
-     * 鏃ユ湡
+     * 璁惧缂栧彿
      */
-    private String date;
+    private String equipmentId;
     /**
      * 鍒╃敤鐜�
      */
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcHomeEfficiencyVo.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcHomeEfficiencyVo.java
new file mode 100644
index 0000000..7a4df18
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcHomeEfficiencyVo.java
@@ -0,0 +1,32 @@
+package org.jeecg.modules.mdc.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @author Lius
+ * @date 2024/4/11 9:29
+ */
+@Data
+public class MdcHomeEfficiencyVo {
+    /**
+     * 鍒╃敤鐜�
+     */
+    private BigDecimal utilizationRate = BigDecimal.ZERO;
+    /**
+     * 寮�鍔ㄧ巼
+     */
+    private BigDecimal startRate = BigDecimal.ZERO;
+    /**
+     * 寮�鏈虹巼
+     */
+    private BigDecimal openRate = BigDecimal.ZERO;
+    /**
+     * OEE
+     */
+    private BigDecimal overallEquipmentEfficiency = BigDecimal.ZERO;
+
+
+
+}

--
Gitblit v1.9.3