首页 > 数据库 >金蝶云星空批量插入单据到数据库

金蝶云星空批量插入单据到数据库

时间:2024-10-31 10:44:05浏览次数:1  
标签:星空 金蝶 BOS newBillObj Cast 单据 BPW dr FID

##****************************服务插件*******************
#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('System.Data')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.BOS.App.Core')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.Contracts')
clr.AddReference('Kingdee.BOS.ServiceHelper')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.DataEntity 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 Kingdee.BOS.App.Core import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Util import*

ObjList=None;
def OnPreparePropertys(e):
e.FieldKeys.Add("FBillTypeID");
e.FieldKeys.Add("FPAYORGID");
e.FieldKeys.Add("F_DFYHZH");
e.FieldKeys.Add("F_DFZHMC");

def CreateBills(ObjType,dr):
billId=dr["FID"];
entryId=str(dr["FEntryID"]);
seq=str(dr["FSeq"]);
orgID=dr["F_BPW_ORGID"];
XMId=str(dr["F_BPW_XMID"]);
GJBH=str(dr["F_BPW_GJBH"]);
GJName=("{0}").format(dr["F_BPW_GJNAME"]);
GXZYId=str(dr["F_BPW_GXZY"]);
BJKZ=str(dr["F_BPW_BJKZ"]);
fullSN=str(dr["F_BPW_GJSN"]);
SN=str(dr["F_BPW_SN"]);
seq=str(dr["FSeq"]);
GJType=str(dr["F_BPW_GJType"]);
#saveService = ServiceFactory.GetService[ISaveService](this.Context);
newBillObj=DynamicObject(ObjType);
newBillObj["Number"]=fullSN;
newBillObj["Name"]=SN;
#OrgMeta = MetaDataServiceHelper.Load(this.Context, "ORG_Organizations");
#dynamicObjects = BusinessDataServiceHelper.Load(this.Context, pkIds.ToArray(), OrgMeta.BusinessInfo.GetDynamicObjectType());
#orgObj = dynamicObjects[0];
#QTWLBillObj["CreateOrgId"]=orgObj;
newBillObj["CreateOrgId_Id"]=orgID;
#QTWLBillObj["UseOrgId"]=orgObj;
newBillObj["UseOrgId_Id"]=orgID;
newBillObj["F_BPW_XMId_Id"]=XMId;
newBillObj["F_BPW_GJBH"]=GJBH;
newBillObj["F_BPW_GJName"]=GJName;
newBillObj["F_BPW_GXZY_Id"]=GXZYId;
newBillObj["F_BPW_BJKZ"]=BJKZ;
newBillObj["F_BPW_GXJHId"]=billId;
newBillObj["F_BPW_GXJHEntryID"]=entryId;
newBillObj["F_BPW_GXJHSeq"]=seq;
newBillObj["DocumentStatus"]="C";
newBillObj["ForbidStatus"]="A";
newBillObj["F_BPW_SNDetailId"]=str(dr["FDetailID"]);
newBillObj["F_BPW_GJEntryId"]=int(dr["F_BPW_XMENTRYID"]);
newBillObj["F_BPW_GXJHBillNo"]=dr["FBILLNO"];
newBillObj["F_BPW_GXStatus"]="2" if(seq=="1") else "1";
newBillObj["F_BPW_GJType"]=GJType;
return newBillObj;
#数据库批量插入单据
def CreateBillByBulkInsert(GXJHLst):
sql=("""/*dialect*/select
FID=Cast(0 as int),
FMasterId=Cast(0 as int),
FDOCUMENTSTATUS=Cast('C' as varchar(1)),
FFORBIDSTATUS=Cast('A' as varchar(1)),
FCREATEDATE=cast(getdate() as datetime),
FCREATORID=Cast({1} as int),
FMODIFIERID=Cast({1} as int),
FMODIFYDATE=cast(getdate() as datetime),
FCREATEORGID=Cast(t.F_BPW_ORGID as int),
FUSEORGID=Cast(t.F_BPW_ORGID as int),
FNUMBER=Cast(t.F_BPW_GJSN as nvarchar(255)),
SN=t.F_BPW_SN,
F_BPW_XMID=Cast(t.F_BPW_XMID as int),
F_BPW_GXJHID=Cast(t.FID as nvarchar(50)),
F_BPW_GJBH=Cast(t.F_BPW_GJBH as nvarchar(50)),
F_BPW_GXJHENTRYID=Cast(t.FEntryID as nvarchar(50)),
F_BPW_GXZY=Cast(t.F_BPW_GXZY as int),
F_BPW_GXJHSEQ=Cast(t.FSeq as int),
F_BPW_SNDETAILID=Cast(t.FDetailID as nvarchar(50)),
F_BPW_GJNAME=Cast(t.F_BPW_GJNAME as nvarchar(200)),
F_BPW_BJKZ=Cast(t.F_BPW_BJKZ as varchar(20)),
F_BPW_GXJHBILLNO=Cast(t.FBILLNO as nvarchar(50)),
F_BPW_GXSTATUS=Cast(case when t.FSeq=1 then '2' else '1' end as char(1)),
F_BPW_GJENTRYID=Cast(t.F_BPW_XMENTRYID as int),
F_BPW_GJTYPE=Cast(t.F_BPW_GJType as varchar(20)),
F_BPW_ISSN=Cast(t.F_BPW_ISSN as char(1)),
F_BPW_QTY=Cast(t.F_BPW_GJQTY as decimal(23, 10)),
F_BPW_KHBQTY=Cast(CASE when t.FSeq=1 then (Case when t.F_BPW_ISSN<>'1' then t.F_BPW_GJQTY else 1 end) else 0 end as decimal(23, 10))
from
(
select h.FBILLNO,h.FID,en.FEntryID,en.FSeq,h.F_BPW_ORGID,h.F_BPW_XMID,h.F_BPW_GJBH,h.F_BPW_XMENTRYID,
en.F_BPW_GXZY,h.F_BPW_GJNAME,en.F_BPW_BJKZ,xmEN.F_BPW_IsSN,h.F_BPW_XMSEQ,h.F_BPW_GJQTY,
xmSubEn.F_BPW_GJSN,xmSubEn.F_BPW_SN,xmSubEn.FDetailID,xmSubEn.FSeq AS FXMSubEnSeq,xmEN.F_BPW_GJType
from BPW_t_QH_GXPLan h
inner join BPW_t_QH_XMEntry xmEN on xmEN.FEntryID=h.F_BPW_XMENTRYID
inner join BPW_t_QH_XMSNSubEntry xmSubEn on xmSubEn.FEntryID=xmEN.FEntryID
inner join BPW_t_QH_GXJHEntry en on h.FID=en.FID
where xmEN.F_BPW_IsSN='1' and h.FID in ({0})
union all
select h.FBILLNO,h.FID,en.FEntryID,en.FSeq,h.F_BPW_ORGID,h.F_BPW_XMID,h.F_BPW_GJBH,h.F_BPW_XMENTRYID,
en.F_BPW_GXZY,h.F_BPW_GJNAME,en.F_BPW_BJKZ,xmEN.F_BPW_IsSN,h.F_BPW_XMSEQ,h.F_BPW_GJQTY,
xmH.F_BPW_GCDM+'-'+xmH.F_BPW_XMLOT+'-'+xmEN.F_BPW_GJBH as F_BPW_GJSN,xmEN.F_BPW_GJBH as F_BPW_SN,FDetailID=0,FXMSubEnSeq=1,xmEN.F_BPW_GJType
from BPW_t_QH_GXPLan h
inner join BPW_t_QH_XMEntry xmEN on xmEN.FEntryID=h.F_BPW_XMENTRYID
inner join BPW_t_QH_XM xmH on xmH.FID=xmEN.FID
inner join BPW_t_QH_GXJHEntry en on h.FID=en.FID
where xmEN.F_BPW_IsSN<>'1' and h.FID in ({0})
) t
order by Cast(t.F_BPW_XMID as int),cast(t.F_BPW_XMSEQ as int),t.FXMSubEnSeq,t.FSeq """).format(",".join(GXJHLst),this.Context.UserId);
#raise Exception(",".join(GXJHLst));
ds = DBServiceHelper.ExecuteDataSet(this.Context,sql);
tab = ds.Tables[0];
dataCount=tab.Rows.Count;
if(dataCount<=0):
return;
tab.TableName="BPW_t_GJXLHGXJH";
tabLName="BPW_t_GJXLHGXJH_L";
newFIDs = DBServiceHelper.GetSequenceInt64(this.Context, tab.TableName,dataCount);
newLFIDs=DBServiceHelper.GetSequenceInt64(this.Context, tabLName,dataCount);
dtL=DataTable();#多语言表
dtL.TableName = tabLName;
dtL.Columns.Add("FID", Int64().GetType());
dtL.Columns.Add("FPKID", Int64().GetType());
dtL.Columns.Add("FLocaleID", Int32().GetType());
dtL.Columns.Add("FNAME", "".ToString().GetType());
dtL.Columns.Add("FDESCRIPTION", "".ToString().GetType());
dtL.BeginLoadData();
i=0;
for dr in tab.Rows:
FID=newFIDs[i];
dr["FID"]=FID;
dr["FMasterId"]=FID;
rowDatas=List[object]();
rowDatas.Add(FID);
rowDatas.Add(newLFIDs[i]);
rowDatas.Add(2052);
rowDatas.Add(("{0}").format(dr["SN"]));
rowDatas.Add("数据库插入");
dtL.LoadDataRow(rowDatas.ToArray(), True);
i=i+1;
dtL.EndLoadData();
tab.Columns.Remove("SN");
DBUtils.BulkInserts(this.Context, tab);
DBUtils.BulkInserts(this.Context, dtL);
#msg=("{0}\r\n---{1}").format(tab.Rows.Count,dtL.Rows.Count);
#raise Exception(msg);
def EndOperationTransaction(e):
global ObjList;
formID="BPW_QH_GJXLHGXJH";
Meta=MetaDataServiceHelper.GetFormMetaData(this.Context, formID);
ObjType=Meta.BusinessInfo.GetDynamicObjectType();
ObjList=List[DynamicObject]();
GXJHLst=list(str(billObj["Id"]) for billObj in e.DataEntitys);
if(len(GXJHLst)<=0):
return;
CreateBillByBulkInsert(GXJHLst);
return;
#msg=("工序计划[{0}]").format(len(GXJHLst));
#raise Exception(msg);
sql=("""select h.FBILLNO,h.FID,en.FEntryID,en.FSeq,h.F_BPW_ORGID,h.F_BPW_XMID,h.F_BPW_GJBH,h.F_BPW_XMENTRYID,
en.F_BPW_GXZY,xmSubEn.F_BPW_GJSN,xmSubEn.F_BPW_SN,xmSubEn.FDetailID,h.F_BPW_GJNAME,en.F_BPW_BJKZ,xmEN.F_BPW_GJType
from BPW_t_QH_GXPLan h
inner join BPW_t_QH_XMSNSubEntry xmSubEn on xmSubEn.FEntryID=h.F_BPW_XMENTRYID
inner join BPW_t_QH_XMEntry xmEN on xmEN.FEntryID=xmSubEn.FEntryID
inner join BPW_t_QH_GXJHEntry en on h.FID=en.FID
where xmEN.F_BPW_GJType='1' AND h.FID in ({0}) """).format(",".join(GXJHLst));
tabRows=DBUtils.ExecuteDynamicObject(this.Context,sql);
if(tabRows.Count<=0):
return;
for dr in tabRows:
newBillObj=CreateBills(ObjType,dr);
ObjList.Add(newBillObj);
DBServiceHelper.LoadReferenceObject(this.Context, ObjList.ToArray(), ObjType, True);
#msg=("{0}").format(JsonUtil.Serialize(ObjList));
#DataWriterObj=BusinessDataWriter(this.Context);
#DataWriterObj.Save(ObjList.ToArray());
#saveResult=BusinessDataServiceHelper.Draft(this.Context, Meta.BusinessInfo,ObjList.ToArray(), None, "OnlySaveAudit");

标签:星空,金蝶,BOS,newBillObj,Cast,单据,BPW,dr,FID
From: https://www.cnblogs.com/woshinige/p/18517223

相关文章

  • 金蝶云星空获取简单账表数据写入临时表中
    #引入clr运行库importclr#添加对cloud插件开发的常用组件的引用clr.AddReference('System')clr.AddReference('System.Data')clr.AddReference('Kingdee.BOS')clr.AddReference('Kingdee.BOS.Core')clr.AddReference('Kingdee.BOS.App')clr.Ad......
  • 金蝶云星空与吉客云的采购入库数据无缝对接方案
    在企业信息化建设中,数据的高效集成和处理是确保业务顺畅运行的关键环节。本文将聚焦于一个实际的系统对接集成案例——金蝶云星空的数据如何无缝对接到吉客云,实现采购入库数据的高效传输与处理。本次集成方案名为“金蝶采购入库对接吉客云采购入库”,主要涉及两个核心平台:金蝶云星......
  • 利用API接口实现旺店通和金蝶系统的无缝数据对接
    旺店通销售出库对接金蝶销售订单(线下)的技术实现在企业日常运营中,数据的高效流转和准确对接是确保业务顺畅运行的关键。本文将聚焦于一个具体案例:如何通过轻易云数据集成平台,实现旺店通·企业奇门的数据无缝对接到金蝶云星空系统。我们将详细探讨这一过程中涉及的技术要点和解决方......
  • 数据集成案例:金蝶云采购入库单到旺店通委外仓
    标准-金蝶-采购入库单——>旺店通-委外仓入(入库业务)集成案例分享在企业信息化系统中,数据的高效流动和准确对接是确保业务顺畅运行的关键。本文将分享一个实际运行的集成方案:如何将金蝶云星空中的采购入库单数据无缝集成到旺店通·旗舰版的委外仓入库业务中。为了实现这一目标......
  • 易仓与金蝶云星空的数据无缝对接方案解析
    易仓数据集成到金蝶云星空:R入库单(组装)-其他入库单20230620在企业信息化管理中,数据的高效流转和准确对接至关重要。本文将分享一个具体的系统对接集成案例,即如何将易仓的数据集成到金蝶云星空平台,方案名称为“R入库单(组装)-其他入库单20230620”。本次集成任务主要涉及两个关键API......
  • 如何通过轻易云实现旺店通与金蝶云数据集成
    旺店通其他入库委外同步--114:从旺店通·企业奇门到金蝶云星空的数据集成案例在本次技术案例中,我们将详细探讨如何通过轻易云数据集成平台,实现旺店通·企业奇门数据与金蝶云星空的无缝对接。具体方案为“旺店通其他入库委外同步--114”,旨在确保数据高效、准确地从旺店通·企业奇门......
  • 轻易云平台成功实现金蝶云星空与马帮的数据同步
    新增供应商同步金蝶=》马帮(测试通过)在企业信息化系统中,数据的高效集成与同步是确保业务流程顺畅运行的关键环节。本文将分享一个实际案例,展示如何通过轻易云数据集成平台实现金蝶云星空与马帮之间的数据对接。具体方案为“新增供应商同步金蝶=》马帮(测试通过)”。在这个案例中,我......
  • 高效集成:金蝶云星空与聚水潭的数据对接方案
    高效集成:金蝶云星空与聚水潭的数据对接方案金蝶云星空与聚水潭的高效数据集成方案在企业日常运营中,销售订单的数据处理和管理是至关重要的一环。为了实现金蝶云星空与聚水潭之间的无缝对接,我们设计并实施了“金蝶--线下快递销售订单=>聚水潭--销售订单上传”的集成方案。本案例......
  • 使用轻易云高效集成旺店通与金蝶云星空
    旺店通销售出库集成到金蝶云星空的技术实现在企业信息化管理中,数据的高效流动和准确对接是提升业务效率的关键。本文将详细介绍如何通过轻易云数据集成平台,将旺店通·企业奇门中的销售出库数据无缝集成到金蝶云星空系统中,实现销售出库单的自动化处理。集成背景与需求本次集成任务旨......
  • 企业数据高效集成:聚水潭与金蝶系统对接实战
    聚水潭盘亏-金蝶其他出库:高效数据集成方案在企业管理系统中,如何实现不同平台间的数据无缝对接一直是一个关键挑战。本文将分享一个具体的技术案例:如何通过轻易云数据集成平台,将聚水潭的盘亏数据高效集成到金蝶云星空的其他出库模块。背景与需求分析在本次集成项目中,我们需要从......