This commit is contained in:
@@ -311,6 +311,7 @@ namespace AyaNova.Biz
|
||||
case NotifyEventType.GeneralNotification:
|
||||
case NotifyEventType.NotifyHealthCheck://created by job processor itself
|
||||
case NotifyEventType.ServerOperationsProblem:
|
||||
case NotifyEventType.PMGenerationFailed:
|
||||
break;
|
||||
default://this will likely be a development error, not a production error so no need to log etc
|
||||
throw (new System.NotSupportedException($"NotifyEventProcessor:AddGeneralNotifyEvent - Type of event {eventType} is unexpected and not supported"));
|
||||
|
||||
@@ -988,6 +988,90 @@ namespace AyaNova.Biz
|
||||
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);//Note: will properly handle all delete events and event removal if deleted
|
||||
|
||||
//SPECIFIC EVENTS FOR THIS OBJECT
|
||||
PM oCurrent = null;
|
||||
bool SameTags = true;
|
||||
if (currentObj != null)
|
||||
{
|
||||
oCurrent = (PM)currentObj;
|
||||
SameTags = NotifyEventHelper.TwoObjectsHaveSameTags(proposedObj.Tags, currentObj.Tags);
|
||||
}
|
||||
|
||||
#region STOP GENERATING DATE REACHED
|
||||
|
||||
if (ayaEvent == AyaEvent.Created && oProposed.StopGeneratingDate != null)
|
||||
{
|
||||
//PMStopGeneratingDateReached Created here on workorder creation for any subscribers
|
||||
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.PMStopGeneratingDateReached).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(proposedObj.Tags, sub.Tags))
|
||||
{
|
||||
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.PMStopGeneratingDateReached,
|
||||
UserId = sub.UserId,
|
||||
AyaType = proposedObj.AyaType,
|
||||
ObjectId = proposedObj.Id,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = oProposed.Serial.ToString(),
|
||||
EventDate = (DateTime)oProposed.StopGeneratingDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}//StopGeneratingDate
|
||||
|
||||
if (ayaEvent == AyaEvent.Modified)
|
||||
{// PMStopGeneratingDateReached modified in some way, could be tags, could be date either of which is relevant to this notification block
|
||||
|
||||
//differences requiring re-processing of notification??
|
||||
if (oProposed.StopGeneratingDate != oCurrent.StopGeneratingDate || !SameTags)
|
||||
{
|
||||
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.PMStopGeneratingDateReached);
|
||||
|
||||
//new has date?
|
||||
if (oProposed.StopGeneratingDate != null)
|
||||
{
|
||||
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.PMStopGeneratingDateReached).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(proposedObj.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.PMStopGeneratingDateReached,
|
||||
UserId = sub.UserId,
|
||||
AyaType = proposedObj.AyaType,
|
||||
ObjectId = proposedObj.Id,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = oProposed.Serial.ToString(),
|
||||
EventDate = (DateTime)oProposed.StopGeneratingDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//StopGeneratingDate
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1352,22 +1436,6 @@ namespace AyaNova.Biz
|
||||
//SPECIFIC EVENTS FOR THIS OBJECT
|
||||
|
||||
|
||||
//## 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);
|
||||
|
||||
|
||||
// //## CREATED / MODIFIED EVENTS
|
||||
// if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
|
||||
// {
|
||||
|
||||
// //todo: fix etc, tons of shit here incoming
|
||||
|
||||
// }
|
||||
|
||||
}//end of process notifications
|
||||
|
||||
|
||||
@@ -4728,8 +4796,8 @@ namespace AyaNova.Biz
|
||||
|
||||
if (p == null)
|
||||
{
|
||||
//extremely unlikely to happen but just in case...
|
||||
log.LogError($"PMBiz - PM was not fetchable when attempting to process PM id: {pmid}, deleted during processing?");
|
||||
//todo: NOTIFY FAIL
|
||||
continue;
|
||||
}
|
||||
try
|
||||
@@ -4819,7 +4887,7 @@ namespace AyaNova.Biz
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.LogError(ex, $"PMBiz::GenerateAsync error updating PM after generation {p.Serial}");
|
||||
//todo: NOTIFY FAIL
|
||||
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.PMGenerationFailed, $"Error updating PM after generation {p.Serial}", "Preventive Maintenance", ex);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -4828,7 +4896,7 @@ namespace AyaNova.Biz
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.LogError(ex, $"PMBiz::GenerateAsync error generating Work order from PM {p.Serial}");
|
||||
//todo: NOTIFY FAIL
|
||||
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.PMGenerationFailed, $"Error generating Work order from PM {p.Serial}", "Preventive Maintenance", ex);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -4947,7 +5015,7 @@ namespace AyaNova.Biz
|
||||
requestQuantity = pmp.Quantity;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
//not already requested, so check inventory, this is new
|
||||
var CurrentInventory = await ct.PartInventory.AsNoTracking().OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == pmp.PartId && m.PartWarehouseId == pmp.PartWarehouseId);
|
||||
if (CurrentInventory.Balance < pmp.Quantity)
|
||||
@@ -4960,7 +5028,7 @@ namespace AyaNova.Biz
|
||||
|
||||
//Add request if necessary
|
||||
if (requestQuantity != 0)
|
||||
{
|
||||
{
|
||||
var wipr = new WorkOrderItemPartRequest();
|
||||
wipr.PartId = pmp.PartId;
|
||||
wipr.PartWarehouseId = pmp.PartWarehouseId;
|
||||
@@ -5090,7 +5158,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
var err = $"PMBiz::NewServiceWorkOrderFromPMAsync error creating from PM {p.Serial}\r\n{biz.GetErrorsAsString()}";
|
||||
log.LogError(err);
|
||||
//todo: NOTIFY FAIL
|
||||
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.PMGenerationFailed, $"Error generating Work order from PM {p.Serial}\r\n{biz.GetErrorsAsString()}", "Preventive Maintenance");
|
||||
return false;
|
||||
}
|
||||
#if (DEBUG)
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace AyaNova.Biz
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.LogError(ex, $"Error processing PMGenerate ");
|
||||
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.PMGenerationFailed, "PM Generate failure","Preventive Maintenance", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user