optimize
wet 1 year ago
parent f569cdb4fe
commit 2595c61d65

@ -204,6 +204,7 @@ namespace Myshipping.Application
[HttpPost("/BookingOrder/PageData")]
public async Task<dynamic> PageData(BookingOrderInput input)
{
List<long> userlist = await _right.GetDataScopeList(351064299098181);
List<long?> pidlist = new List<long?>();
if (!string.IsNullOrWhiteSpace(input.SEALNO) || !string.IsNullOrWhiteSpace(input.CNTRNO))

@ -50,7 +50,14 @@ public class CommonConst
/// </summary>
public const string CACHE_KEY_USERDATASCOPEZDY = "userdatascopezdy";
/// <summary>
/// SysEmp
/// </summary>
public const string CACHE_KEY_SysEmp = "SysEmp";
/// <summary>
/// SysOrg
/// </summary>
public const string CACHE_KEY_SysOrg = "SysOrg";
#region 公共数据库
/// <summary>

@ -20,14 +20,15 @@ public class SysEmpService : ISysEmpService, ITransient
private readonly ISysEmpExtOrgPosService _sysEmpExtOrgPosService;
private readonly ISysEmpPosService _sysEmpPosService;
public SysEmpService(SqlSugarRepository<SysEmp> sysEmpRep,
private readonly ISysCacheService _sysCache;//缓存
public SysEmpService(SqlSugarRepository<SysEmp> sysEmpRep, ISysCacheService sysCache,
ISysEmpExtOrgPosService sysEmpExtOrgPosService,
ISysEmpPosService sysEmpPosService)
{
_sysEmpRep = sysEmpRep;
_sysEmpExtOrgPosService = sysEmpExtOrgPosService;
_sysEmpPosService = sysEmpPosService;
_sysCache = sysCache;
}
/// <summary>
@ -91,6 +92,8 @@ public class SysEmpService : ISysEmpService, ITransient
// 更新职位信息
await _sysEmpPosService.AddOrUpdate(emp.Id, sysEmpParam.PosIdList);
var Emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysEmp, Emp);
_sysEmpRep.CurrentCommitTran();
}
catch (System.Exception)
@ -115,6 +118,8 @@ public class SysEmpService : ISysEmpService, ITransient
u.OrgName = orgName;
});
await _sysEmpRep.UpdateAsync(emps);
var Emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysEmp, Emp);
}
/// <summary>
@ -146,6 +151,8 @@ public class SysEmpService : ISysEmpService, ITransient
await _sysEmpPosService.DeleteEmpPosInfoByUserId(empId);
// 删除员工信息
await _sysEmpRep.DeleteAsync(emp);
var Emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysEmp, Emp);
_sysEmpRep.CurrentCommitTran();
}
catch (System.Exception)

@ -145,6 +145,9 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_DATASCOPE);
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE);
}
var Org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysOrg, Org);
}
/// <summary>
@ -219,7 +222,8 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
}
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_DATASCOPE);
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE);
var Org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysOrg, Org);
}
/// <summary>
@ -272,7 +276,7 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
await _sysOrgRep.AsUpdateable(sysOrg).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
_sysOrgRep.CurrentCommitTran();
}
catch (System.Exception)
{
@ -281,7 +285,8 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
}
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_DATASCOPE);
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE);
var Org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysOrg, Org);
}
/// <summary>
@ -387,6 +392,7 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
[HttpGet("/sysOrg/treeList")]
public async Task<dynamic> GetOrgTreeList()
{
var orgs = await _sysOrgRep
.Where(u => u.Status == (int)CommonStatus.ENABLE && u.TenantId == UserManager.TENANT_ID)
.OrderBy(u => u.Sort)
@ -410,15 +416,37 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
/// <returns></returns>
public async Task<List<long>> GetUserIdListInOrg(long orgId)
{
List<SysOrg> org = new List<SysOrg>();
List<SysEmp> emp = new List<SysEmp>();
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_SysOrg))
{
org = await _sysCacheService.GetAsync<List<SysOrg>>(CommonConst.CACHE_KEY_SysOrg);
}
else
{
org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysOrg, org);
}
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_SysEmp))
{
emp = await _sysCacheService.GetAsync<List<SysEmp>>(CommonConst.CACHE_KEY_SysEmp);
}
else
{
emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysEmp, emp);
}
//获取所有子部门
var orgIdList = _sysOrgRep.AsQueryable()
.Where(x => x.Pids.Contains($"[{orgId}]"))
var orgIdList = org.Where(x => x.Pids.Contains($"[{orgId}]"))
.Select(x => x.Id)
.ToList();
//获取部门下的人
var uidList = _sysEmpRep.AsQueryable()
.Where(x => x.OrgId == orgId || orgIdList.Contains(x.OrgId))
var uidList = emp.Where(x => x.OrgId == orgId || orgIdList.Contains(x.OrgId))
.Select(x => x.Id)
.ToList();

@ -119,7 +119,7 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, I
throw Oops.Bah("请上传正确数据!");
}
if (input.childrens!=null&& input.childrens.Count()>0)
if (input.childrens != null && input.childrens.Count() > 0)
{
await _sysUserDataScopeRep.DeleteAsync(x => x.SysUserId == input.UserId);
@ -140,7 +140,7 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, I
var userdatalist = await _sysUserDataScopeRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_USERDATASCOPEZDY, userdatalist);
}
}
catch (System.Exception)
{
@ -148,17 +148,40 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, I
}
}
/// <summary>
/// 获取权限合集
/// </summary>
/// <param name="menuid">菜单id</param>
/// <param name="IsEdit">是否查看编辑权限</param>
/// <returns></returns>
public async Task<List<long>> GetDataScopeList(long menuid,bool IsEdit=false)
/// <summary>
/// 获取权限合集
/// </summary>
/// <param name="menuid">菜单id</param>
/// <param name="IsEdit">是否查看编辑权限</param>
/// <returns></returns>
public async Task<List<long>> GetDataScopeList(long menuid, bool IsEdit = false)
{
List<SysDataUserMenu> list = new List<SysDataUserMenu>();
List<SysUserDataScope> zdylist = new List<SysUserDataScope>();
List<SysOrg> org = new List<SysOrg>();
List<SysEmp> emp = new List<SysEmp>();
List<long> datascope = new List<long>();
if (_sysCache.Exists(CommonConst.CACHE_KEY_SysOrg))
{
org = await _sysCache.GetAsync<List<SysOrg>>(CommonConst.CACHE_KEY_SysOrg);
}
else
{
org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysOrg, org);
}
if (_sysCache.Exists(CommonConst.CACHE_KEY_SysEmp))
{
emp = await _sysCache.GetAsync<List<SysEmp>>(CommonConst.CACHE_KEY_SysEmp);
}
else
{
emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysEmp, emp);
}
if (_sysCache.Exists(CommonConst.CACHE_KEY_USERDATASCOPE))
{
list = await _sysCache.GetAsync<List<SysDataUserMenu>>(CommonConst.CACHE_KEY_USERDATASCOPE);
@ -189,33 +212,38 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, I
}
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();
var orgidlist = emp.Where(x => x.Id == UserManager.UserId).Select(x => x.OrgId).ToList();
datascope = emp.Where(x => orgidlist.Contains(x.OrgId)).Select(x => x.Id).ToList();
}
else if (_dataScopeType == DataScopeType.DEPT_WITH_CHILD)
{
//获取本部门
long orgid = _sysEmpRep.Where(x => x.Id == UserManager.UserId).Select(x => x.OrgId).First();
long orgid = emp.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();
var orglist = org.Where(x => x.TenantId == UserManager.TENANT_ID && x.Pids.Contains(orgid.ToString())).Select(x => x.Id).ToList();
orglist.Add(orgid);
datascope = await _sysEmpRep.Where(x => orglist.Contains(x.OrgId)).Select(x => x.Id).ToListAsync();
datascope = emp.Where(x => orglist.Contains(x.OrgId)).Select(x => x.Id).ToList();
}
else if (_dataScopeType == DataScopeType.DEFINE)
{
var sysorg= zdylist.Where(x => x.SysUserId == UserManager.UserId).Select(x => x.SysOrgId).ToList();
List<long> orglist=new List<long>();
var sysorg = zdylist.Where(x => x.SysUserId == UserManager.UserId).Select(x => x.SysOrgId).ToList();
List<long> orglist = new List<long>();
foreach (var orgId in sysorg)
{
var o= _sysOrgRep.AsQueryable().Where(x => x.Pids.Contains(orgId.ToString())).Select(x => x.Id).ToList();
var o = org.Where(x => x.Pids.Contains(orgId.ToString())).Select(x => x.Id).ToList();
orglist = orglist.Union(o).ToList();
}
var useridlist = _sysEmpRep.AsQueryable().Where(x => orglist.Contains(x.OrgId)).Select(x => x.Id).ToList();
var useridlist = emp.Where(x => orglist.Contains(x.OrgId)).Select(x => x.Id).ToList();
datascope = useridlist;
}
else
{
datascope.Add(UserManager.UserId);
}
if (IsEdit && datascope == null)
{
datascope.Add(UserManager.UserId);
}
return datascope;
}

Loading…
Cancel
Save