二开案例.列表插件.使用AfterCreateSqlBuilderParameter事件干预列表查询
【应用场景】使用列表插件对列表查询进行干预。
【案例演示】采购订单,列表查询,在列表插件中对列表查询强制增加一些过滤条件。
【实现步骤】
<1>编写列表插件,代码如下。
using Kingdee.BOS;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.List.PlugIn.Args;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Util;
using System.ComponentModel;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【列表插件】使用AfterCreateSqlBuilderParameter事件干预列表查询
/// </summary>
[Description("【列表插件】使用AfterCreateSqlBuilderParameter事件干预列表查询"), HotUpdate]
public class AppendListQueryFilterStringListPlugIn : AbstractListPlugIn
{
/// <summary>
/// 准备过滤参数(此事件主要用于附加各种SQL过滤条件)
/// </summary>
/// <param name="e"></param>
public override void PrepareFilterParameter(FilterArgs e)
{
base.PrepareFilterParameter(e);
// 文本字段
e.FilterString = e.FilterString.JoinFilterString("FBillNo LIKE 'CG%'");
// 基础资料字段(基础资料字段标识.引用字段标识)
//e.FilterString = e.FilterString.JoinFilterString("FMaterialId.FNumber Like N'%0.0000.01%'");
//// 单据体主键字段(单据体标识_分录主键标识)
//e.FilterString = e.FilterString.JoinFilterString("FPOOrderEntry_FEntryID NOT IN (1,2,3)");
//// 子单据体主键字段(单据体标识_分录主键标识)
//e.FilterString = e.FilterString.JoinFilterString("FEntryDeliveryPlan_FDetailId NOT IN (5,6,7)");
}
/// <summary>
/// 在构建完sql取数参数之后进一步干预列表过滤()
/// 1.此事件在PrepareFilterParameter事件之后执行
/// 2.整个SqlBuilderParameter都当成参数传入事件中,相比PrepareFilterParameter事件,此事件中插件可操控范围更大了
/// 3.此事件是能对过滤动作进行干预的最后的机会
/// </summary>
/// <param name="e"></param>
public override void AfterCreateSqlBuilderParameter(SqlBuilderParameterArgs e)
{
base.AfterCreateSqlBuilderParameter(e);
// 附加常规过滤条件
e.sqlBuilderParameter.FilterClauseWihtKey = e.sqlBuilderParameter.FilterClauseWihtKey.JoinFilterString("FBillNo LIKE '%DD%'");
// 表连接之表变量
var pks = new long[] { 100001, 100002, 100003, 100004, 100005, 100006 };
var sqlParam = new SqlParam("@PKValue", KDDbType.udt_inttable, pks);
var pkTmpTable = StringUtils.GetSqlWithCardinality(pks.Length, "@PKValue", 1);
var joinTable = new ExtJoinTableDescription
{
JoinOption = QueryBuilderParemeter.JoinOption.LeftJoin,
TableName = pkTmpTable,
TableNameAs = "tp801",
FieldName = "FID",
ScourceKey = "FID"
};
e.sqlBuilderParameter.SqlParams.Add(sqlParam);
e.sqlBuilderParameter.ExtJoinTables.Add(joinTable);
// 表连接之物理表
var joinTable2 = new ExtJoinTableDescription
{
TableName = "T_PUR_POCHANGE",
TableNameAs = "tp802",
FieldName = "FID",
ScourceKey = "FID"
};
e.sqlBuilderParameter.ExtJoinTables.Add(joinTable2);
// 修改隔离组织
e.sqlBuilderParameter.IsolationOrgList.Add(100001);
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,注册列表插件,保存元数据,开发完毕。
现在可以登录业务站点,打开采购订单列表,检验一下插件效果啦。
从数据库抓到的SQL可知,插件中附件的各种过滤条件,最后全部都融入到列表查询SQL中啦。
SELECT *
FROM ( SELECT t0.FBILLNO AS FBILLNO ,
t0.FDATE AS FDATE ,
t0.FSUPPLIERID AS FSupplierId_Id ,
t0.FDOCUMENTSTATUS AS FDOCUMENTSTATUS ,
t0.FPURCHASEORGID AS FPurchaseOrgId_Id ,
t0.FCLOSESTATUS AS FCLOSESTATUS ,
t3.FMATERIALID AS FMaterialId_Id ,
t3.FUNITID AS FUnitId_Id ,
t3.FQTY AS FQTY ,
t3_D.FDELIVERYDATE AS FDELIVERYDATE ,
t3.FGIVEAWAY AS FGIVEAWAY ,
t3.FMRPCLOSESTATUS AS FMRPCLOSESTATUS ,
t0.FBILLTYPEID AS FBILLTYPEID ,
t0.FPURCHASEORGID AS FPURCHASEORGID ,
t0.FOBJECTTYPEID AS FOBJECTTYPEID ,
t0.FID AS FID ,
t3.FENTRYID AS t3_FENTRYID ,
t3.FSEQ AS t3_FSeq ,
ROW_NUMBER() OVER ( ORDER BY t0.FCREATEDATE DESC, t0.FBILLNO DESC , t3.FSEQ ASC ) fidentityid
FROM T_PUR_POORDER t0
LEFT JOIN T_PUR_POORDERENTRY t3 ON ( t0.FID = t3.FID )
LEFT JOIN T_PUR_POORDERENTRY_D t3_D ON ( t3.FENTRYID = t3_D.FENTRYID )
LEFT JOIN ( select /*+ cardinality(b 6)*/ FID from table(fn_StrSplit(@PKValue,',',1)) b ) tp801 ON (tp801.FID=t0.FID)
INNER JOIN T_PUR_POCHANGE tp802 ON (tp802.FID=t0.FID)
WHERE ( (( ( ( t0.FCREATEDATE >= {TS '2020-11-01 00:00:00'} )
AND ( t0.FCREATEDATE < {TS '2020-12-01 00:00:00'} )
)
AND ( t0.FBILLNO LIKE 'CG%' )
)
AND ( t0.FBILLNO LIKE '%DD%' ))
)
AND ( t0.FPURCHASEORGID IN ( 1, 100001, 100002, 100003,
100004, 100005, 100006,
100007, 135255, 135713,
135879, 136122, 136492,
144050, 151026, 151043,
174323, 304707 ) )
AND t0.FPURCHASEORGID IN ( 100003, 100001, 0 )
AND t0.FOBJECTTYPEID = 'PUR_PurchaseOrder'
) TLIST
WHERE fidentityid >= 1
AND fidentityid <= 200;
【参考资料】
【二开案例.列表插件.使用PrepareFilterParameter事件干预列表查询】https://vip.kingdee.com/article/93658176121078272
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.列表插件.使用AfterCreateSqlBuilderParameter事件干预列表查询
本文2024-09-23 04:21:06发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164745.html