fix 调整访客预约
This commit is contained in:
@@ -14,17 +14,23 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "父id")]
|
||||
public long AppointmentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// no
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "用户no")]
|
||||
public string UserNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流水号
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "流水号")]
|
||||
public string FlowId { get; set; }
|
||||
public string No { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否外部人员
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit")]
|
||||
public bool IsExternal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// no
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "用户No")]
|
||||
public string UserNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 访客名称
|
||||
@@ -38,11 +44,6 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "手机号")]
|
||||
public string Phone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否外部人员
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit")]
|
||||
public bool IsExternal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 身份证
|
||||
@@ -54,16 +55,10 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity
|
||||
public string IdNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 预计到达
|
||||
/// 车牌
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "预计到达")]
|
||||
public DateTime Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 预计离开
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "预计离开")]
|
||||
public DateTime End { get; set; }
|
||||
[SugarColumn(ColumnDescription = "车牌")]
|
||||
public string LicensePlate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
@@ -74,6 +69,12 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true, ColumnDescription = "备注")]
|
||||
[SugarColumn(ColumnDescription = "备注")]
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 社保照片url
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "社保照片url")]
|
||||
public string ImageUrl { get; set; }
|
||||
}
|
||||
@@ -3,28 +3,70 @@ using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Visitor.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 访客预约
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "VisitorAppointment", TableDescription = "访客预约")]
|
||||
public class VisitorAppointmentEntity : SugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 流水号
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对接人工号
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string DepartmentNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来访人公司
|
||||
/// </summary>
|
||||
public string Company { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请时间
|
||||
/// </summary>
|
||||
public DateTime ApplyTime { get; set; }
|
||||
|
||||
public string AreaCustomCode { get; set; }
|
||||
/// <summary>
|
||||
/// 预约区域
|
||||
/// </summary>
|
||||
public string ApplyArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 预约厂区
|
||||
/// </summary>
|
||||
public string Factory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请事由
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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) });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Dlhis.External.Appointment.Request;
|
||||
|
||||
namespace Dlhis.External.Appointment.Services;
|
||||
|
||||
public interface IAppointmentService : IScopeDependency
|
||||
{
|
||||
Task ReceiveAsync(AppointmentReceiveRequest request);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -24,20 +24,6 @@ public class AppointmentsController : ControllerBase
|
||||
_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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预约申请分页
|
||||
/// </summary>
|
||||
|
||||
@@ -7,8 +7,6 @@ namespace Dlhis.Visitor.Appointment.Services;
|
||||
|
||||
public interface IAppointmentService : IScopeDependency
|
||||
{
|
||||
Task ReceiveAsync(AppointmentReceiveRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 预约分页
|
||||
/// </summary>
|
||||
|
||||
@@ -64,7 +64,7 @@ public class AppointmentAreaService : IAppointmentAreaService
|
||||
public async Task AssignAsync(AppointmentAreaAssignRequest request)
|
||||
{
|
||||
var userNos = await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.LeftJoin<VisitorAppointmentEntity>((x, y) => x.FlowId == y.FlowId)
|
||||
.LeftJoin<VisitorAppointmentEntity>((x, y) => x.No == y.No)
|
||||
.Where(x => x.Status == AppointmentDetailEnumType.Arrived)
|
||||
.Where((x, y) => y.AreaCustomCode == request.CustomCode)
|
||||
.Select(x => x.UserNo)
|
||||
|
||||
@@ -27,89 +27,6 @@ public class AppointmentService : IAppointmentService
|
||||
_dataProtectionProvider = dataProtectionProvider;
|
||||
}
|
||||
|
||||
public async Task ReceiveAsync(AppointmentReceiveRequest request)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<VisitorAppointmentEntity>().Where(x => x.FlowId == request.FlowId).AnyAsync();
|
||||
exists.ThrowIfTrue("已经存在申请");
|
||||
|
||||
var area = await _dbContext.Queryable<AppointmentAreaEntity>()
|
||||
.Where(x => x.Name == request.ApplyArea)
|
||||
.Where(x => x.TenantId == request.Factory)
|
||||
.FirstAsync();
|
||||
area.ThrowIfNull("预约区域不存在");
|
||||
|
||||
var where = LinqExpressionExtensions.False<VisitorAppointmentDetailEntity>();
|
||||
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<VisitorAppointmentDetailEntity>()
|
||||
.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<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,
|
||||
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<Pagination<AppointmentPageResponse>> GetPageAsync(AppointmentPageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<VisitorAppointmentEntity>()
|
||||
|
||||
Reference in New Issue
Block a user