diff --git a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs index 5ade578a..a253aeb8 100644 --- a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs +++ b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs @@ -14,17 +14,23 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity [SugarColumn(IsNullable = false, ColumnDescription = "父id")] public long AppointmentId { get; set; } - /// - /// no - /// - [SugarColumn(IsNullable = false, ColumnDescription = "用户no")] - public string UserNo { get; set; } - /// /// 流水号 /// [SugarColumn(IsNullable = false, ColumnDescription = "流水号")] - public string FlowId { get; set; } + public string No { get; set; } + + /// + /// 是否外部人员 + /// + [SugarColumn(IsNullable = false, ColumnDataType = "bit")] + public bool IsExternal { get; set; } + + /// + /// no + /// + [SugarColumn(IsNullable = false, ColumnDescription = "用户No")] + public string UserNo { get; set; } /// /// 访客名称 @@ -38,11 +44,6 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity [SugarColumn(IsNullable = false, ColumnDescription = "手机号")] public string Phone { get; set; } - /// - /// 是否外部人员 - /// - [SugarColumn(IsNullable = false, ColumnDataType = "bit")] - public bool IsExternal { get; set; } /// /// 身份证 @@ -54,16 +55,10 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity public string IdNo { get; set; } /// - /// 预计到达 + /// 车牌 /// - [SugarColumn(IsNullable = false, ColumnDescription = "预计到达")] - public DateTime Start { get; set; } - - /// - /// 预计离开 - /// - [SugarColumn(IsNullable = false, ColumnDescription = "预计离开")] - public DateTime End { get; set; } + [SugarColumn(ColumnDescription = "车牌")] + public string LicensePlate { get; set; } /// /// 状态 @@ -74,6 +69,12 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity /// /// 备注 /// - [SugarColumn(IsNullable = true, ColumnDescription = "备注")] + [SugarColumn(ColumnDescription = "备注")] public string Remark { get; set; } + + /// + /// 社保照片url + /// + [SugarColumn(ColumnDescription = "社保照片url")] + public string ImageUrl { 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 b895f0e5..5a54b39f 100644 --- a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentEntity.cs +++ b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentEntity.cs @@ -3,28 +3,70 @@ using SqlSugar; namespace Dlhis.Entity.Visitor.Entity; +/// +/// 访客预约 +/// [SugarTable(TableName = "VisitorAppointment", TableDescription = "访客预约")] public class VisitorAppointmentEntity : SugarBaseEntity { /// /// 流水号 /// - [SugarColumn(IsNullable = false, ColumnDescription = "流水号", UniqueGroupNameList = new[] { "idx_VisitorAppointment_FlowId" })] - public string FlowId { get; set; } + [SugarColumn(IsNullable = false, ColumnDescription = "流水号", UniqueGroupNameList = new[] { "idx_VisitorAppointment_no " })] + public string No { get; set; } + /// + /// 标题 + /// public string Title { get; set; } + /// + /// 对接人工号 + /// public string Code { get; set; } - public string Name { get; set; } - - public string Description { get; set; } - - public string DepartmentNo { get; set; } - + /// + /// 来访人公司 + /// public string Company { get; set; } + /// + /// 申请时间 + /// public DateTime ApplyTime { get; set; } - public string AreaCustomCode { get; set; } -} + /// + /// 预约区域 + /// + public string ApplyArea { get; set; } + + /// + /// 预约厂区 + /// + public string Factory { get; set; } + + /// + /// 申请事由 + /// + public string Reason { get; set; } + + /// + /// 访客开始 + /// + public DateTime Start { get; set; } + + /// + /// 访问结束 + /// + public DateTime End { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 是否进入车间 + /// + public bool IsEnterWorkplace { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.External/Appointment/Controllers/AppointmentsController.cs b/Src/Dlhis.External/Appointment/Controllers/AppointmentsController.cs new file mode 100644 index 00000000..5f0e57ed --- /dev/null +++ b/Src/Dlhis.External/Appointment/Controllers/AppointmentsController.cs @@ -0,0 +1,37 @@ +using Dlhis.External.Appointment.Request; +using Dlhis.External.Appointment.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.External.Appointment.Controllers; + +/// +/// 预约 +/// +[Authorize] +[ApiController] +[Route("api/[controller]")] +public class AppointmentsController : ControllerBase +{ + private readonly IAppointmentService _appointmentService; + + public AppointmentsController(IAppointmentService appointmentService) + { + _appointmentService = appointmentService; + } + + /// + /// 接受预约申请 + /// + /// + /// + [AllowAnonymous] + [Transactional] + [IgnoreTenant] + [HttpPost("receive")] + public async Task ReceiveAsync(AppointmentReceiveRequest request) + { + await _appointmentService.ReceiveAsync(request); + } +} diff --git a/Src/Dlhis.External/Appointment/Dto/AppointmentReceiveItemDto.cs b/Src/Dlhis.External/Appointment/Dto/AppointmentReceiveItemDto.cs new file mode 100644 index 00000000..e1aab234 --- /dev/null +++ b/Src/Dlhis.External/Appointment/Dto/AppointmentReceiveItemDto.cs @@ -0,0 +1,41 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.External.Appointment.Dto; + +public class AppointmentReceiveItemDto +{ + /// + /// 姓名 + /// + [Required(ErrorMessage = "姓名必填")] + public string Name { get; set; } + + /// + /// 手机号 + /// + [StringLength(11, MinimumLength = 11)] + [Required(ErrorMessage = "手机号必填")] + public string Phone { get; set; } + + /// + /// 身份证 + /// + [StringLength(18, MinimumLength = 18)] + [Required(ErrorMessage = "身份证必填")] + public string IdNo { get; set; } + + /// + /// 车牌 + /// + public string LicensePlate { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 社保照片 + /// + public string ImageUrl { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.External/Appointment/Request/AppointmentReceiveRequest.cs b/Src/Dlhis.External/Appointment/Request/AppointmentReceiveRequest.cs new file mode 100644 index 00000000..60a50aab --- /dev/null +++ b/Src/Dlhis.External/Appointment/Request/AppointmentReceiveRequest.cs @@ -0,0 +1,98 @@ +using System.ComponentModel.DataAnnotations; +using Dlhis.External.Appointment.Dto; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.External.Appointment.Request; + +public class AppointmentReceiveRequest : IValidatableObject +{ + /// + /// 流水号 + /// + [Required(ErrorMessage = "流水号必填")] + public string No { get; set; } + + /// + /// 标题 + /// + [Required(ErrorMessage = "标题必填")] + public string Title { get; set; } + + /// + /// 对接人工号 + /// + [Required(ErrorMessage = "对接人工号必填")] + public string Code { get; set; } + + /// + /// 预约区域 + /// + [Required(ErrorMessage = "申请预约区域必填")] + public string ApplyArea { get; set; } + + /// + /// 来访人公司 + /// + [Required(ErrorMessage = "来源公司不可为空")] + public string Company { get; set; } + + /// + /// 申请时间 + /// + public DateTime ApplyTime { get; set; } + + /// + /// 预约厂区 + /// + [Required(ErrorMessage = "厂区不可为空")] + public string Factory { get; set; } + + /// + /// 申请事由 + /// + [Required(ErrorMessage = "申请事由不能为空")] + public string Reason { get; set; } + + /// + /// 访客开始 + /// + public DateTime Start { get; set; } + + /// + /// 访问结束 + /// + public DateTime End { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 是否进入车间 + /// + public bool IsEnterWorkplace { get; set; } + + /// + /// 明细 + /// + [MinLength(1, ErrorMessage = "明细必填")] + public List Items { get; set; } + + + public IEnumerable Validate(ValidationContext validationContext) + { + if (IsEnterWorkplace) + { + if (Items.Any(x => x.ImageUrl.IsEmpty())) + { + yield return new ValidationResult("社保照片不可为空", new[] { "ImageUrl" }); + } + } + + if (Start >= End) + { + yield return new ValidationResult("来访时间不能大于等于离开时间", new[] { nameof(Start), nameof(End) }); + } + } +} \ No newline at end of file diff --git a/Src/Dlhis.External/Appointment/Services/IAppointmentService.cs b/Src/Dlhis.External/Appointment/Services/IAppointmentService.cs new file mode 100644 index 00000000..1a730865 --- /dev/null +++ b/Src/Dlhis.External/Appointment/Services/IAppointmentService.cs @@ -0,0 +1,8 @@ +using Dlhis.External.Appointment.Request; + +namespace Dlhis.External.Appointment.Services; + +public interface IAppointmentService : IScopeDependency +{ + Task ReceiveAsync(AppointmentReceiveRequest request); +} \ 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 new file mode 100644 index 00000000..68e00939 --- /dev/null +++ b/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs @@ -0,0 +1,88 @@ +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Visitor.Entity; +using Dlhis.Entity.Visitor.Enums; +using Dlhis.External.Appointment.Request; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.External.Appointment.Services.Implements; + +public class AppointmentService : IAppointmentService +{ + private readonly IDbContext _dbContext; + + public AppointmentService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task ReceiveAsync(AppointmentReceiveRequest request) + { + var exists = await _dbContext.Queryable().Where(x => x.No == request.No).AnyAsync(); + exists.ThrowIfTrue("已经存在申请"); + + var id = await _dbContext.InsertReturnIdentityAsync(new VisitorAppointmentEntity + { + No = request.No, + Title = request.Title, + Code = request.Code, + Company = request.Company, + ApplyTime = request.ApplyTime, + ApplyArea = request.ApplyArea, + Factory = request.Factory, + Reason = request.Reason, + Start = request.Start, + End = request.End, + Remark = request.Remark, + IsEnterWorkplace = request.IsEnterWorkplace + }); + + foreach (var item in request.Items) + { + var no = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo).Select(x => x.No).SingleAsync(); + var isExternal = no.IsEmpty(); + if (isExternal) + { + var gainfoExternal = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo).FirstAsync(); + if (gainfoExternal == null) + { + gainfoExternal = new GainfoExternalEntity + { + No = Guid.NewGuid().ToString(), + Code = item.IdNo, + IdNo = item.IdNo, + Name = item.Name, + Company = request.Company, + Phone = item.Phone + }; + await _dbContext.InsertAsync(gainfoExternal); + } + else + { + gainfoExternal.Phone = item.Phone; + gainfoExternal.Company = request.Company; + + await _dbContext.UpdateAsync(gainfoExternal); + } + + no = gainfoExternal.No; + } + + var detail = new VisitorAppointmentDetailEntity + { + UserNo = no, + AppointmentId = id, + No = request.No, + IdNo = item.IdNo, + Name = item.Name, + Phone = item.Phone, + Remark = item.Remark, + Status = AppointmentDetailEnumType.Wait, + IsExternal = isExternal, + LicensePlate = item.LicensePlate + }; + + await _dbContext.InsertAsync(detail); + } + } +} \ No newline at end of file diff --git a/Src/Dlhis.External/Dlhis.External.csproj b/Src/Dlhis.External/Dlhis.External.csproj index 772581d6..67473bd6 100644 --- a/Src/Dlhis.External/Dlhis.External.csproj +++ b/Src/Dlhis.External/Dlhis.External.csproj @@ -8,6 +8,10 @@ ..\.. + + bin\Debug\Dlhis.External.xml + + diff --git a/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs b/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs index 90678864..b8d63ac1 100644 --- a/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs +++ b/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs @@ -23,21 +23,7 @@ public class AppointmentsController : ControllerBase { _appointmentService = appointmentService; } - - /// - /// 接受预约申请 - /// - /// - /// - [AllowAnonymous] - [Transactional] - [IgnoreTenant] - [HttpPost("receive")] - public async Task ReceiveAsync(AppointmentReceiveRequest request) - { - await _appointmentService.ReceiveAsync(request); - } - + /// /// 预约申请分页 /// diff --git a/Src/Dlhis.Visitor/Appointment/Services/IAppointmentService.cs b/Src/Dlhis.Visitor/Appointment/Services/IAppointmentService.cs index 1b0b83f7..e601d02f 100644 --- a/Src/Dlhis.Visitor/Appointment/Services/IAppointmentService.cs +++ b/Src/Dlhis.Visitor/Appointment/Services/IAppointmentService.cs @@ -7,8 +7,6 @@ namespace Dlhis.Visitor.Appointment.Services; public interface IAppointmentService : IScopeDependency { - Task ReceiveAsync(AppointmentReceiveRequest request); - /// /// 预约分页 /// diff --git a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs index 599726d3..467a11eb 100644 --- a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs +++ b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs @@ -64,7 +64,7 @@ public class AppointmentAreaService : IAppointmentAreaService public async Task AssignAsync(AppointmentAreaAssignRequest request) { var userNos = await _dbContext.Queryable() - .LeftJoin((x, y) => x.FlowId == y.FlowId) + .LeftJoin((x, y) => x.No == y.No) .Where(x => x.Status == AppointmentDetailEnumType.Arrived) .Where((x, y) => y.AreaCustomCode == request.CustomCode) .Select(x => x.UserNo) diff --git a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs index 8e00af9c..345fcba3 100644 --- a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs @@ -27,89 +27,6 @@ public class AppointmentService : IAppointmentService _dataProtectionProvider = dataProtectionProvider; } - public async Task ReceiveAsync(AppointmentReceiveRequest request) - { - var exists = await _dbContext.Queryable().Where(x => x.FlowId == request.FlowId).AnyAsync(); - exists.ThrowIfTrue("已经存在申请"); - - var area = await _dbContext.Queryable() - .Where(x => x.Name == request.ApplyArea) - .Where(x => x.TenantId == request.Factory) - .FirstAsync(); - area.ThrowIfNull("预约区域不存在"); - - var where = LinqExpressionExtensions.False(); - request.Items.ForEach(item => { where = where.Or(x => !(x.End < request.Start || x.Start > request.End)).And(x => x.IdNo == item.IdNo); }); - - var existsDetails = await _dbContext.Queryable() - .Where(where) - .Where(x => x.Status == AppointmentDetailEnumType.Wait || x.Status == AppointmentDetailEnumType.Arrived) - .ToListAsync(); - - existsDetails.ThrowIfExists($"{existsDetails.Select(x => x.Name).Join(",")}存在预约时间冲突,请检查"); - - var id = await _dbContext.InsertReturnIdentityAsync(new VisitorAppointmentEntity - { - FlowId = request.FlowId, - Name = request.Name, - Code = request.Code, - Description = request.Description, - Title = request.Title, - Company = request.Company, - ApplyTime = request.ApplyTime, - AreaCustomCode = area.CustomCode, - }); - - foreach (var item in request.Items) - { - var no = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo).Select(x => x.No).SingleAsync(); - var isExternal = no.IsEmpty(); - if (isExternal) - { - var gainfoExternal = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo).FirstAsync(); - if (gainfoExternal == null) - { - gainfoExternal = new GainfoExternalEntity - { - No = Guid.NewGuid().ToString(), - Code = item.IdNo, - IdNo = item.IdNo, - Name = item.Name, - Company = request.Company, - Phone = item.Phone - }; - await _dbContext.InsertAsync(gainfoExternal); - } - else - { - gainfoExternal.Phone = item.Phone; - gainfoExternal.Company = request.Company; - - await _dbContext.UpdateAsync(gainfoExternal); - } - - no = gainfoExternal.No; - } - - var detail = new VisitorAppointmentDetailEntity - { - UserNo = no, - AppointmentId = id, - FlowId = request.FlowId, - Start = request.Start, - End = request.End, - IdNo = item.IdNo, - Name = item.Name, - Phone = item.Phone, - Remark = item.Remark, - Status = AppointmentDetailEnumType.Wait, - IsExternal = isExternal, - }; - - await _dbContext.InsertAsync(detail); - } - } - public async Task> GetPageAsync(AppointmentPageRequest request) { return await _dbContext.Queryable()