From c84b8e49549fe96286a5e2172f9fe5e9c78fbb9e Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 13 Nov 2025 17:56:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=A4=96=E9=83=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=B0=81=E8=A3=85=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/AppointmentService.cs | 12 ++- .../Services/Implements/GainfoFaceService.cs | 90 +++++++++++-------- 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs index c261fdd6..c8060cc3 100644 --- a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs @@ -103,6 +103,9 @@ public class AppointmentService : IAppointmentService var detail = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); detail.ThrowIfNull("预约信息不存在"); + //提前传 + await UploadFaceToDhAsync(detail.IdNo, request.Base64Image); + if (detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait) { detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived; @@ -122,16 +125,19 @@ public class AppointmentService : IAppointmentService }); await GenerateDeviceTasksAsync(detail, false, DeviceTaskEnumType.Add, "访客门岗认证生成"); + } + private async Task UploadFaceToDhAsync(string idNo, string base64Image) + { try { var r = await _dhApi.SendFaceAsync(new FaceRequest { - IdNo = detail.IdNo, - Face = request.Base64Image + IdNo = idNo, + Face = base64Image }); - _logger.LogInformation("上传face数据到大华成功: {idNo} . {json}", detail.IdNo, r.ToJson()); + _logger.LogInformation("上传face数据到大华成功: {idNo} . {json}", idNo, r.ToJson()); } catch (Exception e) { diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs index f0536eb7..9763488b 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs @@ -342,39 +342,8 @@ public class GainfoFaceService : IGainfoFaceService await _faceDbContext.UpdateAsync(face); } - try - { - var r = await _jinkoJipApi.SyncFaceToSapAsync(new SyncFaceRequest - { - UserCode = face.UserCode, - Base64 = face.Face - }); - - if (r.OLX == "S") - { - await _faceDbContext.Updateable() - .SetColumns(x => x.IsSync == true) - .Where(x => x.UserCode == face.UserCode) - .ExecuteCommandAsync(); - } - } - catch (Exception e) - { - _logger.LogError(e, "上传face数据到sap失败:{message}", e.Message); - } - - // try - // { - // await _hainingApi.UploadAsync(new HainingApiUploadRequest() - // { - // Code = gainfo.Code, - // Base64 = request.Face - // }); - // } - // catch (Exception e) - // { - // _logger.LogError(e, "上传face数据到老系统失败:{message}", e.Message); - // } + await FaceUploadToSapSafelyAsync(face.UserCode, face.Face); + //await FaceUploadToOldSystemSafelyAsync(face.UserCode, face.Face); //生成任务 await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType, "照片上传生成"); @@ -386,7 +355,7 @@ public class GainfoFaceService : IGainfoFaceService { foreach (var request in requests) { - var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.Code == request.UserNo).FirstAsync(); + var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.Code == request.UserNo).SingleAsync(); gainfo.ThrowIfNull("人员档案信息不存在"); var face = await _faceDbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); @@ -425,8 +394,7 @@ public class GainfoFaceService : IGainfoFaceService await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType, "照片上传生成"); } } - - + public async Task GetFaceByUserCodeAsync(string userCode) { var face = await _faceDbContext.Queryable() @@ -525,4 +493,54 @@ public class GainfoFaceService : IGainfoFaceService r.IsPresent().ThrowIfTrue($"{r.Join("\r\n")}"); } } + + /// + /// 上传到sap + /// + /// + /// + private async Task FaceUploadToSapSafelyAsync(string userCode, string faceBase64) + { + try + { + var r = await _jinkoJipApi.SyncFaceToSapAsync(new SyncFaceRequest + { + UserCode = userCode, + Base64 = faceBase64 + }); + + if (r.OLX == "S") + { + await _faceDbContext.Updateable() + .SetColumns(x => x.IsSync == true) + .Where(x => x.UserCode == userCode) + .ExecuteCommandAsync(); + } + } + catch (Exception e) + { + _logger.LogError(e, "上传face数据到sap失败:{message}", e.Message); + } + } + + /// + /// 上传到老系统(兼容) + /// + /// + /// + private async Task FaceUploadToOldSystemSafelyAsync(string userCode, string faceBase64) + { + try + { + await _hainingApi.UploadAsync(new HainingApiUploadRequest() + { + Code = userCode, + Base64 = faceBase64 + }); + } + catch (Exception e) + { + _logger.LogError(e, "上传face数据到老系统失败:{message}", e.Message); + } + } } \ No newline at end of file