This commit is contained in:
2021-01-01 16:40:25 +00:00
parent 31a5d4c0a7
commit c3f475aadf
5 changed files with 51 additions and 30 deletions

View File

@@ -208,6 +208,10 @@ namespace AyaNova.Biz
// CLEAN OUT OLD EVENTS // CLEAN OUT OLD EVENTS
// //
// //
//Any specific event created in objects biz code (not simply "Modified")
//should trigger this remove code prior to updates etc where it creates a new one
//particularly for future delivery ones but will catch the case of a quick double edit of an object that
//would alter what gets delivered in the notification and before it's sent out yet
public static async Task ClearPriorEventsForObject(AyContext ct, AyaType ayaType, long objectId, NotifyEventType eventType) public static async Task ClearPriorEventsForObject(AyContext ct, AyaType ayaType, long objectId, NotifyEventType eventType)
{ {
var eventsToDelete = await ct.NotifyEvent.Where(z => z.AyaType == ayaType && z.ObjectId == objectId && z.EventType == eventType).ToListAsync(); var eventsToDelete = await ct.NotifyEvent.Where(z => z.AyaType == ayaType && z.ObjectId == objectId && z.EventType == eventType).ToListAsync();
@@ -215,6 +219,9 @@ namespace AyaNova.Biz
ct.NotifyEvent.RemoveRange(eventsToDelete); ct.NotifyEvent.RemoveRange(eventsToDelete);
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
} }
//scorched earth one for outright delete of objects when you don't want any prior events left for it
//probably only ever used for the delete event, can't think of another one right now new years morning early 2021 a bit hungover but possibly there is :)
public static async Task ClearPriorEventsForObject(AyContext ct, AyaType ayaType, long objectId) public static async Task ClearPriorEventsForObject(AyContext ct, AyaType ayaType, long objectId)
{ {
var eventsToDelete = await ct.NotifyEvent.Where(z => z.AyaType == ayaType && z.ObjectId == objectId).ToListAsync(); var eventsToDelete = await ct.NotifyEvent.Where(z => z.AyaType == ayaType && z.ObjectId == objectId).ToListAsync();

View File

@@ -288,8 +288,6 @@ namespace AyaNova.Biz
/* /*
UnitWarrantyExpiry = 25,//* Unit object created, advance notice can be used, tag conditional UnitWarrantyExpiry = 25,//* Unit object created, advance notice can be used, tag conditional
//MIGRATE_OUTSTANDING
UnitMeterReadingMultipleExceeded = 26,//* UnitMeterReading object, Created, conditional on DecValue as the Multiple threshold, if passed then notifies
*/ */
//## DELETED EVENTS //## DELETED EVENTS
@@ -300,15 +298,16 @@ namespace AyaNova.Biz
//let this code below handle the refreshing addition that could have changes //let this code below handle the refreshing addition that could have changes
//## CREATED EVENTS //## CREATED / MODIFIED EVENTS
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified) if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
{ {
Unit o = (Unit)proposedObj; Unit o = (Unit)proposedObj;
//UNIT WARRANTY EXPIRY //# UNIT WARRANTY EXPIRY
{ {
//first remove any existing, potentially stale notifyevents for this exact object and notifyeventtype
await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Unit, o.Id, NotifyEventType.UnitWarrantyExpiry);
//does the unit even have a model or warranty? //does the unit even have a model or warranty?
int effectiveWarrantyMonths = 0; int effectiveWarrantyMonths = 0;
//unit has own warranty terms //unit has own warranty terms
@@ -359,7 +358,23 @@ namespace AyaNova.Biz
} }
} }
} }
} }//warranty 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
//}
} }

View File

@@ -50,8 +50,8 @@ namespace AyaNova.Models
public NotifyEvent() public NotifyEvent()
{ {
Created = EventDate = DateTime.UtcNow; Created = EventDate = DateTime.UtcNow;
IdValue = 0; // IdValue = 0;
DecValue = 0; // DecValue = 0;
AyaType = AyaType.NoType; AyaType = AyaType.NoType;
ObjectId = 0; ObjectId = 0;
Name = string.Empty; Name = string.Empty;

View File

@@ -58,12 +58,12 @@ namespace AyaNova.Models
public Customer Customer { get; set; } public Customer Customer { get; set; }
[JsonIgnore] [JsonIgnore]
public UnitModel UnitModel { get; set; } public UnitModel UnitModel { get; set; }
[JsonIgnore] // [JsonIgnore]
public Unit ParentUnit { get; set; } // public Unit ParentUnit { get; set; }
[JsonIgnore] [JsonIgnore]
public Vendor PurchasedFromVendor { get; set; } public Vendor PurchasedFromVendor { get; set; }
[JsonIgnore] // [JsonIgnore]
public Unit ReplacedByUnit { get; set; } // public Unit ReplacedByUnit { get; set; }
}//eoc }//eoc

View File

@@ -22,7 +22,7 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 15; private const int DESIRED_SCHEMA_LEVEL = 15;
internal const long EXPECTED_COLUMN_COUNT = 596; internal const long EXPECTED_COLUMN_COUNT = 614;
internal const long EXPECTED_INDEX_COUNT = 175; internal const long EXPECTED_INDEX_COUNT = 175;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
@@ -714,6 +714,16 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
await ExecQueryAsync("CREATE INDEX avendor_tags ON avendor using GIN(tags)"); await ExecQueryAsync("CREATE INDEX avendor_tags ON avendor using GIN(tags)");
await ExecQueryAsync("ALTER TABLE auser add FOREIGN KEY (vendorid) REFERENCES avendor(id)"); await ExecQueryAsync("ALTER TABLE auser add FOREIGN KEY (vendorid) REFERENCES avendor(id)");
//UNITMODEL
await ExecQueryAsync("CREATE TABLE aunitmodel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text null, active bool, " +
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
"number text not null, vendorid bigint null references avendor(id), upc text null, lifetimewarranty bool not null, introduceddate timestamp null, " +
"discontinued bool not null, discontinueddate timestamp null, warrantylength integer null, warrantyterms text null " +
")");
await ExecQueryAsync("CREATE UNIQUE INDEX aunitmodel_name_id_idx ON aunitmodel (id, name);");
await ExecQueryAsync("CREATE INDEX aunitmodel_tags ON aunitmodel using GIN(tags)");
//UNIT //UNIT
await ExecQueryAsync("CREATE TABLE aunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active bool, " + await ExecQueryAsync("CREATE TABLE aunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active bool, " +
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " + "notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
@@ -729,17 +739,6 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
await ExecQueryAsync("CREATE INDEX aunit_tags ON aunit using GIN(tags)"); await ExecQueryAsync("CREATE INDEX aunit_tags ON aunit using GIN(tags)");
//UNITMODEL
await ExecQueryAsync("CREATE TABLE aunitmodel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text null, active bool, " +
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
"number text not null, vendorid bigint null references avendor(id), upc text null, lifetimewarranty bool not null, introduceddate timestamp null, " +
"discontinued bool not null, discontinueddate timestamp null, warrantylength integer null, warrantyterms text null " +
")");
await ExecQueryAsync("CREATE UNIQUE INDEX aunitmodel_name_id_idx ON aunitmodel (id, name);");
await ExecQueryAsync("CREATE INDEX aunitmodel_tags ON aunitmodel using GIN(tags)");
//---------- //----------
//WORKORDER //WORKORDER
await ExecQueryAsync("CREATE TABLE aworkorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial bigint generated by default as identity not null, active bool, " + await ExecQueryAsync("CREATE TABLE aworkorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial bigint generated by default as identity not null, active bool, " +