From 5ff07e61ef6e7939756700f33e660ce10e41fe5c Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 5 Sep 2024 16:53:09 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=BB=93=E6=9E=84=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/VisitorAppointmentDetailEntity.cs | 55 ++++++++++++-- .../Entity/VisitorAppointmentEntity.cs | 43 ----------- .../Dto/AppointmentReceiveItemDto.cs | 74 +++++++++++++++++- .../VisitorAppointmentReceiveRequest.cs | 75 +------------------ .../Services/Implements/AppointmentService.cs | 48 +++++------- 5 files changed, 142 insertions(+), 153 deletions(-) diff --git a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs index 4f288a49..ee427536 100644 --- a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs +++ b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs @@ -52,10 +52,46 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity public string LicensePlate { get; set; } /// - /// 状态 + /// 预约门禁区域 /// - [SugarColumn(IsNullable = false, ColumnDescription = "状态", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] - public VisitorAppointmentDetailStatusEnumType Status { get; set; } + public string ApplyDoorArea { get; set; } + + /// + /// 访客开始 + /// + public DateTime DoorStart { get; set; } + + /// + /// 访问结束 + /// + public DateTime DoorEnd { get; set; } + + /// + /// 是否进入车间 + /// + public bool IsEnterWorkplace { get; set; } + + /// + /// 申请车间区域 + /// + [SugarColumn(ColumnDescription = "车间区域", IsJson = true, DefaultValue = "[]")] + public List ApplyWorkplaceAreas { get; set; } + + /// + /// 车间访问开始 + /// + public DateTime? WorkplaceStart { get; set; } + + /// + /// 车间访问结束 + /// + public DateTime? WorkplaceEnd { get; set; } + + /// + /// 社保照片url + /// + [SugarColumn(ColumnDescription = "社保照片url")] + public string ImageUrl { get; set; } /// /// 备注 @@ -63,9 +99,16 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity [SugarColumn(ColumnDescription = "备注")] public string Remark { get; set; } + /// - /// 社保照片url + /// 门禁状态 /// - [SugarColumn(ColumnDescription = "社保照片url")] - public string ImageUrl { get; set; } + [SugarColumn(IsNullable = false, ColumnDescription = "门禁状态", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public VisitorAppointmentDetailStatusEnumType DoorStatus { get; set; } + + /// + /// 车间状态 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "车间状态", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public VisitorAppointmentDetailStatusEnumType WorkplaceStatus { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentEntity.cs b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentEntity.cs index 323449a0..9cc68b92 100644 --- a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentEntity.cs +++ b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentEntity.cs @@ -37,43 +37,6 @@ public class VisitorAppointmentEntity : SugarBaseEntity /// public DateTime Date { get; set; } - /// - /// 预约门禁区域 - /// - public string ApplyDoorArea { get; set; } - - - /// - /// 访客开始 - /// - public DateTime DoorStart { get; set; } - - /// - /// 访问结束 - /// - public DateTime DoorEnd { get; set; } - - /// - /// 是否进入车间 - /// - public bool IsEnterWorkplace { get; set; } - - /// - /// 申请车间区域 - /// - [SugarColumn(ColumnDescription = "车间区域", IsJson = true, DefaultValue = "[]")] - public List ApplyWorkplaceAreas { get; set; } - - /// - /// 车间访问开始 - /// - public DateTime? WorkplaceStart { get; set; } - - /// - /// 车间访问结束 - /// - public DateTime? WorkplaceEnd { get; set; } - /// /// 备注 /// @@ -88,10 +51,4 @@ public class VisitorAppointmentEntity : SugarBaseEntity /// 申请事由 /// public string Reason { get; set; } - - /// - /// 状态 - /// - [SugarColumn(IsNullable = false, ColumnDescription = "状态", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] - public VisitorAppointmentStatusEnumType Status { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.External/Appointment/Dto/AppointmentReceiveItemDto.cs b/Src/Dlhis.External/Appointment/Dto/AppointmentReceiveItemDto.cs index 538a73b4..bd0fd1b5 100644 --- a/Src/Dlhis.External/Appointment/Dto/AppointmentReceiveItemDto.cs +++ b/Src/Dlhis.External/Appointment/Dto/AppointmentReceiveItemDto.cs @@ -1,8 +1,9 @@ using System.ComponentModel.DataAnnotations; +using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.External.Appointment.Dto; -public class AppointmentReceiveItemDto +public class AppointmentReceiveItemDto : IValidatableObject { /// /// 姓名 @@ -28,7 +29,7 @@ public class AppointmentReceiveItemDto /// [Required(ErrorMessage = "证件号/工号")] public string IdNo { get; set; } - + /// /// 车牌 /// @@ -43,4 +44,73 @@ public class AppointmentReceiveItemDto /// 社保照片 /// public string ImageUrl { get; set; } + + + /// + /// 预约门岗区域 + /// + [Required(ErrorMessage = "预约门岗区域不可为空")] + public string ApplyDoorArea { get; set; } + + /// + /// 访客开始 + /// + public DateTime DoorStart { get; set; } + + /// + /// 访问结束 + /// + public DateTime DoorEnd { get; set; } + + /// + /// 是否进入车间 + /// + public bool IsEnterWorkplace { get; set; } + + /// + /// 申请车间区域 + /// + public List ApplyWorkplaceAreas { get; set; } + + /// + /// 车间访问开始 + /// + public DateTime? WorkplaceStart { get; set; } + + /// + /// 车间访问结束 + /// + public DateTime? WorkplaceEnd { get; set; } + + /// + public IEnumerable Validate(ValidationContext validationContext) + { + if (DoorStart >= DoorEnd) + { + yield return new ValidationResult($"{Name}门禁来访时间有误", new[] { nameof(DoorStart) }); + } + + if (IsEnterWorkplace) + { + if (ApplyWorkplaceAreas.IsEmpty()) + { + yield return new ValidationResult($"{Name}车间区域不可为空", new[] { nameof(ApplyWorkplaceAreas) }); + } + + if (WorkplaceStart >= WorkplaceEnd) + { + yield return new ValidationResult($"{Name}车间来访时间有误", new[] { nameof(WorkplaceStart) }); + } + + if (WorkplaceStart < DoorStart || WorkplaceStart > DoorEnd) + { + yield return new ValidationResult($"{Name}车间来访时间需在门禁时间范围内", new[] { nameof(WorkplaceStart) }); + } + + if (WorkplaceEnd < DoorStart || WorkplaceEnd > DoorEnd) + { + yield return new ValidationResult($"{Name}车间来访时间需在门禁时间范围内", new[] { nameof(WorkplaceStart) }); + } + } + } } \ No newline at end of file diff --git a/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs b/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs index c426c6a3..86c34468 100644 --- a/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs +++ b/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs @@ -1,10 +1,9 @@ using System.ComponentModel.DataAnnotations; using Dlhis.External.Appointment.Dto; -using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.External.Appointment.Request; -public class VisitorAppointmentReceiveRequest : IValidatableObject +public class VisitorAppointmentReceiveRequest { /// /// 流水号 @@ -24,12 +23,6 @@ public class VisitorAppointmentReceiveRequest : IValidatableObject [Required(ErrorMessage = "对接人工号不可为空")] public string Code { get; set; } - /// - /// 预约门岗区域 - /// - [Required(ErrorMessage = "预约门岗区域不可为空")] - public string ApplyDoorArea { get; set; } - /// /// 来访人来源/公司 /// @@ -41,36 +34,6 @@ public class VisitorAppointmentReceiveRequest : IValidatableObject /// public DateTime Date { get; set; } - /// - /// 访客开始 - /// - public DateTime DoorStart { get; set; } - - /// - /// 访问结束 - /// - public DateTime DoorEnd { get; set; } - - /// - /// 是否进入车间 - /// - public bool IsEnterWorkplace { get; set; } - - /// - /// 申请车间区域 - /// - public List ApplyWorkplaceAreas { get; set; } - - /// - /// 车间访问开始 - /// - public DateTime? WorkplaceStart { get; set; } - - /// - /// 车间访问结束 - /// - public DateTime? WorkplaceEnd { get; set; } - /// /// 备注 /// @@ -94,40 +57,4 @@ public class VisitorAppointmentReceiveRequest : IValidatableObject /// [MinLength(1, ErrorMessage = "明细必填")] public List Items { get; set; } - - public IEnumerable Validate(ValidationContext validationContext) - { - if (DoorStart >= DoorEnd) - { - yield return new ValidationResult("门禁来访时间有误", new[] { nameof(DoorStart) }); - } - - if (IsEnterWorkplace) - { - if (ApplyWorkplaceAreas.IsEmpty()) - { - yield return new ValidationResult("车间区域不可为空", new[] { nameof(ApplyWorkplaceAreas) }); - } - - if (WorkplaceStart >= WorkplaceEnd) - { - yield return new ValidationResult("车间来访时间有误", new[] { nameof(WorkplaceStart) }); - } - - if (WorkplaceStart < DoorStart || WorkplaceStart > DoorEnd) - { - yield return new ValidationResult("车间来访时间需在门禁时间范围内", new[] { nameof(WorkplaceStart) }); - } - - if (WorkplaceEnd < DoorStart || WorkplaceEnd > DoorEnd) - { - yield return new ValidationResult("车间来访时间需在门禁时间范围内", new[] { nameof(WorkplaceStart) }); - } - - if (Items.Any(x => x.ImageUrl.IsEmpty())) - { - yield return new ValidationResult("请上传社保照片", new[] { nameof(WorkplaceStart) }); - } - } - } } \ No newline at end of file diff --git a/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs index 5bc3edeb..ff1b7951 100644 --- a/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs @@ -26,20 +26,7 @@ public class AppointmentService : IAppointmentService var exists = await _dbContext.Queryable().Where(x => x.No == request.No).AnyAsync(); exists.ThrowIfTrue("已经存在申请"); - var existsDoorArea = await _dbContext.Queryable() - .Where(x => x.TenantId == request.Factory) - .Where(x => x.Name == request.ApplyDoorArea) - .AnyAsync(); - - var existsWorkplace = true; - if (request.IsEnterWorkplace) - { - var count = await _dbContext.Queryable().Where(x => x.TenantId == request.Factory) - .Where(x => request.ApplyWorkplaceAreas.Contains(x.Name)) - .CountAsync(); - - existsWorkplace = request.ApplyWorkplaceAreas.Count == count; - } + var areas = await _dbContext.Queryable().Where(x => x.TenantId == request.Factory).ToListAsync(); var mst = new VisitorAppointmentEntity { @@ -53,21 +40,10 @@ public class AppointmentService : IAppointmentService Code = request.Code, Source = request.Source, Date = request.Date, - ApplyDoorArea = request.ApplyDoorArea, Factory = request.Factory, Reason = request.Reason, - DoorStart = request.DoorStart, - DoorEnd = request.DoorEnd, Remark = request.Remark, - IsEnterWorkplace = request.IsEnterWorkplace, - ApplyWorkplaceAreas = request.ApplyWorkplaceAreas, - WorkplaceStart = request.WorkplaceStart, - WorkplaceEnd = request.WorkplaceEnd }; - if (!existsDoorArea || !existsWorkplace) - { - mst.Status = VisitorAppointmentStatusEnumType.Obsolete; - } await _dbContext.InsertAsync(mst); @@ -100,7 +76,7 @@ public class AppointmentService : IAppointmentService } } - (gainfo.Type == GainfoUserTypeEnumType.External && request.IsEnterWorkplace && item.ImageUrl.IsEmpty()).ThrowIfTrue($"{item.Name}的社保照片不可为空"); + (gainfo.Type == GainfoUserTypeEnumType.External && item.IsEnterWorkplace && item.ImageUrl.IsEmpty()).ThrowIfTrue($"{item.Name}的社保照片不可为空"); var detail = new VisitorAppointmentDetailEntity { @@ -111,10 +87,26 @@ public class AppointmentService : IAppointmentService Name = item.Name, Phone = item.Phone, Remark = item.Remark, - Status = mst.Status == VisitorAppointmentStatusEnumType.Valid + DoorStatus = areas.Where(x => x.Type == AppointmentAreaEnumType.Door) + .Select(x => x.Name) + .Contains(item.ApplyDoorArea) ? VisitorAppointmentDetailStatusEnumType.Wait : VisitorAppointmentDetailStatusEnumType.Obsolete, - LicensePlate = item.LicensePlate + LicensePlate = item.LicensePlate, + ApplyDoorArea = item.ApplyDoorArea, + DoorStart = item.DoorStart, + DoorEnd = item.DoorEnd, + IsEnterWorkplace = item.IsEnterWorkplace, + WorkplaceStatus = item.IsEnterWorkplace && + item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace) + .Select(x => x.Name) + .Contains(p)) + ? VisitorAppointmentDetailStatusEnumType.Wait + : VisitorAppointmentDetailStatusEnumType.Obsolete, + ApplyWorkplaceAreas = item.ApplyWorkplaceAreas, + WorkplaceStart = item.WorkplaceStart, + WorkplaceEnd = item.WorkplaceEnd, + ImageUrl = item.ImageUrl }; await _dbContext.InsertAsync(detail);