feat 生日券功能,自动上传消费数据,提醒访客到期
This commit is contained in:
77
Src/Dlhis.ScheduledTask/Jobs/TipAppointmentExpireJob.cs
Normal file
77
Src/Dlhis.ScheduledTask/Jobs/TipAppointmentExpireJob.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Basic.Api.Requests;
|
||||
using Dlhis.Entity.Visitor.Entity;
|
||||
using Dlhis.Entity.Visitor.Enums;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 每天10点提醒访客预约到期
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(TipAppointmentExpireJob), "0 0 10 * * ?", Name = "提醒到访人访客将要到期")]
|
||||
public class TipAppointmentExpireJob : BaseJob
|
||||
{
|
||||
private readonly IDingTalkApi _dingTalkApi;
|
||||
|
||||
public TipAppointmentExpireJob(IServiceProvider serviceProvider, IDingTalkApi dingTalkApi) : base(serviceProvider)
|
||||
{
|
||||
_dingTalkApi = dingTalkApi;
|
||||
}
|
||||
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var details = await DbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived) ||
|
||||
(x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived))
|
||||
.ToListAsync();
|
||||
|
||||
var warningDetails = new List<VisitorAppointmentDetailEntity>();
|
||||
foreach (var detail in details)
|
||||
{
|
||||
if (IsWarningData(detail))
|
||||
{
|
||||
warningDetails.Add(detail);
|
||||
}
|
||||
}
|
||||
|
||||
if (warningDetails.Any())
|
||||
{
|
||||
foreach (var item in warningDetails.GroupBy(x => x.No))
|
||||
{
|
||||
var appointment = await DbContext.Queryable<VisitorAppointmentEntity>()
|
||||
.Where(x => x.No == item.Key)
|
||||
.SingleAsync();
|
||||
|
||||
await _dingTalkApi.SendWorkMessageAsync(new JinkoSendWorkMessageRequest
|
||||
{
|
||||
WorkCodes = new List<string> { appointment.Code },
|
||||
Content = $"您的访客预约 {appointment.No}《{appointment.Title}》中有访客即将到达访问结束时间,请及时处理。"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsWarningData(VisitorAppointmentDetailEntity detail)
|
||||
{
|
||||
var now = DateTime.Now.Date.AddDays(-3);
|
||||
if (detail.IsEnterDoorArea
|
||||
&& detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived
|
||||
&& detail.DoorEnd.Value.Date == now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (detail.IsEnterWorkplace
|
||||
&& detail.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived
|
||||
&& detail.WorkplaceEnd.Value.Date <= now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user