对比新文件 |
| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.modules.dnc.entity.ComponentPermission; |
| | | import org.jeecg.modules.dnc.mapper.ComponentPermissionMapper; |
| | | import org.jeecg.modules.dnc.ucenter.UserDepartExt; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.dnc.service.IComponentPermissionService; |
| | | import org.apache.commons.collections4.ListUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class ComponentPermissionServiceImpl extends ServiceImpl<ComponentPermissionMapper, ComponentPermission> implements IComponentPermissionService { |
| | | @Override |
| | | public ComponentPermission getByComponentIdAndUserId(String componentId, String userId) { |
| | | if(!ValidateUtil.validateString(componentId) || !ValidateUtil.validateString(userId)) |
| | | return null; |
| | | List<ComponentPermission> permissions = super.lambdaQuery().eq(ComponentPermission::getComponentId, componentId).eq(ComponentPermission::getUserId, userId).list(); |
| | | if(permissions == null || permissions.isEmpty()) |
| | | return null; |
| | | return permissions.get(0); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean deleteByComponentId(String componentId) { |
| | | if(!ValidateUtil.validateString(componentId)) |
| | | return false; |
| | | LambdaQueryWrapper<ComponentPermission> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(ComponentPermission::getComponentId, componentId); |
| | | return super.remove(lambdaQueryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserDepartExt> getUserPermsByComponentId(String componentId) { |
| | | return super.getBaseMapper().getUserPermsByComponentId(componentId); |
| | | } |
| | | |
| | | @Override |
| | | public List<SysUser> getUserNonPermsByComponentId(String componentId) { |
| | | return super.getBaseMapper().getUserNonPermsByComponentId(componentId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean removeByCollection(List<ComponentPermission> permissionList) { |
| | | if(permissionList == null || permissionList.isEmpty()) |
| | | return false; |
| | | if(permissionList.size() == 1) |
| | | return super.removeById(permissionList.get(0).getId()); |
| | | List<String> ids = new ArrayList<>(); |
| | | permissionList.forEach(item -> { |
| | | ids.add(item.getId()); |
| | | }); |
| | | return super.removeByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<ComponentPermission> getByComponentId(String componentId) { |
| | | List<ComponentPermission> list = super.lambdaQuery().eq(ComponentPermission::getComponentId, componentId).list(); |
| | | if(list == null) |
| | | list = Collections.emptyList(); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<ComponentPermission> getByComponentIdsAndUserIds(List<String> componentIds, List<String> userIds) { |
| | | if(componentIds == null || componentIds.isEmpty() || userIds == null || userIds.isEmpty()) |
| | | return null; |
| | | List<ComponentPermission> total = new ArrayList<>(); |
| | | List<List<String>> compListArr; |
| | | List<List<String>> userListArr; |
| | | if(componentIds.size() > 1000){ |
| | | compListArr = ListUtils.partition(componentIds, 100); |
| | | }else { |
| | | compListArr = ListUtils.partition(componentIds, 1000); |
| | | } |
| | | if(userIds.size() > 1000){ |
| | | userListArr = ListUtils.partition(userIds, 100); |
| | | }else { |
| | | userListArr = ListUtils.partition(userIds, 1000); |
| | | } |
| | | for(List<String> compList : compListArr) { |
| | | for(List<String> userList : userListArr){ |
| | | LambdaQueryWrapper<ComponentPermission> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.in(ComponentPermission::getComponentId, compList); |
| | | queryWrapper.in(ComponentPermission::getUserId, userList); |
| | | List<ComponentPermission> list = super.list(queryWrapper); |
| | | if(list != null && !list.isEmpty()){ |
| | | total.addAll(list); |
| | | } |
| | | } |
| | | } |
| | | return total; |
| | | } |
| | | } |