This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user