feat 部门数分页
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Request;
|
||||||
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Basic.Organization.Services;
|
using Dlhis.Basic.Organization.Services;
|
||||||
using Kurisu.AspNetCore.MVC;
|
using Kurisu.AspNetCore.MVC;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@@ -31,4 +33,14 @@ public class DepartmentsController : ControllerBase
|
|||||||
{
|
{
|
||||||
return await _departmentService.GetTreeAsync();
|
return await _departmentService.GetTreeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取部门树分页
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("treepage")]
|
||||||
|
public async Task<Pagination<DepartmentTreeResponse>> GetTreePageAsync([FromQuery]DepartmentPageRequest request)
|
||||||
|
{
|
||||||
|
return await _departmentService.GetTreePageAsync(request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Organization.Request
|
||||||
|
{
|
||||||
|
public class DepartmentPageRequest : PageDto
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Request;
|
||||||
|
using Dlhis.Basic.Organization.Response;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Organization.Services;
|
namespace Dlhis.Basic.Organization.Services;
|
||||||
|
|
||||||
public interface IDepartmentService : IScopeDependency
|
public interface IDepartmentService : IScopeDependency
|
||||||
{
|
{
|
||||||
Task<List<DepartmentTreeResponse>> GetTreeAsync();
|
Task<List<DepartmentTreeResponse>> GetTreeAsync();
|
||||||
|
|
||||||
|
Task<Pagination<DepartmentTreeResponse>> GetTreePageAsync(DepartmentPageRequest request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Request;
|
||||||
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||||
|
|
||||||
@@ -28,6 +31,34 @@ public class DepartmentService : IDepartmentService
|
|||||||
return tops;
|
return tops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Pagination<DepartmentTreeResponse>> GetTreePageAsync(DepartmentPageRequest request)
|
||||||
|
{
|
||||||
|
var departments = await _dbContext
|
||||||
|
.Queryable<DepartmentEntity>()
|
||||||
|
.WhereIF(!request.Search.IsEmpty(),x => x.Name.Contains(request.Search)).ToListAsync();
|
||||||
|
|
||||||
|
var tops = departments.Where(x => x.PNo.IsEmpty()).Adapt<List<DepartmentTreeResponse>>();
|
||||||
|
|
||||||
|
tops.ForEach(x =>
|
||||||
|
{
|
||||||
|
RecursionGetNext(x, departments);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 分页操作
|
||||||
|
var startIndex = (request.PageIndex - 1) * request.PageSize;
|
||||||
|
var pagedData = tops.Skip(startIndex).Take(request.PageSize).ToList();
|
||||||
|
|
||||||
|
var pagination = new Pagination<DepartmentTreeResponse>
|
||||||
|
{
|
||||||
|
PageIndex = request.PageIndex,
|
||||||
|
PageSize = request.PageSize,
|
||||||
|
Total = tops.Count, // 使用原始列表的总数进行分页
|
||||||
|
Data = pagedData
|
||||||
|
};
|
||||||
|
|
||||||
|
return pagination;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentEntity> departments)
|
private void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentEntity> departments)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user