Search in sources :

Example 1 with SysRolePermission

use of vip.mate.system.entity.SysRolePermission in project matecloud by matevip.

the class SysRoleController method savePermission.

/**
 * 角色权限设置
 *
 * @param roleId  角色Id
 * @param ids    多个id使用逗号分隔
 * @return Result
 */
@PreAuth
@Log(value = "角色权限设置", exception = "角色权限设置")
@PostMapping("/set-permission")
@ApiOperation(value = "角色权限设置", notes = "角色权限设置")
@ApiImplicitParams({ @ApiImplicitParam(name = "roleId", required = true, value = "角色ID", paramType = "form"), @ApiImplicitParam(name = "ids", required = true, value = "多个用,号隔开", paramType = "form") })
public Result<?> savePermission(@RequestParam String roleId, @RequestParam String ids) {
    Collection longs = CollectionUtil.stringToCollection(ids);
    long roleIdc = CollectionUtil.strToLong(roleId, 0L);
    LambdaQueryWrapper<SysRolePermission> lambdaQueryWrapper = new LambdaQueryWrapper<>();
    lambdaQueryWrapper.eq(SysRolePermission::getRoleId, roleIdc);
    sysRolePermissionService.remove(lambdaQueryWrapper);
    for (Iterator<Long> it = longs.iterator(); it.hasNext(); ) {
        SysRolePermission sysRolePermission = new SysRolePermission();
        long menuId = it.next();
        sysRolePermission.setMenuId(menuId);
        sysRolePermission.setRoleId(roleIdc);
        sysRolePermissionService.saveOrUpdate(sysRolePermission);
    }
    redisService.del("getPermission-" + roleId);
    return Result.success("操作成功");
}
Also used : SysRolePermission(vip.mate.system.entity.SysRolePermission) Collection(java.util.Collection) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) PreAuth(vip.mate.core.auth.annotation.PreAuth) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) Log(vip.mate.core.log.annotation.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with SysRolePermission

use of vip.mate.system.entity.SysRolePermission in project matecloud by matevip.

the class SysRoleServiceImpl method set.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean set(SysRole sysRole) {
    this.saveOrUpdate(sysRole);
    if (ObjectUtil.isNotEmpty(sysRole.getMenu())) {
        List<SysRolePermission> collect = sysRole.getMenu().stream().map(s -> {
            SysRolePermission sysRolePermission = new SysRolePermission();
            sysRolePermission.setMenuId(Long.valueOf(s));
            sysRolePermission.setRoleId(sysRole.getId());
            return sysRolePermission;
        }).collect(Collectors.toList());
        // 根据角色ID删除所有菜单值
        sysRolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getRoleId, sysRole.getId()));
        // 重新写入角色对应的权限值
        sysRolePermissionService.saveBatch(collect);
    }
    return Boolean.TRUE;
}
Also used : ISysUserService(vip.mate.system.service.ISysUserService) SysUser(vip.mate.system.entity.SysUser) Arrays(java.util.Arrays) ObjectUtil(cn.hutool.core.util.ObjectUtil) ISysRolePermissionService(vip.mate.system.service.ISysRolePermissionService) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysRolePermission(vip.mate.system.entity.SysRolePermission) Service(org.springframework.stereotype.Service) Map(java.util.Map) ISysRoleService(vip.mate.system.service.ISysRoleService) SysRolePOI(vip.mate.system.poi.SysRolePOI) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) Search(vip.mate.core.database.entity.Search) SysRoleVO(vip.mate.system.vo.SysRoleVO) SysRole(vip.mate.system.entity.SysRole) PageUtil(vip.mate.core.database.util.PageUtil) Collectors(java.util.stream.Collectors) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) SysRoleMapper(vip.mate.system.mapper.SysRoleMapper) Lazy(org.springframework.context.annotation.Lazy) IPage(com.baomidou.mybatisplus.core.metadata.IPage) BeanUtils(org.springframework.beans.BeanUtils) Transactional(org.springframework.transaction.annotation.Transactional) SysRolePermission(vip.mate.system.entity.SysRolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 SysRolePermission (vip.mate.system.entity.SysRolePermission)2 ObjectUtil (cn.hutool.core.util.ObjectUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BeanUtils (org.springframework.beans.BeanUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Lazy (org.springframework.context.annotation.Lazy)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1 PreAuth (vip.mate.core.auth.annotation.PreAuth)1