diff --git a/Src/Dlhis.External/OpenApi/Controllers/DepartmentsController.cs b/Src/Dlhis.External/OpenApi/Controllers/DepartmentsController.cs
new file mode 100644
index 00000000..4641a78e
--- /dev/null
+++ b/Src/Dlhis.External/OpenApi/Controllers/DepartmentsController.cs
@@ -0,0 +1,30 @@
+using Dlhis.External.OpenApi.Response;
+using Dlhis.External.OpenApi.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Dlhis.External.OpenApi.Controllers;
+
+[Authorize]
+[Route("api/[controller]")]
+[ApiController]
+public class DepartmentsController : ControllerBase
+{
+ private readonly IGainfoService _gainfoService;
+
+ public DepartmentsController(IGainfoService gainfoService)
+ {
+ _gainfoService = gainfoService;
+ }
+
+ ///
+ /// 获取所有部门信息
+ ///
+ ///
+ [HttpGet("all")]
+ public async Task> GetDepartmentsAsync()
+ {
+ return await _gainfoService.GetDepartmentsAsync();
+ }
+}
diff --git a/Src/Dlhis.External/OpenApi/Response/DepartmentOpenResponse.cs b/Src/Dlhis.External/OpenApi/Response/DepartmentOpenResponse.cs
new file mode 100644
index 00000000..a331dd78
--- /dev/null
+++ b/Src/Dlhis.External/OpenApi/Response/DepartmentOpenResponse.cs
@@ -0,0 +1,18 @@
+using SqlSugar;
+
+namespace Dlhis.External.OpenApi.Response;
+
+public class DepartmentOpenResponse
+{
+ public string No { get; set; }
+
+ ///
+ /// 上级部门号
+ ///
+ public string PNo { get; set; }
+
+ ///
+ /// 部门名称
+ ///
+ public string Name { get; set; }
+}
diff --git a/Src/Dlhis.External/OpenApi/Services/IGainfoService.cs b/Src/Dlhis.External/OpenApi/Services/IGainfoService.cs
index df584ad5..12dcbadd 100644
--- a/Src/Dlhis.External/OpenApi/Services/IGainfoService.cs
+++ b/Src/Dlhis.External/OpenApi/Services/IGainfoService.cs
@@ -5,4 +5,6 @@ namespace Dlhis.External.OpenApi.Services;
public interface IGainfoService : IScopeDependency
{
Task> GetAllGainfosAsync();
+
+ Task> GetDepartmentsAsync();
}
diff --git a/Src/Dlhis.External/OpenApi/Services/Implements/GainfoService.cs b/Src/Dlhis.External/OpenApi/Services/Implements/GainfoService.cs
index 83458286..e279c30e 100644
--- a/Src/Dlhis.External/OpenApi/Services/Implements/GainfoService.cs
+++ b/Src/Dlhis.External/OpenApi/Services/Implements/GainfoService.cs
@@ -18,4 +18,11 @@ public class GainfoService : IGainfoService
var data = await _redisCache.ListRangeAsync("gainfo:shanxi");
return data.Select(x => x.ToString().ToObject()).ToList();
}
+
+ public async Task> GetDepartmentsAsync()
+ {
+ var departmentKey = "department:all";
+ var data = await _redisCache.ListRangeAsync(departmentKey);
+ return data.Select(x => x.ToString().ToObject()).ToList();
+ }
}
diff --git a/Src/Dlhis.ScheduledTask/Common/Dto/DepartmentOpenResponse.cs b/Src/Dlhis.ScheduledTask/Common/Dto/DepartmentOpenResponse.cs
new file mode 100644
index 00000000..5070c610
--- /dev/null
+++ b/Src/Dlhis.ScheduledTask/Common/Dto/DepartmentOpenResponse.cs
@@ -0,0 +1,18 @@
+using SqlSugar;
+
+namespace Dlhis.ScheduledTask.Common.Dto;
+
+public class DepartmentOpenResponse
+{
+ public string No { get; set; }
+
+ ///
+ /// 上级部门号
+ ///
+ public string PNo { get; set; }
+
+ ///
+ /// 部门名称
+ ///
+ public string Name { get; set; }
+}
diff --git a/Src/Dlhis.ScheduledTask/Jobs/SyncShanxiGainfoJob.cs b/Src/Dlhis.ScheduledTask/Jobs/SyncShanxiGainfoJob.cs
index dd5238bb..57a5905c 100644
--- a/Src/Dlhis.ScheduledTask/Jobs/SyncShanxiGainfoJob.cs
+++ b/Src/Dlhis.ScheduledTask/Jobs/SyncShanxiGainfoJob.cs
@@ -62,5 +62,23 @@ public class SyncShanxiGainfoJob : BaseJob
{
await _redisCache.ListLeftPushAsync(key, item);
}
+
+
+ var departmentKey = "department:all";
+ await _redisCache.KeyDeleteAsync(departmentKey);
+
+ var departments = await DbContext.Queryable()
+ .Select((x) => new DepartmentOpenResponse
+ {
+ Name = x.Name,
+ No = x.No,
+ PNo = x.PNo,
+ })
+ .ToListAsync();
+
+ foreach (var item in departments)
+ {
+ await _redisCache.ListLeftPushAsync(departmentKey, item);
+ }
}
}