2025-04-24 18:31:27 +08:00
|
|
|
|
using Kingdee.CDP.WebApi.SDK;
|
|
|
|
|
using Kingdee.CDP.WebApi.SDK.DataEntify;
|
|
|
|
|
using MyCode.Project.Domain.Config;
|
|
|
|
|
using MyCode.Project.Domain.Message.Act.PurchaseOrder;
|
|
|
|
|
using MyCode.Project.Domain.Message.Request.KingDee;
|
|
|
|
|
using MyCode.Project.Infrastructure.Common;
|
|
|
|
|
using MyCode.Project.Infrastructure.Exceptions;
|
|
|
|
|
using MyCode.Project.Infrastructure.WebPost;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Mail;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MyCode.Project.OutSideService.Implementation
|
|
|
|
|
{
|
|
|
|
|
public class KingDeeService: IKingDeeService
|
|
|
|
|
{
|
|
|
|
|
public KingDeeService()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
public static K3CloudApi staClient = null;
|
|
|
|
|
public static DateTime timeOut = DateTime.Now;
|
|
|
|
|
public string AddTiaoMaUrl = "api/UHIK_BD_BarCodeMainFile/Save";
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取一个K3客户端
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2025-05-16 18:37:51 +08:00
|
|
|
|
public K3CloudApi GetK3CloudClient(string yuYan = "")
|
2025-04-24 18:31:27 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* "Kingdee": {
|
|
|
|
|
"Default": {
|
|
|
|
|
//第三方系统登录授权的账套ID
|
|
|
|
|
"AcctID": "65edc24ab975db",
|
|
|
|
|
//第三方系统登录授权的应用ID
|
|
|
|
|
"AppID": "302967_20fp7YsL2kpWR9VG5Y3LSbUHzv3/SDmv",
|
|
|
|
|
//第三方系统登录授权的应用密钥
|
|
|
|
|
"AppSec": "5e38f16711514126ae1511ca4ead3232",
|
|
|
|
|
//第三方系统登录授权的用户
|
|
|
|
|
"UserName": "ERP1",
|
|
|
|
|
//账套语系,默认2052
|
|
|
|
|
"LCID": 2052,
|
|
|
|
|
//服务Url地址 (只有私有云用户需要配置Serverurl,公有云用户走网关不需要配置)
|
|
|
|
|
"ServerUrl": "http://8.138.110.197/K3Cloud",
|
|
|
|
|
// 时间
|
|
|
|
|
"Timestamp": 30
|
|
|
|
|
}
|
2025-05-16 18:37:51 +08:00
|
|
|
|
}
|
|
|
|
|
语言ID,中文2052(默认),英文1033,繁体3076;
|
2025-04-24 18:31:27 +08:00
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* */
|
|
|
|
|
|
2025-05-16 18:37:51 +08:00
|
|
|
|
if (staClient == null || DateTime.Now>timeOut ||1==1)
|
2025-04-24 18:31:27 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string AppID = ConfigurationManager.AppSettings.Get("X-KDApi-AppID");
|
|
|
|
|
string UserName = ConfigurationManager.AppSettings.Get("X-KDApi-UserName");
|
|
|
|
|
string AcctID = ConfigurationManager.AppSettings.Get("X-KDApi-AcctID");
|
|
|
|
|
string AppSec = ConfigurationManager.AppSettings.Get("X-KDApi-AppSec");
|
|
|
|
|
string LCID = ConfigurationManager.AppSettings.Get("X-KDApi-LCID");
|
2025-05-16 18:37:51 +08:00
|
|
|
|
if (yuYan != "")
|
|
|
|
|
LCID = yuYan;
|
2025-04-24 18:31:27 +08:00
|
|
|
|
string ServerUrl = ConfigurationManager.AppSettings.Get("X-KDApi-ServerUrl");
|
2025-05-16 18:37:51 +08:00
|
|
|
|
//staClient = new K3CloudApi(ServerUrl);
|
2025-04-24 18:31:27 +08:00
|
|
|
|
timeOut = DateTime.Now.AddMinutes(5);
|
2025-05-16 18:37:51 +08:00
|
|
|
|
staClient = new K3CloudApi();
|
|
|
|
|
staClient.InitClient(AcctID, AppID, AppSec, UserName, int.Parse(LCID), "100", ServerUrl);
|
2025-04-24 18:31:27 +08:00
|
|
|
|
//staClient.InitClient("65edc24ab975db", "302967_20fp7YsL2kpWR9VG5Y3LSbUHzv3/SDmv", "5e38f16711514126ae1511ca4ead3232", "ERP1", 2052, "100", "http://8.138.110.197/k3cloud/");
|
|
|
|
|
}
|
|
|
|
|
return staClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取供应商
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetBDSupplier()
|
|
|
|
|
{
|
|
|
|
|
//GetK3CloudClient2();
|
|
|
|
|
var staClient2 = GetK3CloudClient();
|
|
|
|
|
//staClient.InitClient("65edc24ab975db", "302967_20fp7YsL2kpWR9VG5Y3LSbUHzv3/SDmv", "5e38f16711514126ae1511ca4ead3232", "ERP1", 2052, "100", "http://8.138.110.197/k3cloud/");
|
|
|
|
|
BillQuery billQuery = new BillQuery();
|
|
|
|
|
billQuery = new BillQuery()
|
|
|
|
|
{
|
|
|
|
|
FormId = "BD_Supplier",
|
|
|
|
|
FieldKeys = "FNumber,FCountry,FName",
|
2025-04-28 10:25:01 +08:00
|
|
|
|
Limit = 900000,
|
2025-04-24 18:31:27 +08:00
|
|
|
|
StartRow = 0,
|
|
|
|
|
};
|
|
|
|
|
string json = JsonHelper.ToJson(billQuery);
|
|
|
|
|
var sds= staClient2.BillQuery(json);
|
|
|
|
|
//string resultJson = JsonHelper.ToJson(sds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sds;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取采购组织
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetFPurchaseOrgList()
|
|
|
|
|
{
|
|
|
|
|
//GetK3CloudClient2();
|
|
|
|
|
var staClient2 = GetK3CloudClient();
|
|
|
|
|
//staClient.InitClient("65edc24ab975db", "302967_20fp7YsL2kpWR9VG5Y3LSbUHzv3/SDmv", "5e38f16711514126ae1511ca4ead3232", "ERP1", 2052, "100", "http://8.138.110.197/k3cloud/");
|
|
|
|
|
BillQuery billQuery = new BillQuery();
|
|
|
|
|
billQuery = new BillQuery()
|
|
|
|
|
{
|
|
|
|
|
FormId = "ORG_Organizations",
|
|
|
|
|
FieldKeys = "FNumber,FName,FORGID",
|
2025-04-28 10:25:01 +08:00
|
|
|
|
Limit = 90000,
|
2025-04-24 18:31:27 +08:00
|
|
|
|
StartRow = 0,
|
|
|
|
|
};
|
|
|
|
|
string json = JsonHelper.ToJson(billQuery);
|
|
|
|
|
var sds = staClient2.BillQuery(json);
|
|
|
|
|
//string resultJson = JsonHelper.ToJson(sds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sds;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
2025-05-16 18:37:51 +08:00
|
|
|
|
public string QueryList(BillQuery queryParam,string yuYan="")
|
2025-04-24 18:31:27 +08:00
|
|
|
|
{
|
2025-05-16 18:37:51 +08:00
|
|
|
|
staClient = GetK3CloudClient(yuYan);
|
2025-04-24 18:31:27 +08:00
|
|
|
|
//staClient.InitClient("65edc24ab975db", "302967_20fp7YsL2kpWR9VG5Y3LSbUHzv3/SDmv", "5e38f16711514126ae1511ca4ead3232", "ERP1", 2052, "100", "http://8.138.110.197/k3cloud/");
|
|
|
|
|
//BillQuery billQuery = new BillQuery();
|
|
|
|
|
//FieldKeys = "FID,FBillNo,FDate,FBILLTYPEID,FSUPPLIERID,FName,FSupplierId,FModifyDate,FPurchaserId,FMaterialId,FQty,FEntryNote,FBillAllAmount_LC",
|
|
|
|
|
//billQuery = new BillQuery()
|
|
|
|
|
//{
|
|
|
|
|
// FormId = "PUR_PurchaseOrder",
|
|
|
|
|
// FieldKeys = "FID,FBillNo,FDate,FBILLTYPEID,FSUPPLIERID,FSupplierId.FNAME,FSupplierId,FModifyDate,FPurchaserId,FMaterialId,FQty,FEntryNote,FBillAllAmount_LC",
|
|
|
|
|
// Limit = 20,
|
|
|
|
|
// StartRow = 0,
|
|
|
|
|
//};
|
|
|
|
|
var datastr =JsonHelper.ToJson(queryParam);
|
|
|
|
|
var resultString = staClient.BillQuery(datastr);
|
|
|
|
|
// 包含ErrorCode认定为失败
|
|
|
|
|
if (resultString.Contains("ErrorCode"))
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("金蝶云接口调用失败,请检查");
|
|
|
|
|
LogHelper.Error(resultString);
|
|
|
|
|
throw new Exception("单据在云星空已锁定,请联系采购员");
|
|
|
|
|
}
|
|
|
|
|
//List<dynamic> result = JsonSerializer.Deserialize<List<dynamic>>(resultString);
|
|
|
|
|
//var total = this.GetTotal(queryParam);
|
|
|
|
|
//return new ViewListOutput(result, total);
|
|
|
|
|
|
|
|
|
|
return resultString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 保存一个订单对象
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存一个订单对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="formId"></param>
|
|
|
|
|
/// <param name="billSave"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string Save(string formId, BillSave billSave)
|
|
|
|
|
{
|
|
|
|
|
staClient = GetK3CloudClient();
|
|
|
|
|
var datastr = JsonHelper.ToJson(billSave);
|
|
|
|
|
//LogHelper.Info(datastr);
|
|
|
|
|
var resultString = staClient.Save(formId, datastr);
|
|
|
|
|
if (resultString.Contains("ErrorCode"))
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("金蝶云接口调用失败,请检查");
|
|
|
|
|
LogHelper.Error(resultString);
|
|
|
|
|
throw new Exception("单据在云星空已锁定,请联系采购员");
|
|
|
|
|
}
|
|
|
|
|
var result = JsonHelper.ToObject<Dictionary<string, Dictionary<string, dynamic>>>(resultString);
|
|
|
|
|
var data = result["Result"]["ResponseStatus"];
|
|
|
|
|
return resultString;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Push(下推订单)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下推订单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="formId"></param>
|
|
|
|
|
/// <param name="billPush"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
public string Push(string formId, BillPush billPush)
|
|
|
|
|
{
|
|
|
|
|
staClient = GetK3CloudClient();
|
|
|
|
|
var datastr = JsonHelper.ToJson(billPush);
|
|
|
|
|
LogHelper.Info(datastr);
|
|
|
|
|
var resultString = staClient.Push(formId, datastr);
|
|
|
|
|
if (resultString.Contains("ErrorCode"))
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("金蝶云接口调用失败,请检查");
|
|
|
|
|
LogHelper.Error(resultString);
|
|
|
|
|
throw new Exception("单据在云星空已锁定,请联系采购员");
|
|
|
|
|
}
|
|
|
|
|
var result = JsonHelper.ToObject<dynamic>(resultString);
|
|
|
|
|
var data = result["Result"]["ResponseStatus"]["SuccessEntitys"];
|
|
|
|
|
return JsonHelper.ToJson( data);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region AddTiaoMa(批量新增条码档案的接口)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量新增条码档案的接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="list"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
public string AddTiaoMa(string json)
|
|
|
|
|
{
|
|
|
|
|
List<AddTiaoMa> list = JsonHelper.ToObject<List<AddTiaoMa>>(json);
|
2025-04-28 15:44:41 +08:00
|
|
|
|
List<string> barcodeList = new List<string>();
|
|
|
|
|
List<AddTiaoMa> senList = new List<AddTiaoMa>();
|
|
|
|
|
list.ForEach(t =>
|
|
|
|
|
{
|
|
|
|
|
if (!barcodeList.Contains(t.FBarCode))
|
|
|
|
|
{
|
|
|
|
|
t.FBarCodeRule = "01";
|
|
|
|
|
senList.Add(t);
|
|
|
|
|
barcodeList.Add(t.FBarCode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-24 18:31:27 +08:00
|
|
|
|
AddTiaoMaConfig addconfig = new AddTiaoMaConfig();
|
|
|
|
|
addconfig.Key = "qwe123!@#";
|
2025-04-28 15:44:41 +08:00
|
|
|
|
addconfig.Items = senList;
|
2025-04-24 18:31:27 +08:00
|
|
|
|
WebUtils webUtils = new WebUtils();
|
|
|
|
|
string json2 = JsonHelper.ToJson(addconfig);
|
|
|
|
|
string ServerUrl = ConfigurationManager.AppSettings.Get("TiaoMaUrl");
|
|
|
|
|
string url = ServerUrl + AddTiaoMaUrl;
|
|
|
|
|
LogHelper.Info("批量新增条码档案的接口");
|
|
|
|
|
LogHelper.Info(url);
|
|
|
|
|
LogHelper.Info(json2);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var resultString = webUtils.DoPostJson(url, json2);
|
|
|
|
|
LogHelper.Info(resultString);
|
|
|
|
|
var result = JsonHelper.ToObject<dynamic>(resultString);
|
|
|
|
|
var code = result["code"];
|
|
|
|
|
if (code != "200")
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("金蝶云接口调用失败,请检查");
|
|
|
|
|
LogHelper.Error(result["msg"]);
|
|
|
|
|
throw new BaseException("金蝶云接口调用失败,请检查"+ result["msg"]);
|
|
|
|
|
}
|
|
|
|
|
//if (resultString.Contains("ErrorCode"))
|
|
|
|
|
//{
|
|
|
|
|
// LogHelper.Error("金蝶云接口调用失败,请检查");
|
|
|
|
|
// LogHelper.Error(resultString);
|
|
|
|
|
// throw new Exception("金蝶云接口调用失败,请检查");
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//var result = JsonHelper.ToObject<dynamic>(resultString);
|
|
|
|
|
//var data = result["Result"]["ResponseStatus"]["SuccessEntitys"];
|
|
|
|
|
//return JsonHelper.ToJson(data);
|
|
|
|
|
return resultString;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("批量新增条码档案的接口出错");
|
|
|
|
|
LogHelper.Error(ex);
|
|
|
|
|
throw new BaseException(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Delete(删除某个订单)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除某个订单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="formId"></param>
|
|
|
|
|
/// <param name="billdelete"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
|
|
|
|
|
public dynamic Delete(string formId, BillDelete billdelete)
|
|
|
|
|
{
|
|
|
|
|
staClient = GetK3CloudClient();
|
|
|
|
|
var datastr = JsonHelper.ToJson(billdelete);
|
|
|
|
|
LogHelper.Info(datastr);
|
|
|
|
|
var resultString = staClient.Delete(formId, datastr);
|
|
|
|
|
if (resultString.Contains("ErrorCode"))
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("金蝶云接口调用失败,请检查");
|
|
|
|
|
LogHelper.Error(resultString);
|
|
|
|
|
throw new Exception("单据在云星空已锁定,请联系采购员");
|
|
|
|
|
}
|
|
|
|
|
var result = JsonHelper.ToObject<dynamic>(resultString);
|
|
|
|
|
var data = result["Result"]["ResponseStatus"]["SuccessEntitys"];
|
|
|
|
|
return JsonHelper.ToJson(data);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|