From 1f360c800571069e6289fc23588dd9d658f5d3ec Mon Sep 17 00:00:00 2001
From: cheche <717840555@qq.com>
Date: Tue, 20 Feb 2024 11:07:04 +0800
Subject: [PATCH] =?UTF-8?q?feat=20=E9=83=A8=E9=97=A8=E6=95=B0=E5=88=86?=
=?UTF-8?q?=E9=A1=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/DepartmentsController.cs | 14 +++++++-
.../Request/DepartmentPageRequest.cs | 8 +++++
.../Services/IDepartmentService.cs | 6 +++-
.../Services/Implements/DepartmentService.cs | 33 ++++++++++++++++++-
4 files changed, 58 insertions(+), 3 deletions(-)
create mode 100644 Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs
diff --git a/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs b/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs
index 55fa4c2b..678e2e0a 100644
--- a/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs
+++ b/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs
@@ -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 Kurisu.AspNetCore.MVC;
+using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -31,4 +33,14 @@ public class DepartmentsController : ControllerBase
{
return await _departmentService.GetTreeAsync();
}
+
+ ///
+ /// 获取部门树分页
+ ///
+ ///
+ [HttpGet("treepage")]
+ public async Task> GetTreePageAsync([FromQuery]DepartmentPageRequest request)
+ {
+ return await _departmentService.GetTreePageAsync(request);
+ }
}
diff --git a/Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs b/Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs
new file mode 100644
index 00000000..cdba378c
--- /dev/null
+++ b/Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs
@@ -0,0 +1,8 @@
+using Kurisu.Core.DataAccess.Dto;
+
+namespace Dlhis.Basic.Organization.Request
+{
+ public class DepartmentPageRequest : PageDto
+ {
+ }
+}
diff --git a/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs b/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs
index 5e3784c1..cfd0b9d2 100644
--- a/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs
+++ b/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs
@@ -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;
public interface IDepartmentService : IScopeDependency
{
Task> GetTreeAsync();
+
+ Task> GetTreePageAsync(DepartmentPageRequest request);
}
diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs
index 3c207dc8..a39166e4 100644
--- a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs
+++ b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs
@@ -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 Kurisu.AspNetCore.Utils.Extensions;
+using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Services;
using Mapster;
+using System.Collections.Generic;
namespace Dlhis.Basic.Organization.Services.Implements;
@@ -28,6 +31,34 @@ public class DepartmentService : IDepartmentService
return tops;
}
+ public async Task> GetTreePageAsync(DepartmentPageRequest request)
+ {
+ var departments = await _dbContext
+ .Queryable()
+ .WhereIF(!request.Search.IsEmpty(),x => x.Name.Contains(request.Search)).ToListAsync();
+
+ var tops = departments.Where(x => x.PNo.IsEmpty()).Adapt>();
+
+ 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
+ {
+ PageIndex = request.PageIndex,
+ PageSize = request.PageSize,
+ Total = tops.Count, // 使用原始列表的总数进行分页
+ Data = pagedData
+ };
+
+ return pagination;
+
+ }
private void RecursionGetNext(DepartmentTreeResponse current, List departments)
{