From a6efc98ddf0afc935ad88d91f8817f5fc2593169 Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期二, 08 七月 2025 20:32:25 +0800 Subject: [PATCH] 设备表-通过EAM中心ids获取设备树 --- lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java | 7 + lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentEamCenterUtil.java | 73 ++++++++++++++++++ lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java | 68 +++++++++++++++++ lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java | 7 + lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml | 6 + lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java | 14 +++ lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java | 17 ++++ 7 files changed, 192 insertions(+), 0 deletions(-) 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 4aafa9e..6ca720a 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 @@ -26,6 +26,13 @@ List<EamEquipment> queryByProductionId(String productionId); /** + * 鏌ヨEAM寤烘ā涓嬬殑璁惧 + * @param eamCenterId + * @return + */ + List<EamEquipment> queryByEamCenterId(String eamCenterId); + + /** * 鍒嗛〉鏌ヨ * @param page * @param queryWrapper diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml index ffe7f6b..a48ead6 100644 --- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml +++ b/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> 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 9594a46..8df7846 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 @@ -37,6 +37,13 @@ List<EamEquipmentTree> loadTreeListByProductionIds(String ids); /** + * 鑾峰彇EAM涓績涓嬬殑璁惧淇℃伅 + * @param ids EAM涓績ids + * @return + */ + List<EamEquipmentTree> loadTreeListByEamCenterIds(String ids); + + /** * 璁惧鍙拌处鍒嗛〉鏌ヨ * @param page * @param eamEquipment 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 7146a61..4976c34 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 @@ -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(",")); + //鑾峰彇鎵�鏈塃AM鏁版嵁 + List<BaseFactory> baseFactoryList = baseFactoryService.list(new LambdaQueryWrapper<BaseFactory>().eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(BaseFactory::getSorter)); + List<String> allBaseFactoryIds = new ArrayList<>(); + //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d + 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()); + } + } + } + } diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentEamCenterUtil.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentEamCenterUtil.java new file mode 100644 index 0000000..0a4a081 --- /dev/null +++ b/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; + } + + /** + * 璇ユ柟娉曟槸鎵惧埌骞跺皝瑁呴《绾х埗绫荤殑鑺傜偣鍒癟reeList闆嗗悎 + */ + 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()); + } + } + + /** + * 璇ユ柟娉曟槸灏嗗瓙鑺傜偣涓虹┖鐨凩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 index b21841a..222d290 100644 --- 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 @@ -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; } + + /** + * 灏咵amBaseFactoryTreeModel鐨勯儴鍒嗘暟鎹斁鍦ㄨ瀵硅薄褰撲腑 + * + * @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; + } } 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 1c0803f..5a19efb 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 @@ -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 鏌ヨ鍏抽敭璇� 璁惧缂栧彿锛岃澶囧悕绉版ā绯婂尮閰� -- Gitblit v1.9.3