lyh
2025-07-08 a6efc98ddf0afc935ad88d91f8817f5fc2593169
设备表-通过EAM中心ids获取设备树
已添加1个文件
已修改6个文件
192 ■■■■■ 文件已修改
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentEamCenterUtil.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java
@@ -26,6 +26,13 @@
    List<EamEquipment> queryByProductionId(String productionId);
    /**
     * æŸ¥è¯¢EAM建模下的设备
     * @param eamCenterId
     * @return
     */
    List<EamEquipment> queryByEamCenterId(String eamCenterId);
    /**
     * åˆ†é¡µæŸ¥è¯¢
     * @param page
     * @param queryWrapper
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml
@@ -38,4 +38,10 @@
                           on e.id = ext.id
            ${ew.customSqlSegment}
    </select>
    <select id="queryByEamCenterId" resultType="org.jeecg.modules.eam.entity.EamEquipment">
        select * from
                     eam_equipment
                 where del_flag = 0
        and factory_org_code =(select org_cod,e from eam_base_factory where eam_base_factory.id=#{eamCenterId})
    </select>
</mapper>
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
@@ -37,6 +37,13 @@
    List<EamEquipmentTree> loadTreeListByProductionIds(String ids);
    /**
     * èŽ·å–EAM中心下的设备信息
     * @param ids EAM中心ids
     * @return
     */
    List<EamEquipmentTree> loadTreeListByEamCenterIds(String ids);
    /**
     * è®¾å¤‡å°è´¦åˆ†é¡µæŸ¥è¯¢
     * @param page
     * @param eamEquipment
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -14,6 +14,7 @@
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.tree.FindsEquipmentEamCenterUtil;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.entity.BaseFactoryUser;
import org.jeecg.modules.system.service.IBaseFactoryService;
@@ -119,6 +120,32 @@
        List<EamEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        fillEquipmentByProduction(treeList);
        return treeList;
    }
    /**
     * èŽ·å–EAM中心下的设备信息
     * @param ids EAM中心ids
     * @return
     */
    @Override
    public List<EamEquipmentTree> loadTreeListByEamCenterIds(String ids){
        List<String> baseFactoryIds = Arrays.asList(ids.split(","));
        //获取所有EAM数据
        List<BaseFactory> baseFactoryList = baseFactoryService.list(new LambdaQueryWrapper<BaseFactory>().eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(BaseFactory::getSorter));
        List<String> allBaseFactoryIds = new ArrayList<>();
        //找到所有产线id的上级id
        if (!baseFactoryIds.isEmpty()) {
            for (String baseFactoryId : baseFactoryIds) {
                this.getAllBaseFactoryIds(baseFactoryList, baseFactoryId, allBaseFactoryIds);
            }
        }
        //过滤EAM数据
        List<BaseFactory> list = baseFactoryList.stream().filter((BaseFactory baseFactory) -> allBaseFactoryIds.contains(baseFactory.getId())).collect(Collectors.toList());
        //组装EAM设备树
        List<EamEquipmentTree> treeList = FindsEquipmentEamCenterUtil.wrapEquipmentBaseFactoryTreeList(list);
        //填充设备数据
        fillEquipmentByBaseFactory(treeList);
        return treeList;
    }
@@ -389,6 +416,26 @@
    }
    /**
     * èŽ·å–æ‰€æœ‰çš„äº§çº¿id(包含所有上级)
     */
    private void getAllBaseFactoryIds(List<BaseFactory> baseFactoryList, String baseFactoryId, List<String> allBaseFactoryIds) {
        if (!allBaseFactoryIds.contains(baseFactoryId)) {
            allBaseFactoryIds.add(baseFactoryId);
        }
        for (BaseFactory baseFactory : baseFactoryList) {
            if (StringUtils.isEmpty(baseFactory.getParentId())) {
                continue;
            }
            if (baseFactoryId.equals(baseFactory.getId())) {
                if (!allBaseFactoryIds.contains(baseFactory.getParentId())) {
                    allBaseFactoryIds.add(baseFactory.getParentId());
                    getAllBaseFactoryIds(baseFactoryList, baseFactory.getParentId(), allBaseFactoryIds);
                }
            }
        }
    }
    /**
     * äº§çº¿è®¾å¤‡æ ‘填充设备数据
     */
    private void fillEquipmentByProduction(List<EamEquipmentTree> treeList) {
@@ -409,4 +456,25 @@
        }
    }
    /**
     * äº§çº¿è®¾å¤‡æ ‘填充设备数据
     */
    private void fillEquipmentByBaseFactory(List<EamEquipmentTree> treeList) {
        for (EamEquipmentTree mdcEquipmentTree : treeList) {
            List<EamEquipment> equipmentList = eamEquipmentMapper.queryByEamCenterId(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())) {
                fillEquipmentByBaseFactory(mdcEquipmentTree.getChildren());
            }
        }
    }
}
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentEamCenterUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
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.BaseFactory;
import org.jeecg.modules.system.model.EamBaseFactoryTreeModel;
import java.util.ArrayList;
import java.util.List;
public class FindsEquipmentEamCenterUtil {
    /**
     * èŽ·å– MdcEquipmentTree
     */
    public static List<EamEquipmentTree> wrapEquipmentBaseFactoryTreeList(List<BaseFactory> recordList) {
        List<EamEquipmentTree> idList = new ArrayList<>();
        List<EamBaseFactoryTreeModel> records = new ArrayList<>();
        for (BaseFactory BaseFactory : recordList) {
            records.add(new EamBaseFactoryTreeModel(BaseFactory));
        }
        getChildren(records, idList);
        setEmptyChildrenAsNull(idList);
        return idList;
    }
    /**
     * è¯¥æ–¹æ³•是找到并封装顶级父类的节点到TreeList集合
     */
    private static void getChildren(List<EamBaseFactoryTreeModel> recordList, List<EamEquipmentTree> idList) {
        List<EamBaseFactoryTreeModel> treeList = new ArrayList<>();
        for (EamBaseFactoryTreeModel EamBaseFactoryTreeModel : recordList) {
            if (oConvertUtils.isEmpty(EamBaseFactoryTreeModel.getParentId())) {
//                EamBaseFactoryTreeModel.setType(1);
                treeList.add(EamBaseFactoryTreeModel);
                idList.add(new EamEquipmentTree().convertByBaseFactory(EamBaseFactoryTreeModel));
            }
        }
        getGrandChildren(treeList, recordList, idList);
    }
    /**
     *该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
     */
    private static void getGrandChildren(List<EamBaseFactoryTreeModel> treeList, List<EamBaseFactoryTreeModel> recordList, List<EamEquipmentTree> idList) {
        for (int i = 0; i < treeList.size(); i++) {
            EamBaseFactoryTreeModel model = treeList.get(i);
            EamEquipmentTree mdcEquipmentTree = idList.get(i);
            for (int i1 = 0; i1 < recordList.size(); i1++) {
                EamBaseFactoryTreeModel 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().convertByBaseFactory(m));
                }
            }
            getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
        }
    }
    /**
     * è¯¥æ–¹æ³•是将子节点为空的List集合设置为Null值
     */
    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);
            }
        }
    }
}
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java
@@ -5,6 +5,7 @@
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.system.model.EamBaseFactoryTreeModel;
import org.jeecg.modules.system.model.MdcProductionTreeModel;
import org.jeecg.modules.system.model.SysDepartTreeModel;
@@ -118,4 +119,20 @@
        this.orgType = treeModel.getOrgType();
        return this;
    }
    /**
     * å°†EamBaseFactoryTreeModel的部分数据放在该对象当中
     *
     * @param treeModel
     * @return
     */
    public EamEquipmentTree convertByBaseFactory(EamBaseFactoryTreeModel treeModel) {
        this.key = treeModel.getId();
        this.value = treeModel.getId();
        this.title = treeModel.getFactoryName();
        this.memo = treeModel.getRemark();
//        this.type = treeModel.getType();
        this.orgType = treeModel.getOrgType();
        return this;
    }
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
@@ -316,6 +316,20 @@
        return result;
    }
    @ApiOperation(value = "设备表-通过EAM中心ids获取设备树", notes = "设备表-通过EAM中心ids获取设备树")
    @GetMapping(value = "/loadTreeListByEamCenterIds")
    public Result<List<EamEquipmentTree>> loadTreeListByEamCenterIds(@RequestParam(name = "ids", required = true) String ids) {
        Result<List<EamEquipmentTree>> result = new Result<>();
        try {
            List<EamEquipmentTree> mdcEquipmentTreeList = eamEquipmentService.loadTreeListByEamCenterIds(ids);
            result.setSuccess(true);
            result.setResult(mdcEquipmentTreeList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return result;
    }
    /**
     * æ£€ç´¢è®¾å¤‡
     * @param keyword æŸ¥è¯¢å…³é”®è¯ è®¾å¤‡ç¼–号,设备名称模糊匹配