WebAPI自定义接口调用报表数据原创
34人赞赏了该文章
1.1万次浏览
编辑于2022年12月08日 09:55:51
一、自定义WebAPI接口参考贴:
https://vip.kingdee.com/article/216280036993550080
二、简单帐表的获取数据参考贴:
https://vip.kingdee.com/article/23082
三、下面以物料收发明细报表为例,封装自定义WebAPI,取到报表数据:
using System; using System.Collections.Generic; using System.Linq;using System.Text; using Kingdee.BOS.JSON; using Kingdee.BOS.WebApi.ServicesStub; using Kingdee.BOS.ServiceFacade.KDServiceFx; using Kingdee.BOS.Core; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Report;using Kingdee.BOS.Core.ReportFilter; using Kingdee.BOS.Model.CommonFilter; using Kingdee.BOS.Model.ReportFilter; using Kingdee.BOS.ServiceHelper;u sing Kingdee.BOS.Contracts; using Kingdee.BOS.ServiceFacade; namespace Kingdee.BOS.CustomWebAPI { public class StockDetailRpt : AbstractWebApiBusinessService { public StockDetailRpt(KDServiceContext context) : base(context) { } public string ExecuteService(string str) { var ctx = this.KDContext.Session.AppContext; ISysReportService sysReporSservice = ServiceFactory.GetSysReportService(ctx); var filterMetadata = FormMetaDataCache.GetCachedFilterMetaData(ctx);//加载字段比较条件元数据。 var reportMetadata = FormMetaDataCache.GetCachedFormMetaData(ctx, "STK_StockDetailRpt");//加载物料收发明细表 var reportFilterMetadata = FormMetaDataCache.GetCachedFormMetaData(ctx, "STK_StockDetailFilter");//加载物料收发明细表表过滤条件元数据。 var reportFilterServiceProvider = reportFilterMetadata.BusinessInfo.GetForm().GetFormServiceProvider(); var model = new SysReportFilterModel(); model.SetContext(ctx, reportFilterMetadata.BusinessInfo, reportFilterServiceProvider); model.FormId = reportFilterMetadata.BusinessInfo.GetForm().Id; model.FilterObject.FilterMetaData = filterMetadata; model.InitFieldList(reportMetadata, reportFilterMetadata); model.GetSchemeList();//过滤方案的主键值,可通过该SQL语句查询得到:SELECT * FROM T_BAS_FILTERSCHEME if (this.Model.ParameterData == null) { string formId = this.BusinessInfo.GetForm().ParameterObjectId; if (formId == null || formId.Trim().Length == 0) { formId = FormIdConst.BOS_ReportUserParameter; } FormMetadata formMetadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formId); //用户参数 this.Model.ParameterData = UserParamterServiceHelper.Load(this.Context, formMetadata.BusinessInfo, this.Context.UserId, this.BusinessInfo.GetForm().Id, KeyConst.USERPARAMETER_KEY); } var entity = model.Load("0050569459b3a41211e473b732e4cecf"); var filter = model.GetFilterParameter(); IRptParams p = new RptParams(); p.FormId = reportFilterMetadata.BusinessInfo.GetForm().Id; p.StartRow = 1; p.EndRow = int.MaxValue;//StartRow和EndRow是报表数据分页的起始行数和截至行数,一般取所有数据,所以EndRow取int最大值。 p.FilterParameter = filter; p.FilterFieldInfo = model.FilterFieldInfo; //加上自定义参数,需要自行在报表插件中解析 p.CustomParams.Add("参数key", "参数value"); //修改过滤方案中的参数值 p.FilterParameter.CustomFilter["参数key"]="参数值" MoveReportServiceParameter param = new MoveReportServiceParameter(ctx, reportMetadata.BusinessInfo, Guid.NewGuid().ToString(), p); var rpt= sysReporSservice.GetReportData(param); SerializerProxy serialHelper = new SerializerProxy(MessageFormats.Json, UTF8Encoding.UTF8, false, "", true); var str = serialHelper.Serialize(rpt.DataSource); return str; } } } 备注:rpt.DataSource 这里面是所有的数据,DataTable类型; rpt.listCount是分页条件总数,Int 类型; rpt.CurrentConditionData是当前页分页条件,Dictionary过滤方案不支持在运行时动态修改
四、在账表取数插件中取自定义参数:
/// <summary> /// 账表取数插件,把数据灌入临时表事件 /// </summary> public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName) { //假设自定义参数为物料编码 object customValue = null; string materialNo = string.Empty; filter.CustomParams.TryGetValue("参数key", out customValue); if (customValue != null) { materialNo = customValue.ToString(); }
五、树形帐表的数据获取:
ReportServiceParameter param = new ReportServiceParameter(this.Context, reportMetadata.BusinessInfo, pageIdd, p); ITreeReport rpt= sysReporSservice.GetTreeReportData(param);
推荐阅读