From 80cabc1fec87b8f8cf8026ae1a5c14aa2cab4527 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 08 五月 2025 17:52:11 +0800
Subject: [PATCH] update

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcBoardServiceImpl.java |  142 ++++++++++++++++++++++++++--------------------
 1 files changed, 80 insertions(+), 62 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcBoardServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcBoardServiceImpl.java
index a3bb917..468d909 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcBoardServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcBoardServiceImpl.java
@@ -2,11 +2,13 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.sun.org.apache.bcel.internal.generic.NEW;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.modules.mdc.constant.MdcConstant;
 import org.jeecg.modules.mdc.entity.Equipment;
 import org.jeecg.modules.mdc.entity.MdcEquipment;
 import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo;
+import org.jeecg.modules.mdc.entity.MdcOeeInfo;
 import org.jeecg.modules.mdc.service.*;
 import org.jeecg.modules.mdc.util.DateUtils;
 import org.jeecg.modules.mdc.vo.MdcBoardRateVo;
@@ -58,10 +60,6 @@
         if (StringUtils.isBlank(productionId)) {
             MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getParentId, ""));
             productionId = mdcProduction.getId();
-            result.put("productionName", mdcProduction.getProductionName());
-        } else {
-            MdcProduction mdcProduction = mdcProductionService.getById(productionId);
-            result.put("productionName", mdcProduction.getProductionName());
         }
         List<String> proIds = mdcProductionService.findChildByProId(productionId);
         if (proIds == null || proIds.isEmpty()) {
@@ -132,29 +130,50 @@
         LocalDate now = LocalDate.now();
         Date startDate = DateUtils.toDate(now.plusDays(-15).toString(), DateUtils.STR_DATE);
         Date endDate = DateUtils.toDate(now.plusDays(-1).toString(), DateUtils.STR_DATE);
+        String start = DateUtils.format(startDate, DateUtils.STR_DATE);
+        String end = DateUtils.format(endDate, DateUtils.STR_DATE);
         List<String> dateList = DateUtils.getDatesStringList(startDate, endDate);
-        List<String> dates = new ArrayList<>();
-        List<MdcBoardRateVo> dataList = new ArrayList<>();
-        for (String date : dateList) {
-            MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo();
-            String s = date.substring(5, 10);
-            dates.add(s);
-            mdcBoardRateVo.setDate(s);
-            // TEEP 寮�鏈虹巼 寮�鍔ㄧ巼
-            MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquipmentAndDate(equipmentIdList, date.replaceAll("-", ""));
-            mdcBoardRateVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
-            mdcBoardRateVo.setOpenRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
-            if (mdcEquipmentStatisticalInfo.getOpenLong().compareTo(BigDecimal.ZERO) > 0) {
-                mdcBoardRateVo.setStartRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
-            }
-            // OEE
-            BigDecimal oee = mdcOeeInfoService.findByEquIdsAndDate(equipmentIdList, date);
-            if (oee != null) {
-                mdcBoardRateVo.setOee(oee.setScale(2, RoundingMode.HALF_UP));
-            }
-            dataList.add(mdcBoardRateVo);
-        }
+        List<String> dates = dateList.stream().map(date -> date.substring(5, 10)).collect(Collectors.toList());
         result.put("dateList", dates);
+        Map<String, MdcBoardRateVo> statisticsMap = new LinkedHashMap<>();
+        dateList.forEach(date -> {
+            statisticsMap.put(date, new MdcBoardRateVo(date.substring(5, 10)));
+        });
+
+        // TEEP 寮�鏈虹巼 寮�鍔ㄧ巼
+        List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquipmentAndDate(equipmentIdList, start.replaceAll("-", ""), end.replaceAll("-", ""));
+        if (mdcEquipmentStatisticalInfo != null && !mdcEquipmentStatisticalInfo.isEmpty()) {
+            mdcEquipmentStatisticalInfo.forEach(equipmentStatisticalInfo -> {
+                String date = DateUtils.format(DateUtils.toDate(equipmentStatisticalInfo.getTheDate(), DateUtils.STRDATE), DateUtils.STR_DATE);
+                if (statisticsMap.containsKey(date)) {
+                    MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(date);
+                    if (equipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) {
+                        mdcBoardRateVo.setUtilizationRate(equipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
+                    }
+                    if (equipmentStatisticalInfo.getOpenLong().compareTo(BigDecimal.ZERO) > 0) {
+                        mdcBoardRateVo.setOpenRate(equipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
+                    }
+                    if (equipmentStatisticalInfo.getOpenLong().compareTo(BigDecimal.ZERO) > 0) {
+                        mdcBoardRateVo.setStartRate(equipmentStatisticalInfo.getProcessLong().multiply(new BigDecimal("100").divide(equipmentStatisticalInfo.getOpenLong(), 2, RoundingMode.HALF_UP)));
+                    }
+                    statisticsMap.put(date, mdcBoardRateVo);
+                }
+            });
+        }
+        // OEE
+        List<MdcOeeInfo> oeeInfo = mdcOeeInfoService.findByEquIdsAndDate(equipmentIdList, start, end);
+        if (oeeInfo != null && !oeeInfo.isEmpty()) {
+            oeeInfo.forEach(mdcOeeInfo -> {
+                if (statisticsMap.containsKey(mdcOeeInfo.getTheDate())) {
+                    MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(mdcOeeInfo.getTheDate());
+                    if (mdcOeeInfo.getOee().compareTo(BigDecimal.ZERO) > 0) {
+                        mdcBoardRateVo.setOee(mdcOeeInfo.getOee().setScale(2, RoundingMode.HALF_UP));
+                    }
+                    statisticsMap.put(mdcOeeInfo.getTheDate(), mdcBoardRateVo);
+                }
+            });
+        }
+        List<MdcBoardRateVo> dataList = new ArrayList<>(statisticsMap.values());
         result.put("dataList", dataList);
         return result;
     }
@@ -180,25 +199,44 @@
         LocalDate now = LocalDate.now();
         Date startDate = DateUtils.toDate(now.plusDays(-7).toString(), DateUtils.STR_DATE);
         Date endDate = DateUtils.toDate(now.plusDays(-1).toString(), DateUtils.STR_DATE);
+        String start = DateUtils.format(startDate, DateUtils.STR_DATE);
+        String end = DateUtils.format(endDate, DateUtils.STR_DATE);
         List<String> dayBetween = DateUtils.getDatesStringList(startDate, endDate);
-        List<String> dateList = new ArrayList<>();
-        List<MdcBoardRateVo> dataList = new ArrayList<>();
-        for (String date : dayBetween) {
-            MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo();
-            String s = date.substring(5, 10);
-            dateList.add(s);
-            mdcBoardRateVo.setDate(s);
-            // TEEP
-            MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdAndDate(equipmentId, date.replaceAll("-", ""));
-            mdcBoardRateVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
-            // OEE
-            BigDecimal oee = mdcOeeInfoService.findByEquIdAndDate(equipmentId, date);
-            if (oee != null) {
-                mdcBoardRateVo.setOee(oee.setScale(2, RoundingMode.HALF_UP));
-            }
-            dataList.add(mdcBoardRateVo);
-        }
+        List<String> dateList = dayBetween.stream().map(date -> date.substring(5, 10)).collect(Collectors.toList());
         result.put("dateList", dateList);
+        Map<String, MdcBoardRateVo> statisticsMap = new LinkedHashMap<>();
+        dayBetween.forEach(date -> {
+            statisticsMap.put(date, new MdcBoardRateVo(date.substring(5, 10)));
+        });
+        // TEEP
+        List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdAndDate(equipmentId, start.replaceAll("-", ""), end.replaceAll("-", ""));
+        if (mdcEquipmentStatisticalInfo != null && !mdcEquipmentStatisticalInfo.isEmpty()) {
+            mdcEquipmentStatisticalInfo.forEach(equipmentStatisticalInfo -> {
+                String date = DateUtils.format(DateUtils.toDate(equipmentStatisticalInfo.getTheDate(), DateUtils.STRDATE), DateUtils.STR_DATE);
+                if (statisticsMap.containsKey(date)) {
+                    MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(date);
+                    if (equipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) {
+                        mdcBoardRateVo.setUtilizationRate(equipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP));
+                    }
+                    statisticsMap.put(date, mdcBoardRateVo);
+                }
+            });
+        }
+        // OEE
+        List<MdcOeeInfo> oeeInfo = mdcOeeInfoService.findByEquIdAndDate(equipmentId, start, end);
+        if (oeeInfo != null && !oeeInfo.isEmpty()) {
+            oeeInfo.forEach(mdcOeeInfo -> {
+                if (statisticsMap.containsKey(mdcOeeInfo.getTheDate())) {
+                    MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(mdcOeeInfo.getTheDate());
+                    if (mdcOeeInfo.getOee().compareTo(BigDecimal.ZERO) > 0) {
+                        mdcBoardRateVo.setOee(mdcOeeInfo.getOee().setScale(2, RoundingMode.HALF_UP));
+                    }
+                    statisticsMap.put(mdcOeeInfo.getTheDate(), mdcBoardRateVo);
+                }
+            });
+        }
+
+        List<MdcBoardRateVo> dataList = new ArrayList<>(statisticsMap.values());
         result.put("dataList", dataList);
         return result;
     }
@@ -242,24 +280,4 @@
         return result;
     }
 
-//    /**
-//     * 璁惧浜у搧鍚堟牸鐜�
-//     */
-//    @Override
-//    public Map<String, Object> passRate(String equipmentId) {
-//        Map<String, Object> result = new HashMap<>();
-//        LocalDate now = LocalDate.now();
-//        Date start = DateUtils.toDate(now.plusMonths(-6).toString(), DateUtils.STR_DATE);
-//        Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE);
-//        List<String> monthBetween = DateUtils.getMonthBetween(start, end);
-//        List<String> dateList = new ArrayList<>();
-//        for (String month : monthBetween) {
-//            String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�";
-//            dateList.add(name);
-//            MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo();
-//            // 鍚堟牸鐜�
-//
-//        }
-//        return result;
-//    }
 }

--
Gitblit v1.9.3