From 91cb72c509126001750739f98d86c66b807ec8dc Mon Sep 17 00:00:00 2001 From: "Infineon\\Ouellette" Date: Mon, 18 Nov 2024 11:14:11 -0700 Subject: [PATCH] Added in additional logic to keep repeated notifications from sending --- LSL2/STPROC/PM_SERVICES.txt | 213 +++++++++++++++++++++--------------- 1 file changed, 123 insertions(+), 90 deletions(-) diff --git a/LSL2/STPROC/PM_SERVICES.txt b/LSL2/STPROC/PM_SERVICES.txt index bc137df..c0ef574 100644 --- a/LSL2/STPROC/PM_SERVICES.txt +++ b/LSL2/STPROC/PM_SERVICES.txt @@ -32,6 +32,13 @@ LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Headers = 'Logging DTM' : @FM : 'ToolID' : @FM : 'Notes' : @FM : 'Message' objLogScrubbers = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$) +LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\PM\Notifications' +LogDate = Oconv(Date(), 'D4/') +LogTime = Oconv(Time(), 'MTS') +LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' PM_Notifications.csv' +Headers = 'Logging DTM' : @FM : 'ToolID' : @FM : 'Message' +objLogNotifications = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$) + LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM ChangeModes = Database_Services('ReadDataRow', 'APP_INFO', 'QUAL_CHANGE_MODES') @@ -644,18 +651,18 @@ end service Service SendPMNotifications() hSysLists = Database_Services('GetTableHandle', 'SYSLISTS') Lock hSysLists, ServiceKeyID then - PMStatuses = Pm_Services('GetPMStatuses') - * Recipients = Lsl_Users_Services('GetOnShiftUsersByClass', 'Si Shift Supervisors', 0) - * Recipients := @VM : Lsl_Users_Services('GetOnShiftUsersByClass', 'Lead Operator', 0) - SentFrom = 'OI_ADMIN' - AttachWindow = '' - AttachKey = '' - SendToGroup = '' + errMessage = '' + PMStatuses = Pm_Services('GetPMStatuses') + SentFrom = 'OI_ADMIN' + AttachWindow = '' + AttachKey = '' + SendToGroup = '' for each PMStatusLine in PMStatuses using @FM Status = PMStatusLine<1,COL$STATUS> LastNotification = PMStatusLine<1,COL$NOTIFICAITON> PMDesc = XLATE('PM_SPEC', PMStatusLine<1,COL$PMSKEY>, PM_SPEC_DESC$, 'X') PMKey = PMStatusLine<1,COL$CURRPMKEY> + PMRec = Database_Services('ReadDataRow', 'PM', PMKey) PMSpecKey = PMStatusLine<1, COL$PMSKEY> PMSRec = Database_Services('ReadDataRow', 'PM_SPEC', PMSpecKey) @@ -667,33 +674,120 @@ Service SendPMNotifications() Begin Case Case Status EQ 'EARLY' IF SendEarlyNotification then - Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey) - Subject = 'PM Task Coming Due' - Message = 'Tool: ': Tool : ' - ' :PMDesc:" is coming due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') - Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup - obj_Notes('Create',Parms) - PMRec = Datetime() - Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) + If PMRec EQ '' then + PMRec = Datetime() + Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) + if Error_Services('NoError') then + Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey) + if Error_Services('NoError') then + Subject = 'PM Task Coming Due' + Message = 'Tool: ': Tool : ' - ' :PMDesc:" is coming due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') + Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup + obj_Notes('Create',Parms) + end else + errMessage = Error_Services('GetMessage') + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'EARLY notification failed - ' : errMessage + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end + end else + errMessage = Error_Services('GetMessage') + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'EARLY notification failed - ' : errMessage + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end + end else + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'EARLY notification did not send because it has been marked as being already sent.' + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end end Case Status EQ 'DUE' If SendDueNotification then - Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey) - Subject = 'PM Task Due' - Message = 'Tool: ': Tool : ' - ' :PMDesc:" is due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') - Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup - obj_Notes('Create',Parms) - PMRec = Datetime() - Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) + If PMRec EQ '' then + PMRec = Datetime() + Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) + if Error_Services('NoError') then + Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey) + if Error_Services('NoError') then + Subject = 'PM Task Due' + Message = 'Tool: ': Tool : ' - ' :PMDesc:" is due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') + Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup + obj_Notes('Create',Parms) + end else + errMessage = Error_Services('GetMessage') + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'DUE notification failed - ' : errMessage + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end + end else + errMessage = Error_Services('GetMessage') + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'DUE notification failed - ' : errMessage + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end + end else + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'DUE notification did not send because it has been marked as being already sent.' + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end end Case Status EQ 'LATE' if SendLateNotification then - Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey) - Subject = 'PM overdue' - Message = 'Tool: ': Tool : ' - ' :PMDesc:" is overdue. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') - Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup - obj_Notes('Create',Parms) - PMRec = Datetime() - Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) + If PMRec EQ '' then + PMRec = Datetime() + Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) + if Error_Services('NoError') then + Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey) + if Error_Services('NoError') then + Subject = 'PM overdue' + Message = 'Tool: ': Tool : ' - ' :PMDesc:" is overdue. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') + Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup + obj_Notes('Create',Parms) + end else + errMessage = Error_Services('GetMessage') + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'LATE notification failed - ' : errMessage + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end + end else + errMessage = Error_Services('GetMessage') + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'LATE notification failed - ' : errMessage + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end + end else + LogData = '' + LogData<1> = LoggingDTM;//Defined at entry of subroutine + LogData<2> = Tool + LogData<3> = PMDesc + LogData<4> = 'LATE notification did not send because it has been marked as being already sent.' + Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$) + end end End Case end @@ -703,68 +797,6 @@ Service SendPMNotifications() end service -* Service SendPMNotifications() -* -* hSysLists = Database_Services('GetTableHandle', 'SYSLISTS') -* Lock hSysLists, ServiceKeyID then -* -* PMStatuses = Pm_Services('GetPMStatuses') -* Recipients = Lsl_Users_Services('GetOnShiftUsersByClass', 'Si Shift Supervisors', 0) -* Recipients := @VM : Lsl_Users_Services('GetOnShiftUsersByClass', 'Lead Operator', 0) -* SentFrom = 'OI_ADMIN' -* AttachWindow = '' -* AttachKey = '' -* SendToGroup = '' -* for each PMStatusLine in PMStatuses using @FM -* Status = PMStatusLine<1,COL$STATUS> -* LastNotification = PMStatusLine<1,COL$NOTIFICAITON> -* PMDesc = XLATE('PM_SPEC', PMStatusLine<1,COL$PMSKEY>, PM_SPEC_DESC$, 'X') -* PMKey = PMStatusLine<1,COL$CURRPMKEY> -* PMRec = Database_Services('ReadDataRow', 'PM', PMKey) -* PMSpecKey = PMStatusLine<1, COL$PMSKEY> -* PMSRec = Database_Services('ReadDataRow', 'PM_SPEC', PMSpecKey) -* //SendNotification = PMSRec -* SendEarlyNotification = PMSRec -* SendDueNotification = PMSRec -* SendLateNotification = PMSRec -* If LastNotification EQ '' then -* Begin Case -* Case Status EQ 'EARLY' -* IF SendEarlyNotification then -* Subject = 'PM Task Coming Due' -* Message = PMDesc:" is coming due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') -* Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup -* obj_Notes('Create',Parms) -* PMRec = Datetime() -* Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) -* end -* Case Status EQ 'DUE' -* If SendDueNotification then -* Subject = 'PM Task Due' -* Message = PMDesc:" is due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') -* Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup -* obj_Notes('Create',Parms) -* PMRec = Datetime() -* Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) -* end -* Case Status EQ 'LATE' -* if SendLateNotification then -* Subject = 'PM overdue' -* Message = PMDesc:" is overdue. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT') -* Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup -* obj_Notes('Create',Parms) -* PMRec = Datetime() -* Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1) -* end -* End Case -* end -* Next PMStatus -* Unlock hSysLists, ServiceKeyID else Null -* end -* -* end service - - Service GetPMStatuses() SendEarlyCnt = 0 @@ -934,3 +966,4 @@ Service CompleteScrubberPM(ScrubberID) end end service +