From 1292cf73f7db223f35ab450eabeeedbf8802eb5a Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 14 三月 2024 09:35:32 +0800
Subject: [PATCH] 首页设备状态计数接口

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java |  163 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 117 insertions(+), 46 deletions(-)

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 5891439..1e21981 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
@@ -21,10 +21,7 @@
 import org.jeecg.modules.mdc.util.DateUtils;
 import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil;
 import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil;
-import org.jeecg.modules.mdc.vo.MdcEquipmentDepVo;
-import org.jeecg.modules.mdc.vo.MdcEquipmentProVo;
-import org.jeecg.modules.mdc.vo.MdcEquipmentVo;
-import org.jeecg.modules.mdc.vo.WorkshopEquipmentVo;
+import org.jeecg.modules.mdc.vo.*;
 import org.jeecg.modules.system.entity.MdcEquipmentDepart;
 import org.jeecg.modules.system.entity.MdcProduction;
 import org.jeecg.modules.system.entity.MdcProductionEquipment;
@@ -455,7 +452,7 @@
                             } else {
                                 value = "鏃�";
                             }
-                        }  else if ("alarmContent".equals(englishName)) {
+                        } else if ("alarmContent".equals(englishName)) {
                             if (oporation == 22) {
                                 List<MdcAlarmInfo> mdcAlarmInfo = mdcAlarmInfoService.list(new LambdaQueryWrapper<MdcAlarmInfo>().eq(MdcAlarmInfo::getDriveType, mdcEquipment.getDriveType()).eq(MdcAlarmInfo::getAlarmCode, equipmentLog.getAlarm()).eq(MdcAlarmInfo::getIsUse, 0));
                                 if (mdcAlarmInfo != null && !mdcAlarmInfo.isEmpty()) {
@@ -759,8 +756,13 @@
                 Map<String, Object> param = new HashMap<>();
                 param.put("columns", builder.toString());
                 param.put("tableName", saveTableName);
-                Map<String, Object> map = this.baseMapper.getWorkLineLast(param);
-                if (map != null) {
+                Map<String, Object> map = new HashMap<>();
+                try {
+                    map = this.baseMapper.getWorkLineLast(param);
+                } catch (Exception e) {
+                    log.error("鏌ヨ鍗曡〃鏁版嵁鍑哄樊锛�", e);
+                }
+                if (!map.isEmpty()) {
                     for (MdcEquipmentThreshold mdcEquipmentThreshold : mdcEquipmentThresholdList) {
                         Integer actualValue = Integer.valueOf(map.get(mdcEquipmentThreshold.getEnglishName()).toString());
                         Integer max = mdcEquipmentThreshold.getMaxThreshold();
@@ -790,45 +792,6 @@
                     }
                 }
             }
-
-
-//            //鏌ヨ鍗曡〃鏁版嵁
-//            MdcEquipmentDto mdcEquipmentDto = this.baseMapper.getWorkLineLast(saveTableName);
-//            if (mdcEquipmentDto != null) {
-//                MessageDTO messageDTO = new MessageDTO();
-//                messageDTO.setTitle("璁惧杩愯杞�熸姤璀︼紒");
-//                messageDTO.setCategory("棰勮娑堟伅");
-//                messageDTO.setFromUser("admin");
-//                messageDTO.setToUser("admin");
-//                Integer spindlespeed = Integer.valueOf(mdcEquipmentDto.getSpindlespeed());
-//                Integer actualspindlespeed = Integer.valueOf(mdcEquipmentDto.getActualspindlespeed());
-//                if (range.equals(0)) {
-//                    if (spindlespeed > actualspindlespeed) {
-//                        // 瀹為檯鍊煎ぇ浜庤瀹氬��   楂�
-//                        messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶囪繍琛岃浆閫熼珮鎶ヨ锛�");
-//                        sysBaseApi.sendSysAnnouncement(messageDTO);
-//                    } else if (spindlespeed < actualspindlespeed) {
-//                        // 瀹為檯鍊煎皬浜庤瀹氬��   浣�
-//                        messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶囪繍琛岃浆閫熶綆鎶ヨ锛�");
-//                        sysBaseApi.sendSysAnnouncement(messageDTO);
-//                    }
-//                } else {
-//                    int max = actualspindlespeed + actualspindlespeed * (range / 100);
-//                    int min = actualspindlespeed - actualspindlespeed * (range / 100);
-//                    if (spindlespeed > max || spindlespeed < min) {
-//                        if (spindlespeed > actualspindlespeed) {
-//                            // 瀹為檯鍊煎ぇ浜庤瀹氬��   楂�
-//                            messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶囪繍琛岃浆閫熼珮鎶ヨ锛�");
-//                            sysBaseApi.sendSysAnnouncement(messageDTO);
-//                        } else if (spindlespeed < actualspindlespeed) {
-//                            // 瀹為檯鍊煎皬浜庤瀹氬��   浣�
-//                            messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶囪繍琛岃浆閫熶綆鎶ヨ锛�");
-//                            sysBaseApi.sendSysAnnouncement(messageDTO);
-//                        }
-//                    }
-//                }
-//
-//            }
         }
 
     }
@@ -849,4 +812,112 @@
         return this.baseMapper.exportXlsList(mdcEquipment);
     }
 
+    /**
+     * 閫氳繃杞﹂棿ids鑾峰彇璁惧鏍�
+     *
+     * @param ids
+     * @return
+     */
+    @Override
+    public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids) {
+        List<String> productionIds = Arrays.asList(ids.split(","));
+        //鑾峰彇鎵�鏈変骇绾挎暟鎹�
+        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
+        List<String> allProductionIds = new ArrayList<>();
+        //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d
+        if (!productionIds.isEmpty()) {
+            for (String productionId : productionIds) {
+                this.getAllProductionIds(productionList, productionId, allProductionIds);
+            }
+        }
+        //杩囨护浜х嚎鏁版嵁
+        List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList());
+        //缁勮浜х嚎璁惧鏍�
+        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
+        //濉厖璁惧鏁版嵁
+        FillEquipmentByProduction(treeList);
+        return treeList;
+    }
+
+    /**
+     * 鏌ヨ鍗曡〃鏁版嵁
+     * @param tableName
+     * @return
+     */
+    @Override
+    public MdcEquipmentDto getWorkLineLast(String tableName) {
+        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;
+    }
+
 }

--
Gitblit v1.9.3