|
@ -1,4 +1,3 @@ |
|
|
|
|
|
|
|
|
namespace Admin.NET.Core.Service; |
|
|
namespace Admin.NET.Core.Service; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -42,7 +41,8 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
var iSugarQueryable = _sysOrgRep.AsQueryable().OrderBy(u => u.OrderNo); |
|
|
var iSugarQueryable = _sysOrgRep.AsQueryable().OrderBy(u => u.OrderNo); |
|
|
|
|
|
|
|
|
// 带条件筛选时返回列表数据
|
|
|
// 带条件筛选时返回列表数据
|
|
|
if (!string.IsNullOrWhiteSpace(input.Name) || !string.IsNullOrWhiteSpace(input.Code) || !string.IsNullOrWhiteSpace(input.Type)) |
|
|
if (!string.IsNullOrWhiteSpace(input.Name) || !string.IsNullOrWhiteSpace(input.Code) || |
|
|
|
|
|
!string.IsNullOrWhiteSpace(input.Type)) |
|
|
{ |
|
|
{ |
|
|
return await iSugarQueryable.WhereIF(userOrgIdList.Count > 0, u => userOrgIdList.Contains(u.Id)) |
|
|
return await iSugarQueryable.WhereIF(userOrgIdList.Count > 0, u => userOrgIdList.Contains(u.Id)) |
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) |
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) |
|
@ -58,7 +58,8 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id, userOrgIdList.Select(d => (object)d).ToArray()); |
|
|
orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id, |
|
|
|
|
|
userOrgIdList.Select(d => (object)d).ToArray()); |
|
|
// 递归禁用没权限的机构(防止用户修改或创建无权的机构和用户)
|
|
|
// 递归禁用没权限的机构(防止用户修改或创建无权的机构和用户)
|
|
|
HandlerOrgTree(orgTree, userOrgIdList); |
|
|
HandlerOrgTree(orgTree, userOrgIdList); |
|
|
} |
|
|
} |
|
@ -69,6 +70,7 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
sysOrg.Children = orgTree; |
|
|
sysOrg.Children = orgTree; |
|
|
orgTree = new List<SysOrg> { sysOrg }; |
|
|
orgTree = new List<SysOrg> { sysOrg }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return orgTree; |
|
|
return orgTree; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -148,6 +150,7 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
DeleteAllUserOrgCache(sysOrg.Id, input.Pid); |
|
|
DeleteAllUserOrgCache(sysOrg.Id, input.Pid); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (input.Id == input.Pid) |
|
|
if (input.Id == input.Pid) |
|
|
throw Oops.Oh(ErrorCodeEnum.D2001); |
|
|
throw Oops.Oh(ErrorCodeEnum.D2001); |
|
|
|
|
|
|
|
@ -246,14 +249,17 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
var userId = long.Parse(userOrgKey.Substring(CacheConst.KeyUserOrg)); |
|
|
var userId = long.Parse(userOrgKey.Substring(CacheConst.KeyUserOrg)); |
|
|
if (userOrgs.Contains(orgId) || userOrgs.Contains(orgPid)) |
|
|
if (userOrgs.Contains(orgId) || userOrgs.Contains(orgPid)) |
|
|
{ |
|
|
{ |
|
|
SqlSugarFilter.DeleteUserOrgCache(userId, _sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); |
|
|
SqlSugarFilter.DeleteUserOrgCache(userId, |
|
|
|
|
|
_sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (orgPid == 0) |
|
|
if (orgPid == 0) |
|
|
{ |
|
|
{ |
|
|
var dataScope = _sysCacheService.Get<int>($"{CacheConst.KeyRoleMaxDataScope}{userId}"); |
|
|
var dataScope = _sysCacheService.Get<int>($"{CacheConst.KeyRoleMaxDataScope}{userId}"); |
|
|
if (dataScope == (int)DataScopeEnum.All) |
|
|
if (dataScope == (int)DataScopeEnum.All) |
|
|
{ |
|
|
{ |
|
|
SqlSugarFilter.DeleteUserOrgCache(userId, _sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); |
|
|
SqlSugarFilter.DeleteUserOrgCache(userId, |
|
|
|
|
|
_sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -275,7 +281,8 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
if (orgIdList == null || orgIdList.Count < 1) |
|
|
if (orgIdList == null || orgIdList.Count < 1) |
|
|
{ |
|
|
{ |
|
|
// 本人创建机构集合
|
|
|
// 本人创建机构集合
|
|
|
var orgList0 = await _sysOrgRep.AsQueryable().Where(u => u.CreateUserId == userId).Select(u => u.Id).ToListAsync(); |
|
|
var orgList0 = await _sysOrgRep.AsQueryable().Where(u => u.CreateUserId == userId).Select(u => u.Id) |
|
|
|
|
|
.ToListAsync(); |
|
|
// 扩展机构集合
|
|
|
// 扩展机构集合
|
|
|
var orgList1 = await _sysUserExtOrgService.GetUserExtOrgList(userId); |
|
|
var orgList1 = await _sysUserExtOrgService.GetUserExtOrgList(userId); |
|
|
// 角色机构集合
|
|
|
// 角色机构集合
|
|
@ -287,6 +294,7 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
orgIdList.Add(_userManager.OrgId); |
|
|
orgIdList.Add(_userManager.OrgId); |
|
|
_sysCacheService.Set($"{CacheConst.KeyUserOrg}{userId}", orgIdList, TimeSpan.FromDays(7)); // 存缓存
|
|
|
_sysCacheService.Set($"{CacheConst.KeyUserOrg}{userId}", orgIdList, TimeSpan.FromDays(7)); // 存缓存
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return orgIdList; |
|
|
return orgIdList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -340,7 +348,8 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 缓存当前用户最大角色数据范围
|
|
|
// 缓存当前用户最大角色数据范围
|
|
|
_sysCacheService.Set(CacheConst.KeyRoleMaxDataScope + _userManager.UserId, strongerDataScopeType, TimeSpan.FromDays(7)); |
|
|
_sysCacheService.Set(CacheConst.KeyRoleMaxDataScope + _userManager.UserId, strongerDataScopeType, |
|
|
|
|
|
TimeSpan.FromDays(7)); |
|
|
|
|
|
|
|
|
// 根据角色集合获取机构集合
|
|
|
// 根据角色集合获取机构集合
|
|
|
var roleOrgIdList = await _sysRoleOrgService.GetRoleOrgIdList(customDataScopeRoleIdList); |
|
|
var roleOrgIdList = await _sysRoleOrgService.GetRoleOrgIdList(customDataScopeRoleIdList); |
|
@ -373,6 +382,7 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
{ |
|
|
{ |
|
|
orgIdList.Add(orgId); |
|
|
orgIdList.Add(orgId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return orgIdList; |
|
|
return orgIdList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -387,4 +397,146 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
var orgTreeList = await _sysOrgRep.AsQueryable().ToChildListAsync(u => u.Pid, pid, true); |
|
|
var orgTreeList = await _sysOrgRep.AsQueryable().ToChildListAsync(u => u.Pid, pid, true); |
|
|
return orgTreeList.Select(u => u.Id).ToList(); |
|
|
return orgTreeList.Select(u => u.Id).ToList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 增加区域
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[ApiDescriptionSettings(Name = "AddArea"), HttpPost] |
|
|
|
|
|
[DisplayName("增加区域")] |
|
|
|
|
|
public async Task<long> AddArea(AddAreaInput input) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!_userManager.SuperAdmin && input.Pid == 0) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2009); |
|
|
|
|
|
|
|
|
|
|
|
if (await _sysOrgRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code)) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2002); |
|
|
|
|
|
|
|
|
|
|
|
if (!_userManager.SuperAdmin && input.Pid != 0) |
|
|
|
|
|
{ |
|
|
|
|
|
// 新增机构父Id不是0,则进行权限校验
|
|
|
|
|
|
var orgIdList = await GetUserOrgIdList(); |
|
|
|
|
|
// 新增机构的父机构不在自己的数据范围内
|
|
|
|
|
|
if (orgIdList.Count < 1 || !orgIdList.Contains(input.Pid)) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2003); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 删除与此父机构有关的用户机构缓存
|
|
|
|
|
|
var pOrg = await _sysOrgRep.GetFirstAsync(u => u.Id == input.Pid); |
|
|
|
|
|
if (pOrg != null) |
|
|
|
|
|
DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); |
|
|
|
|
|
else if (input.Pid == 0) |
|
|
|
|
|
DeleteAllUserOrgCache(0, 0); |
|
|
|
|
|
|
|
|
|
|
|
var newOrg = await _sysOrgRep.AsInsertable(new SysOrg() |
|
|
|
|
|
{ |
|
|
|
|
|
Pid = input.Pid, |
|
|
|
|
|
Status = StatusEnum.Enable, |
|
|
|
|
|
CreateUserId = _userManager.UserId, |
|
|
|
|
|
CreateUserName = _userManager.Account, |
|
|
|
|
|
Name = input.Name, |
|
|
|
|
|
Code = input.Code, |
|
|
|
|
|
Type = "Area", |
|
|
|
|
|
Remark = input.Remark, |
|
|
|
|
|
DirectorId = input.DirectorId |
|
|
|
|
|
}).ExecuteReturnEntityAsync(); |
|
|
|
|
|
return newOrg.Id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 增加基地
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[ApiDescriptionSettings(Name = "AddFactory"), HttpPost] |
|
|
|
|
|
[DisplayName("增加基地")] |
|
|
|
|
|
public async Task<long> AddFactory(AddFactoryInput input) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!_userManager.SuperAdmin && input.Pid == 0) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2009); |
|
|
|
|
|
|
|
|
|
|
|
if (await _sysOrgRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code)) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2002); |
|
|
|
|
|
|
|
|
|
|
|
if (!_userManager.SuperAdmin && input.Pid != 0) |
|
|
|
|
|
{ |
|
|
|
|
|
// 新增机构父Id不是0,则进行权限校验
|
|
|
|
|
|
var orgIdList = await GetUserOrgIdList(); |
|
|
|
|
|
// 新增机构的父机构不在自己的数据范围内
|
|
|
|
|
|
if (orgIdList.Count < 1 || !orgIdList.Contains(input.Pid)) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2003); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 删除与此父机构有关的用户机构缓存
|
|
|
|
|
|
var pOrg = await _sysOrgRep.GetFirstAsync(u => u.Id == input.Pid); |
|
|
|
|
|
if (pOrg != null) |
|
|
|
|
|
DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); |
|
|
|
|
|
else if (input.Pid == 0) |
|
|
|
|
|
DeleteAllUserOrgCache(0, 0); |
|
|
|
|
|
|
|
|
|
|
|
var newOrg = await _sysOrgRep.AsInsertable(new SysOrg() |
|
|
|
|
|
{ |
|
|
|
|
|
Pid = input.Pid, |
|
|
|
|
|
Status = StatusEnum.Enable, |
|
|
|
|
|
CreateUserId = _userManager.UserId, |
|
|
|
|
|
CreateUserName = _userManager.Account, |
|
|
|
|
|
Name = input.Name, |
|
|
|
|
|
Code = input.Code, |
|
|
|
|
|
Type = "Factory", |
|
|
|
|
|
Remark = input.Remark, |
|
|
|
|
|
DirectorId = input.DirectorId, |
|
|
|
|
|
Position = input.Position |
|
|
|
|
|
}).ExecuteReturnEntityAsync(); |
|
|
|
|
|
return newOrg.Id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 增加工作站
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[ApiDescriptionSettings(Name = "AddStation"), HttpPost] |
|
|
|
|
|
[DisplayName("增加工作站")] |
|
|
|
|
|
public async Task<long> AddStation(AddStationInput input) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!_userManager.SuperAdmin && input.Pid == 0) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2009); |
|
|
|
|
|
|
|
|
|
|
|
if (await _sysOrgRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code)) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2002); |
|
|
|
|
|
|
|
|
|
|
|
if (!_userManager.SuperAdmin && input.Pid != 0) |
|
|
|
|
|
{ |
|
|
|
|
|
// 新增机构父Id不是0,则进行权限校验
|
|
|
|
|
|
var orgIdList = await GetUserOrgIdList(); |
|
|
|
|
|
// 新增机构的父机构不在自己的数据范围内
|
|
|
|
|
|
if (orgIdList.Count < 1 || !orgIdList.Contains(input.Pid)) |
|
|
|
|
|
throw Oops.Oh(ErrorCodeEnum.D2003); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 删除与此父机构有关的用户机构缓存
|
|
|
|
|
|
var pOrg = await _sysOrgRep.GetFirstAsync(u => u.Id == input.Pid); |
|
|
|
|
|
if (pOrg != null) |
|
|
|
|
|
DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); |
|
|
|
|
|
else if (input.Pid == 0) |
|
|
|
|
|
DeleteAllUserOrgCache(0, 0); |
|
|
|
|
|
var ids = input.Services?.Select(s => s.Id).ToArray(); |
|
|
|
|
|
var newOrg = await _sysOrgRep.AsInsertable(new SysOrg() |
|
|
|
|
|
{ |
|
|
|
|
|
Pid = input.Pid, |
|
|
|
|
|
Status = StatusEnum.Enable, |
|
|
|
|
|
CreateUserId = _userManager.UserId, |
|
|
|
|
|
CreateUserName = _userManager.Account, |
|
|
|
|
|
Name = input.Name, |
|
|
|
|
|
Code = input.Code, |
|
|
|
|
|
Type = "Station", |
|
|
|
|
|
Remark = input.Remark, |
|
|
|
|
|
DirectorId = input.DirectorId, |
|
|
|
|
|
ServiceIds = ids, |
|
|
|
|
|
}).ExecuteReturnEntityAsync(); |
|
|
|
|
|
return newOrg.Id; |
|
|
|
|
|
} |
|
|
} |
|
|
} |