|
|
|
@ -20,7 +20,7 @@ namespace Myshipping.Core.Service;
|
|
|
|
|
/// 用户数据范围
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings(Name = "SysDataUserMenu", Order = 150)]
|
|
|
|
|
public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController,ITransient
|
|
|
|
|
public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<SysDataUserMenu> _rep; // 用户数据范围表仓储
|
|
|
|
|
private readonly ISysCacheService _sysCache;//缓存
|
|
|
|
@ -33,9 +33,9 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController,IT
|
|
|
|
|
_rep = rep;
|
|
|
|
|
_sysCache = sysCache;
|
|
|
|
|
_sysuser = sysuser;
|
|
|
|
|
_sysUserDataScopeRep=sysUserDataScopeRep;
|
|
|
|
|
_sysUserDataScopeRep = sysUserDataScopeRep;
|
|
|
|
|
_sysEmpRep = sysEmpRep;
|
|
|
|
|
_sysOrgRep= sysOrgRep;
|
|
|
|
|
_sysOrgRep = sysOrgRep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -44,7 +44,8 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController,IT
|
|
|
|
|
/// <param name="userid"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/SysDataUserMenu/GetGrantData")]
|
|
|
|
|
public async Task<dynamic> GetGrantData(long userid) {
|
|
|
|
|
public async Task<dynamic> GetGrantData(long userid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return await _rep.AsQueryable().Where(x => x.SysUserId == userid).ToListAsync();
|
|
|
|
|
}
|
|
|
|
@ -117,30 +118,30 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController,IT
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (input== null)
|
|
|
|
|
if (input == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("请上传正确数据!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _sysUserDataScopeRep.DeleteAsync(x => x.SysUserId == input.UserId);
|
|
|
|
|
|
|
|
|
|
var list = new List<SysUserDataScope>();
|
|
|
|
|
input.childrens.ForEach(u =>
|
|
|
|
|
|
|
|
|
|
var list = new List<SysUserDataScope>();
|
|
|
|
|
input.childrens.ForEach(u =>
|
|
|
|
|
{
|
|
|
|
|
list.Add(
|
|
|
|
|
new SysUserDataScope
|
|
|
|
|
{
|
|
|
|
|
list.Add(
|
|
|
|
|
new SysUserDataScope
|
|
|
|
|
{
|
|
|
|
|
SysUserId = input.UserId,
|
|
|
|
|
SysMenuId=u.MenuId,
|
|
|
|
|
SysOrgId=u.OrgId
|
|
|
|
|
});
|
|
|
|
|
SysUserId = input.UserId,
|
|
|
|
|
SysMenuId = u.MenuId,
|
|
|
|
|
SysOrgId = u.OrgId
|
|
|
|
|
});
|
|
|
|
|
await _sysUserDataScopeRep.InsertAsync(list);
|
|
|
|
|
});
|
|
|
|
|
await _sysUserDataScopeRep.InsertAsync(list);
|
|
|
|
|
|
|
|
|
|
//var userdatalist = _rep.AsQueryable().ToListAsync();
|
|
|
|
|
//_sysCache.Set(CommonConst.CACHE_KEY_USERDATASCOPE, userdatalist);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var userdatalist = _rep.AsQueryable().ToListAsync();
|
|
|
|
|
//_sysCache.Set(CommonConst.CACHE_KEY_USERDATASCOPE, userdatalist);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (System.Exception)
|
|
|
|
|
{
|
|
|
|
@ -172,32 +173,34 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController,IT
|
|
|
|
|
DataScopeType _dataScopeType = list.Where(x => x.SysMenuId == menuid && x.SysUserId == UserManager.UserId).Select(x => x.DataScopeType).FirstOrDefault();
|
|
|
|
|
if (_dataScopeType == DataScopeType.ALL)
|
|
|
|
|
{
|
|
|
|
|
datascope = _sysuser.AsQueryable().Where(x => x.TenantId == UserManager.TENANT_ID).Select(x => x.Id).ToList();
|
|
|
|
|
datascope = null;
|
|
|
|
|
}
|
|
|
|
|
if (_dataScopeType==DataScopeType.SELF) {
|
|
|
|
|
else if (_dataScopeType == DataScopeType.SELF)
|
|
|
|
|
{
|
|
|
|
|
datascope.Add(UserManager.UserId);
|
|
|
|
|
}
|
|
|
|
|
if (_dataScopeType==DataScopeType.DEPT) {
|
|
|
|
|
datascope=await _sysEmpRep.AsQueryable().InnerJoin<SysEmp>((d, t) => d.OrgId == t.OrgId && d.Id == UserManager.UserId).Select(d => d.Id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
else if (_dataScopeType == DataScopeType.DEPT)
|
|
|
|
|
{
|
|
|
|
|
datascope = await _sysEmpRep.AsQueryable().InnerJoin<SysEmp>((d, t) => d.OrgId == t.OrgId && d.Id == UserManager.UserId).Select(d => d.Id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (_dataScopeType == DataScopeType.DEPT_WITH_CHILD)
|
|
|
|
|
else if (_dataScopeType == DataScopeType.DEPT_WITH_CHILD)
|
|
|
|
|
{
|
|
|
|
|
//获取本部门
|
|
|
|
|
long orgid= _sysEmpRep.Where(x=>x.Id==UserManager.UserId).Select(x=>x.OrgId).First();
|
|
|
|
|
long orgid = _sysEmpRep.Where(x => x.Id == UserManager.UserId).Select(x => x.OrgId).First();
|
|
|
|
|
//获取下属部门及下属部门
|
|
|
|
|
var orglist = await _sysOrgRep.Where(x => x.TenantId == UserManager.TENANT_ID && x.Pids.Contains(orgid.ToString())).Select(x => x.Id).ToListAsync();
|
|
|
|
|
orglist.Add(orgid);
|
|
|
|
|
datascope = await _sysEmpRep.Where(x => orglist.Contains(x.OrgId)).Select(x => x.Id).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
if (_dataScopeType == DataScopeType.DEFINE)
|
|
|
|
|
else if (_dataScopeType == DataScopeType.DEFINE)
|
|
|
|
|
{
|
|
|
|
|
datascope=await _sysUserDataScopeRep.AsQueryable().InnerJoin<SysEmp>((d, t) => d.SysOrgId == t.OrgId && d.SysMenuId == menuid && d.SysUserId == UserManager.UserId).Select((d, t) => t.Id).ToListAsync();
|
|
|
|
|
datascope = await _sysUserDataScopeRep.AsQueryable().InnerJoin<SysEmp>((d, t) => d.SysOrgId == t.OrgId && d.SysMenuId == menuid && d.SysUserId == UserManager.UserId).Select((d, t) => t.Id).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datascope.Add(UserManager.UserId);
|
|
|
|
|
}
|
|
|
|
|
return datascope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|