From 67481931fcd4e996efbda82b08bce2b5732704c1 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 2 Feb 2026 15:38:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=AE=BF=E5=AE=A2=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=95=B0=E6=8D=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VisitorAppointmentReceiveRequest.cs | 5 +- .../Services/Implements/AppointmentService.cs | 278 ++++++++++-------- 2 files changed, 166 insertions(+), 117 deletions(-) diff --git a/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs b/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs index 86c34468..8c84a2ee 100644 --- a/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs +++ b/Src/Dlhis.External/Appointment/Request/VisitorAppointmentReceiveRequest.cs @@ -3,7 +3,7 @@ using Dlhis.External.Appointment.Dto; namespace Dlhis.External.Appointment.Request; -public class VisitorAppointmentReceiveRequest +public class VisitorAppointmentReceiveRequest { /// /// 流水号 @@ -57,4 +57,7 @@ public class VisitorAppointmentReceiveRequest /// [MinLength(1, ErrorMessage = "明细必填")] public List Items { get; set; } + + + public bool OnlyCheck { get; set; } } \ 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 8635dbba..6d3c7c93 100644 --- a/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs @@ -31,140 +31,186 @@ public class AppointmentService : IAppointmentService public async Task ReceiveAsync(VisitorAppointmentReceiveRequest request) { - if (request.Factory == "501") - { - await ReSendTo501Async(request); - return; - } + var invalids = new[] { GainfoUserTypeEnumType.Normal, GainfoUserTypeEnumType.SecurityWhite }; var exists = await _dbContext.Queryable().Where(x => x.No == request.No).AnyAsync(); - exists.ThrowIfTrue("已经存在申请"); + exists.ThrowIfTrue("已经存在申请,请勿重复提交"); var areas = await _dbContext.Queryable().Where(x => x.TenantId == request.Factory).ToListAsync(); - var mst = new VisitorAppointmentEntity + if (request.OnlyCheck) { - No = request.No, - Title = request.Title, - Code = request.Code, - Source = request.Source, - Date = request.Date, - Factory = request.Factory, - Reason = request.Reason, - Remark = request.Remark, - }; + var enterDoorAreaIdNos = request.Items.Where(x => x.IsEnterDoorArea).Select(x => x.IdNo).Distinct().ToList(); + var errors = await _dbContext.Queryable() + .Where(x => enterDoorAreaIdNos.Contains(x.IdNo) || enterDoorAreaIdNos.Contains(x.Code)) + .Where(x => invalids.Contains(x.Type)) + .Select(x => x.IdNo + x.Name) + .ToListAsync(); - await _dbContext.InsertAsync(mst); + errors.ThrowIfExists($"内部人员无法发起门岗预约({errors.Join(",")})"); - var invalids = new[] { GainfoUserTypeEnumType.Normal, GainfoUserTypeEnumType.SecurityWhite }; - - var enterDoorAreaIdNos = request.Items.Where(x => x.IsEnterDoorArea).Select(x => x.IdNo).Distinct().ToList(); - var errors = await _dbContext.Queryable() - .Where(x => enterDoorAreaIdNos.Contains(x.IdNo) || enterDoorAreaIdNos.Contains(x.Code)) - .Where(x => invalids.Contains(x.Type)) - .Select(x => x.IdNo + x.Name) - .ToListAsync(); - - errors.ThrowIfExists($"内部人员无法发起门岗预约({errors.Join(",")})"); - - //var idNos = request.Items.Select(x => x.IdNo).Distinct().ToList(); - //var outsources = await _dbContext.Queryable() - // .Where(x => idNos.Contains(x.IdNo) || idNos.Contains(x.Code)) - // .Where(x => x.Type == GainfoUserTypeEnumType.Outsource) - // .Select(x => x.IdNo + x.Name) - // .ToListAsync(); - - //outsources.ThrowIfExists($"存在外包人员申请,请检查一下人员:{outsources.Join(",")}"); - - foreach (var item in request.Items) - { - item.IdNo = item.IdNo.Trim(); - - if (item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door) - .Select(x => x.CustomCode) - .Contains(item.ApplyDoorArea) == false) + foreach (var item in request.Items) { - throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效"); - } + item.IdNo = item.IdNo.Trim(); - if (item.IsEnterWorkplace && - item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace) - .Select(x => x.CustomCode) - .Contains(p)) == false) - { - var workplaceAreas = areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace).Select(x => x.CustomCode); - var notExistsAreas = item.ApplyWorkplaceAreas.Where(x => !workplaceAreas.Contains(x)); - throw new UserFriendlyException($"车间区域{notExistsAreas.Join(",")}无效"); - } - - var gainfo = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo || x.Code == item.IdNo).SingleAsync(); - //外部人员 - if (gainfo == null) - { - gainfo = new GainfoEntity + if (item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door) + .Select(x => x.CustomCode) + .Contains(item.ApplyDoorArea) == false) { - No = Guid.NewGuid().ToString(), - Code = await GetNextExternalCodeAsync(), - Gender = GetGender(item.IdNo), - Type = GainfoUserTypeEnumType.External, - IdNo = item.IdNo, - Name = item.Name, - Source = request.Source, - Phone = item.Phone, - Factory = mst.Factory - }; - await _dbContext.InsertAsync(gainfo); - } - else - { - (invalids.Contains(gainfo.Type) && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约"); - if (gainfo.Type == GainfoUserTypeEnumType.External) - { - gainfo.Source = request.Source; - gainfo.Phone = item.Phone; - gainfo.Factory = mst.Factory; - - await _dbContext.UpdateAsync(gainfo); + throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效"); } - //else if (gainfo.Type == GainfoUserTypeEnumType.Outsource) - //{ - // throw new UserFriendlyException($"访客类型有误!,请检查{gainfo.Name},{gainfo.IdNo}"); - //} + + if (item.IsEnterWorkplace && + item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace) + .Select(x => x.CustomCode) + .Contains(p)) == false) + { + var workplaceAreas = areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace).Select(x => x.CustomCode); + var notExistsAreas = item.ApplyWorkplaceAreas.Where(x => !workplaceAreas.Contains(x)); + throw new UserFriendlyException($"车间区域{notExistsAreas.Join(",")}无效"); + } + + var gainfo = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo || x.Code == item.IdNo).SingleAsync(); + //外部人员 + if (gainfo == null) + { + + } + else + { + (invalids.Contains(gainfo.Type) && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约"); + } + } + } + else + { + if (request.Factory == "501") + { + await ReSendTo501Async(request); + return; } - var detail = new VisitorAppointmentDetailEntity + var mst = new VisitorAppointmentEntity { - UserNo = gainfo.No, No = request.No, - IdType = item.IdType, - IdNo = item.IdNo, - Name = item.Name, - Phone = item.Phone, - Remark = item.Remark, - DoorStatus = item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door) - .Select(x => x.CustomCode) - .Contains(item.ApplyDoorArea) - ? VisitorAppointmentDetailStatusEnumType.Wait - : VisitorAppointmentDetailStatusEnumType.Obsolete, - LicensePlate = item.LicensePlate, - IsEnterDoorArea = item.IsEnterDoorArea, - 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.CustomCode) - .Contains(p)) - ? VisitorAppointmentDetailStatusEnumType.Wait - : VisitorAppointmentDetailStatusEnumType.Obsolete, - ApplyWorkplaceAreas = item.ApplyWorkplaceAreas, - WorkplaceStart = item.WorkplaceStart, - WorkplaceEnd = item.WorkplaceEnd, - ImageUrl = item.ImageUrl + Title = request.Title, + Code = request.Code, + Source = request.Source, + Date = request.Date, + Factory = request.Factory, + Reason = request.Reason, + Remark = request.Remark, }; - await _dbContext.InsertAsync(detail); + var enterDoorAreaIdNos = request.Items.Where(x => x.IsEnterDoorArea).Select(x => x.IdNo).Distinct().ToList(); + var errors = await _dbContext.Queryable() + .Where(x => enterDoorAreaIdNos.Contains(x.IdNo) || enterDoorAreaIdNos.Contains(x.Code)) + .Where(x => invalids.Contains(x.Type)) + .Select(x => x.IdNo + x.Name) + .ToListAsync(); + + errors.ThrowIfExists($"内部人员无法发起门岗预约({errors.Join(",")})"); + + await _dbContext.InsertAsync(mst); + //var idNos = request.Items.Select(x => x.IdNo).Distinct().ToList(); + //var outsources = await _dbContext.Queryable() + // .Where(x => idNos.Contains(x.IdNo) || idNos.Contains(x.Code)) + // .Where(x => x.Type == GainfoUserTypeEnumType.Outsource) + // .Select(x => x.IdNo + x.Name) + // .ToListAsync(); + + //outsources.ThrowIfExists($"存在外包人员申请,请检查一下人员:{outsources.Join(",")}"); + + foreach (var item in request.Items) + { + item.IdNo = item.IdNo.Trim(); + + if (item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door) + .Select(x => x.CustomCode) + .Contains(item.ApplyDoorArea) == false) + { + throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效"); + } + + if (item.IsEnterWorkplace && + item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace) + .Select(x => x.CustomCode) + .Contains(p)) == false) + { + var workplaceAreas = areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace).Select(x => x.CustomCode); + var notExistsAreas = item.ApplyWorkplaceAreas.Where(x => !workplaceAreas.Contains(x)); + throw new UserFriendlyException($"车间区域{notExistsAreas.Join(",")}无效"); + } + + var gainfo = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo || x.Code == item.IdNo).SingleAsync(); + //外部人员 + if (gainfo == null) + { + gainfo = new GainfoEntity + { + No = Guid.NewGuid().ToString(), + Code = await GetNextExternalCodeAsync(), + Gender = GetGender(item.IdNo), + Type = GainfoUserTypeEnumType.External, + IdNo = item.IdNo, + Name = item.Name, + Source = request.Source, + Phone = item.Phone, + Factory = request.Factory + }; + await _dbContext.InsertAsync(gainfo); + } + else + { + (invalids.Contains(gainfo.Type) && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约"); + if (gainfo.Type == GainfoUserTypeEnumType.External) + { + gainfo.Source = request.Source; + gainfo.Phone = item.Phone; + gainfo.Factory = request.Factory; + + await _dbContext.UpdateAsync(gainfo); + } + //else if (gainfo.Type == GainfoUserTypeEnumType.Outsource) + //{ + // throw new UserFriendlyException($"访客类型有误!,请检查{gainfo.Name},{gainfo.IdNo}"); + //} + } + + var detail = new VisitorAppointmentDetailEntity + { + UserNo = gainfo.No, + No = request.No, + IdType = item.IdType, + IdNo = item.IdNo, + Name = item.Name, + Phone = item.Phone, + Remark = item.Remark, + DoorStatus = item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door) + .Select(x => x.CustomCode) + .Contains(item.ApplyDoorArea) + ? VisitorAppointmentDetailStatusEnumType.Wait + : VisitorAppointmentDetailStatusEnumType.Obsolete, + LicensePlate = item.LicensePlate, + IsEnterDoorArea = item.IsEnterDoorArea, + 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.CustomCode) + .Contains(p)) + ? VisitorAppointmentDetailStatusEnumType.Wait + : VisitorAppointmentDetailStatusEnumType.Obsolete, + ApplyWorkplaceAreas = item.ApplyWorkplaceAreas, + WorkplaceStart = item.WorkplaceStart, + WorkplaceEnd = item.WorkplaceEnd, + ImageUrl = item.ImageUrl + }; + + await _dbContext.InsertAsync(detail); + } } }