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") |
|
||||
| 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 readingn *multiple* exceeds selected threshold (e.g. every 10,000 etc) |
|
||||
| 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) |
|
||||
| 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 |
|
||||
|
||||
@@ -229,6 +229,22 @@ namespace AyaNova.Biz
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "DeliveryAddress", "In app delivery should not specify a delivery address");
|
||||
}
|
||||
|
||||
if (proposedObj.EventType == NotifyEventType.UnitMeterReadingMultipleExceeded)
|
||||
{
|
||||
//validate decvalue is a long
|
||||
try
|
||||
{
|
||||
long lValue= System.Convert.ToInt64(proposedObj.DecValue);
|
||||
if(lValue < 5){//arbitrary value
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "DecValue", "Value is too small, must be 5 or higher");
|
||||
}
|
||||
}
|
||||
catch (System.OverflowException)
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "DecValue", "Value is too large, must be less than 9,223,372,036,854,775,807");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -558,18 +558,7 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
}//Contract expiry event
|
||||
|
||||
|
||||
//#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
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -129,6 +129,12 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
//No negative amounts allowed, a meter can count down to zero or up to whatever but it can't go negative or the math breaks down
|
||||
if (proposedObj.Meter < 0)
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Meter", "Negative meter readings not supported");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -205,6 +211,60 @@ namespace AyaNova.Biz
|
||||
//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
|
||||
|
||||
|
||||
*/
|
||||
|
||||
{
|
||||
//see if any subscribers
|
||||
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.UnitMeterReadingMultipleExceeded).ToListAsync();
|
||||
foreach (var sub in subs)
|
||||
{
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) 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
|
||||
|
||||
var lastMeterReading = await ct.UnitMeterReading.AsNoTracking()
|
||||
.Where(x => x.UnitId == proposedObj.UnitId)
|
||||
.OrderByDescending(z => z.MeterDate)
|
||||
.Take(1).FirstOrDefaultAsync();
|
||||
long lastReading = 0;
|
||||
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);
|
||||
|
||||
|
||||
if (sub.DecValue < diff)
|
||||
{
|
||||
//notification is a go
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.WorkorderTotalExceedsThreshold,
|
||||
UserId = sub.UserId,
|
||||
AyaType = AyaType.WorkOrder,
|
||||
ObjectId = oProposed.WorkOrderId,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = $"{WorkorderInfo.Serial.ToString()}",
|
||||
DecValue = GrandTotal
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}//end of process notifications
|
||||
|
||||
|
||||
Reference in New Issue
Block a user