Python操作服务插件发送系统广播消息和普通消息
Python实现通过插件的方式给指定用户发送广播消息和普通消息:
代码示例如下:
import clr clr.AddReference("mscorlib") clr.AddReference("System") clr.AddReference("System.Data") clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS.App") clr.AddReference("Kingdee.K3.MFG.App") clr.AddReference("Kingdee.K3.Core") clr.AddReference("Kingdee.K3.MFG.Contracts") clr.AddReference("Kingdee.BOS.ServiceHelper") clr.AddReference("Kingdee.BOS.Workflow.Models") clr.AddReference("Kingdee.BOS.OrmEngine") clr.AddReference("Kingdee.BOS.DataEntity") clr.AddReference("Newtonsoft.Json") from System import * from System.Data import * from System.Collections.Generic import List as GList from System.ComponentModel import * from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Newtonsoft.Json import * from Kingdee.BOS.Core.Bill.PlugIn import * from Kingdee.BOS.Core.Bill.PlugIn.Args import * from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import * from Kingdee.BOS.Core.Msg import * from Kingdee.BOS.Orm.Drivers import * from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Workflow.Models.WindowRemind import * from Kingdee.BOS.Resource import * def OnPreparePropertys(e): e.FieldKeys.Add("FCreatorID") def EndOperationTransaction(e): receiverIds = GList[object]() # 接受人ID集合 for dataEntitys in e.DataEntitys: creatorId = dataEntitys["CreatorId"] # 单据创建人 if len(receiverIds) > 0: formId = "PLN_FORECAST" # 关联单据的FormID billId = 125385 # 需要打开的单据内码 title = "新消息通知" # 消息标题 message = "你有信息消息,请查收!" # 消息内容 senderId = 16394 # 消息发送人ID # 发送广播信息 SendBroadCastMessage(this.Context, message, receiverIds ) # 发送普通消息 SendMessage(this.Context, formId, billId, title, message, senderId , receiverIds ) ### 发送广播消息 def SendBroadCastMessage(ctx, message, receiverIds): businessInfo = FormMetaDataCache.GetCachedFormMetaData(ctx, "BAS_BROADCASTMSG").BusinessInfo dataType = businessInfo.GetDynamicObjectType() receiverField = businessInfo.GetField("FReceiver") dataObject = DynamicObject(dataType) dataObject["FCREATEDATE"] = DateTime.Now # 创建时间 dataObject["FTITLE"] = LocaleValue("你有新的消息") # 广播标题 dataObject["FCONTENT"] = str.Format("{0}(可在普通消息列表查看详情)", message) # 广播内容 dataObject["FCreatorId_Id"] = 16394 # 广播发布者 dataObject["FSendType"] = 1 # 发送类型 1 - 单发 2 - 多发 dataObject["FIsSendBroadcast"] = True # 是否内部消息 dataObject["FFailureTime"] = DateTime.Now.AddHours(1) # 失效时间 FieldSetValue(ctx, receiverField, dataObject, receiverIds) # 接受人设置 BusinessDataServiceHelper.Save(ctx, dataObject) ### 发送普通消息 def SendMessage(ctx, formId, billId, title, content, senderId, receiverIds): businessInfo = FormMetaDataCache.GetCachedFormMetaData(ctx, "WF_MessageSendBill").BusinessInfo receiverField = businessInfo.GetField("FRECEIVERS") dataType = businessInfo.GetDynamicObjectType() dataObject = DynamicObject(dataType) dataObject["TYPE"] = str(MsgType.CommonMessage) # 销售类别 dataObject["SENDERID_Id"] = senderId # 发送者 FieldSetValue(ctx, receiverField, dataObject, receiverIds) # 接受人设置 dataObject["Title"] = title # 消息标题 dataObject["Content"] = content # 消息内容 dataObject["ObjectTypeId_Id"] = str(formId) # 单据FORMID,用于打开单据 dataObject["KeyValue"] = str(billId) # 单据内码 dataObject["CREATETIME"] = DateTime.Now # 创建时间 msgSend = MessageSend(obj=dataObject) msgSend.KeyValue = str(billId) SMSServiceHelper.SendMessage(ctx=ctx, msgSendInfo=msgSend, outboxToo=True) ### 多选基础资料字段赋值 def FieldSetValue(ctx, field, dataObject, pkValues): mulBaseDataEntitySet = field.GetFieldValue(dataObject) if mulBaseDataEntitySet is None: mulBaseDataEntitySet = DynamicObjectCollection(field.RefEntityDynamicObjectType, dataObject) field.RefEntityDynamicProperty.SetValue(dataObject, mulBaseDataEntitySet) mulBaseDataEntitySet.Clear() baseDataObjects = BusinessDataServiceHelper.LoadFromCache(ctx=ctx, pkArray=pkValues, type=field.RefFormDynamicObjectType) for baseDataObject in baseDataObjects: mulBaseDataEntity = DynamicObject(field.RefEntityDynamicObjectType) mulBaseDataEntitySet.Add(mulBaseDataEntity) field.RefIDDynamicProperty.SetValue(mulBaseDataEntity, baseDataObject[0]) field.DynamicProperty.SetValue(mulBaseDataEntity, baseDataObject)
Python操作服务插件发送系统广播消息和普通消息
Python实现通过插件的方式给指定用户发送广播消息和普通消息: 代码示例如下:import clrclr.AddReference("mscorlib")clr.AddReference...
点击下载文档
本文2024-09-16 17:44:31发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17653.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章