This commit is contained in:
2021-06-09 23:11:29 +00:00
parent ecc0165a09
commit 2e44d19e70
2 changed files with 160 additions and 18 deletions

View File

@@ -3,3 +3,11 @@
This form shows "in app" notifications received in the last 90 days.
Notifications are kept for 90 days then automatically deleted.
Notes for docs / items to cover
- TAG changes on work order header and Workorder related notifications for *descendants* on work orders.
Most work order descendant notifications will use the Work order header tags for comparison with their notification setting with the exception of descendants that have their own Tags (Work order items and Work order item Units are currently the only descendants with their own tags).
For all other descendants, they will process notifications and filter by tag against the work order header tags in place at the moment they are saved after creation or update *only*.
Changing the work order header tags on an existing work order does not automatically trigger a re-evaluation of descendant notification items. Only when those descendants themselves are edited and saved will the tags be re-assessed. This means that ideally tags should be set *first* on the work order before any descendant items that might be dependant on certain tags being present.

View File

@@ -1003,7 +1003,7 @@ namespace AyaNova.Biz
//WorkorderCompletedStatusOverdue Created here on workorder creation for any subscribers
//State notify event processor below has more notes and details and will remove this event if set to a completed state
//If new and has completeby then can do notification
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderCompletedStatusOverdue).ToListAsync();
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderCompletedStatusOverdue).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
@@ -1042,7 +1042,7 @@ namespace AyaNova.Biz
//new has date?
if (oProposed.CompleteByDate != null)
{
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderCompletedStatusOverdue).ToListAsync();
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderCompletedStatusOverdue).ToListAsync();
foreach (var sub in subs)
{
@@ -1264,7 +1264,7 @@ namespace AyaNova.Biz
{
//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.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderStatusChange && z.IdValue == o.WorkOrderStatusId).ToListAsync();
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderStatusChange && z.IdValue == o.WorkOrderStatusId).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
@@ -1294,7 +1294,7 @@ namespace AyaNova.Biz
//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.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.WorkorderStatusAge);
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderStatusAge && z.IdValue == o.WorkOrderStatusId).ToListAsync();
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderStatusAge && z.IdValue == o.WorkOrderStatusId).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
@@ -3231,6 +3231,10 @@ namespace AyaNova.Biz
//
public async Task OutsideServiceHandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null)
{
/*
OutsideServiceOverdue = 16,//* Workorder object , WorkorderItemOutsideService created / updated, sets advance notice on due date tag filterable
OutsideServiceReceived = 17,//* Workorder object , WorkorderItemOutsideService updated, instant notification when item received, tag filterable
*/
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger<WorkOrderBiz>();
if (ServerBootConfig.SEEDING) return;
log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{proposedObj.AyaType}, AyaEvent:{ayaEvent}]");
@@ -3242,22 +3246,154 @@ namespace AyaNova.Biz
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
//SPECIFIC EVENTS FOR THIS OBJECT
WorkOrderItemOutsideService o = (WorkOrderItemOutsideService)proposedObj;
WorkOrderItemOutsideService oProposed = (WorkOrderItemOutsideService)proposedObj;
//## DELETED EVENTS
//any event added below needs to be removed, so
//just blanket remove any event for this object of eventtype that would be added below here
//do it regardless any time there's an update and then
//let this code below handle the refreshing addition that could have changes
// await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, o.Id, NotifyEventType.ContractExpiring);
//standard process above will remove any hanging around when deleted, nothing else specific here to deal with
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, oProposed.WorkOrderItemId, ct);
var WorkorderInfo = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == woId).Select(x => new { Serial = x.Serial, Tags = x.Tags }).FirstOrDefaultAsync();
//## CREATED / MODIFIED EVENTS
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
//## CREATED
if (ayaEvent == AyaEvent.Created)
{
//OutsideServiceOverdue
if (oProposed.ETADate != null)
{
//Conditions: tags + time delayed eta value
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.OutsideServiceOverdue).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//todo: fix etc, tons of shit here incoming
//Tag match? (will be true if no sub tags so always safe to call this)
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.OutsideServiceOverdue,
UserId = sub.UserId,
AyaType = AyaType.WorkOrderItemScheduledUser,
ObjectId = oProposed.Id,
NotifySubscriptionId = sub.Id,
EventDate = (DateTime)oProposed.ETADate,
Name = $"{WorkorderInfo.Serial.ToString()}"
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}//OutsideServiceOverdue
//OutsideServiceReceived (here because it's possible a outside service is entered new with both an eta and received date if entered after the fact)
if (oProposed.ReturnDate != null)
{
//Clear overdue ones as it's now received
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.OutsideServiceOverdue);
//Conditions: tags
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.OutsideServiceReceived).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//Tag match? (will be true if no sub tags so always safe to call this)
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.OutsideServiceReceived,
UserId = sub.UserId,
AyaType = AyaType.WorkOrderItemScheduledUser,
ObjectId = oProposed.Id,
NotifySubscriptionId = sub.Id,
Name = $"{WorkorderInfo.Serial.ToString()}"
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}//OutsideServiceReceived
}
//## MODIFIED
if (ayaEvent == AyaEvent.Modified)
{
WorkOrderItemOutsideService oCurrent = (WorkOrderItemOutsideService)currentObj;
//OutsideServiceOverdue
//if modified then remove any potential prior ones in case irrelevant
if (oProposed.ETADate != oCurrent.ETADate)
{
//eta changed, so first of all remove any prior ones
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.OutsideServiceOverdue);
//now can go ahead and add back again as appropriate
if (oProposed.ETADate != null)
{
//Conditions: tags + time delayed eta value
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.OutsideServiceOverdue).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//Tag match? (will be true if no sub tags so always safe to call this)
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.OutsideServiceOverdue,
UserId = sub.UserId,
AyaType = AyaType.WorkOrderItemScheduledUser,
ObjectId = oProposed.Id,
NotifySubscriptionId = sub.Id,
EventDate = (DateTime)oProposed.ETADate,
Name = $"{WorkorderInfo.Serial.ToString()}"
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}//OutsideServiceOverdue
}
//OutsideServiceReceived
if (oProposed.ReturnDate != oCurrent.ReturnDate && oProposed.ReturnDate != null)//note that this is an instant notification type so no need to clear older ones like above which is time delayed
{
//Clear overdue ones as it's now received
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.OutsideServiceOverdue);
//Conditions: tags
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.OutsideServiceReceived).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//Tag match? (will be true if no sub tags so always safe to call this)
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.OutsideServiceReceived,
UserId = sub.UserId,
AyaType = AyaType.WorkOrderItemScheduledUser,
ObjectId = oProposed.Id,
NotifySubscriptionId = sub.Id,
Name = $"{WorkorderInfo.Serial.ToString()}"
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}//OutsideServiceReceived
}
}//end of process notifications
@@ -4369,7 +4505,7 @@ namespace AyaNova.Biz
{
//Conditions: userid match and tags
//delivery is immediate so no need to remove old ones of this kind
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorder && z.UserId == oProposed.UserId).ToListAsync();
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorder && z.UserId == oProposed.UserId).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
@@ -4405,7 +4541,7 @@ namespace AyaNova.Biz
{
//Conditions: userid match and tags + time delayed age value
//delivery is delayed so need to remove old ones of this kind on update
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorderImminent && z.UserId == oProposed.UserId).ToListAsync();
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorderImminent && z.UserId == oProposed.UserId).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
@@ -4446,7 +4582,7 @@ namespace AyaNova.Biz
{
//Conditions: userid match and tags + time delayed age value
//delivery is delayed so need to remove old ones of this kind on update
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorderImminent && z.UserId == oProposed.UserId).ToListAsync();
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorderImminent && z.UserId == oProposed.UserId).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
@@ -4471,8 +4607,6 @@ namespace AyaNova.Biz
}
}
}//ScheduledOnWorkorderImminent
}
}//end of process notifications