金蝶二开接口对接
This commit is contained in:
@@ -64,12 +64,13 @@ namespace WMS.Web.Api.Controllers
|
||||
private readonly ILingXingService _lingXingService;
|
||||
private readonly IProductInventoryService _productInventoryService;
|
||||
private readonly IJuShuiTanService _juShuiTanService;
|
||||
private readonly IErpInventoryService _erpInventoryService;
|
||||
public TestController(IErpService erpService, IInStockTaskService inStockTaskService, IBoxInventoryRepositories boxInventoryRepositories, IRedisConcurrentProcessService redisConcurrentProcessService,
|
||||
IBasicsRepositories transactionRepositories, IOpsService opsService, IBoxService boxService, IBasicsRepositories basicsRepositories, IMemoryCache memoryCache,
|
||||
IOutStockTaskRepositories outStockTaskRepositories, IOutStockTaskService outStockTaskService, IOptions<AppOptions> options, ILoginService loginService, ISendMessageService sendMessageService,
|
||||
ITakeStockService takeStockService, ITakeStockRepositories takeStockRepositories, IOutStockService outStockService, IInStockTaskRepositories inStockTaskRepositories,
|
||||
IWebHostEnvironment env, IMaterialService materialService, IOutStockRepositories outStockRepositories, IInStockService inStockService, ILingXingService lingXingService
|
||||
, IProductInventoryService productInventoryService, IJuShuiTanService juShuiTanService)
|
||||
, IProductInventoryService productInventoryService, IJuShuiTanService juShuiTanService, IErpInventoryService erpInventoryService)
|
||||
{
|
||||
_inStockService = inStockService;
|
||||
_redisConcurrentProcessService = redisConcurrentProcessService;
|
||||
@@ -96,6 +97,7 @@ namespace WMS.Web.Api.Controllers
|
||||
_lingXingService = lingXingService;
|
||||
_productInventoryService = productInventoryService;
|
||||
_juShuiTanService = juShuiTanService;
|
||||
_erpInventoryService = erpInventoryService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -110,12 +112,14 @@ namespace WMS.Web.Api.Controllers
|
||||
//var m2 = my2.Object;
|
||||
//var md = m2.code;
|
||||
|
||||
//List<(string orgCode, string stockCode)> request = new List<(string orgCode, string stockCode)>();
|
||||
//request.Add(("101", "CK001"));
|
||||
//request.Add(("101", "CK002"));
|
||||
//var list = await _erpService.BillQueryForInventory(request);
|
||||
List<(string orgCode, string stockCode)> request = new List<(string orgCode, string stockCode)>();
|
||||
request.Add(("101", "CK001"));
|
||||
request.Add(("101", "CK002"));
|
||||
var list = await _erpService.BillQueryForInventory(request);
|
||||
|
||||
await _juShuiTanService.GetTest();
|
||||
//await _juShuiTanService.GetTest();
|
||||
string codes = "AD";
|
||||
var b = await _erpInventoryService.Get(codes);
|
||||
|
||||
//LingXingResponse<LingXingStockResponse> r = new LingXingResponse<LingXingStockResponse>();
|
||||
|
||||
|
||||
@@ -37,9 +37,10 @@
|
||||
},
|
||||
"ErpOptions": {
|
||||
"EndpointAddress": "http://erp.orico.com.cn/k3cloud/ERPGW.asmx", //原:119.23.206.129
|
||||
"UserName": "mes", //测试账号密码 mes/A1B2C3Dh/ce20210909 正式账号密码 orico/A123321./Orico
|
||||
"UserName": "mes", //测试账号密码 mes/A1B2C3Dh/ce20210909/666a6c4a522823 正式账号密码 orico/A123321./Orico
|
||||
"Password": "A1B2C3Dh.",
|
||||
"ErpId": "ce20210909"
|
||||
"ErpId": "ce20210909",
|
||||
"ZhangTaoId": "666a6c4a522823"
|
||||
},
|
||||
"OpsOptions": {
|
||||
"Url": "https://api.opsscm.test.f2b211.com/", //https://api.opsscm.test.f2b211.com/
|
||||
|
||||
@@ -4767,6 +4767,11 @@
|
||||
erp-Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Options.ErpOptions.ZhangTaoId">
|
||||
<summary>
|
||||
账号Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Options.lingXingOptions">
|
||||
<summary>
|
||||
领星配置
|
||||
@@ -6018,6 +6023,18 @@
|
||||
<param name="code"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.HttpClientEx.Url" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.HttpClientEx.Content" -->
|
||||
<!-- Badly formed XML comment ignored for member "F:WMS.Web.Domain.Services.Public.HttpClientEx.Cookie" -->
|
||||
<!-- Badly formed XML comment ignored for member "M:WMS.Web.Domain.Services.Public.HttpClientEx.AsyncRequest" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.fstockorgnumbers" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.fmaterialnumbers" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.fstocknumbers" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.flotnumbers" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.isshowstockloc" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.isshowauxprop" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.pageindex" -->
|
||||
<!-- Badly formed XML comment ignored for member "P:WMS.Web.Domain.Services.Public.InventoryParamModel.pagerows" -->
|
||||
<member name="T:WMS.Web.Domain.Services.Public.ErpService">
|
||||
<summary>
|
||||
erp数据交互服务
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -9,30 +10,37 @@ namespace WMS.Web.Core.Dto.Erp
|
||||
/// <summary>
|
||||
/// 物料编码
|
||||
/// </summary>
|
||||
[JsonProperty("FMATERIALNUMBER")]
|
||||
public string MaterialNumber { get; set; }
|
||||
/// <summary>
|
||||
/// 组织编码
|
||||
/// </summary>
|
||||
[JsonProperty("FSTOCKORGNUMBER")]
|
||||
public string OrgCode { get; set; }
|
||||
/// <summary>
|
||||
/// 仓库
|
||||
/// </summary>
|
||||
[JsonProperty("FSTOCKNUMBER")]
|
||||
public string StockCode { get; set; }
|
||||
/// <summary>
|
||||
/// 子仓库
|
||||
/// </summary>
|
||||
[JsonProperty("FSTOCKLOC")]
|
||||
public string Erp_SubStockName { get; set; }
|
||||
/// <summary>
|
||||
/// 批号
|
||||
///</summary>
|
||||
[JsonProperty("FLOTNUMBER")]
|
||||
public string Batch { get; set; }
|
||||
/// <summary>
|
||||
/// 可用量
|
||||
///</summary>
|
||||
[JsonProperty("FAVBQTY")]
|
||||
public decimal Qty { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 库存量
|
||||
///</summary>
|
||||
[JsonProperty("FQTY")]
|
||||
public decimal BeforeQty { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
||||
14
src/WMS.Web.Domain/IService/Public/IErpInventoryService.cs
Normal file
14
src/WMS.Web.Domain/IService/Public/IErpInventoryService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
|
||||
namespace WMS.Web.Domain.IService.Public
|
||||
{
|
||||
public interface IErpInventoryService
|
||||
{
|
||||
Task<Result<List<ErpInventoryDto>>> Get(string stockCodes);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,10 @@ namespace WMS.Web.Domain.Options
|
||||
/// erp-Id
|
||||
/// </summary>
|
||||
public string ErpId { get; set; }
|
||||
/// <summary>
|
||||
/// 账号Id
|
||||
/// </summary>
|
||||
public string ZhangTaoId { get; set; }
|
||||
public readonly string cache_materail_all_key = "erp_materials_list_all";
|
||||
public readonly string cache_materail_key = "erp_materials_list";
|
||||
public readonly string cache_org_key = "erp_org_list";
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace WMS.Web.Domain.Services
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
public readonly IBasicsRepositories _transactionRepositories;
|
||||
public readonly IJuShuiTanService _juShuiTanService;
|
||||
public readonly IErpInventoryService _erpInventoryService;
|
||||
public ProductInventoryService(IErpService erpService,
|
||||
ISingleDataService singleDataService,
|
||||
IErpBasicDataExtendService erpBasicDataExtendService,
|
||||
@@ -35,7 +36,8 @@ namespace WMS.Web.Domain.Services
|
||||
ILingXingService lingXingService,
|
||||
IBasicsRepositories basicsRepositories,
|
||||
IBasicsRepositories transactionRepositories,
|
||||
IJuShuiTanService juShuiTanService)
|
||||
IJuShuiTanService juShuiTanService,
|
||||
IErpInventoryService erpInventoryService)
|
||||
{
|
||||
_erpService = erpService;
|
||||
_singleDataService = singleDataService;
|
||||
@@ -45,6 +47,7 @@ namespace WMS.Web.Domain.Services
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_transactionRepositories = transactionRepositories;
|
||||
_juShuiTanService = juShuiTanService;
|
||||
_erpInventoryService = erpInventoryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
299
src/WMS.Web.Domain/Services/Public/ErpInventoryService.cs
Normal file
299
src/WMS.Web.Domain/Services/Public/ErpInventoryService.cs
Normal file
@@ -0,0 +1,299 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using MySqlX.XDevAPI.Common;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
using WMS.Web.Core.Dto.JuShuiTan;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Domain.Options;
|
||||
using WMS.Web.Domain.Values;
|
||||
|
||||
namespace WMS.Web.Domain.Services.Public
|
||||
{
|
||||
public class ErpInventoryService : IErpInventoryService
|
||||
{
|
||||
private ErpOptions _erpOptions;
|
||||
public ErpInventoryService(IOptions<ErpOptions> erpOptions)
|
||||
{
|
||||
_erpOptions = erpOptions?.Value;
|
||||
}
|
||||
|
||||
private bool Login(HttpClientEx httpClient)
|
||||
{
|
||||
string baseUrl = _erpOptions.EndpointAddress.Replace("/ERPGW.asmx", ""); //"http://192.168.1.1/k3cloud";//服务器地址
|
||||
|
||||
httpClient.Url = string.Format("{0}/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc", baseUrl);
|
||||
List<object> Parameters = new List<object>();
|
||||
Parameters.Add(_erpOptions.ZhangTaoId);//帐套Id
|
||||
Parameters.Add(_erpOptions.UserName);//用户名
|
||||
Parameters.Add(_erpOptions.Password);//密码
|
||||
Parameters.Add(2052);//多语言:中文
|
||||
|
||||
httpClient.Content = JsonConvert.SerializeObject(Parameters);
|
||||
string response = httpClient.AsyncRequest();
|
||||
var iResult = JObject.Parse(response)["LoginResultType"].Value<int>();
|
||||
return iResult == 1 ? true : false;
|
||||
}
|
||||
public async Task<Result<List<ErpInventoryDto>>> Get(string stockCodes)
|
||||
{
|
||||
List<ErpInventoryDto> list = new List<ErpInventoryDto>();
|
||||
HttpClientEx httpClient = new HttpClientEx();
|
||||
var isSuccess = Login(httpClient);
|
||||
string baseUrl = _erpOptions.EndpointAddress.Replace("/ERPGW.asmx", "");
|
||||
httpClient.Url = string.Format("{0}/Kingdee.K3.SCM.WebApi.ServicesStub.InventoryQueryService.GetInventoryData.common.kdsvc", baseUrl);
|
||||
List<object> Parameters = new List<object>();
|
||||
var model = new InventoryParamModel();
|
||||
model.fstocknumbers = stockCodes;
|
||||
//model.fmaterialnumbers = "G01-11-572474";
|
||||
model.isshowauxprop = true;
|
||||
model.isshowstockloc = true;
|
||||
model.pageindex = 1;
|
||||
model.pagerows = 10000;
|
||||
Parameters.Add(model);
|
||||
|
||||
httpClient.Content = JsonConvert.SerializeObject(Parameters);
|
||||
|
||||
string content = httpClient.AsyncRequest();
|
||||
JObject resData = JObject.Parse(content);
|
||||
|
||||
if (resData["success"].ToString().ToLower() != "true")
|
||||
return Result<List<ErpInventoryDto>>.ReFailure(ResultCodes.Erp_Inventory_Error);
|
||||
|
||||
string json = resData["data"].ToString();
|
||||
var datas = JsonConvert.DeserializeObject<List<ErpInventoryDto>>(json);
|
||||
list.AddRange(datas);
|
||||
|
||||
int num = Convert.ToInt32(resData["rowcount"]) / 10000;
|
||||
for (int i = 1; i <= num; i++)
|
||||
{
|
||||
model.pageindex++;
|
||||
|
||||
httpClient.Content = JsonConvert.SerializeObject(Parameters);
|
||||
|
||||
content = httpClient.AsyncRequest();
|
||||
resData = JObject.Parse(content);
|
||||
|
||||
if (resData["success"].ToString().ToLower() != "true")
|
||||
return Result<List<ErpInventoryDto>>.ReFailure(ResultCodes.Erp_Inventory_Error);
|
||||
|
||||
json = resData["data"].ToString();
|
||||
datas = JsonConvert.DeserializeObject<List<ErpInventoryDto>>(json);
|
||||
list.AddRange(datas);
|
||||
}
|
||||
|
||||
var blist = list.Where(w => w.Qty > 0 || w.BeforeQty > 0).ToList();
|
||||
|
||||
return Result<List<ErpInventoryDto>>.ReSuccess(blist);
|
||||
}
|
||||
|
||||
}
|
||||
class HttpClientEx
|
||||
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// Seivice URL
|
||||
|
||||
/// </summary>
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 内容
|
||||
|
||||
/// </summary>
|
||||
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// Cookie,保证登录后,所有访问持有一个Cookie;
|
||||
|
||||
/// </summary>
|
||||
|
||||
static CookieContainer Cookie = new CookieContainer();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// HTTP访问
|
||||
|
||||
/// </summary>
|
||||
|
||||
public string AsyncRequest()
|
||||
|
||||
{
|
||||
|
||||
HttpWebRequest httpRequest = HttpWebRequest.Create(Url) as HttpWebRequest;
|
||||
|
||||
httpRequest.Method = "POST";
|
||||
|
||||
httpRequest.ContentType = "application/json";
|
||||
|
||||
httpRequest.CookieContainer = Cookie;
|
||||
|
||||
httpRequest.Timeout = 1000 * 60 * 10;//10min
|
||||
|
||||
|
||||
|
||||
using (Stream reqStream = httpRequest.GetRequestStream())
|
||||
|
||||
{
|
||||
|
||||
JObject jObj = new JObject();
|
||||
|
||||
jObj.Add("format", 1);
|
||||
|
||||
jObj.Add("useragent", "ApiClient");
|
||||
|
||||
jObj.Add("rid", Guid.NewGuid().ToString().GetHashCode().ToString());
|
||||
|
||||
jObj.Add("parameters", Content);
|
||||
|
||||
jObj.Add("timestamp", DateTime.Now);
|
||||
|
||||
jObj.Add("v", "1.0");
|
||||
|
||||
string sContent = jObj.ToString();
|
||||
|
||||
var bytes = UnicodeEncoding.UTF8.GetBytes(sContent);
|
||||
|
||||
reqStream.Write(bytes, 0, bytes.Length);
|
||||
|
||||
reqStream.Flush();
|
||||
|
||||
}
|
||||
|
||||
using (var repStream = httpRequest.GetResponse().GetResponseStream())
|
||||
|
||||
{
|
||||
|
||||
using (var reader = new StreamReader(repStream))
|
||||
|
||||
{
|
||||
|
||||
return ValidateResult(reader.ReadToEnd());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static string ValidateResult(string responseText)
|
||||
|
||||
{
|
||||
|
||||
if (responseText.StartsWith("response_error:"))
|
||||
|
||||
{
|
||||
|
||||
return responseText.TrimStart("response_error:".ToCharArray());
|
||||
|
||||
}
|
||||
|
||||
return responseText;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
class InventoryParamModel
|
||||
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 库存组织编码,多个使用英文逗号【,】分隔
|
||||
|
||||
/// </summary>
|
||||
|
||||
public string fstockorgnumbers { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 物料编码,多个使用英文逗号【,】分隔
|
||||
|
||||
/// </summary>
|
||||
|
||||
public string fmaterialnumbers { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 仓库编码,多个使用英文逗号【,】分隔
|
||||
|
||||
/// </summary>
|
||||
|
||||
public string fstocknumbers { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 批号编码,多个使用英文逗号【,】分隔
|
||||
|
||||
/// </summary>
|
||||
|
||||
public string flotnumbers { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 是否查询仓位
|
||||
|
||||
/// </summary>
|
||||
|
||||
public bool isshowstockloc { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 是否查询辅助属性
|
||||
|
||||
/// </summary>
|
||||
|
||||
public bool isshowauxprop { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 当前页码
|
||||
|
||||
/// </summary>
|
||||
|
||||
public int pageindex { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 每页显示行数
|
||||
|
||||
/// </summary>
|
||||
|
||||
public int pagerows { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2652,7 +2652,7 @@ namespace WMS.Web.Domain.Services.Public
|
||||
param.FieldKeys = "FMATERIALID.FNumber,FSTOCKORGID.FNumber,FSTOCKID.FNumber,FLot.FNumber,FBASEQTY,FSTOREURNOM,FSTOREURNUM,FSTOCKLOCID.FF100004.FName,FSTOCKLOCID.FF100005.FName,FSTOCKLOCID.FF100007.FName,FSTOCKLOCID.FF100008.FName";
|
||||
param.Limit = 10000;
|
||||
//param.FilterString = $" FMATERIALID.FNumber='G01-11-572474' and FSTOCKID.FNumber='AD' and FBASEQTY>0";
|
||||
param.FilterString = $" FBASEQTY>0";
|
||||
//param.FilterString = $" FBASEQTY>0";
|
||||
for (int i = 0; i < request.Count(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
|
||||
@@ -351,6 +351,7 @@ namespace WMS.Web.Repositories.DependencyInjection
|
||||
Services.AddTransient<ILingXingService, LingXingService>();
|
||||
Services.AddTransient<IProductInventoryService, ProductInventoryService>();
|
||||
Services.AddTransient<IJuShuiTanService, JuShuiTanService>();
|
||||
Services.AddTransient<IErpInventoryService, ErpInventoryService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user