diff --git a/src/WMS.Web.Api/Controllers/TestController.cs b/src/WMS.Web.Api/Controllers/TestController.cs index d50e867e..91f1ddc1 100644 --- a/src/WMS.Web.Api/Controllers/TestController.cs +++ b/src/WMS.Web.Api/Controllers/TestController.cs @@ -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 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 r = new LingXingResponse(); diff --git a/src/WMS.Web.Api/appsettings.json b/src/WMS.Web.Api/appsettings.json index 0cfe7887..a37022d5 100644 --- a/src/WMS.Web.Api/appsettings.json +++ b/src/WMS.Web.Api/appsettings.json @@ -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/ diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 431439ff..cabb95dc 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -4767,6 +4767,11 @@ erp-Id + + + 账号Id + + 领星配置 @@ -6018,6 +6023,18 @@ + + + + + + + + + + + + erp数据交互服务 diff --git a/src/WMS.Web.Core/Dto/Erp/ErpInventoryDto.cs b/src/WMS.Web.Core/Dto/Erp/ErpInventoryDto.cs index 30597164..173e7c87 100644 --- a/src/WMS.Web.Core/Dto/Erp/ErpInventoryDto.cs +++ b/src/WMS.Web.Core/Dto/Erp/ErpInventoryDto.cs @@ -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 /// /// 物料编码 /// + [JsonProperty("FMATERIALNUMBER")] public string MaterialNumber { get; set; } /// /// 组织编码 /// + [JsonProperty("FSTOCKORGNUMBER")] public string OrgCode { get; set; } /// /// 仓库 /// + [JsonProperty("FSTOCKNUMBER")] public string StockCode { get; set; } /// /// 子仓库 /// + [JsonProperty("FSTOCKLOC")] public string Erp_SubStockName { get; set; } /// /// 批号 /// + [JsonProperty("FLOTNUMBER")] public string Batch { get; set; } /// /// 可用量 /// + [JsonProperty("FAVBQTY")] public decimal Qty { get; set; } = 0; /// /// 库存量 /// + [JsonProperty("FQTY")] public decimal BeforeQty { get; set; } = 0; } } diff --git a/src/WMS.Web.Domain/IService/Public/IErpInventoryService.cs b/src/WMS.Web.Domain/IService/Public/IErpInventoryService.cs new file mode 100644 index 00000000..e5fbb1f8 --- /dev/null +++ b/src/WMS.Web.Domain/IService/Public/IErpInventoryService.cs @@ -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>> Get(string stockCodes); + } +} diff --git a/src/WMS.Web.Domain/Options/ErpOptions.cs b/src/WMS.Web.Domain/Options/ErpOptions.cs index f61280ea..588f3629 100644 --- a/src/WMS.Web.Domain/Options/ErpOptions.cs +++ b/src/WMS.Web.Domain/Options/ErpOptions.cs @@ -28,6 +28,10 @@ namespace WMS.Web.Domain.Options /// erp-Id /// public string ErpId { get; set; } + /// + /// 账号Id + /// + 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"; diff --git a/src/WMS.Web.Domain/Services/ProductInventoryService.cs b/src/WMS.Web.Domain/Services/ProductInventoryService.cs index 068c3a29..76bdd28e 100644 --- a/src/WMS.Web.Domain/Services/ProductInventoryService.cs +++ b/src/WMS.Web.Domain/Services/ProductInventoryService.cs @@ -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; } /// diff --git a/src/WMS.Web.Domain/Services/Public/ErpInventoryService.cs b/src/WMS.Web.Domain/Services/Public/ErpInventoryService.cs new file mode 100644 index 00000000..5e2efb6f --- /dev/null +++ b/src/WMS.Web.Domain/Services/Public/ErpInventoryService.cs @@ -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?.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 Parameters = new List(); + 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(); + return iResult == 1 ? true : false; + } + public async Task>> Get(string stockCodes) + { + List list = new List(); + 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 Parameters = new List(); + 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>.ReFailure(ResultCodes.Erp_Inventory_Error); + + string json = resData["data"].ToString(); + var datas = JsonConvert.DeserializeObject>(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>.ReFailure(ResultCodes.Erp_Inventory_Error); + + json = resData["data"].ToString(); + datas = JsonConvert.DeserializeObject>(json); + list.AddRange(datas); + } + + var blist = list.Where(w => w.Qty > 0 || w.BeforeQty > 0).ToList(); + + return Result>.ReSuccess(blist); + } + + } + class HttpClientEx + + { + + /// + + /// Seivice URL + + /// + + public string Url { get; set; } + + /// + + /// 内容 + + /// + + public string Content { get; set; } + + /// + + /// Cookie,保证登录后,所有访问持有一个Cookie; + + /// + + static CookieContainer Cookie = new CookieContainer(); + + + + /// + + /// HTTP访问 + + /// + + 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 + + { + + /// + + /// 库存组织编码,多个使用英文逗号【,】分隔 + + /// + + public string fstockorgnumbers { get; set; } + + + + /// + + /// 物料编码,多个使用英文逗号【,】分隔 + + /// + + public string fmaterialnumbers { get; set; } + + + + /// + + /// 仓库编码,多个使用英文逗号【,】分隔 + + /// + + public string fstocknumbers { get; set; } + + + + /// + + /// 批号编码,多个使用英文逗号【,】分隔 + + /// + + public string flotnumbers { get; set; } + + + + /// + + /// 是否查询仓位 + + /// + + public bool isshowstockloc { get; set; } + + + + /// + + /// 是否查询辅助属性 + + /// + + public bool isshowauxprop { get; set; } + + + + /// + + /// 当前页码 + + /// + + public int pageindex { get; set; } + + + + /// + + /// 每页显示行数 + + /// + + public int pagerows { get; set; } + + } + +} diff --git a/src/WMS.Web.Domain/Services/Public/ErpService.cs b/src/WMS.Web.Domain/Services/Public/ErpService.cs index d3d397d6..2103b6a6 100644 --- a/src/WMS.Web.Domain/Services/Public/ErpService.cs +++ b/src/WMS.Web.Domain/Services/Public/ErpService.cs @@ -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) diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs index 1d24b33e..e74e61a9 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs @@ -351,6 +351,7 @@ namespace WMS.Web.Repositories.DependencyInjection Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); } } }