|
@@ -1,10 +1,14 @@
|
|
|
using System;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using System.Linq;
|
|
|
+using VCommon.DataModel;
|
|
|
using VCommon.VApplication.Authorization;
|
|
|
using VCommon.VApplication.Dto;
|
|
|
using VCommon.VApplication.Linq.Expressions;
|
|
|
using VCommon.VAutoMapper;
|
|
|
using VCommon.VOpenApi.VAspNetCore;
|
|
|
using VCommonCoreExample.AppServices.Basic;
|
|
|
+using VCommonCoreExample.AppServices.System.Dto;
|
|
|
using VCommonCoreExample.AppServices.System.Roles.Dto;
|
|
|
using VCommonCoreExample.Authorization;
|
|
|
using VCommonCoreExample.Caching;
|
|
@@ -38,7 +42,7 @@ namespace VCommonCoreExample.AppServices.System.Roles
|
|
|
private readonly IPermissionManager _permissionManager;
|
|
|
private readonly AuthCache _authCache;
|
|
|
|
|
|
- public RoleService(IPermissionManager permissionManager,AuthCache authCache)
|
|
|
+ public RoleService(IPermissionManager permissionManager, AuthCache authCache)
|
|
|
{
|
|
|
_permissionManager = permissionManager;
|
|
|
_authCache = authCache;
|
|
@@ -61,7 +65,15 @@ namespace VCommonCoreExample.AppServices.System.Roles
|
|
|
|
|
|
public RoleFormPrepOutput FormPrep(Guid? input)
|
|
|
{
|
|
|
- var result = new RoleFormPrepOutput(_permissionManager.GetPermissionTreeOutput(VSession.Side));
|
|
|
+ var tree = _permissionManager.GetPermissionTreeOutput(VSession.Side);
|
|
|
+
|
|
|
+ var treeOutput = TreeCopy.CreateFrom<PermissionNodeOutput, ElTreeNode, string, string>(tree,
|
|
|
+ (k, v, c) => new ElTreeNode { Key = k, Label = v, Children = c.ToArray() },
|
|
|
+ p => p.Code,
|
|
|
+ p => p.Name,
|
|
|
+ p => p.Children);
|
|
|
+
|
|
|
+ var result = new RoleFormPrepOutput(treeOutput.ToArray());
|
|
|
if (input.HasValue)
|
|
|
{
|
|
|
using var repo = GetRepository();
|
|
@@ -91,17 +103,17 @@ namespace VCommonCoreExample.AppServices.System.Roles
|
|
|
{
|
|
|
foreach (var s in input.PermissionSet)
|
|
|
{
|
|
|
- if (false == _permissionManager.ValidPermission(s)) throw new VFriendlyException($"无效的权限代码:{s}");
|
|
|
+ if (false == _permissionManager.ValidPermission(s)) throw new VFriendlyException($"无效的权限代码:{s}");
|
|
|
}
|
|
|
|
|
|
var repo = GetRepository();
|
|
|
- if(repo.CheckExist(p => p.Id != input.Id && p.Name == input.Name)) throw new VFriendlyException("角色名称已经存在");
|
|
|
+ if (repo.CheckExist(p => p.Id != input.Id && p.Name == input.Name)) throw new VFriendlyException("角色名称已经存在");
|
|
|
|
|
|
var entity = repo.GetEntityOrDefault(input.Id) ?? throw new VFriendlyException("找不到角色");
|
|
|
input.MapTo(entity);
|
|
|
repo.SaveChanges();
|
|
|
|
|
|
- _authCache.ClearRole(VSession.TenantId,entity.Id);
|
|
|
+ _authCache.ClearRole(VSession.TenantId, entity.Id);
|
|
|
}
|
|
|
|
|
|
public void Delete(DeleteInput input)
|