diff --git a/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs b/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs index 13305706..2723925d 100644 --- a/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs +++ b/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs @@ -1,7 +1,7 @@ -using System.ComponentModel.DataAnnotations; using Dlhis.Basic.Appointment.Request; using Dlhis.Basic.Appointment.Response; using Dlhis.Basic.Appointment.Services; +using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Microsoft.AspNetCore.Authorization; @@ -60,6 +60,15 @@ public class AppointmentsController : ControllerBase await _appointmentService.ConfirmAsync(request); } + [AllowAnonymous] + [HttpPost("face/update")] + [Transactional] + [IgnoreTenant] + public async Task GenerateTaskAndUpdateFaceAsync(AppointmentConfirmRequest request) + { + await _appointmentService.GenerateTaskAndUpdateFaceAsync(request.Id, request.Base64Image, DeviceTaskEnumType.Update); + } + /// /// 根据身份证获取当天预约信息 /// diff --git a/Src/Dlhis.Basic/Appointment/Request/AppointmentConfirmRequest.cs b/Src/Dlhis.Basic/Appointment/Request/AppointmentConfirmRequest.cs index c544bb98..8c3c207a 100644 --- a/Src/Dlhis.Basic/Appointment/Request/AppointmentConfirmRequest.cs +++ b/Src/Dlhis.Basic/Appointment/Request/AppointmentConfirmRequest.cs @@ -6,4 +6,9 @@ public class AppointmentConfirmRequest /// 预约明细id /// public long Id { get; set; } -} + + /// + /// base64 image + /// + public string Base64Image { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Appointment/Request/AppointmentPageRequest.cs b/Src/Dlhis.Basic/Appointment/Request/AppointmentPageRequest.cs index 5ac43759..00a1c3f4 100644 --- a/Src/Dlhis.Basic/Appointment/Request/AppointmentPageRequest.cs +++ b/Src/Dlhis.Basic/Appointment/Request/AppointmentPageRequest.cs @@ -4,7 +4,7 @@ using Kurisu.AspNetCore.DataAccess.Dto; namespace Dlhis.Basic.Appointment.Request; -public class AppointmentPageRequest : PageDto , IValidatableObject +public class AppointmentPageRequest : PageDto, IValidatableObject { public DateTimePeriod SearchDateTimePeriod { get; set; } @@ -15,6 +15,7 @@ public class AppointmentPageRequest : PageDto , IValidatableObject { SearchDateTimePeriod.End = SearchDateTimePeriod.End!.Value.AddDays(1).AddSeconds(-1); } + yield break; } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs index fad36689..fc7ecb08 100644 --- a/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs @@ -1,5 +1,6 @@ using Dlhis.Basic.Appointment.Request; using Dlhis.Basic.Appointment.Response; +using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.DataAccess.Dto; using Microsoft.AspNetCore.Mvc; @@ -40,4 +41,6 @@ public interface IAppointmentService : IScopeDependency Task> GetRecordPageByIdNoAsync([FromQuery] AppointmentIdNoPageRequest request); Task GetSummaryAsync(string factory, DateTime start, DateTime end); + + Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs index 288e9ead..c9a0df5c 100644 --- a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs @@ -1,10 +1,13 @@ using Dlhis.Basic.Appointment.Request; using Dlhis.Basic.Appointment.Response; +using Dlhis.Basic.Organization.Request; +using Dlhis.Basic.Organization.Services; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Visitor.Entity; using Dlhis.Entity.Visitor.Enums; +using Kurisu.AspNetCore.Authentication.Abstractions; using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; @@ -20,19 +23,29 @@ public class AppointmentService : IAppointmentService { private readonly IDbContext _dbContext; private readonly IDataProtectionProvider _dataProtectionProvider; + private readonly ICurrentUser _currentUser; + private readonly IGainfoFaceService _gainfoFaceService; - public AppointmentService(IDbContext dbContext, IDataProtectionProvider dataProtectionProvider) + public AppointmentService(IDbContext dbContext, + IDataProtectionProvider dataProtectionProvider, + ICurrentUser currentUser, + IGainfoFaceService gainfoFaceService) { _dbContext = dbContext; _dataProtectionProvider = dataProtectionProvider; + _currentUser = currentUser; + _gainfoFaceService = gainfoFaceService; } public async Task> GetPageAsync(AppointmentPageRequest request) { + var factory = _currentUser.GetStringTenantId(); + return await _dbContext.Queryable() .WhereIF(request.SearchDateTimePeriod.HasValue(), x => x.Date >= request.SearchDateTimePeriod.Start && x.Date <= request.SearchDateTimePeriod.End) .WhereIF(request.Search.IsPresent(), x => x.Code == request.Search) + .Where(x => x.Factory == factory) .Select() .ToPageListAsync(request); } @@ -50,6 +63,19 @@ public class AppointmentService : IAppointmentService var detail = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); detail.ThrowIfNull("预约信息不存在"); + detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived; + detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Arrived; + detail.ArrivedTime = DateTime.Now; + + await _dbContext.UpdateAsync(detail); + await GenerateTaskAndUpdateFaceAsync(detail.Id, request.Base64Image, DeviceTaskEnumType.Add); + } + + public async Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType) + { + var detail = await _dbContext.Queryable().Where(x => x.Id == detailId).SingleAsync(); + detail.ThrowIfNull("预约信息不存在"); + var areaCodes = GetValidAreaCodes(detail); var existsAreaCodes = await _dbContext.Queryable().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync(); @@ -68,17 +94,18 @@ public class AppointmentService : IAppointmentService DeviceUniqueNo = x.UniqueNo, Status = DeviceTaskStatusEnumType.Wait, UserNo = detail.UserNo, - Type = DeviceTaskEnumType.Add, + Type = deviceTaskType, Priority = 100, TenantId = x.TenantId, Source = DeviceTaskSourceEnumType.Appointment, Version = 0, }).ToList()); - detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived; - detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Arrived; - detail.ArrivedTime = DateTime.Now; - await _dbContext.UpdateAsync(detail); + await _gainfoFaceService.UploadExternalFaceAsync(new GainfoUploadFaceRequest + { + UserNo = detail.IdNo, + Face = base64 + }); } @@ -149,7 +176,7 @@ public class AppointmentService : IAppointmentService } catch (Exception) { - throw new UserFriendlyException("凭证有误"); + //ignore } var page = await _dbContext.Queryable() @@ -174,14 +201,17 @@ public class AppointmentService : IAppointmentService var @in = await _dbContext.Queryable() .Where(x => (x.IsEnterDoorArea && ((x.DoorStart >= start && x.DoorStart <= end) || x.DoorEnd >= start && x.DoorEnd <= end)) || - (x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end)))) + (x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end))) + ) + .Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived)) .Where(x => SqlFunc.Subqueryable().Where(p => p.Factory == factory).Any()) .CountAsync(); var notIn = await _dbContext.Queryable() .Where(x => (x.IsEnterDoorArea && ((x.DoorStart >= start && x.DoorStart <= end) || x.DoorEnd >= start && x.DoorEnd <= end)) || - (x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end)))) - .Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Leave) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Leave)) + (x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end))) + ) + .Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Wait)) .Where(x => SqlFunc.Subqueryable().Where(p => p.Factory == factory).Any()) .CountAsync(); @@ -189,6 +219,7 @@ public class AppointmentService : IAppointmentService .Where(x => (x.IsEnterDoorArea && x.DoorEnd >= start && x.DoorEnd <= end) || (x.IsEnterWorkplace && x.WorkplaceEnd >= start && x.WorkplaceEnd <= end) ) + .Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Leave) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Leave)) .Where(x => SqlFunc.Subqueryable().Where(p => p.Factory == factory).Any()) .CountAsync(); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs index 966dd47a..bbcff7e5 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs @@ -3,7 +3,6 @@ using Dlhis.Basic.Organization.Api; using Dlhis.Basic.Organization.Api.Request; using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; -using Dlhis.Entity.Basic.Dto; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Device.Enums; @@ -104,17 +103,13 @@ public class GainfoFaceService : IGainfoFaceService } catch (Exception) { - throw new UserFriendlyException("凭证有误,无法获取人脸数"); + //ignore } var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.External) .Where(x => x.IdNo == request.UserNo) .SingleAsync(); - gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.Working) - .Where(x => x.IdNo == request.UserNo) - .SingleAsync(); - gainfo.ThrowIfNull("人员信息不存在"); var face = await _faceDbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoStore.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoStore.cs index 5d7f9b32..f84fdd28 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoStore.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoStore.cs @@ -30,6 +30,11 @@ public class GainfoStore : IGainfoStore return _dbContext.Queryable(); } + if (gainfoStatus == GainfoStatusEnumType.External) + { + return _dbContext.Queryable().Where(x => x.Type == GainfoUserTypeEnumType.External); + } + var tableName = typeof(GainfoEntity).GetCustomAttribute()!.TableName; return _dbContext.Queryable().AS(tableName + gainfoStatus); } @@ -83,5 +88,4 @@ public class GainfoStore : IGainfoStore return tableName; } - -} +} \ No newline at end of file