This commit is contained in:
2021-06-11 18:35:26 +00:00
parent 3445b26886
commit a34bd3a941

View File

@@ -1303,7 +1303,12 @@ namespace AyaNova.Biz
log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{proposedObj.AyaType}, AyaEvent:{ayaEvent}]"); log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{proposedObj.AyaType}, AyaEvent:{ayaEvent}]");
bool isNew = currentObj == null; bool isNew = currentObj == null;
WorkOrderState oProposed = (WorkOrderState)proposedObj;
var WorkorderInfo = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == oProposed.WorkOrderId).Select(x => new { Serial = x.Serial, Tags = x.Tags }).FirstOrDefaultAsync();
WorkOrderStatus wos = await ct.WorkOrderStatus.AsNoTracking().FirstOrDefaultAsync(x => x.Id == oProposed.WorkOrderStatusId);
oProposed.Name = WorkorderInfo.Serial.ToString();
oProposed.Tags = WorkorderInfo.Tags;
//STANDARD EVENTS FOR ALL OBJECTS //STANDARD EVENTS FOR ALL OBJECTS
//NONE: state notifications are specific and not the same as for general objects so don't process standard events //NONE: state notifications are specific and not the same as for general objects so don't process standard events
@@ -1315,11 +1320,9 @@ namespace AyaNova.Biz
//NOTE: ID, state notifications are for the Workorder, not the state itself unlike other objects, so use the WO type and ID here for all notifications //NOTE: ID, state notifications are for the Workorder, not the state itself unlike other objects, so use the WO type and ID here for all notifications
WorkOrderState o = (WorkOrderState)proposedObj;
WorkOrderStatus wos = await ct.WorkOrderStatus.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.WorkOrderStatusId);
// WorkOrder wo = await ct.WorkOrder.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.WorkOrderId);
var WorkorderInfo = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == o.WorkOrderId).Select(x => new { Serial = x.Serial, Tags = x.Tags }).FirstOrDefaultAsync();
//## DELETED EVENTS //## DELETED EVENTS
//A state cannot be deleted so nothing to handle that is required //A state cannot be deleted so nothing to handle that is required
@@ -1339,7 +1342,7 @@ namespace AyaNova.Biz
{ {
//Conditions: must match specific status id value and also tags below //Conditions: must match specific status id value and also tags below
//delivery is immediate so no need to remove old ones of this kind //delivery is immediate so no need to remove old ones of this kind
var subs = await ct.NotifySubscription.AsNoTracking().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 == oProposed.WorkOrderStatusId).ToListAsync();
foreach (var sub in subs) foreach (var sub in subs)
{ {
//not for inactive users //not for inactive users
@@ -1353,7 +1356,7 @@ namespace AyaNova.Biz
EventType = NotifyEventType.WorkorderStatusChange, EventType = NotifyEventType.WorkorderStatusChange,
UserId = sub.UserId, UserId = sub.UserId,
AyaType = AyaType.WorkOrder, AyaType = AyaType.WorkOrder,
ObjectId = o.WorkOrderId, ObjectId = oProposed.WorkOrderId,
NotifySubscriptionId = sub.Id, NotifySubscriptionId = sub.Id,
Name = $"{WorkorderInfo.Serial.ToString()} - {wos.Name}" Name = $"{WorkorderInfo.Serial.ToString()} - {wos.Name}"
}; };
@@ -1369,7 +1372,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 //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: //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); await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.WorkorderStatusAge);
var subs = await ct.NotifySubscription.AsNoTracking().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 == oProposed.WorkOrderStatusId).ToListAsync();
foreach (var sub in subs) foreach (var sub in subs)
{ {
//not for inactive users //not for inactive users
@@ -1383,7 +1386,7 @@ namespace AyaNova.Biz
EventType = NotifyEventType.WorkorderStatusAge, EventType = NotifyEventType.WorkorderStatusAge,
UserId = sub.UserId, UserId = sub.UserId,
AyaType = AyaType.WorkOrder, AyaType = AyaType.WorkOrder,
ObjectId = o.WorkOrderId, ObjectId = oProposed.WorkOrderId,
NotifySubscriptionId = sub.Id, NotifySubscriptionId = sub.Id,
Name = $"{WorkorderInfo.Serial.ToString()} - {wos.Name}" Name = $"{WorkorderInfo.Serial.ToString()} - {wos.Name}"
}; };
@@ -1410,7 +1413,7 @@ namespace AyaNova.Biz
if (wos.Completed) if (wos.Completed)
{ {
//Workorder was just set to a completed status so remove any notify events lurking to deliver for overdue //Workorder was just set to a completed status so remove any notify events lurking to deliver for overdue
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, o.WorkOrderId, NotifyEventType.WorkorderCompletedStatusOverdue); await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, oProposed.WorkOrderId, NotifyEventType.WorkorderCompletedStatusOverdue);
} }
}//workorder complete by overdue change event }//workorder complete by overdue change event