|
|
@ -48,18 +48,33 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code == input.Code) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Type), u => u.Type == input.Type) |
|
|
|
.Mapper(o => |
|
|
|
{ |
|
|
|
o.Services = SqlFunc.Subqueryable<SysStationService>() |
|
|
|
.WhereIF(o.ServiceIds is not null, s => o.ServiceIds.Contains(s.Id)).ToList(); |
|
|
|
}) |
|
|
|
.ToListAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
var orgTree = new List<SysOrg>(); |
|
|
|
if (_userManager.SuperAdmin) |
|
|
|
{ |
|
|
|
orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id); |
|
|
|
orgTree = await iSugarQueryable |
|
|
|
.Mapper(o => |
|
|
|
{ |
|
|
|
o.Services = SqlFunc.Subqueryable<SysStationService>() |
|
|
|
.WhereIF(o.ServiceIds is not null, s => o.ServiceIds.Contains(s.Id)).ToList(); |
|
|
|
}).ToTreeAsync(u => u.Children, u => u.Pid, input.Id); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id, |
|
|
|
userOrgIdList.Select(d => (object)d).ToArray()); |
|
|
|
orgTree = await iSugarQueryable.Mapper(o => |
|
|
|
{ |
|
|
|
o.Services = SqlFunc.Subqueryable<SysStationService>() |
|
|
|
.WhereIF(o.ServiceIds is not null, s => o.ServiceIds.Contains(s.Id)).ToList(); |
|
|
|
}) |
|
|
|
.ToTreeAsync(u => u.Children, u => u.Pid, input.Id, |
|
|
|
userOrgIdList.Select(d => (object)d).ToArray()); |
|
|
|
// 递归禁用没权限的机构(防止用户修改或创建无权的机构和用户)
|
|
|
|
HandlerOrgTree(orgTree, userOrgIdList); |
|
|
|
} |
|
|
@ -119,7 +134,7 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
|
DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); |
|
|
|
else if (input.Pid == 0) |
|
|
|
DeleteAllUserOrgCache(0, 0); |
|
|
|
|
|
|
|
input.ServiceIds = input.Services?.Select(u => u.Id).ToArray(); |
|
|
|
var newOrg = await _sysOrgRep.AsInsertable(input.Adapt<SysOrg>()).ExecuteReturnEntityAsync(); |
|
|
|
return newOrg.Id; |
|
|
|
} |
|
|
@ -397,193 +412,4 @@ public class SysOrgService : IDynamicApiController, ITransient |
|
|
|
var orgTreeList = await _sysOrgRep.AsQueryable().ToChildListAsync(u => u.Pid, pid, true); |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
// public async Task<List<AreaOutput>> GetUserAreaList(QueryAreaInput input)
|
|
|
|
// {
|
|
|
|
// var userOrgIdList = await GetUserOrgIdList();
|
|
|
|
// var iSugarQueryable = _sysOrgRep.AsQueryable().OrderBy(u => u.OrderNo)
|
|
|
|
// .Where(a => a.Type == "Area");
|
|
|
|
// var orgTree = new List<SysOrg>();
|
|
|
|
// if (_userManager.SuperAdmin)
|
|
|
|
// {
|
|
|
|
// orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id,
|
|
|
|
// userOrgIdList.Select(d => (object)d).ToArray());
|
|
|
|
// // 递归禁用没权限的机构(防止用户修改或创建无权的机构和用户)
|
|
|
|
// HandlerOrgTree(orgTree, userOrgIdList);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// var sysOrg = await _sysOrgRep.GetSingleAsync(u => u.Id == input.Id);
|
|
|
|
// if (sysOrg != null)
|
|
|
|
// {
|
|
|
|
// sysOrg.Children = orgTree;
|
|
|
|
// orgTree = new List<SysOrg> { sysOrg };
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return orgTree;
|
|
|
|
// if (!string.IsNullOrWhiteSpace(input.Name) || !string.IsNullOrWhiteSpace(input.Code))
|
|
|
|
// {
|
|
|
|
// 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.Code), u => u.Code == input.Code)
|
|
|
|
// .Select(a => a.Adapt<AreaOutput>())
|
|
|
|
// .Mapper(a =>
|
|
|
|
// {
|
|
|
|
// a.Factories = a.Children.Where(c => c.Type == "Factory").Select(s => s.Adapt<FactoryOutput>())
|
|
|
|
// .Select(t =>
|
|
|
|
// {
|
|
|
|
// t.Stations = t.Children.Where(c => c.Type == "Station")
|
|
|
|
// .Select(s => s.Adapt<StationOutput>()).ToList();
|
|
|
|
// return t;
|
|
|
|
// })
|
|
|
|
// .ToList();
|
|
|
|
// })
|
|
|
|
// .ToListAsync();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
/// <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?.ToList(), |
|
|
|
}).ExecuteReturnEntityAsync(); |
|
|
|
return newOrg.Id; |
|
|
|
} |
|
|
|
} |