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
This commit is contained in:
Ouellette Jonathan (CSC FI SPS MESLEO) 2025-04-17 02:00:31 +02:00
parent 6575d73001
commit 2ab1c9cd9d

View File

@ -38,7 +38,7 @@ GoToService
Return Response or "" Return Response or ""
Options MonaResources = 'FILE_GENERATION', 'FILE_TRANSMISSION', 'FILE_AVAILABILITY' Options MonaResources = 'FILE_GENERATION', 'FILE_TRANSMISSION', 'FILE_AVAILABILITY', 'FTP_SERVER_REACHABLE'
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SERVICES // SERVICES
@ -113,24 +113,22 @@ end service
// //
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
Service CheckFileAvailability(StartDate, EndDate) Service CheckFileAvailability(StartDate, EndDate)
Error_Services('Clear') Error_Services('Clear')
NetworkError = False$
OPEN 'COC' TO COCTable ELSE OPEN 'COC' TO COCTable ELSE
Error_Services('Add', 'Unable to open COC Table') Error_Services('Add', 'Unable to open COC Table')
Return Return
END END
Statement1 = 'SELECT COC BY ENTRY_DATE WITH ENTRY_DATE GE ' : Quote(StartDate) SelectQuery = 'SELECT COC BY ENTRY_DATE WITH ENTRY_DATE GE ' : Quote(StartDate) : ' AND WITH ENTRY_DATE LE ' : Quote(EndDate)
Statement2 = 'SELECT COC WITH ENTRY_DATE LE ' : Quote(EndDate)
Clearselect Clearselect
RList(Statement1, 5, '', '', '') RList(SelectQuery, 5, '', '', '')
RList(Statement2, 5, '', '', '')
If @List_Active EQ 3 AND @RecCount NE 0 then If @List_Active EQ 3 AND @RecCount NE 0 then
Done = 0 Done = 0
LOOP LOOP
READNEXT COCNo ELSE Done = 1 READNEXT COCNo ELSE Done = 1
UNTIL Done UNTIL Done OR NetworkError
READ COCRec FROM COCTable, COCNo THEN READ COCRec FROM COCTable, COCNo THEN
WONo = COCRec<COC_WO_NO$> WONo = COCRec<COC_WO_NO$>
CustNo = XLATE('COC', COCNo, 'WO_CUST_NO_EX', 'X') CustNo = XLATE('COC', COCNo, 'WO_CUST_NO_EX', 'X')
@ -141,6 +139,7 @@ Service CheckFileAvailability(StartDate, EndDate)
NewCOC<COC_FTP_SHOULD_EXIST$> = True$ NewCOC<COC_FTP_SHOULD_EXIST$> = True$
Gosub CompanyExceptionCheck Gosub CompanyExceptionCheck
DeleteScript = True$ DeleteScript = True$
Query = '*' : COCNo : '*' Query = '*' : COCNo : '*'
QueryResult = FTP_Services('ListDirectory', FTPHost, Username, Password, RemoteDirectory, Query, '', DeleteScript, SSH, '') QueryResult = FTP_Services('ListDirectory', FTPHost, Username, Password, RemoteDirectory, Query, '', DeleteScript, SSH, '')
ErrTest = Error_Services('GetMessage') ErrTest = Error_Services('GetMessage')
@ -151,32 +150,44 @@ Service CheckFileAvailability(StartDate, EndDate)
end end
end else end else
// Ignore ssh_init and network errors // 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.') Error_Services('Add', 'Expected file for shipment ' : COCNo : ' missing.')
NewCOC<COC_FTP_EXISTS$> = False$ NewCOC<COC_FTP_EXISTS$> = False$
Database_Services('WriteDataRow', 'COC', COCNo, NewCOC, True$, False$, False$) Database_Services('WriteDataRow', 'COC', COCNo, NewCOC, True$, False$, False$)
Gosub LogMissingFile Gosub LogMissingFile
End End else
NetworkError = True$
end
end end
end end
END END
REPEAT REPEAT
end end
// Code to run COC SELECT and change MONA Status // Code to run COC SELECT and change MONA Status
If NetworkError EQ False$ then
Shipment_Services('ClearMONACritical', 'FTP_SERVER_REACHABLE')
EarliestDate = Shipment_Services('GetEarliestDate') EarliestDate = Shipment_Services('GetEarliestDate')
EarliestDate = OConv(EarliestDate, 'D4-') EarliestDate = OConv(EarliestDate, 'D4-')
Statement1 = 'SELECT COC BY ENTRY_DATE WITH ENTRY_DATE GE ' : Quote(EarliestDate) 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'
Statement2 = 'SELECT COC WITH FTP_SHOULD_EXIST EQ 1 AND WITH FTP_EXISTS EQ 0'
Clearselect Clearselect
RList(Statement1, 5, '', '', '') RList(SelectQuery, 5, '', '', '')
RList(Statement2, 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 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.') 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 end else
Shipment_Services('ClearMONACritical', 'FILE_AVAILABILITY') Shipment_Services('ClearMONACritical', 'FILE_AVAILABILITY')
end end
end else
Shipment_Services('SetMONAWarning', 'FTP_SERVER_REACHABLE')
Error_Services('Add', Service : 'service failed. ''An issue connecting to the FTP server has occured.')
end
end service end service
@ -192,7 +203,7 @@ Service GetEarliestDate()
TodayDate = Date() 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.//////////////////////////////////// /////// 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') TempEarliestDate = Iconv(TempEarliestDate, 'D')
LastYearDate = TodayDate - 365 LastYearDate = TodayDate - 365
If LastYearDate LT TempEarliestDate then If LastYearDate LT TempEarliestDate then
@ -217,7 +228,7 @@ End Service
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
Service SetMONACritical(MONAResource=MONAResources, ErrorMessage) 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') Mona_Services('SendBufferedStatus', 'GRP_OPENINSIGHT_MES_OP_FE_COC', MONAResource, 'CRITICAL')
If ErrorMessage NE '' then If ErrorMessage NE '' then
// Log error // Log error
@ -250,7 +261,30 @@ Service SetMONACritical(MONAResource=MONAResources, ErrorMessage)
End Service 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 // ClearMONACritical
// //
@ -261,7 +295,7 @@ End Service
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
Service ClearMONACritical(MONAResource=MONAResources) 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') Mona_Services('SendBufferedStatus', 'GRP_OPENINSIGHT_MES_OP_FE_COC', MONAResource, 'OK')
end else end else
Error_Services('Add', 'Invalid COC MONA resource.') Error_Services('Add', 'Invalid COC MONA resource.')
@ -365,3 +399,4 @@ CompanyExceptionCheck:
return return