权限修改 添加英文字段、租户取消授权菜单

usertest
ZR20090193-陈敬勇 5 months ago
parent 4c398bf0be
commit 104697e40b

@ -136,11 +136,24 @@ public class DataResult : DataResult<object>
var result = string.Empty;
var setInfo = db.Queryable<SysLanguageSet>().Where(x => x.MultiCode == multiCode && x.LanguageType == language && x.IsPlaceholder == true)
.First();
if (language != "CN" && setInfo.IsNull())
if (setInfo.IsNotNull())
{
throw new Exception($"未设置多语言:"+ language + "下的消息提示代码:"+ multiCode);
}
desc = setInfo.Content;
desc = setInfo.Content;
}
else
{
if (language == "CN")
{
var fieldInfo = typeof(MultiLanguageConst).GetField(nameof(multiCode));
var attribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
desc = attribute?.Description ?? string.Empty;
}
else
{
throw new Exception($"未设置多语言:" + language + "下的消息提示代码:" + multiCode);
}
}
return new DataResult(ResultCode.Error, string.Format(desc, placeholde1, placeholde2, placeholde3, placeholde4, placeholde5), multiCode);
}

@ -22,6 +22,11 @@ public class RouteItem
public string Name { get; set; }
public string EnName { get; set; }
public bool IsCache { get; set; }
public string Component { get; set; }
public string Redirect { get; set; }
@ -45,6 +50,7 @@ public class RouteMeta
/// </summary>
public string Title { get; set; }
public string Icon { get; set; }
}

@ -531,6 +531,7 @@ public class CommonService : ICommonService
Path = a.Url,
Name = a.PermissionName,
Component = a.Component,
IsCache = a.IsCache,
Meta = new RouteMeta()
{
Title = a.Title,
@ -619,6 +620,7 @@ public class CommonService : ICommonService
ParentId = a.PermissionId,
Path = a.Url,
Name = a.PermissionName,
EnName = a.PermissionEnName,
Component = a.Component,
Redirect = a.Redirect,
SortCode = a.SortCode,
@ -651,7 +653,9 @@ public class CommonService : ICommonService
ParentId = a.ParentId,
Path = a.Url,
Name = a.PermissionName,
EnName = a.PermissionEnName,
Component = a.Component,
IsCache = a.IsCache,
Meta = new RouteMeta()
{
Title = a.Title,
@ -676,7 +680,9 @@ public class CommonService : ICommonService
ParentId = a.ParentId,
Path = a.Url,
Name = a.PermissionName,
EnName = a.PermissionEnName,
Component = a.Component,
IsCache = a.IsCache,
Meta = new RouteMeta()
{
Title = a.Title,
@ -744,6 +750,7 @@ public class CommonService : ICommonService
.Select(a => new PermissionTreeList
{
Title = a.PermissionName,
EnTitle = a.PermissionEnName,
Key = a.Id,
Icon = a.Icon
})
@ -758,6 +765,7 @@ public class CommonService : ICommonService
.Select(a => new PermissionTreeList
{
Title = a.PermissionName,
EnTitle = a.PermissionEnName,
Key = a.Id,
Icon = a.Icon
}).ToList();

@ -69,7 +69,7 @@ public class TenantService : ITenantService
/// <returns></returns>
public DataResult<long[]> GetTenantPermission(string id)
{
var data = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x => x.TenantId == long.Parse(id))
var data = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x => x.TenantId == long.Parse(id) && x.IsHidden == false)
.Select(x => x.PermissionId).ToArray();
return DataResult<long[]>.Success("获取数据成功!", data, MultiLanguageConst.DataQuerySuccess);
}
@ -87,16 +87,23 @@ public class TenantService : ITenantService
db.Ado.BeginTran();
var existPermissions = db.Queryable<SysPermissionTenant>().Filter(null, true)
.Where(x => x.TenantId == req.TenantId).Select(n => n.PermissionId).ToArray();
.Where(x => x.TenantId == req.TenantId && x.IsHidden == false).Select(n => n.PermissionId).ToArray();
var hiddenPermissions = db.Queryable<SysPermissionTenant>().Filter(null, true)
.Where(x => x.TenantId == req.TenantId && x.IsHidden == true).Select(n => n.PermissionId).ToArray();
var tenant = db.Queryable<SysTenant>().First(x => x.Id == req.TenantId);
IEnumerable<long> delPermissions = existPermissions.AsQueryable().Except(req.PermissionIds);
// if (delPermissions.Count() > 0)
// {
// var delPers = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x =>
// x.TenantId == req.TenantId && delPermissions.Contains(x.PermissionId))
// .ToList();
// db.Deleteable(delPers).ExecuteCommand();
// }
//取消权限
if (delPermissions.Count() > 0)
{
var delPers = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x =>
x.TenantId == req.TenantId && delPermissions.Contains(x.PermissionId))
.ToList();
foreach (var item in delPers)
{
item.IsHidden = true;
}
db.Updateable(delPers).ExecuteCommand();
}
IEnumerable<long> addPermissions = req.PermissionIds.AsQueryable().Except(existPermissions);
if (addPermissions.Count() > 0)
@ -111,24 +118,37 @@ public class TenantService : ITenantService
//写入租户管理员权限
var rolePerList = new List<SysRolePermission>();
foreach (var item in addPers)
{
var rolePer = item.Adapt<SysRolePermission>();
rolePer.RoleId = tenantRole.Id;
rolePer.PermissionId = item.Id;
rolePer.IsPermission = 1;
{
if (!db.Queryable<SysRolePermission>().Where(x => x.RoleId == tenantRole.Id && x.PermissionId == item.Id).Any())
{
var rolePer = item.Adapt<SysRolePermission>();
rolePer.RoleId = tenantRole.Id;
rolePer.PermissionId = item.Id;
rolePer.IsPermission = 1;
rolePerList.Add(rolePer);
rolePerList.Add(rolePer);
}
}
db.Insertable(rolePerList).ExecuteCommandAsync();
#endregion 处理租户管理员新增权限
var tenantPerList = new List<SysPermissionTenant>();
foreach (var item in addPers)
{
var tenantPer = item.Adapt<SysPermissionTenant>();
tenantPer.TenantId = req.TenantId;
tenantPer.PermissionId = item.Id;
if (hiddenPermissions.Contains(item.Id))
{
var tenantPer = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x => x.PermissionId == item.Id && x.TenantId == req.TenantId && x.IsHidden == true).First();
tenantPer.IsHidden = false;
db.Updateable(tenantPer).ExecuteCommand();
}
else
{
var tenantPer = item.Adapt<SysPermissionTenant>();
tenantPer.TenantId = req.TenantId;
tenantPer.PermissionId = item.Id;
tenantPerList.Add(tenantPer);
tenantPerList.Add(tenantPer);
}
}
db.Insertable(tenantPerList).ExecuteCommand();

Loading…
Cancel
Save