You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.2 KiB
108 lines
3.2 KiB
using SqlSugar;
|
|
using Wood.Cache;
|
|
using Wood.Data.Repository;
|
|
using Wood.Entity;
|
|
using Wood.Entity.SystemManage;
|
|
using Wood.Service.BaseService;
|
|
using Wood.Service.SystemManage.Dto;
|
|
using Wood.Service.SystemManage.Manager;
|
|
using Wood.Service.SystemManage.Param;
|
|
using Wood.Util;
|
|
using Wood.Util.JwtAuthorization;
|
|
|
|
namespace Wood.Service.SystemManage
|
|
{
|
|
/// <summary>
|
|
/// 机构管理
|
|
/// </summary>
|
|
public class OrgService : ApiCRUDService<OrgEntity, OrgEntity, OrgAddParam, OrgUpdateParam>
|
|
{
|
|
private readonly OrgManager _orgManager;
|
|
private readonly SqlSugarRepository<TenantEntity> _tenantRepository;
|
|
|
|
public OrgService(OrgManager orgManager, SqlSugarRepository<TenantEntity> tenantRepository):base(orgManager.AsRepository())
|
|
{
|
|
_orgManager = orgManager;
|
|
_tenantRepository = tenantRepository;
|
|
}
|
|
public async Task<List<OrgTreeDto>> TreeList(OrgTreeListParam param)
|
|
{
|
|
var user = this.UserInfo();
|
|
long rootId = user!.OrgId;
|
|
//超级管理员可以看到所有机构
|
|
if (user.IsSuperAdmin)
|
|
rootId = 0;
|
|
//租户管理员可以看到当下租户的所有机构
|
|
else if (user.IsTenantAdmin)
|
|
{
|
|
var tenant = await _tenantRepository.GetByIdAsync(user.TenantId);
|
|
rootId = tenant.OrgId;
|
|
}
|
|
var query = _orgManager.AsQueryable()
|
|
.WhereIF(!string.IsNullOrEmpty(param.Name), it => it.OrgName.Contains(param.Name!) || it.FormCode.Contains(param.Name!))
|
|
.Select(it => new OrgTreeDto()
|
|
{
|
|
Id = it.Id.SelectAll()
|
|
});
|
|
|
|
if (param.HasCondition())
|
|
return await query.ToListAsync();
|
|
else
|
|
return await query.ToTreeAsync(it => it.Children, it => it.ParentId, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有机构
|
|
/// 用于El树形结构
|
|
/// </summary>
|
|
/// <returns>用于El树形结构</returns>
|
|
public async Task<List<ElTreeDto>> ElTreeList(OrgTreeListParam param)
|
|
{
|
|
var user = this.UserInfo();
|
|
long rootId = user!.OrgId;
|
|
//超级管理员可以看到所有机构
|
|
if (user.IsSuperAdmin)
|
|
rootId = 0;
|
|
//租户管理员可以看到当下租户的所有机构
|
|
else if (user.IsTenantAdmin)
|
|
{
|
|
var tenant = await _tenantRepository.GetByIdAsync(user.TenantId);
|
|
rootId = tenant.OrgId;
|
|
}
|
|
var query = _orgManager.AsQueryable()
|
|
.WhereIF(!string.IsNullOrEmpty(param.Name), it => it.OrgName.Contains(param.Name!) || it.FormCode.Contains(param.Name!))
|
|
.Select(it => new ElTreeDto()
|
|
{
|
|
Id = it.Id,
|
|
Label = it.OrgName,
|
|
ParentId = it.ParentId,
|
|
Disabled = (it.Status == 0)
|
|
});
|
|
|
|
if (param.HasCondition())
|
|
return await query.ToListAsync();
|
|
else
|
|
return await query.ToTreeAsync(it => it.Children, it => it.ParentId, 0);
|
|
}
|
|
|
|
public async Task<int> GetMaxSort()
|
|
{
|
|
var result = await this._orgManager.AsQueryable().MaxAsync(it => it.Sort);
|
|
return result + 10;
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public override async Task Delete(BaseIdListParam param)
|
|
{
|
|
if (param.Ids.Any())
|
|
{
|
|
foreach (var item in param.Ids)
|
|
{
|
|
var childs = await _orgManager.AsQueryable().ToChildListAsync(it => it.ParentId, item);
|
|
var childIds = childs.Select(it => it.Id).ToList();
|
|
await _orgManager.AsRepository().FakeDeleteAsync(it => childIds.Contains(it.Id));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|