重构角色管理,数据权限更完善
This commit is contained in:
parent
f8d6a23cf0
commit
6c6d51a4d2
|
@ -15,6 +15,7 @@ import net.maku.system.service.SysRoleMenuService;
|
||||||
import net.maku.system.service.SysRoleService;
|
import net.maku.system.service.SysRoleService;
|
||||||
import net.maku.system.vo.SysMenuVO;
|
import net.maku.system.vo.SysMenuVO;
|
||||||
import net.maku.system.query.SysRoleQuery;
|
import net.maku.system.query.SysRoleQuery;
|
||||||
|
import net.maku.system.vo.SysRoleDataScopeVO;
|
||||||
import net.maku.system.vo.SysRoleVO;
|
import net.maku.system.vo.SysRoleVO;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -93,6 +94,15 @@ public class SysRoleController {
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("data-scope")
|
||||||
|
@Operation(summary = "数据权限")
|
||||||
|
@PreAuthorize("hasAuthority('sys:role:update')")
|
||||||
|
public Result<String> dataScope(@RequestBody @Valid SysRoleDataScopeVO vo){
|
||||||
|
sysRoleService.dataScope(vo);
|
||||||
|
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@Operation(summary = "删除")
|
@Operation(summary = "删除")
|
||||||
@PreAuthorize("hasAuthority('sys:role:delete')")
|
@PreAuthorize("hasAuthority('sys:role:delete')")
|
||||||
|
|
|
@ -4,6 +4,7 @@ import net.maku.framework.common.page.PageResult;
|
||||||
import net.maku.framework.common.service.BaseService;
|
import net.maku.framework.common.service.BaseService;
|
||||||
import net.maku.system.entity.SysRoleEntity;
|
import net.maku.system.entity.SysRoleEntity;
|
||||||
import net.maku.system.query.SysRoleQuery;
|
import net.maku.system.query.SysRoleQuery;
|
||||||
|
import net.maku.system.vo.SysRoleDataScopeVO;
|
||||||
import net.maku.system.vo.SysRoleVO;
|
import net.maku.system.vo.SysRoleVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,5 +24,7 @@ public interface SysRoleService extends BaseService<SysRoleEntity> {
|
||||||
|
|
||||||
void update(SysRoleVO vo);
|
void update(SysRoleVO vo);
|
||||||
|
|
||||||
|
void dataScope(SysRoleDataScopeVO vo);
|
||||||
|
|
||||||
void delete(List<Long> idList);
|
void delete(List<Long> idList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,12 @@ import net.maku.system.service.SysRoleMenuService;
|
||||||
import net.maku.system.service.SysRoleService;
|
import net.maku.system.service.SysRoleService;
|
||||||
import net.maku.system.service.SysUserRoleService;
|
import net.maku.system.service.SysUserRoleService;
|
||||||
import net.maku.system.query.SysRoleQuery;
|
import net.maku.system.query.SysRoleQuery;
|
||||||
|
import net.maku.system.vo.SysRoleDataScopeVO;
|
||||||
import net.maku.system.vo.SysRoleVO;
|
import net.maku.system.vo.SysRoleVO;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,14 +65,11 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntit
|
||||||
SysRoleEntity entity = SysRoleConvert.INSTANCE.convert(vo);
|
SysRoleEntity entity = SysRoleConvert.INSTANCE.convert(vo);
|
||||||
|
|
||||||
// 保存角色
|
// 保存角色
|
||||||
entity.setDataScope(DataScopeEnum.CUSTOM.getValue());
|
entity.setDataScope(DataScopeEnum.SELF.getValue());
|
||||||
baseMapper.insert(entity);
|
baseMapper.insert(entity);
|
||||||
|
|
||||||
// 保存角色菜单关系
|
// 保存角色菜单关系
|
||||||
sysRoleMenuService.saveOrUpdate(entity.getId(), vo.getMenuIdList());
|
sysRoleMenuService.saveOrUpdate(entity.getId(), vo.getMenuIdList());
|
||||||
|
|
||||||
// 保存角色数据权限关系
|
|
||||||
sysRoleDataScopeService.saveOrUpdate(entity.getId(), vo.getOrgIdList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,9 +82,22 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntit
|
||||||
|
|
||||||
// 更新角色菜单关系
|
// 更新角色菜单关系
|
||||||
sysRoleMenuService.saveOrUpdate(entity.getId(), vo.getMenuIdList());
|
sysRoleMenuService.saveOrUpdate(entity.getId(), vo.getMenuIdList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void dataScope(SysRoleDataScopeVO vo) {
|
||||||
|
SysRoleEntity entity = getById(vo.getId());
|
||||||
|
entity.setDataScope(vo.getDataScope());
|
||||||
|
// 更新角色
|
||||||
|
updateById(entity);
|
||||||
|
|
||||||
// 更新角色数据权限关系
|
// 更新角色数据权限关系
|
||||||
|
if(vo.getDataScope().equals(DataScopeEnum.CUSTOM.getValue())){
|
||||||
sysRoleDataScopeService.saveOrUpdate(entity.getId(), vo.getOrgIdList());
|
sysRoleDataScopeService.saveOrUpdate(entity.getId(), vo.getOrgIdList());
|
||||||
|
}else {
|
||||||
|
sysRoleDataScopeService.deleteByRoleIdList(Collections.singletonList(vo.getId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package net.maku.system.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色数据权限
|
||||||
|
*
|
||||||
|
* @author 阿沐 babamu@126.com
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "角色数据权限")
|
||||||
|
public class SysRoleDataScopeVO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "id")
|
||||||
|
@NotNull(message = "角色ID不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "数据范围 0:全部数据 1:本部门及子部门数据 2:本部门数据 3:本人数据 4:自定义数据")
|
||||||
|
@NotNull(message = "数据范围不能为空")
|
||||||
|
private Integer dataScope;
|
||||||
|
|
||||||
|
@Schema(description = "机构ID列表")
|
||||||
|
private List<Long> orgIdList;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user