二开案例.服务插件.创建单据时不记录修改人
【应用场景】
单据在新增保存时,系统默认会将最后修改人和最后修改日期字段赋值为等于单据的当前创建人和创建日期字段的值。
某些特殊场景下,可能希望在新增保存单据时,不要记录修改人信息。受限于平台设计,目前想实现不记录修改人信息还挺麻烦的。
【案例演示】
采购订单,新增保存时,不记录修改人和修改日期。
【实现步骤】
<1>编写服务插件,代码如下。
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using System.Collections.Generic;
using System.ComponentModel;
//using System.Linq;
namespace Jac.XkDemo.BOS.App.PlugIn
{
/// <summary>
/// 【服务插件】创建单据时不记录修改人
/// </summary>
[Description("【服务插件】创建单据时不记录修改人"), HotUpdate]
public class ResetModifyerAfterSaveOperationServicePlugIn : AbstractOperationServicePlugIn
{
/// <summary>
/// 修改人字段标识
/// </summary>
const string ModifierIdFieldKey = "FModifierId";
/// <summary>
/// 修改时间字段标识
/// </summary>
const string ModifyDateFieldKey = "FModifyDate";
public override void OnPrepareOperationServiceOption(OnPrepareOperationServiceEventArgs e)
{
base.OnPrepareOperationServiceOption(e);
if (!string.IsNullOrWhiteSpace(this.FormOperation.LoadKeys) && this.FormOperation.LoadKeys != "null")
{
// 设置操作完后刷新修改人字段
var loadKeys = KDObjectConverter.DeserializeObject<List<string>>(this.FormOperation.LoadKeys);
if (loadKeys == null)
{
loadKeys = new List<string>();
}
if (!loadKeys.Contains(ModifierIdFieldKey))
{
loadKeys.Add(ModifierIdFieldKey);
}
if (!loadKeys.Contains(ModifyDateFieldKey))
{
loadKeys.Add(ModifyDateFieldKey);
}
this.FormOperation.LoadKeys = KDObjectConverter.SerializeObject(loadKeys);
}
}
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
if (this.FormOperation.OperationId == 8)
{
var needSaveIds = new List<object>();
foreach (var dataEntity in e.DataEntitys)
{
if (!dataEntity.DataEntityState.FromDatabase)
{
// 清除单据在内存数据包中的修改人数据
dataEntity["ModifierId_Id"] = null;
dataEntity["ModifierId"] = null;
dataEntity["ModifyDate"] = null;
needSaveIds.Add(dataEntity[0]);
}
}
if (needSaveIds.Count > 0)
{
ResetModifyer(Context, this.BusinessInfo, needSaveIds);
}
}
}
/// <summary>
/// 清除单据的修改人
/// </summary>
/// <param name="ctx"></param>
/// <param name="businessInfo"></param>
/// <param name="ids"></param>
private void ResetModifyer(Context ctx, BusinessInfo businessInfo, List<object> ids)
{
//var modifyerField = businessInfo.Entrys[0].Fields.FirstOrDefault(o => o is ModifyerField) as ModifyerField;
//var modifyDateField = businessInfo.Entrys[0].Fields.FirstOrDefault(o => o is ModifyDateField) as ModifyDateField;
var modifyerField = businessInfo.GetField(ModifierIdFieldKey) as ModifyerField;
var modifyDateField = businessInfo.GetField(ModifyDateFieldKey) as ModifyDateField;
if (modifyerField == null || modifyDateField == null)
{
return;
}
var sql = string.Format("UPDATE {0} SET {1}=0,{2}=NULL WHERE {3} IN ({4})"
, modifyerField.Entity.TableName
, modifyerField.FieldName
, modifyDateField.FieldName
, modifyerField.Entity.EntryPkFieldName
, string.Join(",", ids));
DBUtils.Execute(ctx, sql);
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,保存操作上注册服务插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开采购订单新增界面,保存单据,此时不再记录修改人信息。
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.服务插件.创建单据时不记录修改人
本文2024-09-23 04:08:23发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-163390.html