From d4c42dade56ff6c2bd5ca83819f8a8f56430e682 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 16 五月 2024 11:18:37 +0800
Subject: [PATCH] 问题反馈

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 288 insertions(+), 12 deletions(-)

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 25b9414..6968763 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
@@ -1,15 +1,18 @@
 package org.jeecg.modules.mdc.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import org.jeecg.modules.mdc.entity.EquipmentLog;
+import org.jeecg.common.system.vo.DictModel;
+import org.jeecg.modules.mdc.constant.MdcConstant;
+import org.jeecg.modules.mdc.dto.MdcEquipmentDto;
+import org.jeecg.modules.mdc.entity.*;
 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.service.*;
 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.mdc.vo.*;
 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;
@@ -29,10 +32,25 @@
     private IMdcEquipmentService mdcEquipmentService;
 
     @Resource
-    private IEquipmentLogService equipmentLogService;
+    private IEquipmentService equipmentService;
+
+    @Resource
+    private ISysDictService sysDictService;
+
+    @Resource
+    private IEquipmentWorkLineService equipmentWorkLineService;
 
     @Resource
     private MdcHomeMapper mdcHomeMapper;
+
+    @Resource
+    private IMdcProductionService mdcProductionService;
+
+    @Resource
+    private IEquipmentLogService equipmentLogService;
+
+    @Resource
+    private IMdcFeedbackService mdcFeedbackService;
 
     /**
      * 璁惧杩愯鐘舵�佺粺璁�
@@ -64,11 +82,12 @@
         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()) {
+//        List<EquipmentLog> logList = equipmentLogService.getEquipmentStatusList(equipmentIdList);
+        List<Equipment> equipmentList = equipmentService.list(new LambdaQueryWrapper<Equipment>().in(Equipment::getEquipmentid, equipmentIdList));
+        if (equipmentList != null && !equipmentList.isEmpty()) {
+            for (Equipment equipment : equipmentList) {
+                if (equipment.getOporation() != null) {
+                    switch (equipment.getOporation()) {
                         case 1:
                         case 2:
                             mdcEquipmentStatusVo.setWaitCount(mdcEquipmentStatusVo.getWaitCount() + 1);
@@ -138,6 +157,9 @@
                 result.add(mdcCommonVo);
             }
         }
+        if (!result.isEmpty()) {
+            result.sort(Comparator.comparing(MdcCommonVo::getValue).reversed());
+        }
         return result;
     }
 
@@ -154,6 +176,7 @@
                 MdcCommonVo mdcCommonVo = new MdcCommonVo();
                 mdcCommonVo.setName(mdcProduction.getProductionName());
                 mdcCommonVo.setProductionCode(mdcProduction.getProductionCode());
+                mdcCommonVo.setProductionId(mdcProduction.getId());
                 //鑾峰彇姝ゅ眰绾т笅璁惧
                 List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId());
                 if (equipmentIdList == null || equipmentIdList.isEmpty()) {
@@ -229,4 +252,257 @@
         result.put("oeeList", oeeList);
         return result;
     }
+
+    /**
+     * 宸ユ绾у墠涓冨ぉ鍒╃敤鐜囨姌绾垮浘
+     */
+    @Override
+    public Map<String, Object> getEquipmentDayUtilizationStatistics(String userId, String key) {
+        Map<String, Object> result = new HashMap<>();
+        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
+        //鑾峰彇鍓嶄竷澶╂棩鏈熼泦鍚�
+        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()) {
+            List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().in(MdcEquipment::getEquipmentId, equipmentIdList));
+            result.put("mdcEquipmentList", mdcEquipmentList);
+            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) {
+            EquipmentDayUtilizationVo equipmentDayUtilizationVo = new EquipmentDayUtilizationVo();
+            String item = date.substring(4);
+            if (item.startsWith("0")) {
+                item = item.substring(1);
+                String sub = item.substring(1);
+                if (sub.startsWith("0")) {
+                    item = item.substring(0, 1) + "鏈�" + sub.substring(1) + "鏃�";
+                } else {
+                    item = item.substring(0, 1) + "鏈�" + item.substring(1) + "鏃�";
+                }
+            } else {
+                String sub = item.substring(2);
+                if (sub.startsWith("0")) {
+                    item = item.substring(0, 2) + "鏈�" + sub.substring(2) + "鏃�";
+                } else {
+                    item = item.substring(0, 2) + "鏈�" + item.substring(2) + "鏃�";
+                }
+            }
+            dateList.add(item);
+            equipmentDayUtilizationVo.setDate(item);
+            if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
+                //鑾峰彇鍓嶄竷澶╁埄鐢ㄧ巼鏁版嵁
+                List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfos = mdcHomeMapper.getEquipmentDayUtilizationStatistics(equipmentIdList, dayBetween);
+                if (mdcEquipmentStatisticalInfos != null && !mdcEquipmentStatisticalInfos.isEmpty()) {
+                    for (MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo : mdcEquipmentStatisticalInfos) {
+                        if (mdcEquipmentStatisticalInfo.getTheDate().equals(date)) {
+                            equipmentDayUtilizationVo.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) {
+                                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(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
+                            }
+                        }
+                    }
+                } else {
+                    dataList.add(equipmentDayUtilizationVo);
+                }
+            } else {
+                dataList.add(equipmentDayUtilizationVo);
+            }
+        }
+        result.put("dateList", dateList);
+        result.put("dataList", dataList);*/
+        return result;
+    }
+
+    /**
+     * 鏌ヨ璁惧涓婃湀OEE
+     */
+    @Override
+    public List<MdcOverallEquipmentEfficiency> getEquipmentOEEMonthStatistics(String userId, String key) {
+        List<MdcOverallEquipmentEfficiency> result = new ArrayList<>();
+        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
+        if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
+            String validDate = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH);
+            result = mdcHomeMapper.getEquipmentOEEMonthStatistics(validDate, equipmentIdList);
+        }
+        return result;
+    }
+
+    /**
+     * 宸ユ绾ц澶囨晥鐜�
+     */
+    @Override
+    public MdcHomeEfficiencyVo getEquipmentEfficiencyStatistics(String userId, String key) {
+        MdcHomeEfficiencyVo result = new MdcHomeEfficiencyVo();
+        result.setProductionId(key);
+        MdcProduction mdcProduction = mdcProductionService.getById(key);
+        result.setProductionName(mdcProduction.getProductionName());
+        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;
+    }
+
+    /**
+     * 璁惧绾ф晥鐜囩粺璁�
+     */
+    @Override
+    public MdcHomeEfficiencyVo getEquipmentLevelEfficiencyStatistics(String equipmentId) {
+        MdcEquipment mdcEquipment = mdcEquipmentService.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
+        if (mdcEquipment == null) {
+            return null;
+        }
+        MdcHomeEfficiencyVo result = new MdcHomeEfficiencyVo();
+        String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
+        MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcHomeMapper.getUtilizationByDay(Arrays.asList(equipmentId.split(",")), date);
+        if (mdcEquipmentStatisticalInfo != null) {
+            result.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 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).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(Arrays.asList(equipmentId.split(",")), month);
+        if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
+            result.setOverallEquipmentEfficiency(BigDecimal.ZERO);
+        } else {
+            result.setOverallEquipmentEfficiency(oee.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
+        }
+        return result;
+    }
+
+    /**
+     * 璁惧绾ф暣骞村害鍒╃敤鐜�
+     */
+    @Override
+    public Map<String, Object> getEquipmentAnnualEfficiencyStatistics(String equipmentId) {
+        MdcEquipment mdcEquipment = mdcEquipmentService.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
+        if (mdcEquipment == null) {
+            return null;
+        }
+        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<MdcHomeEquipmentVo> dataList = new ArrayList<>();
+        for (String month : monthBetween) {
+            String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�";
+            dateList.add(name);
+            //鍒╃敤鐜囧拰oee
+            MdcHomeEquipmentVo mdcHomeEquipmentVo = new MdcHomeEquipmentVo();
+            mdcHomeEquipmentVo.setMonth(name);
+            //鍒╃敤鐜�
+            Map<String, Object> resultMap = mdcHomeMapper.getUtilizationByMonth(Arrays.asList(equipmentId.split(",")), month.replace("-", ""));
+            if (resultMap != null && resultMap.get("processLong") != null) {
+                BigDecimal processLong = BigDecimal.valueOf((Double) resultMap.get("processLong"));
+                BigDecimal openLong = BigDecimal.valueOf((Double) resultMap.get("openLong"));
+                BigDecimal processDay = new BigDecimal((Integer) resultMap.get("processDay"));
+                if (BigDecimal.ZERO.compareTo(processLong) == -1) {
+                    mdcHomeEquipmentVo.setUtilizationRate(processLong.divide(processDay.multiply(new BigDecimal("86400")), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
+                    if (BigDecimal.ZERO.compareTo(openLong) == -1) {
+                        mdcHomeEquipmentVo.setStartRate(openLong.divide(new BigDecimal("86400"), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
+                        mdcHomeEquipmentVo.setOpenRate(processDay.divide(openLong, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
+                    }
+                }
+            }
+
+            //OEE
+            BigDecimal oee = mdcHomeMapper.getOeeByDate(Arrays.asList(equipmentId.split(",")), month);
+            if (oee != null && !(oee.compareTo(BigDecimal.ZERO) == 0)) {
+                mdcHomeEquipmentVo.setOverallEquipmentEfficiency(oee.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
+            }
+            dataList.add(mdcHomeEquipmentVo);
+        }
+        result.put("dateList", dateList);
+        result.put("dataList", dataList);
+        return result;
+    }
+
+    /**
+     * 璁惧绾ц澶囧垪琛�
+     */
+    @Override
+    public List<MdcEquipment> getEquipmentList(String key) {
+        return mdcHomeMapper.getEquipmentList(key);
+    }
+
+    @Override
+    public MdcEquipmentDto getEquipmentDetails(String equipmentId) {
+        MdcEquipment mdcEquipment = mdcEquipmentService.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
+        List<DictModel> dictModelList = sysDictService.queryEnableDictItemsByCode(MdcConstant.SERIA_TYPE);
+        if (dictModelList != null && !dictModelList.isEmpty()) {
+            for (DictModel dictModel : dictModelList) {
+                if (dictModel.getValue().equals(mdcEquipment.getDriveType())) {
+                    return null;
+                }
+            }
+        }
+        String saveTableName = mdcEquipment.getSaveTableName();
+        MdcEquipmentDto dto = equipmentWorkLineService.getMacingDataList(saveTableName);
+        if (dto != null) {
+            if ("LSV2".equals(mdcEquipment.getDriveType())) {
+                dto.setSpindlebeilv(dto.getSFeed());
+                dto.setFeedbeilv(dto.getFFeed());
+                dto.setRapidfeed(dto.getRapidfeed());
+                dto.setNCVersion(dto.getNCVersion());
+                dto.setTNCVersion(dto.getTNCVersion());
+                dto.setOPTVersion(dto.getOPTVersion());
+                dto.setPLCVersion(dto.getPLCVersion());
+            }
+            // 鏌ヨ璁惧鐘舵��
+            EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
+            Integer oporation = equipmentLog.getOporation();
+            if (oporation == 22) {
+                dto.setALRMstate(equipmentLog.getAlarm());
+            } else {
+                dto.setALRMstate("鏃�");
+            }
+        } else {
+            return null;
+        }
+        return dto;
+    }
+
+    @Override
+    public List<MdcFeedback> getFeedbackList(String key) {
+        return mdcFeedbackService.list(new LambdaQueryWrapper<MdcFeedback>().eq(MdcFeedback::getProductionId, key).orderByDesc(MdcFeedback::getCreateTime));
+    }
 }

--
Gitblit v1.9.3