From 2ab1c9cd9d29887718b9705634d7efab16be5d0d Mon Sep 17 00:00:00 2001 From: "Ouellette Jonathan (CSC FI SPS MESLEO)" Date: Thu, 17 Apr 2025 02:00:31 +0200 Subject: [PATCH] Merged PR 15152: Combined queries into one. Seemed to solve the issue. Also updated the COC fi... Combined queries into one. Seemed to solve the issue. Also updated the COC field indexes for good measure. Related work items: #254332 --- LSL2/STPROC/SHIPMENT_SERVICES.txt | 87 ++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 26 deletions(-) diff --git a/LSL2/STPROC/SHIPMENT_SERVICES.txt b/LSL2/STPROC/SHIPMENT_SERVICES.txt index bbc06e4..1875a1f 100644 --- a/LSL2/STPROC/SHIPMENT_SERVICES.txt +++ b/LSL2/STPROC/SHIPMENT_SERVICES.txt @@ -38,7 +38,7 @@ GoToService Return Response or "" -Options MonaResources = 'FILE_GENERATION', 'FILE_TRANSMISSION', 'FILE_AVAILABILITY' +Options MonaResources = 'FILE_GENERATION', 'FILE_TRANSMISSION', 'FILE_AVAILABILITY', 'FTP_SERVER_REACHABLE' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // SERVICES @@ -53,7 +53,7 @@ Options MonaResources = 'FILE_GENERATION', 'FILE_TRANSMISSION', 'FILE_AVAILABILI // //---------------------------------------------------------------------------------------------------------------------- Service CycleRetentionDates() - + hSysLists = Database_Services('GetTableHandle', 'SYSLISTS') Lock hSysLists, ServiceKeyID then CycleRec = Xlate('APP_INFO', 'COC_AVAILABILITY', '', 'X') @@ -113,24 +113,22 @@ end service // //---------------------------------------------------------------------------------------------------------------------- Service CheckFileAvailability(StartDate, EndDate) - Error_Services('Clear') + NetworkError = False$ OPEN 'COC' TO COCTable ELSE Error_Services('Add', 'Unable to open COC Table') Return END - Statement1 = 'SELECT COC BY ENTRY_DATE WITH ENTRY_DATE GE ' : Quote(StartDate) - Statement2 = 'SELECT COC WITH ENTRY_DATE LE ' : Quote(EndDate) + SelectQuery = 'SELECT COC BY ENTRY_DATE WITH ENTRY_DATE GE ' : Quote(StartDate) : ' AND WITH ENTRY_DATE LE ' : Quote(EndDate) Clearselect - RList(Statement1, 5, '', '', '') - RList(Statement2, 5, '', '', '') + RList(SelectQuery, 5, '', '', '') If @List_Active EQ 3 AND @RecCount NE 0 then Done = 0 LOOP READNEXT COCNo ELSE Done = 1 - UNTIL Done + UNTIL Done OR NetworkError READ COCRec FROM COCTable, COCNo THEN WONo = COCRec CustNo = XLATE('COC', COCNo, 'WO_CUST_NO_EX', 'X') @@ -141,6 +139,7 @@ Service CheckFileAvailability(StartDate, EndDate) NewCOC = True$ Gosub CompanyExceptionCheck DeleteScript = True$ + Query = '*' : COCNo : '*' QueryResult = FTP_Services('ListDirectory', FTPHost, Username, Password, RemoteDirectory, Query, '', DeleteScript, SSH, '') ErrTest = Error_Services('GetMessage') @@ -151,32 +150,44 @@ Service CheckFileAvailability(StartDate, EndDate) end end else // Ignore ssh_init and network errors - If ( (IndexC(ErrTest, 'ssh_init', 1) EQ 0) and (IndexC(ErrTest, 'Network error', 1) EQ 0 ) ) then + If ( (IndexC(ErrTest, 'ssh_init', 1) EQ 0) and (IndexC(ErrTest, 'Network error', 1) EQ 0 ) and (IndexC(ErrTest, 'Access Denied', 1) EQ 0)) then Error_Services('Add', 'Expected file for shipment ' : COCNo : ' missing.') NewCOC = False$ Database_Services('WriteDataRow', 'COC', COCNo, NewCOC, True$, False$, False$) Gosub LogMissingFile - End + End else + NetworkError = True$ + end end end END REPEAT end // Code to run COC SELECT and change MONA Status - EarliestDate = Shipment_Services('GetEarliestDate') - EarliestDate = OConv(EarliestDate, 'D4-') - Statement1 = 'SELECT COC BY ENTRY_DATE WITH ENTRY_DATE GE ' : Quote(EarliestDate) - Statement2 = 'SELECT COC WITH FTP_SHOULD_EXIST EQ 1 AND WITH FTP_EXISTS EQ 0' - Clearselect - RList(Statement1, 5, '', '', '') - RList(Statement2, 5, '', '', '') - - If @List_Active EQ 3 AND @RecCount NE 0 then - Shipment_Services('SetMONACritical', 'FILE_AVAILABILITY', 'Error locating expected COC file(s). Please review the logs and correct.') + If NetworkError EQ False$ then + Shipment_Services('ClearMONACritical', 'FTP_SERVER_REACHABLE') + EarliestDate = Shipment_Services('GetEarliestDate') + EarliestDate = OConv(EarliestDate, 'D4-') + SelectQuery = 'SELECT COC BY ENTRY_DATE WITH ENTRY_DATE GE ' : Quote(EarliestDate) : ' AND WITH FTP_SHOULD_EXIST EQ 1 AND WITH FTP_EXISTS EQ 0' + Clearselect + RList(SelectQuery, 5, '', '', '') + MissingCOCs = '' + Done = False$ + LOOP + READNEXT MissingCOCNo ELSE Done = 1 + UNTIL Done + MissingCOCs<-1> = MissingCOCNo + REPEAT + If @List_Active EQ 3 AND @RecCount NE 0 then + swap @FM with ',' in MissingCOCs + Shipment_Services('SetMONACritical', 'FILE_AVAILABILITY', 'Error locating expected COC file(s). Please review the logs and correct. ' : MissingCOCs) + end else + Shipment_Services('ClearMONACritical', 'FILE_AVAILABILITY') + end end else - Shipment_Services('ClearMONACritical', 'FILE_AVAILABILITY') + Shipment_Services('SetMONAWarning', 'FTP_SERVER_REACHABLE') + Error_Services('Add', Service : 'service failed. ''An issue connecting to the FTP server has occured.') end - end service @@ -192,7 +203,7 @@ Service GetEarliestDate() TodayDate = Date() /////// Earliest Date where all documents to date are accounted for. To be used until 3-2-25, after which the earliest date should always just be 1 year before the current date.//////////////////////////////////// - TempEarliestDate = '3-2-24' + TempEarliestDate = '4-14-24' TempEarliestDate = Iconv(TempEarliestDate, 'D') LastYearDate = TodayDate - 365 If LastYearDate LT TempEarliestDate then @@ -217,7 +228,7 @@ End Service //---------------------------------------------------------------------------------------------------------------------- Service SetMONACritical(MONAResource=MONAResources, ErrorMessage) - IF MONAResource = 'FILE_GENERATION' OR MONAResource = 'FILE_TRANSMISSION' OR MONAResource = 'FILE_AVAILABILITY' then + IF MONAResource = 'FILE_GENERATION' OR MONAResource = 'FILE_TRANSMISSION' OR MONAResource = 'FILE_AVAILABILITY' OR MONAResource = 'FTP_SERVER_REACHABLE' then Mona_Services('SendBufferedStatus', 'GRP_OPENINSIGHT_MES_OP_FE_COC', MONAResource, 'CRITICAL') If ErrorMessage NE '' then // Log error @@ -250,7 +261,30 @@ Service SetMONACritical(MONAResource=MONAResources, ErrorMessage) End Service - +Service SetMONAWarning(MONAResource=MONAResources, ErrorMessage) + + IF MONAResource = 'FILE_GENERATION' OR MONAResource = 'FILE_TRANSMISSION' OR MONAResource = 'FILE_AVAILABILITY' OR MONAResource = 'FTP_SERVER_REACHABLE' then + Mona_Services('SendBufferedStatus', 'GRP_OPENINSIGHT_MES_OP_FE_COC', MONAResource, 'WARNING') + If ErrorMessage NE '' then + // Log error + LogDate = Oconv(Date(), 'D4/') + LogTime = Oconv(Time(), 'MTS') + LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\Shipment' + LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_MonA_Warning.log' + Headers = 'Logging DTM' : @FM : 'Error' + ColumnWidths = 30 : @FM : 300 + objMonaLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$) + LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM + LogData = '' + LogData<1> = LoggingDtm + LogData<2> = ErrorMessage + Logging_Services('AppendLog', objMonaLog, LogData, @RM, @FM) + End + end else + Error_Services('Add', 'Invalid COC MONA resource.') + end + +End Service //---------------------------------------------------------------------------------------------------------------------- // ClearMONACritical // @@ -261,7 +295,7 @@ End Service //---------------------------------------------------------------------------------------------------------------------- Service ClearMONACritical(MONAResource=MONAResources) - IF MONAResource = 'FILE_GENERATION' OR MONAResource = 'FILE_TRANSMISSION' OR MONAResource = 'FILE_AVAILABILITY' then + IF MONAResource = 'FILE_GENERATION' OR MONAResource = 'FILE_TRANSMISSION' OR MONAResource = 'FILE_AVAILABILITY' OR MONAResource = 'FTP_SERVER_REACHABLE' then Mona_Services('SendBufferedStatus', 'GRP_OPENINSIGHT_MES_OP_FE_COC', MONAResource, 'OK') end else Error_Services('Add', 'Invalid COC MONA resource.') @@ -365,3 +399,4 @@ CompanyExceptionCheck: return +