| | |
| | | import org.jeecg.modules.dnc.ucenter.UserDepartExt; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.entity.MdcUserProduction; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.dnc.service.IDeviceGroupPermissionService; |
| | | import org.jeecg.modules.system.service.IMdcUserProductionService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Autowired |
| | | @Lazy |
| | | private IDevicePermissionStreamService devicePermissionStreamService; |
| | | @Autowired |
| | | private IMdcUserProductionService mdcUserProductionService; |
| | | |
| | | @Override |
| | | public List<UserDepartExt> getUserPermsByGroupId(String groupId) { |
| | |
| | | public boolean assignAddUser(MdcProduction mdcProduction, Collection<SysUser> userList) { |
| | | if(mdcProduction == null || userList == null || userList.isEmpty()) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | List<DeviceGroupPermission> permissionList = new ArrayList<>(); |
| | | List<MdcUserProduction> mdcUserProductions=new ArrayList<>(); |
| | | List<DevicePermissionStream> permissionStreamList = new ArrayList<>(); |
| | | userList.forEach(item -> { |
| | | DeviceGroupPermission en = groupPermissionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId()); |
| | | MdcUserProduction en = mdcUserProductionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId()); |
| | | if(en == null) { |
| | | en = new DeviceGroupPermission(); |
| | | en.setUserId(item.getId()); |
| | | en.setGroupId(mdcProduction.getId()); |
| | | permissionList.add(en); |
| | | en = new MdcUserProduction(item.getId(),mdcProduction.getId()); |
| | | mdcUserProductions.add(en); |
| | | } |
| | | DevicePermissionStream stream = devicePermissionStreamService.getByGroupIdAndUserId(mdcProduction.getId(), item.getId()); |
| | | if(stream == null) { |
| | |
| | | permissionStreamList.add(stream); |
| | | } |
| | | }); |
| | | if(!permissionList.isEmpty()) { |
| | | boolean b = groupPermissionService.saveBatch(permissionList); |
| | | if(!mdcUserProductions.isEmpty()) { |
| | | boolean b = mdcUserProductionService.saveBatch(mdcUserProductions); |
| | | if(!b) { |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR); |
| | | } |
| | |
| | | public boolean assignRemoveUser(MdcProduction mdcProduction, Collection<SysUser> userList) { |
| | | if(mdcProduction == null || userList == null || userList.isEmpty()) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | List<DeviceGroupPermission> permissionList = new ArrayList<>(); |
| | | List<MdcUserProduction> mdcUserProductions=new ArrayList<>(); |
| | | List<DevicePermissionStream> permissionStreamList = new ArrayList<>(); |
| | | userList.forEach(item -> { |
| | | DeviceGroupPermission en = groupPermissionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId()); |
| | | MdcUserProduction en = mdcUserProductionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId()); |
| | | if(en != null) { |
| | | permissionList.add(en); |
| | | mdcUserProductions.add(en); |
| | | } |
| | | DevicePermissionStream stream = devicePermissionStreamService.getByGroupIdAndUserId(mdcProduction.getId(), item.getId()); |
| | | if(stream != null) { |
| | |
| | | } |
| | | }); |
| | | //校验清空设备分组权限操作 |
| | | List<DeviceGroupPermission> existList = groupPermissionService.getByGroupId(mdcProduction.getId()); |
| | | if(existList.size() <= permissionList.size()) |
| | | List<MdcUserProduction> existList = mdcUserProductionService.list(new QueryWrapper<MdcUserProduction>().eq("pro_id",mdcProduction.getId())); |
| | | if(existList.size() <= mdcUserProductions.size()) |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_USER_NONE); |
| | | if(!permissionList.isEmpty()) { |
| | | boolean b = groupPermissionService.removeByCollection(permissionList); |
| | | if(!mdcUserProductions.isEmpty()) { |
| | | boolean b = mdcUserProductionService.removeByCollection(mdcUserProductions); |
| | | if(!b) { |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR); |
| | | } |