optimize
wet 1 year ago
parent f569cdb4fe
commit 2595c61d65

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

@ -50,7 +50,14 @@ public class CommonConst
/// </summary> /// </summary>
public const string CACHE_KEY_USERDATASCOPEZDY = "userdatascopezdy"; 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 公共数据库 #region 公共数据库
/// <summary> /// <summary>

@ -20,14 +20,15 @@ public class SysEmpService : ISysEmpService, ITransient
private readonly ISysEmpExtOrgPosService _sysEmpExtOrgPosService; private readonly ISysEmpExtOrgPosService _sysEmpExtOrgPosService;
private readonly ISysEmpPosService _sysEmpPosService; private readonly ISysEmpPosService _sysEmpPosService;
private readonly ISysCacheService _sysCache;//缓存
public SysEmpService(SqlSugarRepository<SysEmp> sysEmpRep, public SysEmpService(SqlSugarRepository<SysEmp> sysEmpRep, ISysCacheService sysCache,
ISysEmpExtOrgPosService sysEmpExtOrgPosService, ISysEmpExtOrgPosService sysEmpExtOrgPosService,
ISysEmpPosService sysEmpPosService) ISysEmpPosService sysEmpPosService)
{ {
_sysEmpRep = sysEmpRep; _sysEmpRep = sysEmpRep;
_sysEmpExtOrgPosService = sysEmpExtOrgPosService; _sysEmpExtOrgPosService = sysEmpExtOrgPosService;
_sysEmpPosService = sysEmpPosService; _sysEmpPosService = sysEmpPosService;
_sysCache = sysCache;
} }
/// <summary> /// <summary>
@ -91,6 +92,8 @@ public class SysEmpService : ISysEmpService, ITransient
// 更新职位信息 // 更新职位信息
await _sysEmpPosService.AddOrUpdate(emp.Id, sysEmpParam.PosIdList); await _sysEmpPosService.AddOrUpdate(emp.Id, sysEmpParam.PosIdList);
var Emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysEmp, Emp);
_sysEmpRep.CurrentCommitTran(); _sysEmpRep.CurrentCommitTran();
} }
catch (System.Exception) catch (System.Exception)
@ -115,6 +118,8 @@ public class SysEmpService : ISysEmpService, ITransient
u.OrgName = orgName; u.OrgName = orgName;
}); });
await _sysEmpRep.UpdateAsync(emps); await _sysEmpRep.UpdateAsync(emps);
var Emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysEmp, Emp);
} }
/// <summary> /// <summary>
@ -146,6 +151,8 @@ public class SysEmpService : ISysEmpService, ITransient
await _sysEmpPosService.DeleteEmpPosInfoByUserId(empId); await _sysEmpPosService.DeleteEmpPosInfoByUserId(empId);
// 删除员工信息 // 删除员工信息
await _sysEmpRep.DeleteAsync(emp); await _sysEmpRep.DeleteAsync(emp);
var Emp = await _sysEmpRep.AsQueryable().ToListAsync();
_sysCache.Set(CommonConst.CACHE_KEY_SysEmp, Emp);
_sysEmpRep.CurrentCommitTran(); _sysEmpRep.CurrentCommitTran();
} }
catch (System.Exception) 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_DATASCOPE);
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE); await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE);
} }
var Org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysOrg, Org);
} }
/// <summary> /// <summary>
@ -219,7 +222,8 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
} }
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_DATASCOPE); await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_DATASCOPE);
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE); await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE);
var Org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysOrg, Org);
} }
/// <summary> /// <summary>
@ -281,7 +285,8 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
} }
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_DATASCOPE); await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_DATASCOPE);
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE); await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_USERSDATASCOPE);
var Org = await _sysOrgRep.AsQueryable().ToListAsync();
_sysCacheService.Set(CommonConst.CACHE_KEY_SysOrg, Org);
} }
/// <summary> /// <summary>
@ -387,6 +392,7 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
[HttpGet("/sysOrg/treeList")] [HttpGet("/sysOrg/treeList")]
public async Task<dynamic> GetOrgTreeList() public async Task<dynamic> GetOrgTreeList()
{ {
var orgs = await _sysOrgRep var orgs = await _sysOrgRep
.Where(u => u.Status == (int)CommonStatus.ENABLE && u.TenantId == UserManager.TENANT_ID) .Where(u => u.Status == (int)CommonStatus.ENABLE && u.TenantId == UserManager.TENANT_ID)
.OrderBy(u => u.Sort) .OrderBy(u => u.Sort)
@ -410,15 +416,37 @@ public class SysOrgService : ISysOrgService, IDynamicApiController, ITransient
/// <returns></returns> /// <returns></returns>
public async Task<List<long>> GetUserIdListInOrg(long orgId) 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() var orgIdList = org.Where(x => x.Pids.Contains($"[{orgId}]"))
.Where(x => x.Pids.Contains($"[{orgId}]"))
.Select(x => x.Id) .Select(x => x.Id)
.ToList(); .ToList();
//获取部门下的人 //获取部门下的人
var uidList = _sysEmpRep.AsQueryable() var uidList = emp.Where(x => x.OrgId == orgId || orgIdList.Contains(x.OrgId))
.Where(x => x.OrgId == orgId || orgIdList.Contains(x.OrgId))
.Select(x => x.Id) .Select(x => x.Id)
.ToList(); .ToList();

@ -158,7 +158,30 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, I
{ {
List<SysDataUserMenu> list = new List<SysDataUserMenu>(); List<SysDataUserMenu> list = new List<SysDataUserMenu>();
List<SysUserDataScope> zdylist = new List<SysUserDataScope>(); List<SysUserDataScope> zdylist = new List<SysUserDataScope>();
List<SysOrg> org = new List<SysOrg>();
List<SysEmp> emp = new List<SysEmp>();
List<long> datascope = new List<long>(); 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)) if (_sysCache.Exists(CommonConst.CACHE_KEY_USERDATASCOPE))
{ {
list = await _sysCache.GetAsync<List<SysDataUserMenu>>(CommonConst.CACHE_KEY_USERDATASCOPE); list = await _sysCache.GetAsync<List<SysDataUserMenu>>(CommonConst.CACHE_KEY_USERDATASCOPE);
@ -189,16 +212,17 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, I
} }
else if (_dataScopeType == DataScopeType.DEPT) 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) 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); 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) else if (_dataScopeType == DataScopeType.DEFINE)
{ {
@ -206,16 +230,20 @@ public class SysDataUserMenuService : ISysDataUserMenu, IDynamicApiController, I
List<long> orglist = new List<long>(); List<long> orglist = new List<long>();
foreach (var orgId in sysorg) 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(); 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; datascope = useridlist;
} }
else else
{ {
datascope.Add(UserManager.UserId); datascope.Add(UserManager.UserId);
} }
if (IsEdit && datascope == null)
{
datascope.Add(UserManager.UserId);
}
return datascope; return datascope;
} }

Loading…
Cancel
Save