项目分享-对接一个很坑的WMS系统原创
16人赞赏了该文章
1,257次浏览
编辑于2022年09月08日 10:07:35
当第三方WMS系统是一个很坑的系统 ,没有成熟的框架,没有接口,只是用EasyUi简单搭建的只包含入库单、出库单、物料三部分功能系统时,需要和这个系统进行接口对接。
①和WMS系统确定需要用到的字段,构建对接字段模型。
②编写通用的服务插件(自动提交)和表单插件(手动提交),等WMS系统开发完毕,此处做相应调整。
import clr #添加对cloud插件开发的常用组件的引用 clr.AddReference('System') clr.AddReference('System.Data') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.DataEntity') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS.App') clr.AddReference('Kingdee.BOS.App.Core') clr.AddReference('Kingdee.BOS.ServiceHelper') clr.AddReference("Newtonsoft.Json") #导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入) from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.DependencyRules import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import * from System import * from System.Data import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Core.DynamicForm import * from Kingdee.BOS.Core.Metadata.EntityElement import * from Kingdee.BOS.Core.Metadata.FieldElement import * from Kingdee.BOS.Orm.DataEntity import * from Newtonsoft.Json import JsonConvert from Newtonsoft.Json.Linq import * def BarItemClick(e): key=e.BarItemKey.ToUpperInvariant(); if(key=="TOWMS"): fid=this.View.Model.GetPKValue(); billid=str(this.View.BillBusinessInfo.GetForm().Id); operationName="audit"; strwhere=" and FDOTYPE='" + operationName + "' and FERPBILLTYPE='" + this.View.BusinessInfo.GetForm().Id+"'" sql="/*dialect*/SELECT TOP 1 FID, FMtable,FLtable,FHPARAM,FEPARAM FROM T_WHKF_OAMODEL where FDOCUMENTSTATUS='C' "+strwhere; #this.View.ShowMessage(sql); ds=DBServiceHelper.ExecuteDataSet(this.Context,sql); AllRows=ds.Tables[0].Rows if(AllRows.Count<=0): return; for r in AllRows: tmpsqlM=str(r["FMtable"]); oaid=str(r["FID"]); tmpsqlM=tmpsqlM.replace("@fid","'"+fid+"'"); tmpsqlL=str(r["FLtable"]); tmpsqlL=tmpsqlL.replace("@fid","'"+fid+"'"); posturl=str(r["FHPARAM"]); body=str(r["FEPARAM"]); dsm=DBServiceHelper.ExecuteDataSet(this.Context,tmpsqlM); tabm=dsm.Tables[0]; if(tabm.Rows.Count<=0): continue; mjson=JsonConvert.SerializeObject(tabm); dsl = DBServiceHelper.ExecuteDataSet(this.Context,tmpsqlL); tabl=dsl.Tables[0]; ljson=JsonConvert.SerializeObject(tabl); body=body.replace("{0}",mjson); body=body.replace("{1}",ljson); msg=ToPost(posturl,body,"application/x-www-form-urlencoded",""); #this.View.ShowMessage(msg); logsql=("""/*dialect*/insert into T_ORA_WMSLOG (fid,FBILL,FPKID,FNUMBER,FDATE,FREQUEST,FRESULT,FABOUTID,FDOTYPE,FUSER) values (RIGHT(100000000 + CONVERT(bigint, ABS(CHECKSUM(NEWID()))), 8),'{0}','{1}','{2}',GETDATE(),'{3}','{4}','{5}','{6}','{7}')""").format(billid,fid,"",body,msg,oaid,operationName+"后自动触发",this.Context.UserId) DBServiceHelper.Execute(this.Context,logsql); fanxiesql=("/*dialect*/exec StrFromWms '{0}','{1}','{2}','{3}'").format(billid,fid,msg,this.Context.UserId) DBServiceHelper.Execute(this.Context,fanxiesql); this.View.ShowMessage(msg); def ToPost(posturl,postdata,ftype,fcookie): return "WMS没开发,返回原数据:"+postdata webRequest=HttpWebRequest.Create(posturl) webRequest.Method="POST" if(fcookie<>"" and fcookie!=None): webRequest.Headers.Add("Cookie",fcookie) #webRequest.Headers.Add("Cookie", "kdservice-sessionid=6e1511ab-2f15-4760-8b19-6b46d422a5e3") if(ftype<>""): webRequest.ContentType=ftype #webRequest.ContentType="application/x-www-form-urlencoded" data=Encoding.ASCII.GetBytes(postdata) webRequest.ContentLength=data.Length webRequest.GetRequestStream().Write(data,0,data.Length) webRequest.GetRequestStream().Flush() webRequest.GetRequestStream().Close() webResponse=webRequest.GetResponse() streamReader=StreamReader(webResponse.GetResponseStream(),Encoding.GetEncoding("utf-8")) result=streamReader.ReadToEnd() return result
③创建日志单据
④创建回调参数存储过程,根据WMS返回内容,进行自定义处理。
exec StrFromWms '单据对象','单据内码','WMS返回内容','当前用户'
推荐阅读