二开实现单据保存写入批号主档(Python实现)原创
17人赞赏了该文章
3,536次浏览
编辑于2022年02月22日 17:30:53
业务需求和C#的插件实现,参考文章:【二开实现单据保存写入批号主档】,重写一个Python版本的实现,供参考。
import clr clr.AddReference('System') clr.AddReference('System.Data') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS.App.Core') clr.AddReference('Kingdee.BOS.App') clr.AddReference('Kingdee.BOS.DataEntity') clr.AddReference('Kingdee.BOS.Business.DynamicForm') clr.AddReference('Kingdee.BOS.ServiceHelper') clr.AddReference('Kingdee.BOS.Contracts') from Kingdee.BOS.Log import Logger from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Contracts import * from System.Data import * from System import * from System.Collections import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from System.Collections.Generic import Dictionary from Kingdee.BOS.Core.DynamicForm.PlugIn import * from System import StringComparison from Kingdee.BOS.ServiceHelper import * def AfterExecuteOperationTransaction(e): if(this.OperationResult.IsSuccess == False): return if len(e.DataEntitys) == 0 or e.DataEntitys == None: return havaUpdateLots = Dictionary[str,str]() for bill in e.DataEntitys: lotNote = bill["NOTE"].ToString() if lotNote == "": continue billEntry = bill["STK_MISCELLANEOUSENTRY"] for entry in billEntry: lotId = Convert.ToInt64(entry["Lot_Id"]) if lotId == 0: continue havaUpdateLots.Add(str(lotId), lotNote) if havaUpdateLots.Count > 0: lstSqlObj = List[SqlObject]() lotTmpTable = DBServiceHelper.CreateTemporaryTableName(this.Context) BuildUpdateDestLotTmpTable(this.Context, lotTmpTable) lotDt = DataTable(lotTmpTable); otColumn1 = DataColumn(); otColumn1.ColumnName = "FLOTID" lotDt.Columns.Add(otColumn1) otColumn2 = DataColumn(); otColumn2.ColumnName = "FLOTNOTE" lotDt.Columns.Add(otColumn2) pythondict = dict(havaUpdateLots) for key,value in pythondict.items(): dr = lotDt.NewRow() dr["FLOTID"] = key; dr["FLOTNOTE"] = value; lotDt.Rows.Add(dr); DBUtils.BulkInserts(this.Context, lotDt) sql = '''MERGE INTO T_BD_LOTMASTER IT USING ( SELECT T1.FLOTID, T1.FLOTNOTE FROM {0} T1 JOIN T_BD_LOTMASTER T2 ON T1.FLOTID = T2.FLOTID ) UT ON (IT.FLOTID = UT.FLOTID) WHEN MATCHED THEN UPDATE SET IT.FNOTETEXT = UT.FLOTNOTE; '''.format(lotTmpTable) paras = List[SqlParam](); sqlObject = SqlObject(sql, paras) lstSqlObj.Add(sqlObject) if lstSqlObj.Count > 0: DBUtils.ExecuteBatch(this.Context, lstSqlObj) def BuildUpdateDestLotTmpTable(ctx, tempTableName): sqlTM = " ( FLOTID INT NOT NULL DEFAULT(0), FLOTNOTE NVARCHAR(255) NULL)"; sql = " CREATE TABLE {0} {1} ".format(str(tempTableName), str(sqlTM)) sqls = List[str]() sqls.Add(sql) guid = Guid.NewGuid() idxName = guid.ToString("N").Substring(0, 10) sql = " CREATE INDEX IDX_LOTID{0} ON {1} ({2}) ".format(str(idxName), str(tempTableName), "FLOTID") sqls.Add(sql) DBUtils.ExecuteBatchWithTime(ctx, sqls, sqls.Count, 120)
说明:
1、有时候需要取表头字段,有时取表体字段,根据不同的业务场景针对性修改脚本即可
二开实现单据保存写入批号主档(Python实现).rar(1.34KB)
赞 17
17人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读