From 01ec2740317b3fba6409cbc0ac52f686c6013625 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 15 Jan 2024 16:53:41 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=A0=B9=E6=8D=AE=E5=B7=A5=E5=8F=B7?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BA=BA=E8=84=B8=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicesController.cs | 12 ++++- .../Device/Response/DeviceResponse.cs | 11 ----- .../Device/Services/IDeviceService.cs | 2 + .../Services/Implements/DeviceService.cs | 5 +++ .../Controllers/GainfosController.cs | 11 +++++ .../Organization/Services/IGainfoService.cs | 2 + .../Services/Implements/GainfoService.cs | 45 ++++++++++++++++++- Src/Dlhis.Basic/appsettings.json | 4 ++ Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 13 ------ .../Device/Enums/DeviceFuncEnumType.cs | 12 +++-- .../Services/Implements/AssignmentService.cs | 2 +- 11 files changed, 88 insertions(+), 31 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 610f6768..19d92f35 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -145,8 +145,18 @@ public class DevicesController : ControllerBase /// /// [HttpGet] - public async Task> GetDeviceByNoAsync([FromQuery]DevicePageRequest request) + public async Task> GetDeviceByNoAsync([FromQuery] DevicePageRequest request) { return await _deviceService.GetDeviceByNoAsync(request); } + + /// + /// 获取考勤设备 + /// + /// + [HttpGet("attendances")] + public async Task> GetAttendanceDevicesAsync() + { + return await _deviceService.GetAttendanceDevicesAsync(); + } } diff --git a/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs index a36e18c7..628a35b4 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs @@ -74,17 +74,6 @@ public class DeviceResponse /// public string ConnectionInfo { get; set; } - /// - /// 最后使用人 - /// - public DateTime LastLogId { get; set; } - - /// - /// 最后使用日期 - /// - public DateTime LastLogDateTime { get; set; } - - /// /// 是否启用 /// diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index d13e5dcb..930db433 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -13,4 +13,6 @@ public interface IDeviceService : IScopeDependency Task CheckExistsAsync(string deviceUniqueNo); Task> GetDeviceByNoAsync(DevicePageRequest request); + + Task> GetAttendanceDevicesAsync(); } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index dc5f4e37..bdf243c1 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -164,5 +164,10 @@ public class DeviceService : IDeviceService return page; } + + public Task> GetAttendanceDevicesAsync() + { + throw new NotImplementedException(); + } } diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 7c9fac1b..56b26d43 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -112,5 +112,16 @@ public class GainfosController : ControllerBase { return await _gainfoService.GetFaceAsync(token); } + + /// + /// 获取人脸照片 + /// + /// + /// + [HttpGet("face/{userCode}")] + public async Task GetFaceByUserCodeAsync(string userCode) + { + return await _gainfoService.GetFaceByUserCodeAsync(userCode); + } } diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs index 43c71e75..77e812c1 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs @@ -22,4 +22,6 @@ public interface IGainfoService : IScopeDependency Task UploadFaceAsync(GainfoUploadFaceRequest request); Task GetFaceAsync(string token); + + Task GetFaceByUserCodeAsync(string userCode); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index bb7fb4eb..2c67f1e6 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -1,4 +1,5 @@ -using Dlhis.Basic.Organization.Request; +using System.Threading.Tasks; +using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Enums; @@ -13,6 +14,8 @@ using Kurisu.SqlSugar.Services; using Mapster; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using NetTaste; namespace Dlhis.Basic.Organization.Services.Implements; @@ -266,4 +269,44 @@ public class GainfoService : IGainfoService } }); } + + public async Task GetFaceByUserCodeAsync(string userCode) + { + var gainfo = await _dbContext.Queryable().Where(x => x.Code == userCode).SingleAsync(); + gainfo.ThrowIfNull("人员信息不存在"); + + return await Scoped.Request.Value.CreateAsync(async (sp) => + { + var configuration = sp.GetService(); + + var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; + if (faceConnectionString.IsEmpty()) + { + throw new UserFriendlyException("暂不支持获取人脸"); + } + + var dbContext = sp.GetService(); + //todo 切换连接字符串 + dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; + + var face = await dbContext.Queryable() + .Where(x => x.UserCode == userCode) + .SingleAsync(); + + face.ThrowIfNull("人脸照片尚未录入"); + + var timeLimitedDataProtector = sp.GetService() + .CreateProtector("down:face") + .ToTimeLimitedDataProtector(); + + var faceUrl = configuration.GetSection("FaceUrlOptions:Url").Value; + var limit = configuration.GetSection("FaceUrlOptions:Limit").Get(); + var dataProtectionProvider = sp.GetService(); + + var key = $"face:{userCode}"; + var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(limit)); + + return faceUrl + token; + }); + } } diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 75960c44..d48a4890 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -10,6 +10,10 @@ "CommonRequestUrl": "http://common", "UserRequestUrl": "http://user" }, + "FaceUrlOptions": { + "Url": "https://yikatong.isawesome.cn/api/basic/gainfos/face?token=", + "Limit": 7200 + }, "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index 529fdb59..90e508fe 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -77,19 +77,6 @@ public class DeviceEntity : SugarBaseEntity, ITenantId [SugarColumn(ColumnDescription = "连接信息")] public string ConnectionInfo { get; set; } - /// - /// 最后使用人 - /// - [SugarColumn(IsNullable = true, ColumnDescription = "最后使用人")] - public DateTime? LastLogId { get; set; } - - /// - /// 最后使用日期 - /// - [SugarColumn(IsNullable = true, ColumnDescription = "最后使用日期")] - public DateTime? LastLogDateTime { get; set; } - - /// /// 是否启用 /// diff --git a/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs b/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs index 2d6a2f10..ac475816 100644 --- a/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs +++ b/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs @@ -3,9 +3,9 @@ namespace Dlhis.Entity.Device.Enums; /// -/// 机器设备功能 +/// 设备功能 /// -[Description("机器设备功能")] +[Description("设备功能")] public enum DeviceFuncEnumType { /// @@ -26,14 +26,12 @@ public enum DeviceFuncEnumType [Description("人脸")] Face, - /// /// 刷卡 /// [Description("刷卡")] Card, - /// /// 二维码 /// @@ -46,4 +44,10 @@ public enum DeviceFuncEnumType /// [Description("布控")] Control, + + /// + /// 考勤 + /// + [Description("考勤")] + Attendance, } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index 8b8bd91d..e49d24f0 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -169,7 +169,7 @@ public class AssignmentService : IAssignmentService return Scoped.Request.Value.Create((sp) => { - FaceUrlOptions faceUrlOptions = sp.GetService>().Value; + var faceUrlOptions = sp.GetService>().Value; var dataProtectionProvider = sp.GetService(); var timeLimitedDataProtector = dataProtectionProvider