|
|
@ -1,5 +1,6 @@
|
|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
|
|
|
using DS.Module.Core.Helpers;
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
using DS.WMS.Core.System.Dtos;
|
|
|
|
using DS.WMS.Core.System.Dtos;
|
|
|
|
using DS.WMS.Core.System.Entity;
|
|
|
|
using DS.WMS.Core.System.Entity;
|
|
|
@ -245,4 +246,87 @@ public class SysRoleService : ISysRoleService
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DataResult UpdateClientRolePermission(RolePermissionInput model)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var existPermissions = db.Queryable<SysRolePermission>().Where(x => x.RoleId == model.RoleId && x.IsPermission == 1).Select(n => n.PermissionId).ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerable<long?> delPermissions = existPermissions.AsQueryable().Except(model.PermissionIds);
|
|
|
|
|
|
|
|
if (delPermissions.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
db.Updateable<SysRolePermission>()
|
|
|
|
|
|
|
|
.SetColumns(it => it.IsPermission == 0)//SetColumns是可以叠加的 写2个就2个字段赋值
|
|
|
|
|
|
|
|
.Where(it => it.RoleId == model.RoleId && delPermissions.Contains(it.PermissionId))
|
|
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerable<long?> addPermissions = model.PermissionIds.AsQueryable().Except(existPermissions);
|
|
|
|
|
|
|
|
if (addPermissions.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var existNoPermissions = db.Queryable<SysRolePermission>().Where(x => x.RoleId == model.RoleId && x.IsPermission == 0).Select(n => n.PermissionId).ToArray();
|
|
|
|
|
|
|
|
IEnumerable<long?> updatePermissions = existNoPermissions.AsQueryable().Except(addPermissions);
|
|
|
|
|
|
|
|
if (updatePermissions.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
db.Updateable<SysRolePermission>()
|
|
|
|
|
|
|
|
.SetColumns(it => it.IsPermission == 1)
|
|
|
|
|
|
|
|
.Where(it => it.RoleId == model.RoleId && updatePermissions.Contains(it.PermissionId))
|
|
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerable<long?> addRolePermissions = addPermissions.AsQueryable().Except(existNoPermissions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 租户模块权限检测
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tenant = db.Queryable<SysTenant>().Where(x=>x.Id ==long.Parse(user.TenantId)).First();
|
|
|
|
|
|
|
|
foreach (var item in addRolePermissions)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var per = db.Queryable<SysPermission>().Where(x => x.Id == item)
|
|
|
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
if (per.MenuType == 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var perAuth = db.Queryable<SysTenantPermissionAuth>().Where(x=>x.PermissionId == item).First();
|
|
|
|
|
|
|
|
if (perAuth.IsNotNull())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var authNum = EncrypteHelper.DecryptData(perAuth.AuthNum, tenant.AppSecret);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var roleList = db.Queryable<SysRolePermission>()
|
|
|
|
|
|
|
|
.Where(x => x.PermissionId == item && x.IsPermission == 1).Select(n => n.RoleId).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
roleList.Add(model.RoleId);
|
|
|
|
|
|
|
|
roleList.Distinct();
|
|
|
|
|
|
|
|
var userList = new List<long?>();
|
|
|
|
|
|
|
|
foreach (var role in roleList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var userArr = db.Queryable<SysRoleUser>().Where(x => x.RoleId == role).Select(n => n.UserId)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
userList.AddRange(userArr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userList.Distinct();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var userCount = userList.Count();
|
|
|
|
|
|
|
|
if (userCount>= int.Parse(authNum))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Failed(string.Format("{0}模块数量超出授权数量{1}",per.PermissionName, int.Parse(authNum)),MultiLanguageConst.PerAuthNumLimit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in addRolePermissions)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var permission = new SysRolePermission
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RoleId = model.RoleId,
|
|
|
|
|
|
|
|
PermissionId = item,
|
|
|
|
|
|
|
|
IsPermission = 1,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
db.Insertable(permission).ExecuteCommand();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|