| | |
| | | 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; |
| | |
| | | @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) { |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | //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); |
| | | } |
| | | } |
| | | } |
| | |
| | | // 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; |
| | | } |
| | | |
| | |
| | | // 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; |
| | | } |
| | |
| | | @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<>(); |
| | | //找到所有产线id的上级id |
| | | 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<>(); |
| | | // //找到所有产线id的上级id |
| | | // 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); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | @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<>(); |
| | | //找到所有产线id的上级id |
| | | 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); |
| | | } |
| | | } |
| | | //根据产线集合查找所有设备id |
| | | 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不为空,查询所有下级产线id |
| | | List<String> partProduction = this.findAllProductions(key); |
| | | partProduction.add(key); |
| | | List<String> partFactory = this.findAllFactorys(key); |
| | | partFactory.add(key); |
| | | //过滤无权限产线id |
| | | 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<>(); |
| | | // //找到所有产线id的上级id |
| | | // if (productionIds != null && !productionIds.isEmpty()) { |
| | | // for (String productionId : productionIds) { |
| | | // this.getAllProductionIds(productionList, productionId, allProductionIds); |
| | | // } |
| | | // } |
| | | // //根据产线集合查找所有设备id |
| | | // if (allProductionIds.isEmpty()) { |
| | | // return null; |
| | | // } |
| | | // List<String> equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIds); |
| | | // if (StringUtils.isNotEmpty(key)) { |
| | | // //key不为空,查询所有下级产线id |
| | | // List<String> partProduction = this.findAllProductions(key); |
| | | // partProduction.add(key); |
| | | // //过滤无权限产线id |
| | | // List<String> allProductionIdsByKey = partProduction.stream().filter(allProductionIds::contains).collect(Collectors.toList()); |
| | | // equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIdsByKey); |
| | | // } |
| | | // return equipmentIds; |
| | | // |
| | | } |
| | | |
| | | /** |
| | | * 根据父级id递归查询所有下级id集合 |
| | | */ |
| | | 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; |
| | | } |
| | | |
| | | /** |