From 9885c8d9ae48b6fc877a59ee07764525efa2a717 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 23 Apr 2024 19:10:23 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E7=BB=84=E7=BB=87=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DepartmentsController.cs | 30 +++++++++++++++++++ .../Response/DepartmentOpenResponse.cs | 18 +++++++++++ .../OpenApi/Services/IGainfoService.cs | 2 ++ .../Services/Implements/GainfoService.cs | 7 +++++ .../Common/Dto/DepartmentOpenResponse.cs | 18 +++++++++++ .../Jobs/SyncShanxiGainfoJob.cs | 18 +++++++++++ 6 files changed, 93 insertions(+) create mode 100644 Src/Dlhis.External/OpenApi/Controllers/DepartmentsController.cs create mode 100644 Src/Dlhis.External/OpenApi/Response/DepartmentOpenResponse.cs create mode 100644 Src/Dlhis.ScheduledTask/Common/Dto/DepartmentOpenResponse.cs 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); + } } }