lyh
2025-02-24 3f5737664d799ece89224079860505a009dec32b
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceGroupServiceImpl.java
@@ -39,8 +39,6 @@
    @Autowired
    private IDeviceGroupDepartService deviceGroupDepartService;
    @Autowired
    private IDepartmentService departmentService;
    @Autowired
    @Lazy
    private IDeviceInfoService deviceInfoService;
    @Autowired
@@ -375,83 +373,83 @@
        return deviceGroupDepartService.getDepartNonPermsByGroupId(groupId);
    }
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean assignAddDepartment(String groupId, Integer relativeFlag, String[] departmentIds) {
        if(!ValidateUtil.validateString(groupId) || !ValidateUtil.validateInteger(relativeFlag) || departmentIds == null || departmentIds.length < 1)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<String> ids = new ArrayList<>(departmentIds.length);
        Collections.addAll(ids, departmentIds);
        Collection<Department> departmentList = departmentService.listByIds(ids);
        if(departmentList == null || departmentList.isEmpty() || departmentList.size() != departmentIds.length)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        DeviceGroup deviceGroup = super.getById(groupId);
        if(deviceGroup == null)
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
        boolean b1 = deviceInfoService.checkDevicePerm(1, deviceGroup.getGroupId());
        if(!b1) {
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
        }
        b1 = assignAddDepartment(deviceGroup, departmentList);
        if(!b1) {
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
        }
        if(relativeFlag == 1) {
            //获取分组下所有的子分组
            List<DeviceGroup> childrenList = getChildrenByParentId(deviceGroup.getGroupId());
            if(childrenList != null && !childrenList.isEmpty()) {
                childrenList.forEach(item -> {
                    boolean b = deviceInfoService.checkDevicePerm(1, item.getGroupId());
                    if(b) {
                        b = assignAddDepartment(item, departmentList);
                        if(!b) {
                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                        }
                    }
                });
            }
        }
        return true;
    }
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean assignRemoveDepartment(String groupId, Integer relativeFlag, String[] departmentIds) {
        if(!ValidateUtil.validateString(groupId) || !ValidateUtil.validateInteger(relativeFlag) || departmentIds == null || departmentIds.length < 1)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<String> ids = new ArrayList<>(departmentIds.length);
        Collections.addAll(ids, departmentIds);
        Collection<Department> departmentList = departmentService.listByIds(ids);
        if(departmentList == null || departmentList.isEmpty() || departmentList.size() != departmentIds.length)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        DeviceGroup deviceGroup = super.getById(groupId);
        if(deviceGroup == null)
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
        boolean b1 = deviceInfoService.checkDevicePerm(1, deviceGroup.getGroupId());
        if(!b1) {
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
        }
        b1 = assignRemoveDepartment(deviceGroup, departmentList);
        if(!b1) {
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
        }
        if(relativeFlag == 1) {
            //获取分组下所有的子分组
            List<DeviceGroup> childrenList = getChildrenByParentId(deviceGroup.getGroupId());
            if(childrenList != null && !childrenList.isEmpty()) {
                childrenList.forEach(item -> {
                    boolean b = deviceInfoService.checkDevicePerm(1, item.getGroupId());
                    if(b) {
                        b = assignRemoveDepartment(item, departmentList);
                        if(!b) {
                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                        }
                    }
                });
            }
        }
        return true;
    }
//    @Override
//    @Transactional(rollbackFor = {Exception.class})
//    public boolean assignAddDepartment(String groupId, Integer relativeFlag, String[] departmentIds) {
//        if(!ValidateUtil.validateString(groupId) || !ValidateUtil.validateInteger(relativeFlag) || departmentIds == null || departmentIds.length < 1)
//            ExceptionCast.cast(CommonCode.INVALID_PARAM);
//        List<String> ids = new ArrayList<>(departmentIds.length);
//        Collections.addAll(ids, departmentIds);
//        Collection<Department> departmentList = departmentService.listByIds(ids);
//        if(departmentList == null || departmentList.isEmpty() || departmentList.size() != departmentIds.length)
//            ExceptionCast.cast(CommonCode.INVALID_PARAM);
//        DeviceGroup deviceGroup = super.getById(groupId);
//        if(deviceGroup == null)
//            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
//        boolean b1 = deviceInfoService.checkDevicePerm(1, deviceGroup.getGroupId());
//        if(!b1) {
//            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
//        }
//        b1 = assignAddDepartment(deviceGroup, departmentList);
//        if(!b1) {
//            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
//        }
//        if(relativeFlag == 1) {
//            //获取分组下所有的子分组
//            List<DeviceGroup> childrenList = getChildrenByParentId(deviceGroup.getGroupId());
//            if(childrenList != null && !childrenList.isEmpty()) {
//                childrenList.forEach(item -> {
//                    boolean b = deviceInfoService.checkDevicePerm(1, item.getGroupId());
//                    if(b) {
//                        b = assignAddDepartment(item, departmentList);
//                        if(!b) {
//                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
//                        }
//                    }
//                });
//            }
//        }
//        return true;
//    }
//
//    @Override
//    @Transactional(rollbackFor = {Exception.class})
//    public boolean assignRemoveDepartment(String groupId, Integer relativeFlag, String[] departmentIds) {
//        if(!ValidateUtil.validateString(groupId) || !ValidateUtil.validateInteger(relativeFlag) || departmentIds == null || departmentIds.length < 1)
//            ExceptionCast.cast(CommonCode.INVALID_PARAM);
//        List<String> ids = new ArrayList<>(departmentIds.length);
//        Collections.addAll(ids, departmentIds);
//        Collection<Department> departmentList = departmentService.listByIds(ids);
//        if(departmentList == null || departmentList.isEmpty() || departmentList.size() != departmentIds.length)
//            ExceptionCast.cast(CommonCode.INVALID_PARAM);
//        DeviceGroup deviceGroup = super.getById(groupId);
//        if(deviceGroup == null)
//            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
//        boolean b1 = deviceInfoService.checkDevicePerm(1, deviceGroup.getGroupId());
//        if(!b1) {
//            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
//        }
//        b1 = assignRemoveDepartment(deviceGroup, departmentList);
//        if(!b1) {
//            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
//        }
//        if(relativeFlag == 1) {
//            //获取分组下所有的子分组
//            List<DeviceGroup> childrenList = getChildrenByParentId(deviceGroup.getGroupId());
//            if(childrenList != null && !childrenList.isEmpty()) {
//                childrenList.forEach(item -> {
//                    boolean b = deviceInfoService.checkDevicePerm(1, item.getGroupId());
//                    if(b) {
//                        b = assignRemoveDepartment(item, departmentList);
//                        if(!b) {
//                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
//                        }
//                    }
//                });
//            }
//        }
//        return true;
//    }
    @Override
    @Transactional(rollbackFor = {Exception.class})