Files
jinko.yikatong/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs

48 lines
1.6 KiB
C#

using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
namespace Dlhis.Basic.Organization.Services.Implements;
public class DepartmentService : IDepartmentService
{
private readonly IDbContext _dbContext;
public DepartmentService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<List<DepartmentTreeResponse>> GetTreeAsync()
{
var departments = await _dbContext.Queryable<DepartmentEntity>().Select<DepartmentTreeResponse>().ToListAsync();
//00001000 一定是这个开头的
var tops = departments.Where(x => x.PNo == "00001000").ToList();
tops.ForEach(x => { RecursionGetNext(x, departments); });
return tops;
}
public async Task<List<DepartmentTreeResponse>> GetNextListAsync(string nextNo)
{
return await _dbContext.Queryable<DepartmentEntity>()
.WhereIF(nextNo.IsPresent(), x => x.PNo == nextNo)
.WhereIF(nextNo.IsEmpty(), x => x.PNo == "00001000")
.Select<DepartmentTreeResponse>()
.ToListAsync();
}
//***************************************************** help methods ****************************************************************
private static void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentTreeResponse> data)
{
var next = data.Where(x => x.PNo == current.No).ToList();
current.CurrentNext = next;
foreach (var item in next)
{
RecursionGetNext(item, data);
}
}
}