| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.modules.dnc.entity.DeviceGroup; |
| | | import org.jeecg.modules.dnc.entity.DeviceGroupPermission; |
| | | import org.jeecg.modules.dnc.entity.DevicePermissionStream; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.mapper.DeviceGroupPermissionMapper; |
| | | import org.jeecg.modules.dnc.response.CommonCode; |
| | | import org.jeecg.modules.dnc.response.DeviceGroupCode; |
| | | import org.jeecg.modules.dnc.service.IDevicePermissionStreamService; |
| | | 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.SysUser; |
| | | import org.jeecg.modules.dnc.service.IDeviceGroupPermissionService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class DeviceGroupPermissionServiceImpl extends ServiceImpl<DeviceGroupPermissionMapper, DeviceGroupPermission> implements IDeviceGroupPermissionService { |
| | | @Autowired |
| | | @Lazy |
| | | private IDeviceGroupPermissionService groupPermissionService; |
| | | @Autowired |
| | | @Lazy |
| | | private IDevicePermissionStreamService devicePermissionStreamService; |
| | | |
| | | @Override |
| | | public List<UserDepartExt> getUserPermsByGroupId(String groupId) { |
| | | return super.getBaseMapper().getUserPermsByGroupId(groupId); |
| | |
| | | if(permissions == null || permissions.isEmpty()) |
| | | return false; |
| | | if(permissions.size() == 1){ |
| | | super.removeById(permissions.get(0).getGroupPermId()); |
| | | return super.removeById(permissions.get(0).getGroupPermId()); |
| | | } |
| | | List<String> ids = new ArrayList<>(); |
| | | permissions.forEach(item -> { |
| | |
| | | list = Collections.emptyList(); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | 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<DevicePermissionStream> permissionStreamList = new ArrayList<>(); |
| | | userList.forEach(item -> { |
| | | DeviceGroupPermission en = groupPermissionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId()); |
| | | if(en == null) { |
| | | en = new DeviceGroupPermission(); |
| | | en.setUserId(item.getId()); |
| | | en.setGroupId(mdcProduction.getId()); |
| | | permissionList.add(en); |
| | | } |
| | | DevicePermissionStream stream = devicePermissionStreamService.getByGroupIdAndUserId(mdcProduction.getId(), item.getId()); |
| | | if(stream == null) { |
| | | stream = new DevicePermissionStream(); |
| | | stream.setUserId(item.getId()); |
| | | stream.setGroupId(mdcProduction.getId()); |
| | | permissionStreamList.add(stream); |
| | | } |
| | | }); |
| | | if(!permissionList.isEmpty()) { |
| | | boolean b = groupPermissionService.saveBatch(permissionList); |
| | | if(!b) { |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR); |
| | | } |
| | | } |
| | | if(!permissionStreamList.isEmpty()) { |
| | | boolean b = devicePermissionStreamService.saveBatch(permissionStreamList); |
| | | if(!b) { |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | 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<DevicePermissionStream> permissionStreamList = new ArrayList<>(); |
| | | userList.forEach(item -> { |
| | | DeviceGroupPermission en = groupPermissionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId()); |
| | | if(en != null) { |
| | | permissionList.add(en); |
| | | } |
| | | DevicePermissionStream stream = devicePermissionStreamService.getByGroupIdAndUserId(mdcProduction.getId(), item.getId()); |
| | | if(stream != null) { |
| | | permissionStreamList.add(stream); |
| | | } |
| | | }); |
| | | //校验清空设备分组权限操作 |
| | | List<DeviceGroupPermission> existList = groupPermissionService.getByGroupId(mdcProduction.getId()); |
| | | if(existList.size() <= permissionList.size()) |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_USER_NONE); |
| | | if(!permissionList.isEmpty()) { |
| | | boolean b = groupPermissionService.removeByCollection(permissionList); |
| | | if(!b) { |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR); |
| | | } |
| | | } |
| | | if(!permissionStreamList.isEmpty()) { |
| | | boolean b = devicePermissionStreamService.removeByCollection(permissionStreamList); |
| | | if(!b) { |
| | | ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | } |