This commit is contained in:
2021-08-23 23:50:58 +00:00
parent 36d3bfedfd
commit a500e5b6bd
2 changed files with 15 additions and 30 deletions

View File

@@ -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") |
| 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 |
| 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) |
| 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 |

View File

@@ -201,34 +201,20 @@ namespace AyaNova.Biz
await Task.CompletedTask;
//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
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)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
if (!NotifyEventHelper.ObjectHasAllSubscriptionTags(unitInfo.Tags, sub.Tags)) continue;
//is multiple exceeded??
//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
@@ -241,22 +227,21 @@ namespace AyaNova.Biz
if (lastMeterReading != null)
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
//meter readings are always positive due to biz rule
var diff = Math.Abs(proposedObj.Meter - lastReading);
//meter readings are always positive due to biz rule, dec value is always within long range and greater than 4 (arbitrarily)
long diff = Math.Abs(proposedObj.Meter - lastReading);
if (sub.DecValue < diff)
if (diff >= sub.DecValue)
{
//notification is a go
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.WorkorderTotalExceedsThreshold,
EventType = NotifyEventType.UnitMeterReadingMultipleExceeded,
UserId = sub.UserId,
AyaType = AyaType.WorkOrder,
ObjectId = oProposed.WorkOrderId,
AyaType = AyaType.UnitMeterReading,
ObjectId = proposedObj.Id,
NotifySubscriptionId = sub.Id,
Name = $"{WorkorderInfo.Serial.ToString()}",
DecValue = GrandTotal
Name = $"{unitInfo.Serial}, {unitInfo.Name}",
DecValue = diff
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");