This commit is contained in:
@@ -97,7 +97,7 @@ There are no settings adjustable for in app General notifications, however Users
|
|||||||
| WorkorderTotalExceedsThreshold | The balance of a Work order has exceeded a threshold (the "Andy") |
|
| WorkorderTotalExceedsThreshold | The balance of a Work order has exceeded a threshold (the "Andy") |
|
||||||
| WorkorderStatusAge | A Workorder has been sitting at the selected status for longer than the selected time frame |
|
| WorkorderStatusAge | A Workorder has been sitting at the selected status for longer than the selected time frame |
|
||||||
| UnitWarrantyExpiry | A Unit's warranty expiration date is reached |
|
| UnitWarrantyExpiry | A Unit's warranty expiration date is reached |
|
||||||
| UnitMeterReadingMultipleExceeded | A meter reading has a difference from the last reading by the selected amount (negative OR positive to cover count *down* meters or rollover / reset meters) |
|
| UnitMeterReadingMultipleExceeded | A meter reading has a difference from the last reading by the selected amount (negative OR positive to cover count *down* meters or rollover / reset meters, can tag filter by Unit tag) |
|
||||||
| GeneralNotification | Any general notification including direct text notifications between users (built in but provided for email alternative delivery) |
|
| GeneralNotification | Any general notification including direct text notifications between users (built in but provided for email alternative delivery) |
|
||||||
| ServerOperationsProblem | Any timely and serious issue related to internal AyaNova Server operations requiring attention |
|
| ServerOperationsProblem | Any timely and serious issue related to internal AyaNova Server operations requiring attention |
|
||||||
| QuoteStatusAge | A Quote has been sitting at the selected status for longer than the selected time frame |
|
| QuoteStatusAge | A Quote has been sitting at the selected status for longer than the selected time frame |
|
||||||
|
|||||||
@@ -201,34 +201,20 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
//SPECIFIC EVENTS FOR THIS OBJECT
|
//SPECIFIC EVENTS FOR THIS OBJECT
|
||||||
//#todo: METER READING EVENT
|
|
||||||
//MIGRATE_OUTSTANDING need meter reading object to complete unit notification for UnitMeterReadingMultipleExceeded
|
|
||||||
//UnitMeterReadingMultipleExceeded = 26,//* UnitMeterReading object, Created, conditional on DecValue as the Multiple threshold, if passed then notifies
|
|
||||||
//{
|
|
||||||
//first remove any existing, potentially stale notifyevents for this exact object and notifyeventtype
|
|
||||||
//await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Unit, o.Id, NotifyEventType.UnitMeterReadingMultipleExceeded);
|
|
||||||
|
|
||||||
//then check if unit is still metered etc etc and do the rest once the unit meter reading is coded
|
|
||||||
|
|
||||||
//}
|
|
||||||
/*
|
|
||||||
This could work as a threshold multiple value, i.e. if it's passing a multiple of 50,000 then notify, or notify every 10,000 or something.
|
|
||||||
In saving code it just checks to see if it has crossed the multiple threshold, i.e. calculate the old multiple, calculate the new multiple if over then send notification immediate.
|
|
||||||
Multiple is 10:
|
|
||||||
old was 5, new is 7 so 7-5 < 10 so do nothing
|
|
||||||
old was 5, new is 12 so 12-5=7 < 10 so do nothing
|
|
||||||
old was 5, new is 16 so 16-5==11 > 10 so do notification
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
//UnitMeterReadingMultipleExceeded event
|
||||||
{
|
{
|
||||||
//see if any subscribers
|
//see if any subscribers
|
||||||
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.UnitMeterReadingMultipleExceeded).ToListAsync();
|
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.UnitMeterReadingMultipleExceeded).ToListAsync();
|
||||||
|
if (subs.Count == 0) return;
|
||||||
|
var unitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == proposedObj.UnitId).Select(x => new { x.Name, x.Serial, x.Tags }).FirstOrDefaultAsync();
|
||||||
foreach (var sub in subs)
|
foreach (var sub in subs)
|
||||||
{
|
{
|
||||||
//not for inactive users
|
//not for inactive users
|
||||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||||
|
|
||||||
|
if (!NotifyEventHelper.ObjectHasAllSubscriptionTags(unitInfo.Tags, sub.Tags)) continue;
|
||||||
|
|
||||||
//is multiple exceeded??
|
//is multiple exceeded??
|
||||||
//Formula is to retrieve last highest reading, if it's not found then it's zero
|
//Formula is to retrieve last highest reading, if it's not found then it's zero
|
||||||
//subtract last meter reading from current meter reading and if it's equal or more than threshold trigger notification
|
//subtract last meter reading from current meter reading and if it's equal or more than threshold trigger notification
|
||||||
@@ -241,22 +227,21 @@ namespace AyaNova.Biz
|
|||||||
if (lastMeterReading != null)
|
if (lastMeterReading != null)
|
||||||
lastReading = lastMeterReading.Meter;
|
lastReading = lastMeterReading.Meter;
|
||||||
//NOTE: this will cover scenarios where the meter wraps back to zero or is reset to zero or a meter counts **down** instead of up
|
//NOTE: this will cover scenarios where the meter wraps back to zero or is reset to zero or a meter counts **down** instead of up
|
||||||
//meter readings are always positive due to biz rule
|
//meter readings are always positive due to biz rule, dec value is always within long range and greater than 4 (arbitrarily)
|
||||||
var diff = Math.Abs(proposedObj.Meter - lastReading);
|
long diff = Math.Abs(proposedObj.Meter - lastReading);
|
||||||
|
|
||||||
|
if (diff >= sub.DecValue)
|
||||||
if (sub.DecValue < diff)
|
|
||||||
{
|
{
|
||||||
//notification is a go
|
//notification is a go
|
||||||
NotifyEvent n = new NotifyEvent()
|
NotifyEvent n = new NotifyEvent()
|
||||||
{
|
{
|
||||||
EventType = NotifyEventType.WorkorderTotalExceedsThreshold,
|
EventType = NotifyEventType.UnitMeterReadingMultipleExceeded,
|
||||||
UserId = sub.UserId,
|
UserId = sub.UserId,
|
||||||
AyaType = AyaType.WorkOrder,
|
AyaType = AyaType.UnitMeterReading,
|
||||||
ObjectId = oProposed.WorkOrderId,
|
ObjectId = proposedObj.Id,
|
||||||
NotifySubscriptionId = sub.Id,
|
NotifySubscriptionId = sub.Id,
|
||||||
Name = $"{WorkorderInfo.Serial.ToString()}",
|
Name = $"{unitInfo.Serial}, {unitInfo.Name}",
|
||||||
DecValue = GrandTotal
|
DecValue = diff
|
||||||
};
|
};
|
||||||
await ct.NotifyEvent.AddAsync(n);
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||||
|
|||||||
Reference in New Issue
Block a user