通过执行计划,定时把无法使用API 调用的报表保存到数据库中(自定义获取报表数据)

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:2

通过执行计划,定时把无法使用API 调用的报表保存到数据库中(自定义获取报表数据)

using Kingdee.BOS;

using Kingdee.BOS.App.Data;

using Kingdee.BOS.Contracts;

using Kingdee.BOS.Core;

using Kingdee.BOS.Core.Report;

using Kingdee.BOS.Log;

using Kingdee.BOS.Model.ReportFilter;

using Kingdee.BOS.Orm.DataEntity;

using Kingdee.BOS.ServiceHelper;

using Kingdee.BOS.Util;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Linq;

using System.Text;


namespace YDL.K3.Plugins.Server.ISchedule

{

    [HotUpdate]

    [Description("【执行计划】物料收发明细表保存")]

    public class STK_StockDetailRpt : IScheduleService

    {

        public void Run(Context ctx, Schedule schedule)

        {

            try

            {

                Logger.Info("提示:", "开始查询物料收发明细表!");

                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();

                SysReportFilterModel 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();

                // 金蝶账套ID

                model.Load("xxxxxxxxxxx");

                // 获取当前日期  

                DateTime now = DateTime.Now;

                var filter = model.GetFilterParameter();

                DynamicObject filterObj = filter.CustomFilter;

                // 开始日期

                filterObj["BeginDate"] = new DateTime(now.Year, now.Month, 1).AddMonths(-1);

                // 结束日期

                filterObj["EndDate"] = new DateTime(now.Year, now.Month, 1).AddMonths(1).AddDays(-1).AddMonths(-1);

                //加载创建组织的物料

                //var materialDy = cse["MaterialId"] as DynamicObject;

                //var mastMaterial = BusinessDataServiceHelper.LoadSingle(ctx, materialDy["msterID"], materialDy.DynamicObjectType);

                //filterObj["EndMaterialId"] = mastMaterial;

                //filterObj["EndMaterialId_Id"] = mastMaterial["Id"];

                //filterObj["BeginMaterialId"] = mastMaterial;

                //filterObj["BeginMaterialId_Id"] = mastMaterial["Id"];

                filterObj["StockOrgId"] = 101505;//cse["PurchaseOrgId_Id"];

                IPermissionService permissionService = ServiceFactory.GetPermissionService(ctx);

                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["OpenParameter"] = null;

                p.BaseDataTempTable.AddRange(permissionService.GetBaseDataTempTable(ctx, reportMetadata.BusinessInfo.GetForm().Id));

                MoveReportServiceParameter param = new MoveReportServiceParameter(ctx, reportMetadata.BusinessInfo, Guid.NewGuid().ToString(), p);

                //SerializerProxy serialHelper = new SerializerProxy(MessageFormats.Json, UTF8Encoding.UTF8, false, string.Empty, true);

                //DataTable dt = new DataTable();

                IMoveReport moveReport = sysReporSservice.GetListAndReportData(param);

                //var dtMetaData = FormMetaDataCache.GetCachedFormMetaData(ctx, "QDNF_WLSFDTXX");

                //var DDys = new List<DynamicObject>();

                using (DataTable dt = moveReport.DataSource)

                {

                    if (dt == null)

                        return;


                    var cc = dt.ExtendedProperties;

                    var cccc = cc["BaseTable.0"];



                    string sql = string.Format(@"/*dialext*/ INSERT INTO Wlsfmxb

(FGUID,FSTOCKORGNUMBER,FOWNERNAME,FIOPRICE,FIOAMOUNT,FMATERIALID,FMATERIALNO,FMATERIALNAME,FSTOCKGROUP,FDATE,FCREATEDATE,FLOTNO,FMATERIALTYPENAME,FSTOCKNAME,FDEPARTMENTNAME,FFORMID,FBILLNAME,FBILLID,FBILLNO,FBILLTYPENAME,FMTONO,FSTOCKUNITNAME,FBASEINQTY,FBASEINPRICE,FSTOCKINQTY,FSTOCKINPRICE,FINAMOUNT,FBASEOUTQTY,FBASEOUTPRICE,FSTOCKOUTQTY,FSTOCKOUTPRICE,FOUTAMOUNT,FBASEJCQTY,FBASEJCPRICE,FSTOCKJCQTY,FSTOCKJCPRICE,FJCAMOUNT,FSRCBILLNO,FENTRYTABLE,FBILLENTRYID,F_TZH)

SELECT FGUID,FSTOCKORGNUMBER,FOWNERNAME,FIOPRICE,FIOAMOUNT,FMATERIALID,FMATERIALNO,FMATERIALNAME,FSTOCKGROUP,FDATE,FCREATEDATE,FLOTNO,FMATERIALTYPENAME,FSTOCKNAME,FDEPARTMENTNAME,FFORMID,FBILLNAME,FBILLID,FBILLNO,FBILLTYPENAME,FMTONO,FSTOCKUNITNAME,FBASEINQTY,FBASEINPRICE,FSTOCKINQTY,FSTOCKINPRICE,FINAMOUNT,FBASEOUTQTY,FBASEOUTPRICE,FSTOCKOUTQTY,FSTOCKOUTPRICE,FOUTAMOUNT,FBASEJCQTY,FBASEJCPRICE,FSTOCKJCQTY,FSTOCKJCPRICE,FJCAMOUNT,FSRCBILLNO,FENTRYTABLE,FBILLENTRYID,F_TZH 

FROM {0}", cccc);


                    var a1 = DBUtils.ExecuteDynamicObject(ctx, sql, null, null, System.Data.CommandType.Text);


                }

            }

            catch (Exception ex)

            {

                Logger.Info("错误提示:", ex.ToString());

                throw;

            }

            Logger.Info("提示:", "更新成功!");

        }

    }

}

//                

通过执行计划,定时把无法使用API 调用的报表保存到数据库中(自定义获取报表数据)

using Kingdee.BOS;using Kingdee.BOS.App.Data;using Kingdee.BOS.Contracts;using Kingdee.BOS.Core;using Kingdee.BOS.Core.Report...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息