【应用场景】
通过插件的方式给指定用户发送普通消息。
【案例演示】
采购订单编辑界面,给指定用户发送普通消息。
【实现步骤】
<1>编写表单插件,代码如下。
using Kingdee.BOS; using Kingdee.BOS.App.Data; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Core.Msg; using Kingdee.BOS.Msg; using Kingdee.BOS.Orm; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.ComponentModel; namespace Jac.XkDemo.BOS.Business.PlugIn { /// <summary> /// 【表单插件】发送普通消息 /// </summary> [Description("【表单插件】发送普通消息"), HotUpdate] public class SendCommonMessageFormPlugIn : AbstractDynamicFormPlugIn { public override void BarItemClick(BarItemClickEventArgs e) { base.BarItemClick(e); if (e.BarItemKey.Equals("tbSendMessage", StringComparison.OrdinalIgnoreCase)) { var pkid = ((IBillView)this.View).Model.GetPKValue(); if (pkid == null) { this.View.ShowMessage("请先保存单据!"); return; } var status = ((BillStatusField)this.View.BillBusinessInfo.GetField("FDocumentStatus")).GetStatusName(this.View.Model.GetValue("FDocumentStatus")); var msg = string.Format("订单{0}的状态已变更为【{1}】", this.View.Model.DataObject["BillNo"], status); // 发送消息给多人 var receiverIds = new object[] { 100008, 144527, 146928 }; SendMessage(this.Context, this.View.BillBusinessInfo.GetForm().Id, pkid.ToString() , "采购订单状态变更通知", msg, this.Context.UserId, receiverIds); // 发送消息给某一个人 SendMessage(this.Context, this.View.BillBusinessInfo.GetForm().Id, pkid.ToString() , "采购订单状态变更通知2", msg, this.Context.UserId, 100008); this.View.ShowMessage("消息发送成功!"); } } /// <summary> /// 发送消息(支持多个收件人,写发件箱) /// </summary> /// <param name="ctx">上下文</param> /// <param name="formId">业务对象标识(不可以使用扩展的标识)</param> /// <param name="pkId">单据主键值</param> /// <param name="title">标题</param> /// <param name="content">内容</param> /// <param name="senderId">发生人内码</param> /// <param name="receiverIds">接收人内码集合</param> private static void SendMessage(Context ctx, string formId, string pkId, string title, string content, long senderId, object[] receiverIds) { var businessInfo = FormMetaDataCache.GetCachedFormMetaData(ctx, "WF_MessageSendBill").BusinessInfo; var receiverField = (MulBaseDataField)businessInfo.GetField("FRECEIVERS"); var dt = businessInfo.GetDynamicObjectType(); var dataObject = new DynamicObject(dt); dataObject["TYPE"] = ((int)MsgType.CommonMessage).ToString(); dataObject["SENDERID_Id"] = senderId; FieldSetValue(ctx, receiverField, dataObject, receiverIds); dataObject["Title"] = title; dataObject["Content"] = content; dataObject["ObjectTypeId_Id"] = formId; dataObject["KeyValue"] = pkId; dataObject["CREATETIME"] = DateTime.Now; // 保存消息 var msgSend = new MessageSend(dataObject); msgSend.KeyValue = pkId; SMSServiceHelper.SendMessage(ctx, msgSend, true); } /// <summary> /// 发送消息(精简版,仅支持一个收件人,不写发件箱) /// </summary> /// <param name="ctx">上下文</param> /// <param name="formId">业务对象标识(不可以使用扩展的标识)</param> /// <param name="pkId">单据主键值</param> /// <param name="title">标题</param> /// <param name="content">内容</param> /// <param name="senderId">发生人内码</param> /// <param name="receiverId">接收人内码</param> private static void SendMessage(Context ctx, string formId, string pkId, string title, string content, long senderId, long receiverId) { Message msg = new DynamicObject(Message.MessageDynamicObjectType); msg.MessageId = SequentialGuid.NewGuid().ToString(); msg.MsgType = MsgType.CommonMessage; msg.SenderId = senderId; msg.ReceiverId = receiverId; msg.Title = title; msg.Content = content; msg.ObjectTypeId = formId; msg.KeyValue = pkId; msg.CreateTime = DateTime.Now; // 保存消息 var dataManager = DataManagerUtils.GetDataManager(Message.MessageDynamicObjectType, new OLEDbDriver(ctx)); dataManager.Save(msg.DataEntity); } /// <summary> /// 多选基础资料字段赋值(通过字段修改数据包) /// </summary> /// <param name="ctx">上下文</param> /// <param name="field">多选基础资料字段</param> /// <param name="entityObj">多选基础资料字段所在数据行</param> /// <param name="pkValues">多个基础资料的内码的集合</param> private static void FieldSetValue(Context ctx, MulBaseDataField field, DynamicObject entityObj, object[] pkValues) { // 获取多选基础资料字段的数据包集合 var mulBaseDataEntitySet = field.GetFieldValue(entityObj) as DynamicObjectCollection; if (mulBaseDataEntitySet == null) { mulBaseDataEntitySet = new DynamicObjectCollection(field.RefEntityDynamicObjectType, entityObj); field.RefEntityDynamicProperty.SetValue(entityObj, mulBaseDataEntitySet); } mulBaseDataEntitySet.Clear(); // 从数据库读取指定的基础资料的数据包,并填充到当前多选基础资料字段的数据包集合中 var baseDataObjects = BusinessDataServiceHelper.LoadFromCache(ctx, pkValues, field.RefFormDynamicObjectType); foreach (var baseDataObject in baseDataObjects) { var mulBaseDataEntity = new DynamicObject(field.RefEntityDynamicObjectType); mulBaseDataEntitySet.Add(mulBaseDataEntity); field.RefIDDynamicProperty.SetValue(mulBaseDataEntity, baseDataObject[0]); field.DynamicProperty.SetValue(mulBaseDataEntity, baseDataObject); } } } } ///// <summary> ///// 消息类型 ///// </summary> //public enum MsgType //{ // /// <summary> // /// 工作流消息 // /// </summary> // WorkflowMessage, // /// <summary> // /// 普通消息 // /// </summary> // CommonMessage, // /// <summary> // /// 业务流程普通消息 // /// </summary> // BusinessFlowMessage //}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,菜单集合新增菜单项,注册表单插件,保存元数据,开发完毕。
【插件验证】
登录业务系统,打开采购订单编辑界面,点击【发送消息】菜单。
demo用户发送消息:
demo用户的发件箱:
yh1用户查看消息:
【知识点】
<1>消息对应的业务对象是WF_MessageBill。
<2>消息相关表。
--消息表
SELECT * FROM T_WF_MESSAGE WHERE FTITLE LIKE '%采购订单状态变更通知%'
--发件箱消息表
SELECT * FROM T_WF_MESSAGESEND WHERE FTITLE LIKE '%采购订单状态变更通知%'
<3>用户表。
SELECT FUSERID AS 用户内码,FNAME AS 用户名,* FROM T_SEC_USER
-------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/7549.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~