This commit is contained in:
2022-03-08 19:13:58 +00:00
parent df2997e433
commit 6b988f1732
2 changed files with 108 additions and 1 deletions

View File

@@ -223,6 +223,14 @@ namespace AyaNova.Biz
await ct.SaveChangesAsync();
}
public static async Task ClearPriorCustomerNotifyEventsForObject(AyContext ct, AyaType ayaType, long objectId, NotifyEventType eventType)
{
var eventsToDelete = await ct.CustomerNotifyEvent.Where(z => z.AyaType == ayaType && z.ObjectId == objectId && z.EventType == eventType).ToListAsync();
if (eventsToDelete.Count == 0) return;
ct.CustomerNotifyEvent.RemoveRange(eventsToDelete);
await ct.SaveChangesAsync();
}
//scorched earth one for outright delete of objects when you don't want any prior events left for it
//probably only ever used for the delete event, can't think of another one right now new years morning early 2021 a bit hungover but possibly there is :)
public static async Task ClearPriorEventsForObject(AyContext ct, AyaType ayaType, long objectId)

View File

@@ -1744,7 +1744,7 @@ namespace AyaNova.Biz
await ct.SaveChangesAsync();
}
}
}//workorder status change event
}//workorder status age event
//# COMPLETE BY OVERDUE
@@ -1883,6 +1883,105 @@ namespace AyaNova.Biz
}
}
}//WorkorderCompleted
//## CUSTOMER "PROXY" NOTIFICATIONS
var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == WorkorderInfo.CustomerId).Select(x => new { x.Active, x.Tags, x.EmailAddress }).FirstOrDefaultAsync();
if (custInfo != null && custInfo.Active && !string.IsNullOrWhiteSpace(custInfo.EmailAddress))//can this customer receive *any* customer notifications?
{
//-------- Customer is notifiable ------
//# STATUS CHANGE (create new status)
{
//Conditions: must match specific status id value and also tags below
//delivery is immediate so no need to remove old ones of this kind
var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderStatusChange && z.IdValue == oProposed.WorkOrderStatusId).OrderBy(z => z.Id).ToListAsync();
foreach (var sub in subs)
{
//Object tags must match and Customer tags must match
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags))
{
CustomerNotifyEvent n = new CustomerNotifyEvent()
{
EventType = NotifyEventType.WorkorderStatusChange,
CustomerId = WorkorderInfo.CustomerId,
AyaType = AyaType.WorkOrder,
ObjectId = oProposed.WorkOrderId,
CustomerNotifySubscriptionId = sub.Id,
Name = WorkorderInfo.Serial.ToString()
};
await ct.CustomerNotifyEvent.AddAsync(n);
log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
break;//we have a match no need to process any further subs for this event
}
}
}//workorder status change event
//# STATUS AGE
{
//WorkorderStatusAge = 24,//* Workorder STATUS unchanged for set time (stuck in state), conditional on: Duration (how long stuck), exact status selected IdValue, Tags. Advance notice can NOT be set
//Always clear any old ones for this object as they are all irrelevant the moment the state has changed:
await NotifyEventHelper.ClearPriorCustomerNotifyEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.WorkorderStatusAge);
var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderStatusAge && z.IdValue == oProposed.WorkOrderStatusId).OrderBy(z => z.Id).ToListAsync();
foreach (var sub in subs)
{
//Object tags must match and Customer tags must match
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags))
{
CustomerNotifyEvent n = new CustomerNotifyEvent()
{
EventType = NotifyEventType.WorkorderStatusAge,
CustomerId = WorkorderInfo.CustomerId,
AyaType = AyaType.WorkOrder,
ObjectId = oProposed.WorkOrderId,
CustomerNotifySubscriptionId = sub.Id,
Name = WorkorderInfo.Serial.ToString()
};
await ct.CustomerNotifyEvent.AddAsync(n);
log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
break;//we have a match no need to process any further subs for this event
}
}
}//workorder status age event
//# WorkorderCompleted
{
if (wos.Completed)
{
var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderCompleted).OrderBy(z => z.Id).ToListAsync();
foreach (var sub in subs)
{
//Object tags must match and Customer tags must match
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags))
{
CustomerNotifyEvent n = new CustomerNotifyEvent()
{
EventType = NotifyEventType.WorkorderCompleted,
CustomerId = WorkorderInfo.CustomerId,
AyaType = AyaType.Quote,
ObjectId = oProposed.WorkOrderId,
CustomerNotifySubscriptionId = sub.Id,
Name = WorkorderInfo.Serial.ToString()
};
await ct.CustomerNotifyEvent.AddAsync(n);
log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
break;//we have a match no need to process any further subs for this event
}
}
}
}//WorkorderCompleted
//-----------------------
}//all customer proxy if notifiable
}
}//end of process notifications