z Ws Object Send

download z Ws Object Send

If you can't read please download the document

description

Teste Upload

Transcript of z Ws Object Send

#ZWSOBJECTSEND.SAVEfrom com.ibm.tivoli.maximo.interaction.process import InteractionProcesserdef importScript(): script = None from psdi.server import MXServer mxserver = MXServer.getMXServer() sysuser = mxserver.getSystemUserInfo() impSet = mxserver.getMboSet("AUTOSCRIPT",sysuser) impSet.setWhere("AUTOSCRIPT='IMPORTS'") imp = impSet.moveFirst() if imp != None: script = imp.getString("SOURCE") impSet.close() return scriptexec(importScript())def zwoesristatus(wonum, status, ldstatus): esristatusSet = getMboSet("ZWOESRISTATUS") esristatusSet.setWhere(toSQL("WONUM='?'",wonum)) esristatus = esristatusSet.moveFirst() if esristatus == None: esristatus = esristatusSet.add() esristatus.setValue("WONUM",wonum,2) esristatus.setValue("STATUS", status, 2) esristatus.setValue("STATUS_LONGDESCRIPTION", ldstatus, 2) saveClose(esristatusSet)def sendWOStatus(log,wo): ztype = wo.getMboSet("ZTYPES").moveFirst() ztypewo = wo.getMboSet("ZTYPESWO").moveFirst() from java.text import SimpleDateFormat xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") wsSet = wo.getMboSet('ZWSWO1') header = wsSet.add() header.setValue("TRACKINGID",str(Date().getTime()),11) header.setValue("CREATIONTIME", xmlDate.format(Date()),11)# header.setValue("LOGIN", wo.getString("CHANGEBY"), 11) history = header.getMboSet("ZWSWO3").add() #TIBCO history.setValue("OWNER", wo.getString("CHANGEBY"), 11) history.setValue("DOMAIN", 'APP_MAXIMO', 11) history.setValue("TYPE", 'Interfaces', 11) history.setValue("SERVICENAME",'ZWOESRISTATUS.STATUS.ACTION', 11) history.setValue("ACTION", 'ACTION', 11) history.setValue("VERSION", '1.0', 11) history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11) history.setValue("COMPONENT", 'ZWOTRACK', 11) history.setValue("TRANSPORT", '', 11) history.setValue("SUBJECT", '', 11) history.setValue("STEP", '1', 11) history.setValue("APPLICATION", 'MAXIMO', 11) history.setValue("TRACKINGID", header.getString("TRACKINGID"), 11) #WORKORDER ot = header.getMboSet("ZWSWO16").add() if not wo.isNull("ZCODEMPRESA"): ot.setValue("EMPRESA_CODEMPRESA", wo.getString("ZCODEMPRESA"), 11) ot.setValue("ZWSWO16_CODORDEMTRABALHO", wo.getString("WONUM"), 11) if not wo.isNull("ZCODIGOORDEM"): ot.setValue("ZWSWO16_CODORDEMTRABALHO", wo.getString("ZCODIGOORDEM"), 11) ot.setValue("ZWSWO16_DESCRICAO", wo.getString("DESCRIPTION"), 11) ot.setValue("ZWSWO16_DATACRIACAO", xmlDate.format(wo.getDate("REPORTDATE")), 11) ot.setValue("ZWSWO16_CODSTATUS", wo.getString("STATUS"), 11) ot.setValue("ZWSWO16_TIPOOBJETO", wo.getString("ZTYPE"), 11) ot.setValue("ZWSWO16_TIPOORDEMTRABALHO", wo.getString("WORKTYPE"), 11) ot.setValue("ZWSWO16_FLAGMULTIPLO", "0", 11) if ztype != None and ztype.getBoolean("ESRIMULTISELECT"): ot.setValue("ZWSWO16_FLAGMULTIPLO", "1", 11) ot.setValue("ZWSWO16_FLAGEDICAO", "0", 11) if ztypewo != None and ztypewo.getBoolean("ESRIEDICAO"): ot.setValue("ZWSWO16_FLAGEDICAO", "1", 11) if wo.getString("STATUS") == 'APPR': ot.setValue("ZWSWO16_CODATIVIDADE", 'JB007',11) ot.setValue("ZWSWO16_CODACAO", 'AV002', 11) if wo.getString("STATUS") == 'EXEC': ot.setValue("ZWSWO16_CODATIVIDADE", 'JB008',11) ot.setValue("ZWSWO16_CODACAO", 'AV001', 11) ot.setValue("ZWSWO16_MEDIDAINICIO", str(wo.getDouble("LINEARRELATED.STARTMEASURE")), 11) ot.setValue("ZWSWO16_MEDIDAFIM", str(wo.getDouble("LINEARRELATED.ENDMEASURE")), 11) ot.setValue("ZWSWO16_IDCARTA", wo.getString("LOCATION.ZCARTA.ZCODSIGAS"), 11) ot.setValue("ZWSWO16_DATAACAO", xmlDate.format(wo.getDate("STATUSDATE")), 11) ot.setValue("ZWSWO16_DIAMETRORAMAL", wo.getString("ZDIAMETRO"), 11) ot.setValue("ZWSWO16_MATERIALRAMAL", wo.getString("ZMATERIAL"), 11) ot.setValue("ZWSWO16_COMPRIMENTORAMAL", str(wo.getInt("ZCOMPRIMENTO")), 11) ot.setValue("ZWSWO16_COMENTARIOS", wo.getString("ZCOMENTARIOS"), 11) #ver o comentrio se vale a pena enviar #procura os ativos na MULTIASSETLOCCI ativos = [] for mulci in MboSetIterator(wo.getMboSet("MULTIASSETLOCCI")): if not mulci.isNull("ZCODSIGAS"): ativos.append(mulci.getString("ZCODSIGAS")) if len(ativos) == 0 and not wo.isNull("ZCODSIGAS"): ativos.append(wo.getString("ZCODSIGAS")) codigoAtivoSet = ot.getMboSet("ZWSWO17") for ativosItr in ativos: if ativosItr != '': codigoAtivo = codigoAtivoSet.add() codigoAtivo.setValue("ZWSWO17_CODATIVO", ativosItr, 11) interaction = InteractionProcesser('ZWSWO') close(wsSet) log.start() interaction.invokeservice(wo) log.stop()def sendWOFat(log,wo): from java.text import SimpleDateFormat xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") wsSet = wo.getMboSet('ZWSPC1') header = wsSet.add() header.setValue("TRACKINGID",str(Date().getTime()),11) header.setValue("CREATIONTIME", xmlDate.format(Date()),11)# header.setValue("LOGIN", wo.getString("CHANGEBY"), 11) #TIBCO history = header.getMboSet("ZWSPC3").add() history.setValue("OWNER", wo.getString("CHANGEBY"), 11) history.setValue("DOMAIN", 'APP_MAXIMO', 11) history.setValue("TYPE", 'Interfaces', 11) history.setValue("SERVICENAME",'ZWSPC', 11) history.setValue("ACTION", 'ACTION', 11) history.setValue("VERSION", '1.0', 11) history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11) history.setValue("COMPONENT", 'ZWOTRACK', 11) history.setValue("TRANSPORT", '', 11) history.setValue("SUBJECT", '', 11) history.setValue("STEP", '1', 11) history.setValue("APPLICATION", 'MAXIMO', 11) history.setValue("TRACKINGID", header.getString("TRACKINGID"), 11) #WORKORDER ot = header.getMboSet("ZWSPC16").add() ot.setValue("EMPRESA_CODEMPRESA", wo.getString("ZCODEMPRESA"), 11) ot.setValue("ZWSPC16_CODATIVIDADE", 'JB002', 11) #recepcao do resultado da fatibilidade ot.setValue("ZWSPC16_CODPROCESSOCONS7441", wo.getString("ZCODPROCESSOCONSTRUCAOPAI"), 11) ot.setValue("ZWSPC16_CODAPRECIACAO", wo.getString("ZSRFATIBILIDADE.ZRESULTADO"), 11) ot.setValue("ZWSPC16_COMENTARIOS", None, 11) interaction = InteractionProcesser('ZWSPC') close(wsSet) interaction.invokeservice(wo)def sendAtivoReply(log,zp_eai_header): from java.text import SimpleDateFormat xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") ci = getMbo("CI","1=1") ciSet = ci.getMboSet('ZWSATIVOREPLAY1') header = ciSet.add() header.setValue("TRACKINGID",str(Date().getTime()),11) header.setValue("CREATIONTIME", xmlDate.format(Date()),11)# header.setValue("LOGIN", wo.getString("CHANGEBY"), 11) #TIBCO history = header.getMboSet("ZWSATIVOREPLAY3").add() history.setValue("OWNER", 'MAXADMIN', 11) history.setValue("DOMAIN", 'APP_MAXIMO', 11) history.setValue("TYPE", 'Interfaces', 11) history.setValue("SERVICENAME",'ZWSPC', 11) history.setValue("ACTION", 'ACTION', 11) history.setValue("VERSION", '1.0', 11) history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11) history.setValue("COMPONENT", 'ZWOTRACK', 11) history.setValue("TRANSPORT", '', 11) history.setValue("SUBJECT", '', 11) history.setValue("STEP", '1', 11) history.setValue("APPLICATION", 'MAXIMO', 11) history.setValue("TRACKINGID", zp_eai_header.getString("TRACKINGID"), 11) interaction = InteractionProcesser('ZWSATIVOREPLAY') close(ciSet) interaction.invokeservice(ci) def sendWOAva(log,wo): from java.text import SimpleDateFormat xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") wsSet = wo.getMboSet('ZWSPC1') header = wsSet.add() header.setValue("TRACKINGID",str(Date().getTime()),11) header.setValue("CREATIONTIME", xmlDate.format(Date()),11) #TIBCO history = header.getMboSet("ZWSPC3").add() history.setValue("OWNER", wo.getString("CHANGEBY"), 11) history.setValue("DOMAIN", 'APP_MAXIMO', 11) history.setValue("TYPE", 'Interfaces', 11) history.setValue("SERVICENAME",'ZWSPC', 11) history.setValue("ACTION", 'ACTION', 11) history.setValue("VERSION", '1.0', 11) history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11) history.setValue("COMPONENT", 'ZWOTRACK', 11) history.setValue("TRANSPORT", '', 11) history.setValue("SUBJECT", '', 11) history.setValue("STEP", '1', 11) history.setValue("APPLICATION", 'MAXIMO', 11) history.setValue("TRACKINGID", header.getString("TRACKINGID"), 11) #WORKORDER ot = header.getMboSet("ZWSPC16").add() ot.setValue("EMPRESA_CODEMPRESA", wo.getString("ZCODEMPRESA"), 11) ot.setValue("ZWSPC16_CODATIVIDADE", 'JB005', 11) #recepcao do resultado da fatibilidade# ot.setValue("ZWSPC16_CODPROCESSOCONS7441", wo.getString("ZCODPROCESSOCONSTRUCAOPAI"), 11) ot.setValue("ZWSPC16_CODPROCESSOCONS", wo.getString("ZCODPROCESSOCONSTRUCAO"), 11) ot.setValue("ZWSPC16_CODAPRECIACAO", wo.getString("ZSRAVA.ZRESULTADO"), 11) ot.setValue("ZWSPC16_COMENTARIOS", None, 11) close(wsSet) interaction = InteractionProcesser('ZWSPC') log.start() interaction.invokeservice(wo) log.stop() def sentExpReplay(log,zp_eai_header): from java.text import SimpleDateFormat xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") keySet = zp_eai_header.getMboSet("ZP_EAI_LOG_KEYS") keySet.setWhere("FIELD='ZWS_EXP_SYNCID'") keySet.reset() keyvalue = keySet.moveFirst() close(keySet) if keyvalue == None: return zws_exp_sync = getMbo("ZWS_EXP_SYNC",toSQL("ZWS_EXP_SYNCID=?",keyvalue.getString("VALUE"))) close(zws_exp_sync) if zws_exp_sync == None: return wo = getMbo("WORKORDER","1=1") wsSet = wo.getMboSet('ZWSPCREPLY1') header = wsSet.add() header.setValue("TRACKINGID",str(Date().getTime()),11) header.setValue("CREATIONTIME", xmlDate.format(Date()),11)# header.setValue("LOGIN", wo.getString("CHANGEBY"), 11) #TIBCO history = header.getMboSet("ZWSPCREPLY3").add() history.setValue("OWNER", wo.getString("CHANGEBY"), 11) history.setValue("DOMAIN", 'APP_MAXIMO', 11) history.setValue("TYPE", 'Interfaces', 11) history.setValue("SERVICENAME",'ZWSPC', 11) history.setValue("ACTION", 'ACTION', 11) history.setValue("VERSION", '1.0', 11) history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11) history.setValue("COMPONENT", 'ZWOTRACK', 11) history.setValue("TRANSPORT", '', 11) history.setValue("SUBJECT", '', 11) history.setValue("STEP", '1', 11) history.setValue("APPLICATION", 'MAXIMO', 11) history.setValue("TRACKINGID", zp_eai_header.getString("TRACKINGID"), 11) ot = header.getMboSet("ZWSPCREPLY16").add() ot.setValue("ZWSPCREPLY16_CODSTATUS", zp_eai_header.getString("NCODE"), 11) ot.setValue("ZWSPCREPLY16_DESCSTATUS", zp_eai_header.getString("NDESCRIPTION"), 11) ot.setValue("EMPRESA_CODEMPRESA", zws_exp_sync.getString("CODEMPRESA"), 11) ot.setValue("ZWSPCREPLY16_CODPROCESS9592", zws_exp_sync.getString("CODPROCESSOCONSTRUCAOPAI"), 11) ot.setValue("ZWSPCREPLY16_CODPROCESS", zws_exp_sync.getString("CODPROCESSOCONSTRUCAO"), 11) interaction = InteractionProcesser('ZWSPCREPLY') close(wsSet) close(wo) log.start() interaction.invokeservice(wo) log.stop()def sentOtReplay(log,zp_eai_header): from java.text import SimpleDateFormat xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") keySet = zp_eai_header.getMboSet("ZP_EAI_LOG_KEYS") keySet.setWhere("FIELD='ZWS_OT_SYNCID'") keySet.reset() keyvalue = keySet.moveFirst() close(keySet) if keyvalue == None: return zws_ot_sync = getMbo("ZWS_OT_SYNC",toSQL("ZWS_OT_SYNCID=?",keyvalue.getString("VALUE"))) close(zws_ot_sync) if zws_ot_sync == None: return wo = getMbo("WORKORDER","1=1") wsSet = wo.getMboSet('ZWSWOREPLY1') header = wsSet.add() header.setValue("TRACKINGID",str(Date().getTime()),11) header.setValue("CREATIONTIME", xmlDate.format(Date()),11)# header.setValue("LOGIN", wo.getString("CHANGEBY"), 11) #TIBCO history = header.getMboSet("ZWSWOREPLY3").add() history.setValue("OWNER", wo.getString("CHANGEBY"), 11) history.setValue("DOMAIN", 'APP_MAXIMO', 11) history.setValue("TYPE", 'Interfaces', 11) history.setValue("SERVICENAME",'ZWSPC', 11) history.setValue("ACTION", 'ACTION', 11) history.setValue("VERSION", '1.0', 11) history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11) history.setValue("COMPONENT", 'ZWOTRACK', 11) history.setValue("TRANSPORT", '', 11) history.setValue("SUBJECT", '', 11) history.setValue("STEP", '1', 11) history.setValue("APPLICATION", 'MAXIMO', 11) history.setValue("TRACKINGID", zp_eai_header.getString("TRACKINGID"), 11) ot = header.getMboSet("ZWSWOREPLY16").add() ot.setValue("ZWSWOREPLY16_CODSTATUS", zp_eai_header.getString("NCODE"), 11) ot.setValue("ZWSWOREPLY16_DESCSTATUS", zp_eai_header.getString("NDESCRIPTION"), 11) ot.setValue("PROCESSOCONSTRUCAO_CODP1113", zws_ot_sync.getString("CODEXPEDIENTEPAI"), 11) ot.setValue("PROCESSOCONSTRUCAO_CODP", zws_ot_sync.getString("CODEXPEDIENTERAMAL"), 11) ot.setValue("ZWSWOREPLY16_CODORDEMTR", zws_ot_sync.getString("CODIGOORDEM"), 11) ot.setValue("EMPRESA_CODEMPRESA", zws_ot_sync.getString("CODEMPRESA"), 11) interaction = InteractionProcesser('ZWSWOREPLY') close(wsSet) close(wo) log.start() interaction.invokeservice(wo) log.stop() objectname = mbo.getString("OBJECTNAME")objectid = mbo.getString("OBJECTID")status = mbo.getString("STATUS")wsname = mbo.getString("WSNAME")delete = False if wsname == 'OT' and status == 'PEND': zwoesristatus(objectid,'SEND',None) #envio da OT para o esriif wsname == 'OT' and status == 'SENT': wo = getMbo("WORKORDER",toSQL("WONUM='?'",objectid)) if wo != None: log = Log() log.setOutbound('ZWSObjectSend(OT)') log.setKeyValue('codOrdemTrabalho',objectid) wonum = wo.getString("WONUM") try: sendWOStatus(log,wo) except: type, value, traceback = sys.exc_info() if 'BMXAA4214E' not in value.message: zwoesristatus(wonum,'ERR_COM',value.message) log.setError(sys) else: zwoesristatus(wonum,'WAIT',None) log.setError(None) log.save() close(wo) delete = True #envio do reply do IF ZWS_EXP_SYNCif wsname == 'ZWS_OT_SYNC' and status == 'SENT': zp_eai_header = getMbo("ZP_EAI_LOG_HEADER",toSQL("ZP_EAI_LOG_HEADERID=?",objectid)) if zp_eai_header != None: log = Log() log.setOutbound('ZWS_OT_SYNC_REPLY') log.setKeyValue('ZP_EAI_LOG_HEADERID',objectid) try: sentOtReplay(log,zp_eai_header) except: type, value, traceback = sys.exc_info() if 'BMXAA4214E' not in value.message: log.setError(sys) else: log.setError(None) log.save() close(zp_eai_header) delete = True#envio do reply do IF ZWS_EXP_SYNCif wsname == 'ZWS_EXP_SYNC' and status == 'SENT': zp_eai_header = getMbo("ZP_EAI_LOG_HEADER",toSQL("ZP_EAI_LOG_HEADERID=?",objectid)) if zp_eai_header != None: log = Log() log.setOutbound('ZWS_EXP_SYNC_REPLY') log.setKeyValue('ZP_EAI_LOG_HEADERID',objectid) try: sentExpReplay(log,zp_eai_header) except: type, value, traceback = sys.exc_info() if 'BMXAA4214E' not in value.message: log.setError(sys) else: log.setError(None) log.save() close(zp_eai_header) delete = True #envio do status da Fatibilidadeif wsname == 'FAT' and status == 'SENT': wo = getMbo("WORKORDER",toSQL("WONUM='?'",objectid)) if wo != None: log = Log() log.setOutbound('ZWSObjectSend(FAT)') log.setKeyValue('codOrdemTrabalho',objectid) try: sendWOFat(log,wo) except: type, value, traceback = sys.exc_info() if 'BMXAA4214E' not in value.message: log.setError(sys) else: log.setError(None) log.save() close(wo) delete = True#envio do status do AVAif wsname == 'AVA' and status == 'SENT': wo = getMbo("WORKORDER",toSQL("WONUM='?'",objectid)) if wo != None: log = Log() log.setOutbound('ZWSObjectSend(AVA)') log.setKeyValue('codOrdemTrabalho',objectid) try: sendWOAva(log,wo) except: type, value, traceback = sys.exc_info() if 'BMXAA4214E' not in value.message: log.setError(sys) else: log.setError(None) log.save() close(wo) delete = Trueif wsname == 'ZWS_CI_SYNC' and status == 'SENT': zp_eai_header = getMbo("ZP_EAI_LOG_HEADER",toSQL("ZP_EAI_LOG_HEADERID=?",objectid)) if zp_eai_header != None: log = Log() log.setOutbound('ZWSATIVOREPLAY') log.setKeyValue('ZP_EAI_LOG_HEADERID',objectid) try: sendAtivoReply(log,zp_eai_header) except: type, value, traceback = sys.exc_info() if 'BMXAA4214E' not in value.message: log.setError(sys) else: log.setError(None) log.save() close(zp_eai_header) delete = True if delete: mbo.delete(11)