fix 调整访客预约

This commit is contained in:
2024-08-16 21:48:14 +08:00
parent eed8fd5752
commit c15e545b6d
12 changed files with 353 additions and 133 deletions

View File

@@ -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;
/// <summary>
/// 预约
/// </summary>
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class AppointmentsController : ControllerBase
{
private readonly IAppointmentService _appointmentService;
public AppointmentsController(IAppointmentService appointmentService)
{
_appointmentService = appointmentService;
}
/// <summary>
/// 接受预约申请
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[AllowAnonymous]
[Transactional]
[IgnoreTenant]
[HttpPost("receive")]
public async Task ReceiveAsync(AppointmentReceiveRequest request)
{
await _appointmentService.ReceiveAsync(request);
}
}

View File

@@ -0,0 +1,41 @@
using System.ComponentModel.DataAnnotations;
namespace Dlhis.External.Appointment.Dto;
public class AppointmentReceiveItemDto
{
/// <summary>
/// 姓名
/// </summary>
[Required(ErrorMessage = "姓名必填")]
public string Name { get; set; }
/// <summary>
/// 手机号
/// </summary>
[StringLength(11, MinimumLength = 11)]
[Required(ErrorMessage = "手机号必填")]
public string Phone { get; set; }
/// <summary>
/// 身份证
/// </summary>
[StringLength(18, MinimumLength = 18)]
[Required(ErrorMessage = "身份证必填")]
public string IdNo { get; set; }
/// <summary>
/// 车牌
/// </summary>
public string LicensePlate { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 社保照片
/// </summary>
public string ImageUrl { get; set; }
}

View File

@@ -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
{
/// <summary>
/// 流水号
/// </summary>
[Required(ErrorMessage = "流水号必填")]
public string No { get; set; }
/// <summary>
/// 标题
/// </summary>
[Required(ErrorMessage = "标题必填")]
public string Title { get; set; }
/// <summary>
/// 对接人工号
/// </summary>
[Required(ErrorMessage = "对接人工号必填")]
public string Code { get; set; }
/// <summary>
/// 预约区域
/// </summary>
[Required(ErrorMessage = "申请预约区域必填")]
public string ApplyArea { get; set; }
/// <summary>
/// 来访人公司
/// </summary>
[Required(ErrorMessage = "来源公司不可为空")]
public string Company { get; set; }
/// <summary>
/// 申请时间
/// </summary>
public DateTime ApplyTime { get; set; }
/// <summary>
/// 预约厂区
/// </summary>
[Required(ErrorMessage = "厂区不可为空")]
public string Factory { get; set; }
/// <summary>
/// 申请事由
/// </summary>
[Required(ErrorMessage = "申请事由不能为空")]
public string Reason { get; set; }
/// <summary>
/// 访客开始
/// </summary>
public DateTime Start { get; set; }
/// <summary>
/// 访问结束
/// </summary>
public DateTime End { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 是否进入车间
/// </summary>
public bool IsEnterWorkplace { get; set; }
/// <summary>
/// 明细
/// </summary>
[MinLength(1, ErrorMessage = "明细必填")]
public List<AppointmentReceiveItemDto> Items { get; set; }
public IEnumerable<ValidationResult> 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) });
}
}
}

View File

@@ -0,0 +1,8 @@
using Dlhis.External.Appointment.Request;
namespace Dlhis.External.Appointment.Services;
public interface IAppointmentService : IScopeDependency
{
Task ReceiveAsync(AppointmentReceiveRequest request);
}

View File

@@ -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<VisitorAppointmentEntity>().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<GainfoEntity>().Where(x => x.IdNo == item.IdNo).Select(x => x.No).SingleAsync();
var isExternal = no.IsEmpty();
if (isExternal)
{
var gainfoExternal = await _dbContext.Queryable<GainfoExternalEntity>().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);
}
}
}

View File

@@ -8,6 +8,10 @@
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\Dlhis.External.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
</ItemGroup>