From 3a740faa161ec976986c0735ba18837f570a525f Mon Sep 17 00:00:00 2001
From: hyingbo <1363390067@qq.com>
Date: 星期二, 27 五月 2025 19:04:07 +0800
Subject: [PATCH] 消息类型拆分并按类型推送至不同角色

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java |  164 +++++++++++++++++++++++++-----------------------------
 1 files changed, 77 insertions(+), 87 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 1e21981..91b6923 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
@@ -8,6 +8,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.api.dto.message.MessageDTO;
 import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.constant.enums.MessageSplitTypeEnum;
 import org.jeecg.common.system.api.ISysBaseAPI;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.mdc.dto.MdcEquDepDto;
@@ -227,7 +228,7 @@
     }
 
     @Override
-    public List<MdcEquipmentTree> loadTreeListByDepart(String userId) {
+    public List<MdcEquipmentTree> loadTreeListByDepart(String userId, String key) {
         //鑾峰彇鎵�鏈夐儴闂ㄦ暟鎹�
         List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(SysDepart::getDepartOrder));
         //鏍规嵁鐢ㄦ埛ID鑾峰彇鎷ユ湁鐨勯儴闂╥d闆嗗悎
@@ -244,7 +245,7 @@
         //缁勮閮ㄩ棬璁惧鏍�
         List<MdcEquipmentTree> treeList = FindsEquipmentDepartUtil.wrapEquipmentDepartTreeList(list);
         //濉厖璁惧鏁版嵁
-        FillEquipmentByDepart(treeList);
+        FillEquipmentByDepart(treeList, key);
         return treeList;
     }
 
@@ -253,9 +254,9 @@
      *
      * @param treeList
      */
-    private void FillEquipmentByDepart(List<MdcEquipmentTree> treeList) {
+    private void FillEquipmentByDepart(List<MdcEquipmentTree> treeList, String key) {
         for (MdcEquipmentTree mdcEquipmentTree : treeList) {
-            List<MdcEquipment> equipmentList = this.baseMapper.queryByDepartId(mdcEquipmentTree.getKey());
+            List<MdcEquipment> equipmentList = this.baseMapper.queryByDepartId(mdcEquipmentTree.getKey(), key);
             if (equipmentList != null && !equipmentList.isEmpty()) {
                 for (MdcEquipment mdcEquipment : equipmentList) {
                     MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
@@ -265,7 +266,7 @@
                 mdcEquipmentTree.setLeaf(false);
             }
             if (!mdcEquipmentTree.getChildren().isEmpty()) {
-                FillEquipmentByDepart(mdcEquipmentTree.getChildren());
+                FillEquipmentByDepart(mdcEquipmentTree.getChildren(), key);
             }
         }
     }
@@ -292,7 +293,7 @@
 
 
     @Override
-    public List<MdcEquipmentTree> loadTreeListByProduction(String userId) {
+    public List<MdcEquipmentTree> loadTreeListByProduction(String userId, String key) {
         //鑾峰彇鎵�鏈変骇绾挎暟鎹�
         List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
         //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚�
@@ -309,7 +310,7 @@
         //缁勮浜х嚎璁惧鏍�
         List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
         //濉厖璁惧鏁版嵁
-        FillEquipmentByProduction(treeList);
+        FillEquipmentByProduction(treeList, key);
         return treeList;
     }
 
@@ -375,6 +376,9 @@
         ControlSystem controlSystem = controlSystemService.getByDriveType(mdcEquipmentDto.getDriveType());
         // 鏌ヨ璁惧鐘舵��
         EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
+        if (equipmentLog == null) {
+            return mdcEquipmentDto;
+        }
         Integer oporation = equipmentLog.getOporation();
 
         if (controlSystem != null) {
@@ -419,15 +423,19 @@
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlespeed".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧涓昏酱杞�熷瓧娈祍pindlespeed
                             value = String.valueOf(((new Random().nextInt(35)) + 1) * 100);
+                            mdcEquipmentDto.setSpindlespeed(value);
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindleload".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧涓昏酱璐熻嵎瀛楁spindleload
                             value = String.valueOf(Integer.valueOf(new Random().nextInt(21)));
+                            mdcEquipmentDto.setSpindleload(value);
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlebeilv".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧涓昏酱鍊嶇巼瀛楁spindlebeilv
                             value = String.valueOf((new Random().nextInt(13)) * 10);
+                            mdcEquipmentDto.setSpindlebeilv(value);
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "feedbeilv".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧杩涚粰鍊嶇巼瀛楁feedbeilv
                             value = String.valueOf((new Random().nextInt(13)) * 10);
+                            mdcEquipmentDto.setFeedbeilv(value);
                         } else if ("spindle_current".equals(englishName)) {
                             // 鍏朵粬璁惧鐢垫祦瀛楁
                             String devicePower = mdcEquipment.getDevicePower();
@@ -629,9 +637,9 @@
     /**
      * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹�
      */
-    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) {
+    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList, String key) {
         for (MdcEquipmentTree mdcEquipmentTree : treeList) {
-            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey());
+            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey(), key);
             if (equipmentList != null && !equipmentList.isEmpty()) {
                 for (MdcEquipment mdcEquipment : equipmentList) {
                     MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
@@ -641,7 +649,7 @@
                 mdcEquipmentTree.setLeaf(false);
             }
             if (!mdcEquipmentTree.getChildren().isEmpty()) {
-                FillEquipmentByProduction(mdcEquipmentTree.getChildren());
+                FillEquipmentByProduction(mdcEquipmentTree.getChildren(), key);
             }
         }
     }
@@ -721,8 +729,28 @@
     }
 
     @Override
-    public List<String> listEquipmentId(String equipmentType, List<String> equipmentIdList) {
-        List<MdcEquipment> list = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentType, equipmentType).in(MdcEquipment::getEquipmentId, equipmentIdList));
+    public List<String> listEquipmentId(MdcEfficiencyReportQueryVo vo) {
+        LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
+        if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) {
+            queryWrapper.in(MdcEquipment::getEquipmentId, vo.getEquipmentIdList());
+        }
+        if (StringUtils.isNotEmpty(vo.getEquipmentType())) {
+            queryWrapper.in(MdcEquipment::getEquipmentType, Arrays.asList(vo.getEquipmentType().split(",")));
+        }
+        if (StringUtils.isNotEmpty(vo.getDeviceLevel())) {
+            queryWrapper.in(MdcEquipment::getDeviceLevel, Arrays.asList(vo.getDeviceLevel().split(",")));
+        }
+        if (StringUtils.isNotEmpty(vo.getDriveType())) {
+            queryWrapper.in(MdcEquipment::getDriveType, Arrays.asList(vo.getDriveType().split(",")));
+        }
+        if (StringUtils.isNotEmpty(vo.getDeviceCategory())) {
+            queryWrapper.in(MdcEquipment::getDeviceCategory, Arrays.asList(vo.getDeviceCategory().split(",")));
+        }
+        if (vo.getDeviceImportanceLevel() != null) {
+            queryWrapper.eq(MdcEquipment::getDeviceImportanceLevel, vo.getDeviceImportanceLevel());
+        }
+        List<MdcEquipment> list = super.list(queryWrapper);
+//        List<MdcEquipment> list = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentType, equipmentType).in(MdcEquipment::getEquipmentId, equipmentIdList));
         return list.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
     }
 
@@ -744,8 +772,9 @@
 //        List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getDriveType, "FANUC"));
         List<MdcEquipment> equipmentList = super.list();
         //List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198"));
-
+        Map<String, String> proNamesByEquipmentIds = this.getProNamesByEquipmentIds(equipmentList.stream().map(MdcEquipment::getId).collect(Collectors.toList()));
         for (MdcEquipment mdcEquipment : equipmentList) {
+            String productionName = proNamesByEquipmentIds.get(mdcEquipment.getId());
             List<MdcEquipmentThreshold> mdcEquipmentThresholdList = mdcEquipmentThresholdService.list(new LambdaQueryWrapper<MdcEquipmentThreshold>().eq(MdcEquipmentThreshold::getControlSystemType, mdcEquipment.getDriveType()));
             if (mdcEquipmentThresholdList != null && !mdcEquipmentThresholdList.isEmpty()) {
                 String saveTableName = mdcEquipment.getSaveTableName();
@@ -768,8 +797,9 @@
                         Integer max = mdcEquipmentThreshold.getMaxThreshold();
                         Integer min = mdcEquipmentThreshold.getMinThreshold();
                         MessageDTO messageDTO = new MessageDTO();
-                        messageDTO.setTitle("璁惧" + mdcEquipmentThreshold.getChineseName() + "鎶ヨ锛�");
-                        messageDTO.setCategory("棰勮娑堟伅");
+                        messageDTO.setTitle("銆愯澶囧紓甯告彁閱掋��" + productionName + "杞﹂棿璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶�" + mdcEquipmentThreshold.getChineseName() + "鎶ヨ锛�");
+                        messageDTO.setCategory(CommonConstant.MSG_CATEGORY_2);
+                        messageDTO.setMessageType(MessageSplitTypeEnum.deviceRunError.getType());
                         messageDTO.setFromUser("admin");
                         messageDTO.setToUser("admin");
                         MdcOverrunAlarm mdcOverrunAlarm = new MdcOverrunAlarm();
@@ -778,15 +808,15 @@
                         mdcOverrunAlarm.setRealValue(actualValue.toString());
                         if (actualValue > max) {
                             // 楂�
-                            messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶�" + mdcEquipmentThreshold.getChineseName() + "楂樻姤璀︼紒");
+                            messageDTO.setContent("銆愯澶囧紓甯告彁閱掋��" + productionName + "杞﹂棿璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶�" + mdcEquipmentThreshold.getChineseName() + "楂樻姤璀︼紒");
                             sysBaseApi.sendSysAnnouncement(messageDTO);
-                            mdcOverrunAlarm.setAlarmContent(mdcEquipmentThreshold.getChineseName() + "楂樻姤璀�");
+                            mdcOverrunAlarm.setAlarmContent("銆愯澶囧紓甯告彁閱掋��" + productionName + "杞﹂棿璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶�" + mdcEquipmentThreshold.getChineseName() + "楂樻姤璀︼紒");
                             mdcOverrunAlarmService.save(mdcOverrunAlarm);
                         } else if (actualValue < min) {
                             // 浣�
-                            messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶�" + mdcEquipmentThreshold.getChineseName() + "浣庢姤璀︼紒");
+                            messageDTO.setContent("銆愯澶囧紓甯告彁閱掋��" + productionName + "杞﹂棿璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶�" + mdcEquipmentThreshold.getChineseName() + "浣庢姤璀︼紒");
                             sysBaseApi.sendSysAnnouncement(messageDTO);
-                            mdcOverrunAlarm.setAlarmContent(mdcEquipmentThreshold.getChineseName() + "浣庢姤璀�");
+                            mdcOverrunAlarm.setAlarmContent("銆愯澶囧紓甯告彁閱掋��" + productionName + "杞﹂棿璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶�" + mdcEquipmentThreshold.getChineseName() + "浣庢姤璀︼紒");
                             mdcOverrunAlarmService.save(mdcOverrunAlarm);
                         }
                     }
@@ -835,89 +865,49 @@
         //缁勮浜х嚎璁惧鏍�
         List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
         //濉厖璁惧鏁版嵁
-        FillEquipmentByProduction(treeList);
+        FillEquipmentByProduction(treeList, null);
         return treeList;
     }
 
     /**
      * 鏌ヨ鍗曡〃鏁版嵁
+     *
      * @param tableName
      * @return
      */
     @Override
     public MdcEquipmentDto getWorkLineLast(String tableName) {
-        return this.baseMapper.findWorkLineLast(tableName);
+        try {
+            return this.baseMapper.findWorkLineLast(tableName);
+        } catch (Exception e) {
+            return null;
+        }
     }
 
-    /**
-     * 璁惧杩愯鐘舵�佺粺璁�
-     */
     @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;
+    public List<String> listEquipmentIdShift(MdcEfficiencyReportShiftQueryVo vo) {
+        LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
+        if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) {
+            queryWrapper.in(MdcEquipment::getEquipmentId, vo.getEquipmentIdList());
         }
-        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);
-                }
-            }
+        if (StringUtils.isNotEmpty(vo.getEquipmentType())) {
+            queryWrapper.in(MdcEquipment::getEquipmentType, Arrays.asList(vo.getEquipmentType().split(",")));
         }
-        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;
+        if (StringUtils.isNotEmpty(vo.getDeviceLevel())) {
+            queryWrapper.in(MdcEquipment::getDeviceLevel, Arrays.asList(vo.getDeviceLevel().split(",")));
+        }
+        if (StringUtils.isNotEmpty(vo.getDriveType())) {
+            queryWrapper.in(MdcEquipment::getDriveType, Arrays.asList(vo.getDriveType().split(",")));
+        }
+        if (StringUtils.isNotEmpty(vo.getDeviceCategory())) {
+            queryWrapper.in(MdcEquipment::getDeviceCategory, Arrays.asList(vo.getDeviceCategory().split(",")));
+        }
+        if (vo.getDeviceImportanceLevel() != null) {
+            queryWrapper.eq(MdcEquipment::getDeviceImportanceLevel, vo.getDeviceImportanceLevel());
+        }
+        List<MdcEquipment> list = super.list(queryWrapper);
+//        List<MdcEquipment> list = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentType, equipmentType).in(MdcEquipment::getEquipmentId, equipmentIdList));
+        return list.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
     }
 
 }

--
Gitblit v1.9.3