目前在单据转换分组策略中,只能选择到基础资料或基础资料编码,如果需要根据基础资料中的属性进行分组,则需要插件处理。下面的示例是根据仓库中的仓库属性对单据A批量下推进行分组。
1. 单据A
2. 下推效果
3. 单据转换插件代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement;
namespace Kingdee.BOS.TestPlugIn.ConvertPlugIn
{
[HotUpdate]
[Description("根据仓库的仓库属性进行分组")]
public class GroupByBaseInnerFiledConvertPlugIn : AbstractConvertPlugIn
{
private ConvertRuleElement _convertRule;//转换规则
private string _groupStockPropertyColumnName = string.Empty; //仓库属性分组字段列名
/// <summary>
/// 初始化变量
/// </summary>
/// <param name="e"></param>
public override void OnInitVariable(InitVariableEventArgs e)
{
base.OnInitVariable(e);
this._convertRule = e.Rule;
}
/// <summary>
/// 增加仓库属性到查询数据包中
/// </summary>
/// <param name="e"></param>
public override void OnQueryBuilderParemeter(QueryBuilderParemeterEventArgs e)
{
base.OnQueryBuilderParemeter(e);
SelectorRefItemInfo selectItem = new SelectorRefItemInfo(string.Format("{0}.{1}","FStock1", "FStockProperty"));
string fieldAlias = string.Format("f{0}", e.DicFieldAlias.Count);
e.DicFieldAlias["FStock1.FStockProperty"] = fieldAlias; //仓位属性列别名
selectItem.PropertyName = fieldAlias;
e.SelectItems.Add(selectItem);
this._groupStockPropertyColumnName = fieldAlias;
}
/// <summary>
/// 把仓库属性分组列增加到单据头分组字段中
/// </summary>
/// <param name="e"></param>
public override void OnBeforeGroupBy(BeforeGroupByEventArgs e)
{
base.OnBeforeGroupBy(e);
var groupConfigs = this._convertRule.Policies.Where(x => x is ConvertGroupByPolicyElement);
if (groupConfigs != null && groupConfigs.Any())
{
var groupConfig = groupConfigs.First() as ConvertGroupByPolicyElement;
if (string.IsNullOrEmpty(groupConfig.GroupByField)) //为空则会增加默认分组字段单据内码,如果不需要默认则直接覆盖
{
e.HeadGroupKey = this._groupStockPropertyColumnName;
}
else
{
e.HeadGroupKey = e.HeadGroupKey + "," + this._groupStockPropertyColumnName;
}
}
}
}
}
推荐阅读