#使用技巧#两个数据中心实现跨数据中心进行取数原创
56人赞赏了该文章
1,374次浏览
未经作者许可,禁止转载编辑于2023年02月20日 19:31:38
一、业务需求
需求描述:需要实现两个数据跨数据中心取数,需要写一个插件放在服务器目录下面来执行。
二、实现步骤
首先需要保证两个数据中的科目以及核算维度的基础资料是相同的,以方便取数。
在报表的API工具里面进行测试
具体实现的公式是:=ACCTAPI("034","6405.99|[HSWD03_SYS~+~部门~+~BM000007]|[ZDY0003~+~收入支出~+~ZC0113]","JF","PRE001",RptInfo("RY"),RptInfo("RP"),RptInfo("RP"),0)+Acct("","6405.99[ZDY0003~+~收入支出项~+~ZC0113]","JF","","","",""),这是依据acct公式来进行设置的,利用ACCTAPI来进行设置公式
示例代码:
using Kingdee.BOS;
using Kingdee.BOS.App.KDSCaculateService.Function;
using Kingdee.BOS.WebApi.Client;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
namespace QRAV.GL.Report.API.ServicePlugIn
{
public class CusAcct : AbstractCustomServicePlugIn
{
public override int MinArgs => 8;
public override int MaxArgs => 8;
public override object GetFunctionValue(Context ctx, KDSContext kdsContext, string[] args)
{
using (StreamWriter streamWriter = new StreamWriter("C:\\KingdeeCloudLog\\DBDSyncLog.txt", append: true))
{
streamWriter.WriteLine("开始调用接口:");
}
Dictionary<string, string> dictionary = new Dictionary<string, string>();
using (StreamWriter streamWriter2 = new StreamWriter("C:\\KingdeeCloudLog\\DBDSyncLog.txt", append: true))
{
streamWriter2.WriteLine("获取参数:");
}
dictionary.Add("AcctZB", args[0]);
dictionary.Add("AcctNumber", args[1].ToString());
dictionary.Add("DataType", args[2].ToString());
dictionary.Add("CurrencyNumber", args[3].ToString());
dictionary.Add("Year", args[4].ToString());
dictionary.Add("StartPeriod", args[5].ToString());
dictionary.Add("EndPeriod", args[6].ToString());
dictionary.Add("AccountLevel", args[7].ToString());
K3CloudApiClient k3CloudApiClient = new K3CloudApiClient("星空的网址");
string text = k3CloudApiClient.ValidateLogin("账号的id", "Administrator", "管理员密码", 2052);
int num = Extensions.Value<int>((IEnumerable<JToken>)JObject.Parse(text).get_Item("LoginResultType"));
if (num != 1)
{
return "API登陆失败!";
}
string cDCReportData = GetCDCReportData(dictionary);
string[] array = dictionary["AcctNumber"].Split('|');
string text2 = array[0];
int num2 = array.Length - 1;
List<List<string>> list = new List<List<string>>();
for (int i = 0; i < num2; i++)
{
string text3 = array[i + 1].Replace("[", "").Replace("]", "").Replace("~+~", "|");
string[] array2 = text3.Split('|');
List<string> list2 = new List<string>();
for (int j = 0; j < array2.Length; j++)
{
if (!array2[j].Equals("") && array2[j] != null)
{
list2.Add(array2[j]);
}
}
list.Add(list2);
}
string[] list3 = new string[list.Count];
for (int k = 0; k < list.Count; k++)
{
List<string> list4 = list[k];
list3[k] = list4[2];
}
DataTable dataTable = new DataTable();
dataTable.Columns.Add("AcctNumber");
dataTable.Columns.Add("FlexNumber");
dataTable.Columns.Add("FlexName");
dataTable.Columns.Add("Amount");
dataTable.Columns.Add("IsDetail");
DataTable dataTable2 = new DataTable();
dataTable2.Columns.Add("AcctNumber");
dataTable2.Columns.Add("FISDETAIL");
dataTable2 = getAcctTable(k3CloudApiClient);
if (cDCReportData != "" || cDCReportData != null)
{
JObject val = JObject.Parse(cDCReportData);
if (val != null)
{
string text4 = ((object)val.get_Item("Result")).ToString();
JObject val2 = JObject.Parse(text4);
if (val2 != null && Convert.ToBoolean(((object)val2.get_Item("IsSuccess")).ToString()))
{
int num3 = Convert.ToInt32(((object)val2.get_Item("RowCount")).ToString());
if (num3 > 0)
{
string text5 = ((object)val2.get_Item("Rows")).ToString();
JArray val3 = JArray.Parse(text5);
for (int l = 0; l < val3.get_Count(); l++)
{
JArray val4 = JArray.Parse(((object)val3.get_Item(l)).ToString());
DataRow dataRow = dataTable.NewRow();
dataRow["AcctNumber"] = ((object)val4.get_Item(0)).ToString();
dataRow["FlexNumber"] = ((object)val4.get_Item(1)).ToString();
dataRow["FlexName"] = ((object)val4.get_Item(2)).ToString();
dataRow["Amount"] = ((object)val4.get_Item(3)).ToString();
if (((object)val4.get_Item(0)).ToString().Trim() != "")
{
DataRow[] array3 = dataTable2.Select("AcctNumber ='" + ((object)val4.get_Item(0)).ToString() + "'");
bool flag = false;
if (array3.Length != 0)
{
flag = Convert.ToBoolean(array3[0]["FISDETAIL"].ToString().Trim());
}
if (flag)
{
dataRow["IsDetail"] = 1;
}
else
{
dataRow["IsDetail"] = 0;
}
}
else
{
dataRow["IsDetail"] = null;
}
dataTable.Rows.Add(dataRow);
}
}
}
}
}
List<int> vis = new List<int>();
for (int m = 0; m < list3.Length; m++)
{
vis.Add(0);
}
List<string> listRow = new List<string>();
List<List<string>> ListPer = new List<List<string>>();
if (list3.Length != 0)
{
permutation(0, vis.Count, ref list3, ref listRow, ref vis, ref ListPer);
}
StringBuilder stringBuilder = new StringBuilder();
for (int n = 0; n < ListPer.Count; n++)
{
List<string> list5 = ListPer[n];
StringBuilder stringBuilder2 = new StringBuilder();
for (int num4 = 0; num4 < list5.Count; num4++)
{
stringBuilder2.Append(list5[num4].ToString());
if (num4 != list5.Count - 1)
{
stringBuilder2.Append("/");
}
}
stringBuilder.Append("FlexNumber like '%").Append(stringBuilder2.ToString()).Append("%'");
if (n != ListPer.Count - 1)
{
stringBuilder.Append(" or ");
}
}
decimal num5 = default(decimal);
if (text2 != null && text2 != "")
{
if (stringBuilder.Length > 0)
{
DataRow[] array4 = dataTable.Select("AcctNumber like '" + text2 + "%' and IsDetail='1'");
if (array4.Length != 0)
{
DataTable dataTable3 = ToDataTable(array4);
DataRow[] array5 = dataTable3.Select(stringBuilder.ToString());
for (int num6 = 0; num6 < array5.Length; num6++)
{
if (array5[num6]["Amount"] != null && array5[num6]["Amount"].ToString().Trim() != "")
{
num5 += Convert.ToDecimal(array5[num6]["Amount"].ToString());
}
}
}
}
else
{
DataRow[] array6 = dataTable.Select("AcctNumber like '" + text2 + "%' and IsDetail='1' and FlexNumber <> ''");
for (int num7 = 0; num7 < array6.Length; num7++)
{
if (array6[num7]["Amount"] != null && array6[num7]["Amount"].ToString().Trim() != "")
{
num5 += Convert.ToDecimal(array6[num7]["Amount"].ToString());
}
}
}
}
return num5;
}
private void permutation(int step, int len, ref string[] list, ref List<string> listRow, ref List<int> vis, ref List<List<string>> ListPer)
{
if (step == len)
{
List<string> list2 = new List<string>();
listCopy(listRow, list2);
ListPer.Add(list2);
listRow.Clear();
}
for (int i = 0; i < len; i++)
{
if (vis[i] == 0)
{
vis[i] = 1;
listRow.Add(list[i]);
permutation(step + 1, len, ref list, ref listRow, ref vis, ref ListPer);
vis[i] = 0;
}
}
}
public void listCopy(List<string> a, List<string> b)
{
foreach (string item in a)
{
b.Add(item);
}
}
public DataTable ToDataTable(DataRow[] rows)
{
if (rows == null || rows.Length == 0)
{
return null;
}
DataTable dataTable = rows[0].Table.Clone();
foreach (DataRow dataRow in rows)
{
dataTable.Rows.Add(dataRow.ItemArray);
}
return dataTable;
}
private DataTable getAcctTable(K3CloudApiClient client)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
DataTable dataTable = new DataTable();
dataTable.Columns.Add("AcctNumber");
dataTable.Columns.Add("FISDETAIL");
JObject val = (JObject)(object)new JObject();
val.Add("FormId", JToken.op_Implicit("BD_Account"));
val.Add("FieldKeys", JToken.op_Implicit("FNumber,FISDETAIL"));
val.Add("FilterString", JToken.op_Implicit(""));
List<List<object>> list = client.ExecuteBillQuery(((object)val).ToString());
if (list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
List<object> list2 = list[i];
DataRow dataRow = dataTable.NewRow();
dataRow["AcctNumber"] = list2[0].ToString();
dataRow["FISDETAIL"] = list2[1].ToString();
dataTable.Rows.Add(dataRow);
}
}
return dataTable;
}
private string getAmountFiledName(string dataType)
{
string result = null;
switch (dataType)
{
case "Y":
result = "FBEGINDEBIT";
break;
case "JY":
result = "FBEGINDEBIT";
break;
case "DY":
result = "FENDCREDIT";
break;
case "C":
result = "FBEGINYEARDEBIT";
break;
case "JC":
result = "FBEGINYEARDEBIT";
break;
case "DC":
result = "FBEGINCREDIT";
break;
case "JF":
result = "FDEBIT";
break;
case "DF":
result = "FCREDIT";
break;
case "JL":
result = "FYTDDEBIT";
break;
case "DL":
result = "FYTDCREDIT";
break;
}
return result;
}
private string GetCDCReportData(Dictionary<string, string> reportParam)
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Expected O, but got Unknown
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Expected O, but got Unknown
K3CloudApiClient k3CloudApiClient = new K3CloudApiClient("星空的网址");
string text = k3CloudApiClient.ValidateLogin("账号id", "Administrator", "管理员密码", 2052);
int num = Extensions.Value<int>((IEnumerable<JToken>)JObject.Parse(text).get_Item("LoginResultType"));
if (num == 1)
{
string amountFiledName = getAmountFiledName(reportParam["DataType"]);
if (amountFiledName != null)
{
JObject val = (JObject)(object)new JObject();
val.Add("FieldKeys", JToken.op_Implicit("FBALANCEID,FDETAILNUMBER,FDETAILNAME," + amountFiledName));
val.Add("SchemeId", JToken.op_Implicit(""));
val.Add("StartRow", JToken.op_Implicit(0));
val.Add("Limit", JToken.op_Implicit(10000));
val.Add("IsVerifyBaseDataField", JToken.op_Implicit("true"));
JObject val2 = (JObject)(object)new JObject();
JObject val3 = (JObject)(object)new JObject();
val3.Add("FNumber", JToken.op_Implicit(reportParam["AcctZB"]));
val2.Add("FACCTBOOKID", (JToken)(object)val3);
val2.Add("FCURRENCY", JToken.op_Implicit(1));
val2.Add("FSTARTYEAR", JToken.op_Implicit(reportParam["Year"]));
val2.Add("FSTARTPERIOD", JToken.op_Implicit(reportParam["StartPeriod"]));
val2.Add("FENDYEAR", JToken.op_Implicit(reportParam["Year"]));
val2.Add("FBALANCELEVEL", JToken.op_Implicit(5));
val2.Add("FENDPERIOD", JToken.op_Implicit(reportParam["EndPeriod"]));
val2.Add("FSHOWDETAIL", JToken.op_Implicit(true));
val2.Add("FFORBIDBALANCE", JToken.op_Implicit(true));
val2.Add("FNOTPOSTVOUCHER", JToken.op_Implicit(true));
val2.Add("FDEBITORCREDIT", JToken.op_Implicit(false));
val2.Add("FBALANCEZERO", JToken.op_Implicit(true));
val2.Add("FNOBUSINESS", JToken.op_Implicit(false));
val2.Add("FPERIODNOBALANCE", JToken.op_Implicit(true));
val2.Add("FYEARNOBALANCE", JToken.op_Implicit(true));
val2.Add("FSHOWFULLNAME", JToken.op_Implicit(false));
val2.Add("FDETAILSHOWACCT", JToken.op_Implicit(true));
val2.Add("FSHOWDETAILONLY", JToken.op_Implicit(false));
val2.Add("FEXCLUDEADJUSTVCH", JToken.op_Implicit(false));
val2.Add("FFLEXDEBITORCREDIT", JToken.op_Implicit(false));
val2.Add("FSHOWFLEXBYCOL", JToken.op_Implicit(false));
val.Add("Model", (JToken)(object)val2);
using (StreamWriter streamWriter = new StreamWriter("C:\\KingdeeCloudLog\\DBDSyncLog.txt", append: true))
{
streamWriter.WriteLine("调用接口:" + ((object)val).ToString());
}
string sysReportData = k3CloudApiClient.GetSysReportData("GL_RPT_AccountBalance", ((object)val).ToString());
using (StreamWriter streamWriter2 = new StreamWriter("C:\\KingdeeCloudLog\\DBDSyncLog.txt", append: true))
{
streamWriter2.WriteLine(sysReportData);
}
return sysReportData;
}
return "未填写取值类型";
}
return null;
}
private bool isDetail(K3CloudApiClient client, string acctNumber)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
JObject val = (JObject)(object)new JObject();
val.Add("FormId", JToken.op_Implicit("BD_Account"));
val.Add("FieldKeys", JToken.op_Implicit("FISDETAIL"));
val.Add("FilterString", JToken.op_Implicit("FNumber='" + acctNumber + "'"));
List<List<object>> list = client.ExecuteBillQuery(((object)val).ToString());
if (list.Count > 0)
{
List<object> list2 = list[0];
return Convert.ToBoolean(list2[0]);
}
return false;
}
public CusAcct()
: this()
{
}
}
}
赞 56
56人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读