From b42b180f5c2bc89e494b2274d8d454a4bd6dbf9c Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期五, 21 三月 2025 17:27:59 +0800
Subject: [PATCH] art: 系统管理-用户管理-添加选择设备,并根据是否有设备管理模块功能区分加载 哪个模块的设备倏

---
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java |   77 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
index 9122818..59a388c 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -1,6 +1,9 @@
 package org.jeecg.modules.eam.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
 import org.jeecg.modules.eam.constant.AssetStatusEnum;
@@ -12,11 +15,20 @@
 import org.jeecg.modules.eam.mapper.EamEquipmentMapper;
 import org.jeecg.modules.eam.service.IEamEquipmentExtendService;
 import org.jeecg.modules.eam.service.IEamEquipmentService;
+import org.jeecg.modules.eam.tree.FindsEquipmentProductionUtil;
+import org.jeecg.modules.eam.vo.EamEquipmentTree;
+import org.jeecg.modules.system.entity.MdcProduction;
+import org.jeecg.modules.system.service.IMdcProductionService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 璁惧鍙拌处
@@ -31,6 +43,8 @@
     private EamEquipmentMapper eamEquipmentMapper;
     @Autowired
     private IEamEquipmentExtendService equipmentExtendService;
+    @Autowired
+    private IMdcProductionService mdcProductionService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -55,4 +69,67 @@
         //鎻掑叆璁惧灞ュ巻 TODO
         return eamEquipment;
     }
+
+    @Override
+    public List<EamEquipmentTree> 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<EamEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
+        //濉厖璁惧鏁版嵁
+        fillEquipmentByProduction(treeList);
+        return treeList;
+    }
+
+    /**
+     * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級
+     */
+    private void getAllProductionIds(List<MdcProduction> productionList, String productionId, List<String> allProductionIds) {
+        if (!allProductionIds.contains(productionId)) {
+            allProductionIds.add(productionId);
+        }
+        for (MdcProduction mdcProduction : productionList) {
+            if (StringUtils.isEmpty(mdcProduction.getParentId())) {
+                continue;
+            }
+            if (productionId.equals(mdcProduction.getId())) {
+                if (!allProductionIds.contains(mdcProduction.getParentId())) {
+                    allProductionIds.add(mdcProduction.getParentId());
+                    getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds);
+                }
+            }
+        }
+    }
+
+    /**
+     * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹�
+     */
+    private void fillEquipmentByProduction(List<EamEquipmentTree> treeList) {
+        for (EamEquipmentTree mdcEquipmentTree : treeList) {
+            List<EamEquipment> equipmentList = eamEquipmentMapper.queryByProductionId(mdcEquipmentTree.getKey());
+            if (CollectionUtil.isNotEmpty(equipmentList)) {
+                for (EamEquipment mdcEquipment : equipmentList) {
+                    EamEquipmentTree tree = new EamEquipmentTree().convert(mdcEquipment);
+                    tree.setParentId(mdcEquipmentTree.getKey());
+                    tree.setType(2);
+                    mdcEquipmentTree.getChildren().add(tree);
+                }
+                mdcEquipmentTree.setLeaf(false);
+            }
+            if (CollectionUtil.isNotEmpty(mdcEquipmentTree.getChildren())) {
+                fillEquipmentByProduction(mdcEquipmentTree.getChildren());
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.3