This commit is contained in:
@@ -11,12 +11,12 @@ namespace Dilon.Core.Service
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父Id
|
||||
/// </summary>
|
||||
public long ParentId { get; set; }
|
||||
public string ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
@@ -43,12 +43,12 @@ namespace Dilon.Core.Service
|
||||
/// </summary>
|
||||
public long Pid { get; set; }
|
||||
|
||||
public long GetId()
|
||||
public string GetId()
|
||||
{
|
||||
return Id;
|
||||
}
|
||||
|
||||
public long GetPid()
|
||||
public string GetPid()
|
||||
{
|
||||
return ParentId;
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace Dilon.Core.Service
|
||||
{
|
||||
Task AddOrg(AddOrgInput input);
|
||||
Task DeleteOrg(DeleteOrgInput input);
|
||||
Task<List<long>> GetDataScopeListByDataScopeType(int dataScopeType, long orgId);
|
||||
Task<List<string>> GetDataScopeListByDataScopeType(int dataScopeType, string orgId);
|
||||
Task<SysOrg> GetOrg([FromQuery] QueryOrgInput input);
|
||||
Task<List<OrgOutput>> GetOrgList([FromQuery] OrgInput input);
|
||||
Task<dynamic> GetOrgTree([FromQuery] OrgInput input);
|
||||
Task<dynamic> QueryOrgPageList([FromQuery] PageOrgInput input);
|
||||
Task UpdateOrg(UpdateOrgInput input);
|
||||
Task<List<long>> GetUserDataScopeIdList();
|
||||
Task<List<string>> GetUserDataScopeIdList();
|
||||
}
|
||||
}
|
||||
@@ -57,9 +57,9 @@ namespace Dilon.Core.Service
|
||||
var pId = !string.IsNullOrEmpty(input.Pid?.Trim());
|
||||
var orgs = await _sysOrgRep.DetachedEntities
|
||||
.Where((name, u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")), // 根据机构名称模糊查询
|
||||
(id, u => u.Id == long.Parse(input.Id.Trim())), // 根据机构id查询
|
||||
(id, u => u.Id == input.Id.Trim()), // 根据机构id查询
|
||||
(pId, u => EF.Functions.Like(u.Pids, $"%[{input.Pid.Trim()}]%")
|
||||
|| u.Id == long.Parse(input.Pid.Trim()))) // 根据父机构id查询
|
||||
|| u.Id == input.Pid.Trim())) // 根据父机构id查询
|
||||
.Where(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id)) // 非管理员范围限制
|
||||
.Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort)
|
||||
.Select(u => u.Adapt<OrgOutput>())
|
||||
@@ -72,9 +72,9 @@ namespace Dilon.Core.Service
|
||||
/// </summary>
|
||||
/// <param name="dataScopes"></param>
|
||||
/// <returns></returns>
|
||||
private List<long> GetDataScopeList(List<long> dataScopes)
|
||||
private List<string> GetDataScopeList(List<string> dataScopes)
|
||||
{
|
||||
var dataScopeList = new List<long>();
|
||||
var dataScopeList = new List<string>();
|
||||
// 如果是超级管理员则获取所有组织机构,否则只获取其数据范围的机构数据
|
||||
if (!_userManager.SuperAdmin)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ namespace Dilon.Core.Service
|
||||
{
|
||||
var sysOrg = _sysOrgRep.DetachedEntities.FirstOrDefault(c => c.Id == u);
|
||||
var parentAndChildIdListWithSelf = sysOrg.Pids.TrimEnd(',').Replace("[", "").Replace("]", "")
|
||||
.Split(",").Select(u => long.Parse(u)).ToList();
|
||||
.Split(",").ToList();
|
||||
dataScopeList.AddRange(parentAndChildIdListWithSelf);
|
||||
});
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace Dilon.Core.Service
|
||||
|
||||
var pId = !string.IsNullOrEmpty(input.Pid?.Trim());
|
||||
var orgs = await _sysOrgRep.DetachedEntities
|
||||
.Where(pId, u => u.Pid == long.Parse(input.Pid))
|
||||
.Where(pId, u => u.Pid == input.Pid)
|
||||
.Where(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id))
|
||||
.Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort).ToListAsync();
|
||||
return orgs.Adapt<List<OrgOutput>>();
|
||||
@@ -130,7 +130,7 @@ namespace Dilon.Core.Service
|
||||
{
|
||||
// 新增组织机构的父机构不在自己的数据范围内
|
||||
var dataScopes = await GetUserDataScopeIdList();
|
||||
if (dataScopes.Count < 1 || !dataScopes.Contains(long.Parse(input.Pid)))
|
||||
if (dataScopes.Count < 1 || !dataScopes.Contains(input.Pid))
|
||||
throw Oops.Oh(ErrorCode.D2003);
|
||||
}
|
||||
else
|
||||
@@ -149,7 +149,7 @@ namespace Dilon.Core.Service
|
||||
/// <returns></returns>
|
||||
private async Task FillPids(SysOrg sysOrg)
|
||||
{
|
||||
if (sysOrg.Pid == 0L)
|
||||
if (sysOrg.Pid.Equals(System.Guid.Empty.ToString(), System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
sysOrg.Pids = "[" + 0 + "],";
|
||||
}
|
||||
@@ -169,7 +169,7 @@ namespace Dilon.Core.Service
|
||||
[UnitOfWork]
|
||||
public async Task DeleteOrg(DeleteOrgInput input)
|
||||
{
|
||||
var sysOrg = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == long.Parse(input.Id));
|
||||
var sysOrg = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
|
||||
// 检测数据范围能不能操作这个机构
|
||||
var dataScopes = await GetUserDataScopeIdList();
|
||||
@@ -212,18 +212,18 @@ namespace Dilon.Core.Service
|
||||
{
|
||||
if (input.Pid != "0" && !string.IsNullOrEmpty(input.Pid))
|
||||
{
|
||||
var org = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == long.Parse(input.Pid));
|
||||
var org = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Pid);
|
||||
_ = org ?? throw Oops.Oh(ErrorCode.D2000);
|
||||
}
|
||||
if (input.Id == input.Pid)
|
||||
throw Oops.Oh(ErrorCode.D2001);
|
||||
|
||||
// 如果是编辑,父id不能为自己的子节点
|
||||
var childIdListById = await GetChildIdListWithSelfById(long.Parse(input.Id));
|
||||
if (childIdListById.Contains(long.Parse(input.Pid)))
|
||||
var childIdListById = await GetChildIdListWithSelfById(input.Id);
|
||||
if (childIdListById.Contains(input.Pid))
|
||||
throw Oops.Oh(ErrorCode.D2001);
|
||||
|
||||
var sysOrg = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == long.Parse(input.Id));
|
||||
var sysOrg = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
|
||||
// 检测数据范围能不能操作这个机构
|
||||
var dataScopes = await GetUserDataScopeIdList();
|
||||
@@ -258,7 +258,7 @@ namespace Dilon.Core.Service
|
||||
[HttpGet("/sysOrg/detail")]
|
||||
public async Task<SysOrg> GetOrg([FromQuery] QueryOrgInput input)
|
||||
{
|
||||
return await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == long.Parse(input.Id));
|
||||
return await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -266,7 +266,7 @@ namespace Dilon.Core.Service
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<long>> GetChildIdListWithSelfById(long id)
|
||||
private async Task<List<string>> GetChildIdListWithSelfById(string id)
|
||||
{
|
||||
var childIdList = await _sysOrgRep.DetachedEntities
|
||||
.Where(u => EF.Functions.Like(u.Pids, $"%{id}%"))
|
||||
@@ -282,7 +282,7 @@ namespace Dilon.Core.Service
|
||||
[HttpGet("/sysOrg/tree")]
|
||||
public async Task<dynamic> GetOrgTree([FromQuery] OrgInput input)
|
||||
{
|
||||
var dataScopeList = new List<long>();
|
||||
var dataScopeList = new List<string>();
|
||||
if (!_userManager.SuperAdmin)
|
||||
{
|
||||
var dataScopes = await GetUserDataScopeIdList();
|
||||
@@ -311,10 +311,10 @@ namespace Dilon.Core.Service
|
||||
/// <param name="orgId"></param>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task<List<long>> GetDataScopeListByDataScopeType(int dataScopeType, long orgId)
|
||||
public async Task<List<string>> GetDataScopeListByDataScopeType(int dataScopeType, string orgId)
|
||||
{
|
||||
var orgIdList = new List<long>();
|
||||
if (orgId < 0)
|
||||
var orgIdList = new List<string>();
|
||||
if (string.IsNullOrEmpty(orgId))
|
||||
return orgIdList;
|
||||
|
||||
// 如果是范围类型是全部数据,则获取当前所有的组织架构Id
|
||||
@@ -340,7 +340,7 @@ namespace Dilon.Core.Service
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task<List<long>> GetUserDataScopeIdList()
|
||||
public async Task<List<string>> GetUserDataScopeIdList()
|
||||
{
|
||||
return await App.GetService<ISysUserService>().GetUserDataScopeIdList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user