一、获取泛微OA的Webservices地址。
在对应的文件下面生成 T100目录/aws/4gl下以下命令:
fglwsdl [-command] <filename | url | regex value>
fglwsdl -o aws_work_test http://192.168.X.X/services/NibWorkflowService?wsdl
只在对应目录下生成两个4gl/inc文件
直接调用里面的function即可。
二、编写发送端代码
PRIVATE FUNCTION aint311_OAinsert()
DEFINE l_n,l_i,l_i1 LIKE type_t.num5
DEFINE l_sql STRING
DEFINE l_request STRING
DEFINE l_cnt1,l_cnt2,l_cnt3,l_cnt4,l_msglength,l_msglength2 LIKE type_t.num5
DEFINE l_msg LIKE type_t.chr1000
DEFINE l_msg1 LIKE type_t.chr1000
DEFINE li_result STRING
DEFINE li_msg STRING
#单头数据
DEFINE l_inbi RECORD
DJBH LIKE inbi_t.inbidocno, #单据编号
SQRY LIKE inbi_t.inbi001, #申请人
SQBM LIKE inbi_t.inbi002, #申请部门
SQRQ LIKE inbi_t.inbidocdt, #申请日期
BFYY LIKE inbi_t.inbi003, #报废原因
BZ LIKE inbi_t.inbi021 #备注
END RECORD
#单身数据
DEFINE l_inbj DYNAMIC ARRAY OF RECORD
WLBH LIKE inbj_t.inbj001, #料件编号
PMGG LIKE imaal_t.imaal003, #品名
GG LIKE imaal_t.imaal004, #规格
DW LIKE inbj_t.inbj008, #单位
BFSL LIKE inbj_t.inbj009, #报废数量
ZL LIKE inbj_t.inbjud001, #重量
KW LIKE inbj_t.inbj005, #库位
PH LIKE inbj_t.inbj007, #批号(inbj007)
BZ LIKE inbj_t.inbj031, #备注(inbj031)
GSBM LIKE inbj_t.inbj017 #归属部门
END RECORD
DEFINE g_logtime string
DEFINE tmpXmlFile string
DEFINE r_success LIKE type_t.num5
LET r_success = TRUE
#日志相关记录
LET g_logtime = YEAR(CURRENT) USING "####", MONTH(CURRENT) USING "&&",DAY(CURRENT) USING "&&","-", TIME(CURRENT)
LET g_time = TIME
#抓单头数据
LET l_sql = " SELECT INBIDOCNO,INBI001,INBI002,INBIDOCDT,INBI003,INBI021 FROM INBI_T ",
" WHERE INBIDOCNO = '",g_inbi_m.inbidocno,"' ",
" AND INBIENT = '",g_enterprise,"' AND INBISITE = '",g_site,"' "
PREPARE l_pre1 FROM l_sql
DECLARE l_cur1 CURSOR FOR l_pre1
FOREACH l_cur1 INTO l_inbi.DJBH,l_inbi.SQRY,l_inbi.SQBM,
l_inbi.SQRQ,l_inbi.BFYY,l_inbi.BZ
IF SQLCA.SQLCODE THEN
INITIALIZE g_errparam TO NULL
LET g_errparam.extend = "Foreach:",SQLERRMESSAGE
LET g_errparam.code = SQLCA.SQLCODE
LET g_errparam.popup = TRUE
CALL cl_err()
EXIT FOREACH
END IF
#抓取单身数据
LET l_sql = " SELECT INBJ001,IMAAL003, IMAAL004,INBJ008,INBJ009,INBJUD001,INBJ005,INBJ007,INBJ031,INBJ017 ",
" FROM INBJ_T LEFT JOIN IMAAL_T ON INBJ001 = IMAAL001 AND IMAALENT = '",g_enterprise,"' ",
" WHERE INBJDOCNO = '",g_inbi_m.inbidocno,"' AND inbjent = '",g_enterprise,"' AND inbjsite = '",g_site,"' ",
" ORDER BY inbjseq "
PREPARE l_pre2 FROM l_sql
DECLARE l_cur2 CURSOR FOR l_pre2
LET l_n = 1
FOREACH l_cur2 INTO l_inbj[l_n].WLBH,l_inbj[l_n].PMGG,l_inbj[l_n].GG,l_inbj[l_n].DW,
l_inbj[l_n].BFSL,l_inbj[l_n].ZL,l_inbj[l_n].KW,
l_inbj[l_n].PH,l_inbj[l_n].BZ,l_inbj[l_n].GSBM
IF SQLCA.SQLCODE THEN
INITIALIZE g_errparam TO NULL
LET g_errparam.extend = "Foreach:",SQLERRMESSAGE
LET g_errparam.code = SQLCA.SQLCODE
LET g_errparam.popup = TRUE
CALL cl_err()
EXIT FOREACH
END IF
IF cl_null(l_inbj[l_n].ZL) THEN
LET l_inbj[l_n].ZL = 0
END IF
LET l_n = l_n + 1
END FOREACH
END FOREACH
#组xml
LET l_request = " <?xml version='1.0' encoding='UTF-8'?>",
" <root>",
" <systoken>",
" <syskey>1aa8c155-dcfe-4472-9bfd-55c38c6c47fa </syskey>",
" <syscode>40CE39723A270D4EB9F0D98A234C10A3</syscode>",
" </systoken>",
" <description>",
" <workflowid>58</workflowid>", #流程代码
" <workflowhrmtransrule>3</workflowhrmtransrule>",
" <workflowname>",g_inbi_m.inbidocno,"</workflowname>", #流程名称
" <workflowcreater>",g_inbi_m.inbi001,"</workflowcreater>", #流程发起人
" <workflowlevel>0</workflowlevel>",
" </description>",
" <maintable>",
" <DJBH>",l_inbi.DJBH CLIPPED,"</DJBH>", #单据编号
" <SQRY type='hrm'>",l_inbi.SQRY CLIPPED,"</SQRY>", #申请人
" <SQBM type='department'>",l_inbi.SQRY CLIPPED,"</SQBM>", #申请部门
" <SQRQ>",l_inbi.SQRQ CLIPPED,"</SQRQ>", #申请日期
" <BFYY>",l_inbi.BFYY CLIPPED,"</BFYY>", #报废原因
" <BZ>",l_inbi.BZ,"</BZ>", #备注
" </maintable>",
" <detailtables>",
" <detailtable>"
FOR l_i = 1 TO l_n-1
LET l_request = l_request,
" <row>",
" <WLBH>",l_inbj[l_i].WLBH CLIPPED,"</WLBH>", #料件编号
" <PMGG>",l_inbj[l_i].PMGG CLIPPED,"</PMGG>", #品名
" <GG>",l_inbj[l_i].GG CLIPPED,"</GG>", #规格
" <DW>",l_inbj[l_i].DW CLIPPED,"</DW>", #单位
" <BFSL>",l_inbj[l_i].BFSL CLIPPED,"</BFSL>", #报废数量
" <ZL>",l_inbj[l_i].ZL CLIPPED,"</ZL>", #重量
" <KW>",l_inbj[l_i].KW CLIPPED,"</KW>", #库位
" <PH>",l_inbj[l_i].PH CLIPPED,"</PH>", #批号
" <BZ>",l_inbj[l_i].BZ CLIPPED,"</BZ>", #备注
" <GSBM>",l_inbj[l_i].GSBM CLIPPED,"</GSBM>", #归属部门
" </row>"
END FOR
LET l_request = l_request,
" </detailtable>",
" </detailtables>",
"</root>"
#记录接收集成日志
LET tmpXmlFile = "/ut/toptst/log/INTO_WMS_",g_inbi_m.inbidocno,"_",g_logtime,".log"
RUN "echo '"||l_request||"' > "||tmpXmlFile
#往OA传数据
CALL createWorkflowByXml(l_request) RETURNING li_result,li_msg
LET l_msg = li_msg
IF li_result !='0' THEN
LET r_success = FALSE
LET g_errparam.extend = "送签失败"
LET g_errparam.popup = TRUE
CALL cl_err() #送签失败
ELSE
IF NOT cl_null(l_msg) THEN
SELECT instr(l_msg, '>',1,2) INTO l_cnt1 FROM DUAL #找第2个>的位置
SELECT instr(l_msg, '<',1,3) INTO l_cnt2 FROM DUAL #找第3个<的位置
IF l_cnt2 - l_cnt1 =1 THEN #无OA流程号,送签失败
#定位errmsg的位置
SELECT SUBSTR(l_msg,instr(l_msg, '>',1,6)+1,instr(l_msg, '<',1,7)-instr(l_msg, '>',1,6)-1) into l_msg1 FROM DUAL
INITIALIZE g_errparam TO NULL
LET g_errparam.code = '!'
LET g_errparam.extend = l_msg1
LET g_errparam.popup = TRUE
CALL cl_err()
LET r_success = FALSE
END IF
END IF
#记录返回日志
LET tmpXmlFile = "/ut/toptst/log/RETURN_WMS_",g_inbi_m.inbidocno,"_",g_logtime,".log"
RUN "echo '"||li_msg||"' > "||tmpXmlFile
END IF
RETURN r_success
END FUNCTION
三、改写报废单上的单据状态
#核心逻辑
IF lc_state = 'O' AND l_status = "confirm" THEN
IF cl_ask_confirm("aim-00108") THEN
CALL s_aint311_cnf_chk(g_inbi_m.inbidocno) RETURNING g_success
IF g_success THEN
CALL s_transaction_begin()
CALL s_aint311_cnf_upd(g_inbi_m.inbidocno) RETURNING g_success
IF g_success THEN
#CALL s_transaction_end('Y','0')
#审核完毕提交事务,然后送去OA
CALL aint311_OAinsert() RETURNING g_success
#OA送签
IF g_success THEN #判断OA是否送签成功
CALL s_transaction_end('Y','0')
LET lc_state = 'W'
ELSE
CALL s_transaction_end('N','0')
LET g_action_choice = "statechange"
RETURN
END IF
ELSE
CALL s_transaction_end('N','1')
LET g_action_choice = "statechange"
RETURN
END IF
ELSE
CALL s_transaction_end('N','0')
RETURN
END IF
ELSE
CALL s_transaction_end('N','0')
RETURN
END IF
END IF
四、OA送签流程结束后,反写ERP的单据状态
Demo中没有调用系统标准的审核逻辑。开发时请注意这个细节。
PRIVATE FUNCTION cwssp310_process()
#add-point: 服務邏輯主要處理段的ADP name="cwssp310.process"
DEFINE l_inbidocno LIKE inbi_t.inbidocno, #单据编号
l_stus LIKE type_t.chr1 #状态
LET l_inbidocno = awsp900_01_getParameter("inbidocno")
LET l_stus = awsp900_01_getParameter("stus")
#1 审核 2 提醒 3 归档
IF l_stus = '3' THEN #审核
LET l_stus = 'O'
UPDATE inbi_t SET inbistus = l_stus
WHERE inbient = g_enterprise
AND inbidocno = l_inbidocno
IF SQLCA.sqlcode THEN
INITIALIZE g_errparam TO NULL
LET g_errparam.code = SQLCA.sqlcode
LET g_errparam.extend = 'upd_stus'
LET g_errparam.popup = FALSE
CALL cl_err()
END IF
END IF
IF l_stus = '0' THEN
LET l_stus = 'N' #退回
UPDATE inbi_t SET inbistus = l_stus
WHERE inbient = g_enterprise
AND inbidocno = l_inbidocno
IF SQLCA.sqlcode THEN
INITIALIZE g_errparam TO NULL
LET g_errparam.code = SQLCA.sqlcode
LET g_errparam.extend = 'upd_stus'
LET g_errparam.popup = FALSE
CALL cl_err()
END IF
END IF
#end add-point
END FUNCTION