Alarm trigger with NICA_ORDERS table

solution tested and ready for deployment

updated SRP_Git_Services to handle creating local copies of inherited entities

updated HgCV OCAP order trigger to also look for active prove-in orders

moved error services common into sysprog to avoid compilation issues
This commit is contained in:
Infineon\StieberD
2024-12-12 13:24:48 -07:00
parent 3cd56295dc
commit ab8f9d3c24
24 changed files with 3167 additions and 1571 deletions

View File

@ -20,8 +20,6 @@ Compile function Reactor_Log_Services(@Service, @Params)
??/??/?? jro Original programmer.
***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
$Insert APP_INSERTS
@ -37,10 +35,10 @@ $Insert REACTOR_EQUATES
Declare function Database_Services, Reactor_Log_Services, Obj_React_Item, Set_Status, Errmsg, Error_Services, Utility
Declare function obj_Calendar, NextKey, SRP_JSON, Datetime, Reactor_Services, React_Servs_Services, Logging_Services
Declare function Environment_Services, HttpClient_Services, SRP_List
Declare function Environment_Services, HttpClient_Services, SRP_List, Nica_Orders_Services
Declare subroutine Set_Status, RList, Errmsg, Database_Services, Error_Services, obj_React_Reads, obj_Post_Log, Delay
Declare subroutine obj_Reactor_Log, Btree.Extract, SRP_JSON, Reactor_Services, Logging_Services, Mona_Services, SRP_List
Declare subroutine Reactor_Log_Services
Declare subroutine Reactor_Log_Services, Nica_Orders_Services
GoToService
@ -89,13 +87,14 @@ Service SignReactorLog(ReactorLogID, UserID)
ErrorMsg = ''
If RowExists('REACTOR_LOG', ReactorLogID) then
// Update any NICA checklist order statuses
Reactor_Log_Services('GetReactorLogPMStatus', ReactorLogID)
Nica_Orders_Services('GetOrderUpdates')
If Error_Services('NoError') then
If RowExists('LSL_USERS', UserID) then
ReactorLogRec = Database_Services('ReadDataRow', 'REACTOR_LOG', ReactorLogID)
If Error_Services('NoError') then
// Verify NICA checklists are complete
If Sum(ReactorLogRec<REACTOR_LOG_CHECKLIST_ACTIVE$>) EQ 0 then
ActiveRlNicaOrders = Nica_Orders_Services('GetActiveOrders', 'REACTOR_LOG', ReactorLogID)
If ActiveRLNicaOrders EQ '' then
// Verify reactor number is populated
ReactorNo = ReactorLogRec<REACTOR_LOG_REACTOR$>
If ReactorNo NE '' then
@ -135,6 +134,7 @@ Service SignReactorLog(ReactorLogID, UserID)
Until ErrorMsg NE ''
Next ServiceID
end
// Check if any react items are missing disposition codes
If ErrorMsg EQ '' then
RemRINos = Xlate('REACTOR_LOG', ReactorLogID, 'REM_RI_NO', 'X')
@ -159,7 +159,6 @@ Service SignReactorLog(ReactorLogID, UserID)
end
end
If ErrorMsg EQ '' then
// Check if we need to "post" any items that are being installed
InstRINo = ReactorLogRec<REACTOR_LOG_INST_RI_NO$>
@ -301,16 +300,10 @@ Service SignReactorLog(ReactorLogID, UserID)
ErrorMsg = 'Error in ':Service:' service. Reactor number is missing.'
end
end else
ActiveCheckLists = ''
CheckListTypes = ReactorLogRec<REACTOR_LOG_CHECKLIST_TYPE$>
CheckListActives = ReactorLogRec<REACTOR_LOG_CHECKLIST_ACTIVE$>
For each CheckListType in CheckListTypes using @VM setting vPos
If CheckListActives<0, vPos> EQ True$ then
ActiveCheckLists := CheckListType:','
end
Next CheckListType
If ActiveCheckLists NE '' then ActiveCheckLists[-1, 1] = ''
ErrorMsg = 'Error in ':Service:' service. NICA order(s) ':ActiveCheckLists:' must be completed prior to signing reactor log.'
ActiveChecklistTypes = Xlate('NICA_ORDERS', ActiveRlNicaOrders, 'ORDER_TYPE', 'X')
Swap @VM with ',' in ActiveChecklistTypes
ErrorMsg = 'Error in ':Service:' service. NICA order(s) ':ActiveChecklistTypes
ErrorMsg := ' must be completed prior to signing reactor log.'
end
end else
ErrorMsg = Error_Services('GetMessage')
@ -907,6 +900,21 @@ Service ConvertJSONToRecord(JSON)
end service
Service GetRlChecklistActive(RLKey)
If RLKey NE '' then
ActiveTubeChangeIds = Nica_Orders_Services('GetActiveOrders', 'REACTOR_LOG', RLKey, 'ASM_HTR_TUBE_CHANGE')
ActiveAnnualPmIds = Nica_Orders_Services('GetActiveOrders', 'REACTOR_LOG', RLKey, 'ASM_HTR_ANNUAL_PM')
ActiveSemiannualPmIds = Nica_Orders_Services('GetActiveOrders', 'REACTOR_LOG', RLKey, 'ASM_HTR_SEMIANNUAL_PM')
ActiveFiveAndTenPmIds = Nica_Orders_Services('GetActiveOrders', 'REACTOR_LOG', RLKey, 'ASM_HTR_FIVE_AND_TEN_YEAR_PM')
Response = ( (ActiveTubeChangeIds NE '') or (ActiveAnnualPmIds NE '') or (ActiveSemiannualPmIds NE '') or (ActiveFiveAndTenPmIds NE '') )
end else
Error_Services('Add', 'Error in ':Service:' service. Null ReactNo passed into service.')
end
end service
Service AddComment(Reactor, NewNote, User)
ReactModeNGKey = Xlate('REACTOR_CHILD_KEY_IDS_NG', Reactor, 'REACT_MODE_KEY_IDS', 'X')
@ -928,348 +936,6 @@ Service AddComment(Reactor, NewNote, User)
end service
Service CreateReactorLogPMOrder(RLNo, PmType=PM_TYPES)
Headers = 'Logging DTM' : @FM : 'Machine' : @FM : 'Log'
ColumnWidths = 20 : @FM : 15 : @FM : 300
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\ReactorLogPM'
makeDirSuccess = Utility("MAKEDIR", LogPath)
LogDate = Oconv(Date(), 'D4/')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_ReactorLogPM.csv'
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
RlRec = Database_Services('ReadDataRow', 'REACTOR_LOG', RLNo)
ReactNo = RlRec<REACTOR_LOG_REACTOR$>
Machine = Environment_Services('GetServer')
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Attempting to create PM order for reactor ':ReactNo:' of type ':PMType
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
CurrentPmTypes = RlRec<REACTOR_LOG_CHECKLIST_TYPE$>
PmTypeAlreadyActive = False$
For each ActivePmType in CurrentPmTypes using @VM setting dummy
If ActivePmType EQ PmType then PmTypeAlreadyActive = True$
Next ActivePmType
If PmTypeAlreadyActive EQ False$ then
RlRec<REACTOR_LOG_CHECKLIST_ACTIVE$> = True$
RlRec<REACTOR_LOG_CHECKLIST_TYPE$, -1> = PmType
// Call the API
NicaURL = Environment_Services("GetProveInApiUrl"):'/checklists?'
NicaURL := 'checklistType=':PmType
NicaURL := '&reactorNumber=':ReactNo
Retries = 3
BackoffSeconds = 1
IsSuccessful = False$
OrderId = ''
Loop
while (IsSuccessful EQ False$ and Retries GT 0)
WaitSeconds = (3 - retries) * BackoffSeconds
Delay(WaitSeconds)
Retries = Retries - 1
HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'POST', NicaURL, 'Accept':@VM:'*/*', '', '', '', False$, False$, '')
If HttpResponseJson NE '' then
ObjResponseJson = ''
If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then
OrderId = SRP_JSON(ObjResponseJson, 'GetValue', 'id')
If orderId NE '' then
IsSuccessful = True$
Response = OrderId
end
end
end
SRP_JSON(ObjResponseJson, 'Release')
Repeat
RlRec<REACTOR_LOG_CHECKLIST_ORDER_ID$, -1> = OrderId
Database_Services('WriteDataRow', 'REACTOR_LOG', RlNo, RlRec, True$, False$, True$)
If Environment_Services('IsProd') then
MonAResource = 'GRP_OPENINSIGHT_MES_OP_FE_MESAPROVEINAPI'
end else
MonAResource = 'GRP_OPENINSIGHT_MES_OP_FE_DEV_MESAPROVEINAPI_DEV'
end
StatusName = 'CreateReactorLogPmOrder'
If IsSuccessful then
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Successfully created PM order for reactor ':ReactNo:' and reactor log ':RlNo:' of type ':PmType
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'ok')
end else
Response = 'error'
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Error encountered when attempting to create PM order for reactor ':ReactNo:' and reactor log ':RlNo:' of type ':PmType
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'critical')
Error_Services('Add', 'Error in ' : Service : ' service. Could not create NICA order.')
end
end
end service
Service CancelReactorLogPMOrder(RlNo, OrderId)
Headers = 'Logging DTM' : @FM : 'Machine' : @FM : 'Log'
ColumnWidths = 20 : @FM : 15 : @FM : 300
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\ReactorLogPM'
makeDirSuccess = Utility("MAKEDIR", LogPath)
LogDate = Oconv(Date(), 'D4/')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_ReactorLogPM.csv'
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
RlRec = Database_Services('ReadDataRow', 'REACTOR_LOG', RlNo)
ReactNo = RlRec<REACTOR_LOG_REACTOR$>
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
Machine = Environment_Services('GetServer')
LogData<2> = Machine
LogData<3> = 'Attempting to cancel PM order ' : OrderId : ' for reactor ' : ReactNo : ' and reactor log ' : RlNo
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Response = False$
BaseNicaUrl = Environment_Services("GetProveInApiUrl"):'/checklists?'
NicaUrl = BaseNicaUrl:'checklistOrderId=':OrderId
NicaUrl := '&checklistState=cancelled'
Retries = 3
BackoffSeconds = 1
IsSuccessful = False$
Loop
while (IsSuccessful EQ False$ and Retries GT 0)
WaitSeconds = (3 - Retries) * BackoffSeconds
Delay(WaitSeconds)
Retries = Retries - 1
HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'PUT', NicaUrl, 'Accept':@VM:'*/*', '', '', '', False$, False$, '')
If HttpResponseJson NE '' then
ObjResponseJson = ''
If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then
IsComplete = SRP_JSON(ObjResponseJson, 'GetValue', 'pendingUpdate')
Response = (IsComplete EQ True$)
end
end
SRP_JSON(ObjResponseJson, 'Release')
IsSuccessful = ( (Response EQ True$) or (Response EQ False$) )
Repeat
If Environment_Services('IsProd') then
MonAResource = 'GRP_OPENINSIGHT_MES_OP_FE_MESAPROVEINAPI'
end else
MonAResource = 'GRP_OPENINSIGHT_MES_OP_FE_DEV_MESAPROVEINAPI_DEV'
end
StatusName = 'UpdateReactorLogPmOrderState'
If IsSuccessful and Response NE 'error' then
PmOrderIds = RlRec<REACTOR_LOG_CHECKLIST_ORDER_ID$>
PmOrderIdList = SRP_List('Create', PmOrderIds, @VM)
PmTypes = RlRec<REACTOR_LOG_CHECKLIST_TYPE$>
PmTypeList = SRP_List('Create', PmTypes, @VM)
For each PmOrderId in PmOrderIds using @VM setting Idx
If OrderId EQ PmOrderId then
SRP_List('RemoveAt', PmOrderIdList, Idx)
SRP_List('RemoveAt', PmTypeList, Idx)
end
Next ProveInOrderId
RlRec<REACTOR_LOG_CHECKLIST_ORDER_ID$> = SRP_List("GetVariable", PmOrderIdList, @VM)
RlRec<REACTOR_LOG_CHECKLIST_TYPE$> = SRP_List("GetVariable", PmTypeList, @VM)
SRP_List('Release', PmTypeList)
OrderIdCount = SRP_List("Count", PmOrderIdList)
SRP_List("Release", PmOrderIdList)
// remove flag if pm passed
If OrderIdCount EQ 0 then RlRec<REACTOR_LOG_CHECKLIST_ACTIVE$> = False$
Database_Services('WriteDataRow', 'REACTOR_LOG', RlNo, RlRec, True$, False$, True$)
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Successfully cancelled PM order ' : PmOrderId : ' for reactor ' : ReactNo : ' and reactor log ' : RlNo
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'ok')
end else
Response = 'error'
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Error encountered cancelling PM order ' : PmOrderId : ' for reactor ' : ReactNo : ' and reactor log ' : RlNo
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'critical')
Error_Services('Add', 'Error in ' : Service : ' service. Could not cancel NICA order')
end
end service
Service GetReactorLogPMStatus(RlNo)
Headers = 'Logging DTM' : @FM : 'Machine' : @FM : 'Log'
ColumnWidths = 20 : @FM : 15 : @FM : 300
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\ReactorLogPm'
makeDirSuccess = Utility("MAKEDIR", LogPath)
LogDate = Oconv(Date(), 'D4/')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_ReactorLogPm.csv'
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
RlRec = Database_Services('ReadDataRow', 'REACTOR_LOG', RlNo)
ReactNo = RlRec<REACTOR_LOG_REACTOR$>
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
Machine = Environment_Services('GetServer')
LogData<2> = Machine
LogData<3> = 'Attempting to fetch pm order for reactor ':ReactNo:' and reactor log ':RlNo
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Response = True$
IsSuccessful = True$
// Check flag on reactor first, then call api if necessary
PmActive = RlRec<REACTOR_LOG_CHECKLIST_ACTIVE$>
If PmActive then
PmOrderIds = RlRec<REACTOR_LOG_CHECKLIST_ORDER_ID$>
PmOrderIdList = SRP_List("Create", PmOrderIds, @VM)
PmTypes = RlRec<REACTOR_LOG_CHECKLIST_TYPE$>
PmTypeList = SRP_List("Create", PmTypes, @VM)
For each PmOrderId in PmOrderIds using @VM setting Idx
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Fetching pm order ':PmOrderId
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
BaseNicaUrl = Environment_Services("GetProveInApiUrl"):'/checklists?'
NicaUrl = BaseNicaUrl:'checklistOrderId=':PmOrderId
Retries = 3
BackoffSeconds = 1
IsSuccessful = False$
Loop
while (IsSuccessful EQ False$ and Retries GT 0)
WaitSeconds = (3 - Retries) * BackoffSeconds
Delay(WaitSeconds)
Retries = Retries - 1
HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'GET', NicaUrl, 'Accept':@VM:'*/*', '', '', '', False$, False$, '')
If HttpResponseJson NE '' then
ObjResponseJson = ''
If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then
IsComplete = SRP_JSON(ObjResponseJson, 'GetValue', 'isComplete')
If IsComplete EQ True$ then
SRP_List('RemoveAt', PmOrderIdList, Idx)
SRP_List('RemoveAt', PmTypeList, Idx)
Response = True$
end else
Response = False$
end
end
end
SRP_JSON(ObjResponseJson, 'Release')
IsSuccessful = ( (Response EQ True$) or (Response EQ False$) )
Repeat
Next PmOrderId
If Environment_Services('IsProd') then
MonAResource = 'GRP_OPENINSIGHT_MES_OP_FE_MESAPROVEINAPI'
end else
MonAResource = 'GRP_OPENINSIGHT_MES_OP_FE_DEV_MESAPROVEINAPI_DEV'
end
StatusName = 'GetReactorLogPmOrderStatus'
If IsSuccessful and Response NE 'error' then
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Successfully fetched pm order for reactor ':ReactNo:' and reactor log ':RlNo
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'ok')
end else
Response = 'error'
LogData = ''
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Error encountered when fetching pm order for reactor ':RlNo
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'critical')
Error_Services('Add', 'Error in ' : Service : ' service. Could not retrieve NICA order status.')
end
RlRec<REACTOR_LOG_CHECKLIST_ORDER_ID$> = SRP_List("GetVariable", PmOrderIdList, @VM)
RlRec<REACTOR_LOG_CHECKLIST_TYPE$> = SRP_List("GetVariable", PmTypeList, @VM)
SRP_List('Release', PmTypeList)
OrderIdCount = SRP_List("Count", PmOrderIdList)
SRP_List("Release", PmOrderIdList)
// remove flag if prove in passed
If OrderIdCount EQ 0 then RlRec<REACTOR_LOG_CHECKLIST_ACTIVE$> = False$
Database_Services('WriteDataRow', 'REACTOR_LOG', RlNo, RlRec, True$, False$, True$)
end
end service
Service UpdateReactorLogPMStatuses()
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
Lock hSysLists, ServiceKeyID then
Open 'DICT.REACTOR_LOG' to hDict then
RLKeys = ''
Query = 'CHECKLIST_ACTIVE':@VM:True$:@FM
Flag = ''
Btree.Extract(Query, 'REACTOR_LOG', hDict, RLKeys, '', Flag)
If Flag EQ 0 then
// Btree.Extract successful
If RLKeys NE '' then
For each RLKey in RLKeys using @VM
Reactor_Log_Services("GetReactorLogPMStatus", RLKey)
Next RLKey
end
end else
Error_Services('Add', 'Error in ':Service:' service. Btree.Extract call failed.')
end
end
Unlock hSysLists, ServiceKeyID else Null
end
end service
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal GoSubs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -1282,6 +948,3 @@ ClearCursors:
return