public void Run(Context ctx, Schedule schedule) { string strSql = string.Format(@"/*dialect*/truncate table T_MID_REFERENCE"); DBUtils.Execute(ctx, strSql); ClientFactory clientHelper = new ClientFactory(); JObject jo = new JObject(); //string Mod_time = DateTime.Now.AddDays(1).ToShortDateString(); //IFormatProvider provider = new string Mod_time = DateTime.Now.ToString("yyyy-MM-dd"); jo.Add("modelId", "xgb_toly_01"); jo.Add("acqTime", Mod_time); string result = clientHelper.execute <string>("202325", "ebafe6b2aaf3db31978f71a7cd981de2", jo); JObject rss = JObject.Parse(result); JArray arry = rss["data"] as JArray; // 定义一个DataTable:存储待更新的数据 DataTable dt = new DataTable(); dt.TableName = "T_MID_REFERENCE"; var idCol_1 = dt.Columns.Add("FCUSTOMERID"); idCol_1.DataType = typeof(long); var idCol_2 = dt.Columns.Add("FMATERIALID"); idCol_2.DataType = typeof(long); var idCol_3 = dt.Columns.Add("FQTY"); idCol_3.DataType = typeof(double); dt.BeginLoadData(); foreach (JObject item in arry) { JArray arryEntry = JArray.Parse(item["data"].ToString()); if (arryEntry != null && arryEntry.Count > 0) { foreach (var ob in arryEntry) { dt.LoadDataRow(new object[] { Convert.ToInt64(ob["customerid"].ToString()), Convert.ToUInt64(ob["materialid"].ToString()), Convert.ToDouble(ob["qty"].ToString()) }, true); } } } dt.EndLoadData(); // 批量插入到数据库 DBServiceHelper.BulkInserts(ctx, string.Empty, string.Empty, dt); }
//private string[] strTempTables; /// <summary> /// 扩展取值逻辑 /// </summary> /// <param name="filter"></param> /// <param name="tableName"></param> public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName) { //创建临时表,用于存放扩展字段数据 string strTempTable = AppServiceContext.DBService.CreateTemporaryTableName(this.Context); //获取原报表数据 base.BuilderReportSqlAndTempTable(filter, strTempTable); //组合数据,回写原报表 StringBuilder sb = new StringBuilder(); sb.AppendFormat("select a.*,e.fname F_JN_YDL_AllocUseDeptID_EXT,d.fnumber F_JN_YDL_AllocUseDeptNumber_EXT into {0} from {1} a ", tableName, strTempTable); sb.AppendLine(" left join t_fa_card b on a.fnumber = b.fnumber "); sb.AppendLine(" inner join t_fa_allocation c on b.falterid = c.falterid "); sb.AppendLine(" left join t_bd_department d on c.fusedeptid = d.fdeptid "); sb.AppendLine(" inner join t_bd_department_l e on d.fdeptid = e.fdeptid "); DBUtils.Execute(this.Context, sb.ToString()); //获取报表数据 DataTable dt = this.GetData(tableName, 1, 100000000); if (dt != null && dt.Rows.Count > 0) { //清空报表数据 string strSql = string.Format("delete {0}", tableName); DBUtils.Execute(this.Context, strSql); string temp = ""; for (int i = 0; i < dt.Rows.Count; i++) { if (temp != dt.Rows[i]["FNUMBER"].ToString()) { temp = dt.Rows[i]["FNUMBER"].ToString(); } else { dt.Rows[i]["FOriginalCost"] = 0; dt.Rows[i]["FInputTax"] = 0; dt.Rows[i]["FExpenseValue"] = 0; dt.Rows[i]["FExpenseTax"] = 0; dt.Rows[i]["FOrgVal"] = 0; dt.Rows[i]["FACCUMDEPR"] = 0; dt.Rows[i]["FNETVALUE"] = 0; dt.Rows[i]["FACCUMDEVALUE"] = 0; dt.Rows[i]["FVALUE"] = 0; dt.Rows[i]["FRESIDUALVALUE"] = 0; dt.Rows[i]["FPurchaseValue"] = 0; dt.Rows[i]["FPurchaseDepr"] = 0; dt.Rows[i]["FDeprValue"] = 0; dt.Rows[i]["FCurYearDepr"] = 0; dt.Rows[i]["FDeprRemain"] = 0; //dt.Rows[i]["FLIFEPERIODS"] = 0; //dt.Rows[i]["FUSEDPERIODS"] = 0; //dt.Rows[i]["FDEPRPERIODS"] = 0; } } //填充报表数据 DBServiceHelper.BulkInserts(this.Context, "", "", dt); } AppServiceContext.DBService.DeleteTemporaryTableName(this.Context, new string[] { strTempTable }); }