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/mapper/EamEquipmentMapper.java            |   11 +
 lxzn-module-eam/pom.xml                                                                              |    5 
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java |   77 ++++++++++++
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentProductionUtil.java    |   79 +++++++++++++
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java         |   10 +
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java           |   17 ++
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java                  |  121 ++++++++++++++++++++
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java                  |    2 
 8 files changed, 321 insertions(+), 1 deletions(-)

diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java
index 337ec93..f77b494 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java
@@ -180,4 +180,6 @@
 	 */
 	@ApiModelProperty(value = "浣跨敤閮ㄩ棬鎵�鏈塈D")
 	private String orgParentIds;
+	@ApiModelProperty(value = "MDC璁惧绫诲瀷")
+	private String deviceType;
 }
diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java
index 012f4ab..6f40318 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java
@@ -1,7 +1,10 @@
 package org.jeecg.modules.eam.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Select;
 import org.jeecg.modules.eam.entity.EamEquipment;
+
+import java.util.List;
 
 /**
  * @Description: 璁惧鍙拌处
@@ -10,5 +13,11 @@
  * @Version: V1.0
  */
 public interface EamEquipmentMapper extends BaseMapper<EamEquipment> {
-
+    /**
+     * 鏌ヨ浜х嚎涓嬬殑璁惧
+     * @param productionId 浜х嚎id
+     * @return
+     */
+    @Select("select * from eam_equipment where del_flag = 0 and org_id = #{productionId}")
+    List<EamEquipment> queryByProductionId(String productionId);
 }
diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
index 7c1f7d7..1140567 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
@@ -2,6 +2,9 @@
 
 import org.jeecg.modules.eam.entity.EamEquipment;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.eam.vo.EamEquipmentTree;
+
+import java.util.List;
 
 /**
  * @Description: 璁惧鍙拌处
@@ -16,4 +19,11 @@
      * @param eamEquipment
      */
     EamEquipment saveEquipment(EamEquipment eamEquipment);
+
+    /**
+     * 鑾峰彇浜х嚎涓嬬殑璁惧淇℃伅
+     * @param ids 浜х嚎ids
+     * @return
+     */
+    List<EamEquipmentTree> loadTreeListByProductionIds(String ids);
 }
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());
+            }
+        }
+    }
+
 }
diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentProductionUtil.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentProductionUtil.java
new file mode 100644
index 0000000..e153216
--- /dev/null
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentProductionUtil.java
@@ -0,0 +1,79 @@
+package org.jeecg.modules.eam.tree;
+
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.eam.vo.EamEquipmentTree;
+import org.jeecg.modules.system.entity.MdcProduction;
+import org.jeecg.modules.system.model.MdcProductionTreeModel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 浜х嚎璁惧鏍�
+ * @author: LiuS
+ * @create: 2023-04-03 15:59
+ */
+public class FindsEquipmentProductionUtil {
+
+    /**
+     * 鑾峰彇 MdcEquipmentTree
+     */
+    public static List<EamEquipmentTree> wrapEquipmentProductionTreeList(List<MdcProduction> recordList) {
+        List<EamEquipmentTree> idList = new ArrayList<>();
+        List<MdcProductionTreeModel> records = new ArrayList<>();
+        for (MdcProduction mdcProduction : recordList) {
+            records.add(new MdcProductionTreeModel(mdcProduction));
+        }
+        getChildren(records, idList);
+        setEmptyChildrenAsNull(idList);
+        return idList;
+    }
+
+    /**
+     * 璇ユ柟娉曟槸鎵惧埌骞跺皝瑁呴《绾х埗绫荤殑鑺傜偣鍒癟reeList闆嗗悎
+     */
+    private static void getChildren(List<MdcProductionTreeModel> recordList, List<EamEquipmentTree> idList) {
+        List<MdcProductionTreeModel> treeList = new ArrayList<>();
+        for (MdcProductionTreeModel mdcProductionTreeModel : recordList) {
+            if (oConvertUtils.isEmpty(mdcProductionTreeModel.getParentId())) {
+                mdcProductionTreeModel.setType(1);
+                treeList.add(mdcProductionTreeModel);
+                idList.add(new EamEquipmentTree().convertByProduction(mdcProductionTreeModel));
+            }
+        }
+        getGrandChildren(treeList, recordList, idList);
+    }
+
+    /**
+     *璇ユ柟娉曟槸鎵惧埌椤剁骇鐖剁被涓嬬殑鎵�鏈夊瓙鑺傜偣闆嗗悎骞跺皝瑁呭埌TreeList闆嗗悎
+     */
+    private static void getGrandChildren(List<MdcProductionTreeModel> treeList, List<MdcProductionTreeModel> recordList, List<EamEquipmentTree> idList) {
+        for (int i = 0; i < treeList.size(); i++) {
+            MdcProductionTreeModel model = treeList.get(i);
+            EamEquipmentTree mdcEquipmentTree = idList.get(i);
+            for (int i1 = 0; i1 < recordList.size(); i1++) {
+                MdcProductionTreeModel m = recordList.get(i1);
+                if (m.getParentId() != null && m.getParentId().equals(model.getId())) {
+                    model.getChildren().add(m);
+                    m.setType(1);
+                    mdcEquipmentTree.getChildren().add(new EamEquipmentTree().convertByProduction(m));
+                }
+            }
+            getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
+        }
+    }
+
+    /**
+     * 璇ユ柟娉曟槸灏嗗瓙鑺傜偣涓虹┖鐨凩ist闆嗗悎璁剧疆涓篘ull鍊�
+     */
+    private static void setEmptyChildrenAsNull(List<EamEquipmentTree> idList) {
+        for (EamEquipmentTree mdcEquipmentTree : idList) {
+            if (mdcEquipmentTree.getChildren().isEmpty()) {
+                mdcEquipmentTree.setLeaf(true);
+            } else {
+                setEmptyChildrenAsNull(mdcEquipmentTree.getChildren());
+                mdcEquipmentTree.setLeaf(false);
+            }
+        }
+    }
+}
diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java
new file mode 100644
index 0000000..48e3fe9
--- /dev/null
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java
@@ -0,0 +1,121 @@
+package org.jeecg.modules.eam.vo;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecg.modules.eam.entity.EamEquipment;
+import org.jeecg.modules.system.model.MdcProductionTreeModel;
+import org.jeecg.modules.system.model.SysDepartTreeModel;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 璁惧鏍�
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "璁惧鏍戠粨鏋勬暟鎹疄浣�", description = "璁惧")
+public class EamEquipmentTree implements Serializable {
+
+    /**
+     * 鍓嶇鏁版嵁鏍戜腑鐨刱ey
+     */
+    private String key;
+
+    /**
+     * 鍓嶇鏁版嵁鏍戜腑鐨剉alue
+     */
+    private String value;
+
+    /**
+     * 鍓嶇鏁版嵁鏍戜腑鐨則itle
+     */
+    private String title;
+
+    /**
+     * 鏄惁鏄瓙鑺傜偣
+     */
+    private boolean isLeaf;
+
+    /**
+     * 璁惧缂栧彿锛堝墠绔畾浣嶇敤锛�
+     */
+    private String equipmentId;
+
+    /**
+     * 璁惧鍚嶇О锛堝墠绔畾浣嶇敤锛�
+     */
+    private String equipmentName;
+
+    /**
+     * 鐖剁骇id锛堝墠绔姹傜敤锛�
+     */
+    private String parentId;
+
+    /**
+     * 杞﹂棿鎻忚堪
+     */
+    private String memo;
+
+    /**
+     * 绫诲瀷 1 杞﹂棿 2璁惧
+     */
+    private Integer type;
+
+    /**
+     * orgType
+     */
+    private String orgType;
+
+
+    private List<EamEquipmentTree> children = new ArrayList<>();
+
+    /**
+     * 灏嗚澶囨暟鎹斁鍦ㄨ瀵硅薄涓�
+     *
+     * @param mdcEquipment
+     * @return
+     */
+    public EamEquipmentTree convert(EamEquipment mdcEquipment) {
+        this.key = mdcEquipment.getId();
+        this.value = mdcEquipment.getId();
+        this.title = mdcEquipment.getEquipmentCode() + "/" + mdcEquipment.getEquipmentName();
+        this.equipmentId = mdcEquipment.getEquipmentCode();
+        this.equipmentName = mdcEquipment.getEquipmentName();
+        this.isLeaf = true;
+        return this;
+    }
+
+    /**
+     * 灏哠ysDepartTreeModel鐨勯儴鍒嗘暟鎹斁鍦ㄨ瀵硅薄褰撲腑
+     *
+     * @param treeModel
+     * @return
+     */
+    public EamEquipmentTree convertByDepart(SysDepartTreeModel treeModel) {
+        this.key = treeModel.getId();
+        this.value = treeModel.getId();
+        this.title = treeModel.getDepartName();
+        return this;
+    }
+
+    /**
+     * 灏唌dcProductionTreeModel鐨勯儴鍒嗘暟鎹斁鍦ㄨ瀵硅薄褰撲腑
+     *
+     * @param treeModel
+     * @return
+     */
+    public EamEquipmentTree convertByProduction(MdcProductionTreeModel treeModel) {
+        this.key = treeModel.getId();
+        this.value = treeModel.getId();
+        this.title = treeModel.getProductionName();
+        this.memo = treeModel.getMemo();
+        this.type = treeModel.getType();
+        this.orgType = treeModel.getOrgType();
+        return this;
+    }
+}
diff --git a/lxzn-module-eam/pom.xml b/lxzn-module-eam/pom.xml
index 8d6c34d..53d4c00 100644
--- a/lxzn-module-eam/pom.xml
+++ b/lxzn-module-eam/pom.xml
@@ -25,6 +25,11 @@
             <artifactId>lxzn-module-eam-common</artifactId>
             <version>3.4.3</version>
         </dependency>
+        <dependency>
+            <groupId>org.jeecgframework.boot</groupId>
+            <artifactId>lxzn-module-mdc-common</artifactId>
+            <version>3.4.3</version>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
index 584b493..0433218 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
@@ -12,6 +12,7 @@
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.service.IEamEquipmentService;
+import org.jeecg.modules.eam.vo.EamEquipmentTree;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
@@ -19,6 +20,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * @Description: 璁惧鍙拌处
@@ -152,4 +154,19 @@
         return super.importExcel(request, response, EamEquipment.class);
     }
 
+    @AutoLog(value = "璁惧琛�-閫氳繃杞﹂棿ids鑾峰彇璁惧鏍�")
+    @ApiOperation(value = "璁惧琛�-閫氳繃杞﹂棿ids鑾峰彇璁惧鏍�", notes = "璁惧琛�-閫氳繃杞﹂棿ids鑾峰彇璁惧鏍�")
+    @GetMapping(value = "/loadTreeListByProductionIds")
+    public Result<List<EamEquipmentTree>> loadTreeListByProductionIds(@RequestParam(name = "ids", required = true) String ids) {
+        Result<List<EamEquipmentTree>> result = new Result<>();
+        try {
+            List<EamEquipmentTree> mdcEquipmentTreeList = eamEquipmentService.loadTreeListByProductionIds(ids);
+            result.setSuccess(true);
+            result.setResult(mdcEquipmentTreeList);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+        return result;
+    }
+
 }

--
Gitblit v1.9.3