From 904727f59b7e10a291ce7d1576e33192a619f2f2 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期二, 05 八月 2025 17:08:39 +0800 Subject: [PATCH] MDC设备树和设备权限改造 --- src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java | 189 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 151 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java b/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java index cda1062..05d9f78 100644 --- a/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java +++ b/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java @@ -15,24 +15,23 @@ import org.jeecg.common.system.api.ISysBaseAPI; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.base.entity.Factory; +import org.jeecg.modules.base.service.IFactoryService; +import org.jeecg.modules.base.service.IUserFactoryService; +import org.jeecg.modules.base.service.impl.FactoryServiceImpl; import org.jeecg.modules.mdc.dto.MdcEquDepDto; import org.jeecg.modules.mdc.dto.MdcEquProDto; import org.jeecg.modules.mdc.dto.MdcEquipmentDetailedDto; import org.jeecg.modules.mdc.dto.MdcEquipmentDto; import org.jeecg.modules.mdc.entity.*; -import org.jeecg.modules.mdc.mapper.MdcEquipmentDepartMapper; -import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; -import org.jeecg.modules.mdc.mapper.MdcProductionEquipmentMapper; -import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper; +import org.jeecg.modules.mdc.mapper.*; import org.jeecg.modules.mdc.model.MdcEquipmentTree; import org.jeecg.modules.mdc.service.*; -import org.jeecg.modules.mdc.util.DateUtils; -import org.jeecg.modules.mdc.util.DncCopyEquipment; -import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil; -import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil; +import org.jeecg.modules.mdc.util.*; import org.jeecg.modules.mdc.vo.*; import org.jeecg.modules.system.entity.*; import org.jeecg.modules.system.service.*; +import org.jeecg.modules.system.util.FindsFactorysChildrenUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.CacheEvict; @@ -91,6 +90,15 @@ @Autowired private IEquipmentService equipmentService; + @Autowired + private IFactoryService factoryService; + + @Autowired + private IUserFactoryService userFactoryService; + + @Autowired + private FactoryEquipmentMapper factoryEquipmentMapper; + @Override public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) { @@ -104,7 +112,7 @@ public Map<String, String> getProNamesByEquipmentIds(List<String> equipmentIds) { List<MdcEquipmentProVo> list = this.baseMapper.getProNamesByEquipmentIds(equipmentIds); Map<String, String> res = new HashMap(5); - list.forEach(item -> res.merge(item.getEquipmentId(), item.getProductionName(), (a, b) -> a + "," + b)); + list.forEach(item -> res.merge(item.getEquipmentId(), item.getFactoryName(), (a, b) -> a + "," + b)); return res; } @@ -125,8 +133,8 @@ if (oConvertUtils.isNotEmpty(selectedProduction)) { String[] arr = selectedProduction.split(","); for (String productionId : arr) { - MdcProductionEquipment mdcProductionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId); - mdcProductionEquipmentMapper.insert(mdcProductionEquipment); + FactoryEquipment mdcProductionEquipment = new FactoryEquipment(mdcEquipment.getId(), productionId); + factoryEquipmentMapper.insert(mdcProductionEquipment); } } } @@ -152,17 +160,17 @@ } } //step.3 淇敼浜х嚎 - String productions = mdcEquipment.getSelectedProduction(); + String productions = mdcEquipment.getSelectedFactory(); String[] array = {}; if (oConvertUtils.isNotEmpty(productions)) { array = productions.split(","); } //鍏堝垹鍚庡姞 - mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, mdcEquipment.getId())); + factoryEquipmentMapper.delete(new LambdaQueryWrapper<FactoryEquipment>().eq(FactoryEquipment::getEquipmentId, mdcEquipment.getId())); if (oConvertUtils.isNotEmpty(productions)) { for (String productionId : array) { - MdcProductionEquipment productionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId); - mdcProductionEquipmentMapper.insert(productionEquipment); + FactoryEquipment productionEquipment = new FactoryEquipment(mdcEquipment.getId(), productionId); + factoryEquipmentMapper.insert(productionEquipment); } } } @@ -176,7 +184,7 @@ // 2. 鍒犻櫎璁惧閮ㄩ棬鍏崇郴 line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id)); // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴 - line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id)); + line += factoryEquipmentMapper.delete(new LambdaQueryWrapper<FactoryEquipment>().eq(FactoryEquipment::getEquipmentId, id)); return line != 0; } @@ -189,7 +197,7 @@ // 2. 鍒犻櫎璁惧閮ㄩ棬鍏崇郴 line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().in(MdcEquipmentDepart::getEquipmentId, equipmentIds)); // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴 - line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().in(MdcProductionEquipment::getEquipmentId, equipmentIds)); + line += factoryEquipmentMapper.delete(new LambdaQueryWrapper<FactoryEquipment>().in(FactoryEquipment::getEquipmentId, equipmentIds)); return line != 0; } @@ -293,23 +301,84 @@ @Override public List<MdcEquipmentTree> loadTreeListByProduction(String userId) { //鑾峰彇鎵�鏈変骇绾挎暟鎹� - List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).eq(MdcProduction::getMdcFlag, CommonConstant.DEFAULT_1).orderByAsc(MdcProduction::getProductionOrder)); + List<Factory> factoryList = factoryService.list(new LambdaQueryWrapper<Factory>().eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(Factory::getSorter)); //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� - List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); - List<String> allProductionIds = new ArrayList<>(); + List<String> factoryIds = userFactoryService.queryFactoryIdsByUserId(userId); + List<String> allFactoryIds = new ArrayList<>(); //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d - if (productionIds != null && !productionIds.isEmpty()) { - for (String productionId : productionIds) { - this.getAllProductionIds(productionList, productionId, allProductionIds); + if (factoryIds != null && !factoryIds.isEmpty()) { + for (String factoryId : factoryIds) { + this.getAllFactoryIds(factoryList, factoryId, allFactoryIds); } } //杩囨护浜х嚎鏁版嵁 - List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList()); + List<Factory> list = factoryList.stream().filter((Factory factory) -> allFactoryIds.contains(factory.getId())).collect(Collectors.toList()); //缁勮浜х嚎璁惧鏍� - List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); + List<MdcEquipmentTree> treeList = FindsEquipmentFactoryUtil.wrapEquipmentFactoryTreeList(list); //濉厖璁惧鏁版嵁 - FillEquipmentByProduction(treeList); + FillEquipmentByFactory(treeList); + + +// //鑾峰彇鎵�鏈変骇绾挎暟鎹� +// List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).eq(MdcProduction::getMdcFlag, CommonConstant.DEFAULT_1).orderByAsc(MdcProduction::getProductionOrder)); +// //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� +// List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); +// List<String> allProductionIds = new ArrayList<>(); +// //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d +// if (productionIds != null && !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<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); +// 濉厖璁惧鏁版嵁 +// FillEquipmentByProduction(treeList); return treeList; + } + + /** + * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹� + */ + private void FillEquipmentByFactory(List<MdcEquipmentTree> treeList) { + for (MdcEquipmentTree mdcEquipmentTree : treeList) { + List<MdcEquipment> equipmentList = this.baseMapper.queryByFactoryId(mdcEquipmentTree.getKey()); + if (equipmentList != null && !equipmentList.isEmpty()) { + for (MdcEquipment mdcEquipment : equipmentList) { + MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment); + tree.setParentId(mdcEquipmentTree.getKey()); + tree.setEntity(mdcEquipment); + tree.setType(2); + mdcEquipmentTree.getChildren().add(tree); + } + mdcEquipmentTree.setLeaf(false); + } + if (!mdcEquipmentTree.getChildren().isEmpty()) { + FillEquipmentByFactory(mdcEquipmentTree.getChildren()); + } + } + } + + /** + * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級 + */ + private void getAllFactoryIds(List<Factory> factoryList, String factoryId, List<String> allFactoryIds) { + if (!allFactoryIds.contains(factoryId)) { + allFactoryIds.add(factoryId); + } + for (Factory factory : factoryList) { + if (StringUtils.isEmpty(factory.getParentId())) { + continue; + } + if (factoryId.equals(factory.getId())) { + if (!allFactoryIds.contains(factory.getParentId())) { + allFactoryIds.add(factory.getParentId()); + getAllFactoryIds(factoryList, factory.getParentId(), allFactoryIds); + } + } + } } /** @@ -513,30 +582,74 @@ @Override public List<String> getEquipmentIdsProduction(String userId, String key) { //鑾峰彇鎵�鏈変骇绾挎暟鎹� - List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); + List<Factory> factoryList = factoryService.list(new LambdaQueryWrapper<Factory>().eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0).orderByAsc(Factory::getSorter)); //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� - List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); - List<String> allProductionIds = new ArrayList<>(); + List<String> factoryIds = userFactoryService.queryFactoryIdsByUserId(userId); + List<String> allFactoryIds = new ArrayList<>(); //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d - if (productionIds != null && !productionIds.isEmpty()) { - for (String productionId : productionIds) { - this.getAllProductionIds(productionList, productionId, allProductionIds); + if (factoryIds != null && !factoryIds.isEmpty()) { + for (String productionId : factoryIds) { + this.getAllFactoryIds(factoryList, productionId, allFactoryIds); } } //鏍规嵁浜х嚎闆嗗悎鏌ユ壘鎵�鏈夎澶噄d - if (allProductionIds.isEmpty()) { + if (allFactoryIds.isEmpty()) { return null; } - List<String> equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIds); + List<String> equipmentIds = this.baseMapper.queryIdsByFactorys(allFactoryIds); if (StringUtils.isNotEmpty(key)) { //key涓嶄负绌猴紝鏌ヨ鎵�鏈変笅绾т骇绾縤d - List<String> partProduction = this.findAllProductions(key); - partProduction.add(key); + List<String> partFactory = this.findAllFactorys(key); + partFactory.add(key); //杩囨护鏃犳潈闄愪骇绾縤d - List<String> allProductionIdsByKey = partProduction.stream().filter(allProductionIds::contains).collect(Collectors.toList()); - equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIdsByKey); + List<String> allFactoryIdsByKey = partFactory.stream().filter(allFactoryIds::contains).collect(Collectors.toList()); + equipmentIds = this.baseMapper.queryIdsByFactorys(allFactoryIdsByKey); } return equipmentIds; + + //鑾峰彇鎵�鏈変骇绾挎暟鎹� +// List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); +// //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� +// List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); +// List<String> allProductionIds = new ArrayList<>(); +// //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d +// if (productionIds != null && !productionIds.isEmpty()) { +// for (String productionId : productionIds) { +// this.getAllProductionIds(productionList, productionId, allProductionIds); +// } +// } +// //鏍规嵁浜х嚎闆嗗悎鏌ユ壘鎵�鏈夎澶噄d +// if (allProductionIds.isEmpty()) { +// return null; +// } +// List<String> equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIds); +// if (StringUtils.isNotEmpty(key)) { +// //key涓嶄负绌猴紝鏌ヨ鎵�鏈変笅绾т骇绾縤d +// List<String> partProduction = this.findAllProductions(key); +// partProduction.add(key); +// //杩囨护鏃犳潈闄愪骇绾縤d +// List<String> allProductionIdsByKey = partProduction.stream().filter(allProductionIds::contains).collect(Collectors.toList()); +// equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIdsByKey); +// } +// return equipmentIds; +// + } + + /** + * 鏍规嵁鐖剁骇id閫掑綊鏌ヨ鎵�鏈変笅绾d闆嗗悎 + */ + private List<String> findAllFactorys(String key) { + List<String> factoryIds = new ArrayList<>(); + List<Factory> factorys = factoryService.queryFacByPid(key); + if (factorys != null && !factorys.isEmpty()) { + List<String> ids = factorys.stream().map(Factory::getId).collect(Collectors.toList()); + factoryIds.addAll(ids); + for (Factory factory : factorys) { + List<String> allFactorys = findAllFactorys(factory.getId()); + factoryIds.addAll(allFactorys); + } + } + return factoryIds; } /** -- Gitblit v1.9.3