fix 访客预约自动化处理
This commit is contained in:
@@ -85,12 +85,15 @@ public class AppointmentService : IAppointmentService
|
||||
var detail = await _dbContext.Queryable<VisitorAppointmentDetailEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
detail.ThrowIfNull("预约信息不存在");
|
||||
|
||||
detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived;
|
||||
detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Arrived;
|
||||
detail.ArrivedTime = DateTime.Now;
|
||||
|
||||
await _dbContext.UpdateAsync(detail);
|
||||
await GenerateTaskAndUpdateFaceAsync(detail.Id, request.Base64Image, DeviceTaskEnumType.Add);
|
||||
|
||||
if (detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait)
|
||||
{
|
||||
detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived;
|
||||
}
|
||||
|
||||
detail.ArrivedTime = DateTime.Now;
|
||||
await _dbContext.UpdateAsync(detail);
|
||||
}
|
||||
|
||||
public async Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType)
|
||||
@@ -120,7 +123,7 @@ public class AppointmentService : IAppointmentService
|
||||
Priority = 100,
|
||||
TenantId = x.TenantId,
|
||||
Source = DeviceTaskSourceEnumType.Appointment,
|
||||
Version = 0,
|
||||
Version = 0
|
||||
}).ToList());
|
||||
|
||||
await _gainfoFaceService.UploadExternalFaceAsync(new GainfoUploadFaceRequest
|
||||
@@ -137,14 +140,6 @@ public class AppointmentService : IAppointmentService
|
||||
{
|
||||
yield return detail.ApplyDoorArea;
|
||||
}
|
||||
|
||||
if (detail.IsEnterWorkplace)
|
||||
{
|
||||
foreach (var item in detail.ApplyWorkplaceAreas)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -61,24 +61,25 @@ public class AppointmentService : IAppointmentService
|
||||
IdNo = item.IdNo,
|
||||
Name = item.Name,
|
||||
Source = request.Source,
|
||||
Phone = item.Phone
|
||||
Phone = item.Phone,
|
||||
Factory = mst.Factory
|
||||
};
|
||||
await _dbContext.InsertAsync(gainfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
(gainfo.Type != GainfoUserTypeEnumType.External && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约");
|
||||
|
||||
if (gainfo.Type == GainfoUserTypeEnumType.External)
|
||||
{
|
||||
gainfo.Source = request.Source;
|
||||
gainfo.Phone = item.Phone;
|
||||
gainfo.Factory = mst.Factory;
|
||||
|
||||
await _dbContext.UpdateAsync(gainfo);
|
||||
}
|
||||
}
|
||||
|
||||
//todo
|
||||
//(gainfo.Type == GainfoUserTypeEnumType.External && item.IsEnterWorkplace && item.ImageUrl.IsEmpty()).ThrowIfTrue($"{item.Name}的社保照片不可为空");
|
||||
|
||||
var detail = new VisitorAppointmentDetailEntity
|
||||
{
|
||||
UserNo = gainfo.No,
|
||||
|
||||
82
Src/Dlhis.ScheduledTask/Jobs/AutoConfirmAppointmentJob.cs
Normal file
82
Src/Dlhis.ScheduledTask/Jobs/AutoConfirmAppointmentJob.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Visitor.Entity;
|
||||
using Dlhis.Entity.Visitor.Enums;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 访客预约移除
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(AutoConfirmAppointmentJob), "0 0/5 * * * ?", Name = "访客预约自动处理车间")]
|
||||
public class AutoConfirmAppointmentJob : BaseJob
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public AutoConfirmAppointmentJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var details = await DbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.Where(x => x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait || x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Wait)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var detail in details)
|
||||
{
|
||||
var gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.No == detail.No).SingleAsync();
|
||||
var isExternal = gainfo.Type == GainfoUserTypeEnumType.External;
|
||||
|
||||
var areaCodes = GetValidAreaCodes(isExternal, detail);
|
||||
var existsAreaCodes = await DbContext.Queryable<AppointmentAreaEntity>().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync();
|
||||
|
||||
//当前分配的设备组code
|
||||
var deviceGroupCodes = await DbContext.Queryable<AppointmentAreaAssignmentEntity>()
|
||||
.Where(x => existsAreaCodes.Contains(x.CustomCode))
|
||||
.Select(x => x.DeviceGroupCode)
|
||||
.ToListAsync();
|
||||
|
||||
var deviceCodes = await DbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync();
|
||||
var deviceUniqueNos = await DbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).Select(x => new { x.UniqueNo, x.TenantId }).ToListAsync();
|
||||
|
||||
await DbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity
|
||||
{
|
||||
DeviceType = DeviceTypeEnumType.Door,
|
||||
DeviceUniqueNo = x.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
UserNo = detail.UserNo,
|
||||
Type = DeviceTaskEnumType.Add,
|
||||
Priority = 100,
|
||||
TenantId = x.TenantId,
|
||||
Source = DeviceTaskSourceEnumType.Appointment,
|
||||
Version = 0
|
||||
}).ToList());
|
||||
|
||||
|
||||
if (detail.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived)
|
||||
{
|
||||
detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Leave;
|
||||
}
|
||||
|
||||
await DbContext.UpdateAsync(detail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<string> GetValidAreaCodes(bool isExternal, VisitorAppointmentDetailEntity detail)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
if (detail.IsEnterWorkplace && detail.WorkplaceEnd >= now)
|
||||
{
|
||||
foreach (var item in detail.ApplyWorkplaceAreas)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs
Normal file
87
Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Visitor.Entity;
|
||||
using Dlhis.Entity.Visitor.Enums;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 访客预约移除
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(AutoRemoveAppointmentJob), "0 0/5 * * * ?", Name = "访客预约移除")]
|
||||
public class AutoRemoveAppointmentJob : BaseJob
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public AutoRemoveAppointmentJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var details = await DbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.Where(x => x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived || x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var detail in details)
|
||||
{
|
||||
var areaCodes = GetValidAreaCodes(detail);
|
||||
var existsAreaCodes = await DbContext.Queryable<AppointmentAreaEntity>().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync();
|
||||
|
||||
//当前分配的设备组code
|
||||
var deviceGroupCodes = await DbContext.Queryable<AppointmentAreaAssignmentEntity>()
|
||||
.Where(x => existsAreaCodes.Contains(x.CustomCode))
|
||||
.Select(x => x.DeviceGroupCode)
|
||||
.ToListAsync();
|
||||
|
||||
var deviceCodes = await DbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync();
|
||||
var deviceUniqueNos = await DbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).Select(x => new { x.UniqueNo, x.TenantId }).ToListAsync();
|
||||
|
||||
await DbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity
|
||||
{
|
||||
DeviceType = DeviceTypeEnumType.Door,
|
||||
DeviceUniqueNo = x.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
UserNo = detail.UserNo,
|
||||
Type = DeviceTaskEnumType.Delete,
|
||||
Priority = 100,
|
||||
TenantId = x.TenantId,
|
||||
Source = DeviceTaskSourceEnumType.Appointment,
|
||||
Version = 0
|
||||
}).ToList());
|
||||
|
||||
if (detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived)
|
||||
{
|
||||
detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Leave;
|
||||
}
|
||||
|
||||
if (detail.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived)
|
||||
{
|
||||
detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Leave;
|
||||
}
|
||||
|
||||
await DbContext.UpdateAsync(detail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<string> GetValidAreaCodes(VisitorAppointmentDetailEntity detail)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
if (detail.IsEnterDoorArea && detail.DoorEnd >= now)
|
||||
{
|
||||
yield return detail.ApplyDoorArea;
|
||||
}
|
||||
|
||||
if (detail.IsEnterWorkplace && detail.WorkplaceEnd >= now)
|
||||
{
|
||||
foreach (var item in detail.ApplyWorkplaceAreas)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user