From deebb5dc253a63177e520a11a65173e035ab939a Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 9 Jun 2021 19:53:24 +0000 Subject: [PATCH] --- server/AyaNova/biz/NotifyEventHelper.cs | 8 ++-- server/AyaNova/biz/WorkOrderBiz.cs | 45 +++++++++++++++++-- server/AyaNova/generator/CoreJobNotify.cs | 3 +- .../generator/CoreJobTempFolderCleanup.cs | 3 -- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/server/AyaNova/biz/NotifyEventHelper.cs b/server/AyaNova/biz/NotifyEventHelper.cs index 22996d8f..0cab649c 100644 --- a/server/AyaNova/biz/NotifyEventHelper.cs +++ b/server/AyaNova/biz/NotifyEventHelper.cs @@ -31,13 +31,15 @@ namespace AyaNova.Biz //NOTE: agevalue and advanced notice settings here will ensure that direct in app notifications with a future delivery date ("deadman" switch deliveries) set in their //notifyevent.eventdate will deliver on that date and not immediately to support all the things that are direct built in notifications for future dates //such as for an overdue Review which doesn't have or need it's own notifyeventtype and subscription independently + + //NEW NOTE: above makes not sense, I'm setting these back to timespan zero defaultsub = new NotifySubscription() { UserId = userId, EventType = NotifyEventType.GeneralNotification, DeliveryMethod = NotifyDeliveryMethod.App, - AgeValue = new TimeSpan(0, 0, 1), - AdvanceNotice = new TimeSpan(0, 0, 1) + AgeValue = TimeSpan.Zero,//new TimeSpan(0, 0, 1), + AdvanceNotice = TimeSpan.Zero//new TimeSpan(0, 0, 1) }; await ct.NotifySubscription.AddAsync(defaultsub); await ct.SaveChangesAsync(); @@ -339,7 +341,7 @@ namespace AyaNova.Biz var UserName = await ct.User.AsNoTracking().Where(z => z.Id == userId).Select(z => z.Name).FirstOrDefaultAsync(); //if they don't have a regular inapp subscription create one now - await EnsureDefaultInAppUserNotificationSubscriptionExists(userId, ct); + await EnsureDefaultInAppUserNotificationSubscriptionExists(userId, ct); if (string.IsNullOrWhiteSpace(name)) name = UserName; diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index 8bf3f2aa..9b0a82b1 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -1222,6 +1222,7 @@ namespace AyaNova.Biz // public async Task StateHandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null) { + ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger(); if (ServerBootConfig.SEEDING) return; log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{proposedObj.AyaType}, AyaEvent:{ayaEvent}]"); @@ -4352,13 +4353,51 @@ namespace AyaNova.Biz //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); + var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, o.WorkOrderItemId, ct); + var WorkorderInfo = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == woId).Select(x => new { Serial = x.Serial, Tags = x.Tags }).FirstOrDefaultAsync(); - //## CREATED / MODIFIED EVENTS - if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified) + //## CREATED + if (ayaEvent == AyaEvent.Created) { - //todo: fix etc, tons of shit here incoming + //# ScheduledOnWorkorder event + if (o.UserId != null) + { + //Conditions: userid match and tags + //delivery is immediate so no need to remove old ones of this kind + var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorder && z.UserId == o.UserId).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(WorkorderInfo.Tags, sub.Tags)) + { + NotifyEvent n = new NotifyEvent() + { + EventType = NotifyEventType.WorkorderStatusChange, + UserId = sub.UserId, + AyaType = AyaType.WorkOrder, + ObjectId = o.WorkOrderId, + NotifySubscriptionId = sub.Id, + Name = $"{WorkorderInfo.Serial.ToString()} - {wos.Name}" + }; + await ct.NotifyEvent.AddAsync(n); + log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + } + } + }//workorder status change event + + } + + //## MODIFIED + if (ayaEvent == AyaEvent.Modified) + { + + } diff --git a/server/AyaNova/generator/CoreJobNotify.cs b/server/AyaNova/generator/CoreJobNotify.cs index 1630c08a..48920a19 100644 --- a/server/AyaNova/generator/CoreJobNotify.cs +++ b/server/AyaNova/generator/CoreJobNotify.cs @@ -208,8 +208,7 @@ namespace AyaNova.Biz { await m.SendEmailAsync(deliveryAddress, subject, body, ServerGlobalOpsSettingsCache.Notify); } - } - await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"Test of general notification system", "Error", null, ne.UserId); + } } catch (Exception ex) { diff --git a/server/AyaNova/generator/CoreJobTempFolderCleanup.cs b/server/AyaNova/generator/CoreJobTempFolderCleanup.cs index 2570541c..9f7c22b0 100644 --- a/server/AyaNova/generator/CoreJobTempFolderCleanup.cs +++ b/server/AyaNova/generator/CoreJobTempFolderCleanup.cs @@ -1,9 +1,6 @@ using System; -using System.Diagnostics; using Microsoft.Extensions.Logging; using AyaNova.Util; -using AyaNova.Models; -using Microsoft.EntityFrameworkCore; namespace AyaNova.Biz