feat 增加券导入,获取设备数据权限的人员
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Basic.Api.Requests;
|
||||
using Dlhis.Entity.Visitor.Entity;
|
||||
using Dlhis.Entity.Visitor.Enums;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs.Visitor;
|
||||
|
||||
/// <summary>
|
||||
/// 每天10点提醒访客预约到期
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(TipAppointmentExpireJob), "0 0 10 * * ?", Name = "提醒到访人访客将要到期", RunOnDevelopment = true)]
|
||||
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();
|
||||
|
||||
var name = item.Select(x => x.Name).Join(",");
|
||||
|
||||
await _dingTalkApi.SendWorkMessageAsync(new JinkoSendWorkMessageRequest
|
||||
{
|
||||
WorkCodes = new List<string> { appointment.Code },
|
||||
Content = $"您的访客预约 {appointment.No}《{appointment.Title}》中有 {name} 即将到达访问结束时间,请及时处理。"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsWarningData(VisitorAppointmentDetailEntity detail)
|
||||
{
|
||||
if (detail.IsEnterDoorArea
|
||||
&& detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived
|
||||
&& detail.DoorEnd.Value.Date.AddDays(-3) == DateTime.Today)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (detail.IsEnterWorkplace
|
||||
&& detail.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived
|
||||
&& detail.WorkplaceEnd.Value.Date.AddDays(-3) == DateTime.Today)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user