| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vci.ubcs.code.feign.ICodeClassifyClient; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import com.vci.ubcs.system.dto.ClassifyAuthDTO; |
| | | import com.vci.ubcs.system.entity.ClassifyAuth; |
| | | import com.vci.ubcs.system.entity.Menu; |
| | | import com.vci.ubcs.system.mapper.ClassifyAuthMapper; |
| | |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 分类授权 |
| | | * 分类授权,数据授权 |
| | | * @author ludc |
| | | * @date 2023/12/25 15:35 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 分类授权保存接口 |
| | | * @param classifyAuthList |
| | | * @param classifyAuthListDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R submit(List<ClassifyAuth> classifyAuthList) { |
| | | if(classifyAuthList.isEmpty()){ |
| | | public R submit(ClassifyAuthDTO classifyAuthListDTO) throws ServiceException{ |
| | | // 是清空授权列表 |
| | | if(classifyAuthListDTO.getIsCLear()){ |
| | | if(Func.isEmpty(classifyAuthListDTO.getClassifyId())){ |
| | | return R.fail("清空授权列表时,未获取的分类id"); |
| | | } |
| | | this.classifyAuthMapper.delete(Wrappers.<ClassifyAuth>update() |
| | | .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthListDTO.getClassifyId()) |
| | | ); |
| | | return R.success("授权列表清空成功"); |
| | | } |
| | | |
| | | if(!classifyAuthListDTO.getIsCLear() && classifyAuthListDTO.getClassifyAuthList().isEmpty()){ |
| | | R.fail("授权列表不能为空!"); |
| | | } |
| | | // 判重,查看是否存在同一个classid下配置了相同的角色 |
| | | Map<String, Long> roleidCounts = classifyAuthList.stream() |
| | | Map<String, Long> roleidCounts = classifyAuthListDTO.getClassifyAuthList().stream() |
| | | .collect(Collectors.groupingBy(ClassifyAuth::getRoleId, Collectors.counting())); |
| | | |
| | | // 检查是否有roleid出现次数大于1的情况 |
| | |
| | | } |
| | | |
| | | // 如果传过来的集合中该分类id下删除了部分角色的授权,就需要将该库中classifyId下不存在的数据删掉 |
| | | List<String> roleIds = classifyAuthList.stream().map(ClassifyAuth::getRoleId).collect(Collectors.toList()); |
| | | List<String> roleIds = classifyAuthListDTO.getClassifyAuthList().stream().map(ClassifyAuth::getRoleId).collect(Collectors.toList()); |
| | | // 删除 |
| | | LambdaUpdateWrapper<ClassifyAuth> updateWrapper = Wrappers.<ClassifyAuth>update() |
| | | .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthList.get(0).getClassifyId()) |
| | | .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthListDTO.getClassifyAuthList().get(0).getClassifyId()) |
| | | .notIn(ClassifyAuth::getRoleId, roleIds); |
| | | try { |
| | | this.classifyAuthMapper.delete(updateWrapper); |
| | | }catch (Exception e){ |
| | | throw new ServiceException("分类授权过程中出现错误,错误原因:"+e.getMessage()); |
| | | } |
| | | return R.status(saveOrUpdateBatch(classifyAuthList)); |
| | | return R.status(saveOrUpdateBatch(classifyAuthListDTO.getClassifyAuthList())); |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new ServiceException("缺少必传参数分类id"); |
| | | } |
| | | LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query() |
| | | .lambda().eq(ClassifyAuth::getClassifyId,classifyAuthVO.getClassifyId()); |
| | | .lambda().eq(ClassifyAuth::getClassifyId,classifyAuthVO.getClassifyId()) |
| | | .eq(ClassifyAuth::getAuthType,classifyAuthVO.getAuthType()); |
| | | List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper); |
| | | if(classifyAuths.isEmpty()){ |
| | | return new ArrayList<ClassifyAuthVO>(); |
| | |
| | | /** |
| | | * 查询该分类下,当前登录的角色有哪些按钮权限 |
| | | * @param classifyId |
| | | * @param menuCode |
| | | * @param authType |
| | | * @return |
| | | */ |
| | | public Map<String,Boolean> getAuthButtonList(String classifyId){ |
| | | public Map<String,Boolean> getAuthButtonList(String classifyId,String menuCode,String authType){ |
| | | List<Menu> menuList = this.getButtonList(classifyId, menuCode, authType); |
| | | if(menuList.isEmpty()){ |
| | | return new HashMap<>(); |
| | | } |
| | | Map<String, Boolean> buttonMaps = menuList.stream() |
| | | .collect(Collectors.toMap(Menu::getCode, menu -> true)); |
| | | return buttonMaps; |
| | | } |
| | | |
| | | /** |
| | | * 查询该主数据下,当前登录的角色有哪些按钮菜单权限 |
| | | * @param classifyId |
| | | * @param menuCode |
| | | * @param authType |
| | | * @return |
| | | */ |
| | | public List<Menu> getAuthMenuButtonList(String classifyId,String menuCode,String authType){ |
| | | List<Menu> buttonList = getButtonList(classifyId, menuCode, authType); |
| | | return buttonList; |
| | | } |
| | | |
| | | private List<Menu> getButtonList(String classifyId,String menuCode,String authType){ |
| | | if(Func.isBlank(classifyId)){ |
| | | throw new ServiceException("必传参数分类oid不能为空!"); |
| | | } |
| | |
| | | } |
| | | // 返回的分类oid是当前节点为第一个,后面依次是他的上层节点 |
| | | List<String> classifyOidList = listR.getData(); |
| | | final String roleIds = AuthUtil.getUser().getRoleId(); |
| | | final List<String> roleIds = Func.toStrList(",",AuthUtil.getUser().getRoleId()); |
| | | // 先查询按钮id列表 |
| | | LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query() |
| | | .lambda().eq(ClassifyAuth::getClassifyId, classifyId) |
| | | .eq(ClassifyAuth::getAuthType,authType) |
| | | .in(ClassifyAuth::getRoleId, roleIds); |
| | | List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper); |
| | | //如果当前分类没有找到授权配置,就依次从当前节点往上层节点找授权配置,找到了就停止,没找到就一直找到最后 |
| | |
| | | Boolean isAdmin = VciBaseUtil.checkAdminTenant(); |
| | | // 未配置按钮权限 |
| | | if(!isAdmin && (classifyAuths.isEmpty() || Func.isBlank(classifyAuths.get(0).getButtonIds()))){ |
| | | return new HashMap<>(); |
| | | return new ArrayList<>(); |
| | | } |
| | | List<String> condition1 = new ArrayList<>(); |
| | | List<String> ids = new ArrayList<>(); |
| | | // 如果不是超管用户 |
| | | if(!isAdmin){ |
| | | condition1.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(","))); |
| | | ids.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(","))); |
| | | } |
| | | List<Menu> menuList = menuService.getMenuListById(condition1,"1648879284590858241"); |
| | | if(menuList.isEmpty()){ |
| | | return new HashMap<>(); |
| | | } |
| | | Map<String, Boolean> buttonMaps = menuList.stream() |
| | | .collect(Collectors.toMap(Menu::getCode, menu -> true)); |
| | | return buttonMaps; |
| | | return menuService.getMenuListByCode(ids,menuCode,roleIds); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<String> getViewClassByRoleIds(List<String> roleIds) { |
| | | public List<String> getViewClassByRoleIds(List<String> roleIds,String authType,String buttonCode,String menuCode) { |
| | | if(roleIds.isEmpty()){ |
| | | return new ArrayList<>(); |
| | | } |
| | | return this.classifyAuthMapper.getViewClassByRoleIds(roleIds); |
| | | return this.classifyAuthMapper.getViewClassByRoleIds(roleIds, authType,buttonCode,menuCode); |
| | | } |
| | | |
| | | } |