diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutConverter.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutConverter.cs index 695ae1c38..0910e4add 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutConverter.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutConverter.cs @@ -12,6 +12,7 @@ using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Wms.DataExchange.Domain; using Win_in.Sfs.Wms.DataExchange.WMS.ProductReceiptNote; using Win_in.Sfs.Wms.Store.Application.Contracts; +using Win_in.Sfs.Wms.Store.Domain; namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent; @@ -90,29 +91,47 @@ public class MesOutConverter : IIncomingConverter wmsProductReceiptNoteDetail.WarehouseCode = "T8"; wmsProductReceiptNoteDetail.LocationArea = ""; wmsProductReceiptNoteDetail.LocationGroup = ""; - var loc = await _locationAppService.GetListByTypesAndErpCodeAsync(types, wmsProductReceiptNoteDetail.LocationErpCode).ConfigureAwait(false); + var loc = await _locationAppService.GetListByTypesAndErpCodeAsync(types, wmsProductReceiptNoteDetail.LocationErpCode, wmsProductReceiptNoteDetail.LocationErpCode).ConfigureAwait(false); if (loc != null) { wmsProductReceiptNoteDetail.LocationCode = loc[0].Code; - } + wmsProductReceiptNoteDetail.LocationArea = loc[0].AreaCode; + wmsProductReceiptNoteDetail.LocationGroup = loc[0].LocationGroupCode; + wmsProductReceiptNoteDetail.LocationErpCode = loc[0].ErpLocationCode; + + wmsProductReceiptNoteDetail.HandledToLocationCode = loc[0].Code; + wmsProductReceiptNoteDetail.HandledToLocationArea = loc[0].AreaCode; + wmsProductReceiptNoteDetail.HandledToLocationGroup = loc[0].LocationGroupCode; + wmsProductReceiptNoteDetail.HandledToLocationErpCode = loc[0].ErpLocationCode; + wmsProductReceiptNoteDetail.RecommendToLocationCode = loc[0].Code; + wmsProductReceiptNoteDetail.RecommendToLocationArea = loc[0].AreaCode; + wmsProductReceiptNoteDetail.RecommendToLocationGroup = loc[0].LocationGroupCode; + wmsProductReceiptNoteDetail.RecommendToLocationErpCode = loc[0].ErpLocationCode; + } var item = await _itemBasicAppService.GetByCodeAsync(wmsProductReceiptNoteDetail.ItemCode).ConfigureAwait(false); - if (item != null) - { + if (item != null) + { wmsProductReceiptNoteDetail.ItemName = !string.IsNullOrEmpty(item.Name) ? item.Name : ""; wmsProductReceiptNoteDetail.ItemDesc1 = !string.IsNullOrEmpty(item.Desc1) ? item.Desc1 : ""; wmsProductReceiptNoteDetail.ItemDesc2 = !string.IsNullOrEmpty(item.Desc2) ? item.Desc2 : ""; wmsProductReceiptNoteDetail.Uom = !string.IsNullOrEmpty(item.BasicUom) ? item.BasicUom : ""; - } - else - { + + wmsProductReceiptNoteDetail.ProduceDate = incomingFromExternal.EffectiveDate; + wmsProductReceiptNoteDetail.ArriveDate = incomingFromExternal.EffectiveDate; + wmsProductReceiptNoteDetail.ExpireDate = wmsProductReceiptNoteDetail.ProduceDate.AddDays(item.GetValidateDays()); + + } + else + { + //todo 这里不应该做完工 没有零件 wmsProductReceiptNoteDetail.ItemName = ""; wmsProductReceiptNoteDetail.ItemDesc1 = ""; wmsProductReceiptNoteDetail.ItemDesc2 = ""; wmsProductReceiptNoteDetail.Uom = ""; - } - wmsProductReceiptNote.Details.Add(wmsProductReceiptNoteDetail); + } + wmsProductReceiptNote.Details.Add(wmsProductReceiptNoteDetail); } incomingToWms.DataContent = JsonSerializer.Serialize(wmsProductReceiptNote); incomingToWmsList.Add(incomingToWms); diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutReader.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutReader.cs index 63b9d0c06..def88e103 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutReader.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent/Incoming/MesOutReader.cs @@ -95,7 +95,7 @@ public class MesOutReader : IReader continue; } List types = new List { EnumLocationType.FG, EnumLocationType.WIP }; - var loc = await _locationAppService.GetListByTypesAndErpCodeAsync(types, item.Mesout_loc).ConfigureAwait(false); + var loc = await _locationAppService.GetListByTypesAndErpCodeAsync(types, item.Mesout_loc, item.Mesout_loc).ConfigureAwait(false); if (loc.Count == 0) { mesoutnbr.Add(item.Mesout_ref_nbr); diff --git a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/DataExchangeOptions.cs b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/DataExchangeOptions.cs index 1dc8acf8c..1731c384a 100644 --- a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/DataExchangeOptions.cs +++ b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/DataExchangeOptions.cs @@ -12,6 +12,7 @@ public class IncomingOptions public int PeriodSeconds { get; set; } = 5 * 60; public int RetryTimes { get; set; } = 3; public int BatchSize { get; set; } = 100; + public string apiUrl { get; set; } = ""; } public class OutgoingOptions diff --git a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/IncomingToWmsWorker.cs b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/IncomingToWmsWorker.cs index 347421104..5e915178c 100644 --- a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/IncomingToWmsWorker.cs +++ b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/IncomingToWmsWorker.cs @@ -141,7 +141,7 @@ public class IncomingToWmsWorker : AsyncPeriodicBackgroundWorkerBase await incomingToWms.HandleAsnsAsync(workerContext).ConfigureAwait(false); break; case EnumIncomingDataType.ProductReceipt: - await SendProductReceipt(workerContext, incomingToWms); + await SendProductReceipt(workerContext, incomingToWms).ConfigureAwait(false); break; case EnumIncomingDataType.MaterialRequest: await incomingToWms.HandleMaterialRequestsAsync(workerContext).ConfigureAwait(false); @@ -163,40 +163,52 @@ public class IncomingToWmsWorker : AsyncPeriodicBackgroundWorkerBase default: throw new ArgumentOutOfRangeException(); } - - incomingToWms.SetSuccess(); + if( incomingToWms.Status != EnumExchangeDataStatus.Error) + { + incomingToWms.SetSuccess(); + } } private async Task SendProductReceipt(PeriodicBackgroundWorkerContext workerContext, IncomingToWms incomingToWms) { // 定义请求的 URL - string apiUrl = "http://10.164.113.31:60085/api/wms/store/product-receipt-note"; - - var productReceiptJson = JsonSerializer.Deserialize(incomingToWms.DataContent); - try + // string apiUrl = "http://10.164.113.31:60085/api/wms/store/product-receipt-note"; + + string apiUrl = _options.Value.IncomingOptions.apiUrl; + + if (!string.IsNullOrEmpty(apiUrl)) { - - // 将参数转换为 JSON 格式 - string jsonContent = JsonSerializer.Serialize(productReceiptJson); + var productReceiptJson = JsonSerializer.Deserialize(incomingToWms.DataContent); + try + { - // 创建请求的内容 - StringContent content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); + // 将参数转换为 JSON 格式 + string jsonContent = JsonSerializer.Serialize(productReceiptJson); - - // 发送 POST 请求 - HttpResponseMessage response = await _httpClient.PostAsync(apiUrl, content); + // 创建请求的内容 + StringContent content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); - // 确保响应成功 - response.EnsureSuccessStatusCode(); - // 读取响应内容并返回 - string responseBody = await response.Content.ReadAsStringAsync(); + // 发送 POST 请求 + HttpResponseMessage response = await _httpClient.PostAsync(apiUrl, content).ConfigureAwait(false); + + // 确保响应成功 + response.EnsureSuccessStatusCode(); + + // 读取响应内容并返回 + string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + catch (HttpRequestException ex) + { + // 处理请求异常 + // 可以记录日志或者抛出异常 + Console.WriteLine(ex.Message); + incomingToWms.SetError(EnumExchangeDataErrorCode.Exception, ex.Message); + } } - catch (HttpRequestException ex) + else { - // 处理请求异常 - // 可以记录日志或者抛出异常 - Console.WriteLine(ex.Message); - //incomingToWms.SetError(EnumExchangeDataErrorCode.Exception, ex.Message); + Console.WriteLine("apiUrl未配置!"); + incomingToWms.SetError(EnumExchangeDataErrorCode.Exception, "apiUrl未配置!"); } //finally //{ diff --git a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/appsettings.json b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/appsettings.json index bf959b2e1..c3163280c 100644 --- a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/appsettings.json +++ b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Agent/appsettings.json @@ -1,7 +1,7 @@ { "ConnectionStrings": { - "Default": "Server=10.164.113.32,1818\\SHDB;Database=WMS_DongYang_DataExchange;uid=ShWmsUser;pwd=Faty@Wms_20230413#SH;TrustServerCertificate=True", - "DataExchange": "Server=10.164.113.32,1818\\SHDB;Database=WMS_DongYang_DataExchange;uid=ShWmsUser;pwd=Faty@Wms_20230413#SH;TrustServerCertificate=True" + "Default": "Server=10.164.113.32,1818\\SHDB;Database=Wms_DataExchange_Main_Dy_ShangHai;uid=ShWmsUser;pwd=Faty@Wms_20230413#SH;TrustServerCertificate=True", + "DataExchange": "Server=10.164.113.32,1818\\SHDB;Database=Wms_DataExchange_Main_Dy_ShangHai;uid=ShWmsUser;pwd=Faty@Wms_20230413#SH;TrustServerCertificate=True" }, @@ -43,7 +43,8 @@ "Active": true, "PeriodSeconds": 10, "RetryTimes": 3, - "BatchSize": 100 + "BatchSize": 100, + "apiUrl": "http://10.164.113.31:60085/api/wms/store/product-receipt-note" }, "OutgoingOptions": { "Active": false, @@ -58,3 +59,6 @@ } + + + diff --git a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application.Contracts/Locations/ILocationAppService.cs b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application.Contracts/Locations/ILocationAppService.cs index 2e2f7f1b9..a46e86f0a 100644 --- a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application.Contracts/Locations/ILocationAppService.cs +++ b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application.Contracts/Locations/ILocationAppService.cs @@ -30,4 +30,7 @@ public interface ILocationAppService Task> GetListByManyCodes(List codes); Task> GetListByTypesAndErpCodeAsync(List types, string erpCode); + Task> GetListByTypesAndErpCodeAsync(List types, string erpCode,string locCode); + + } diff --git a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Locations/LocationAppService.cs b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Locations/LocationAppService.cs index 70123d34f..61e0db700 100644 --- a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Locations/LocationAppService.cs +++ b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Locations/LocationAppService.cs @@ -164,6 +164,15 @@ public class LocationAppService var dtos = ObjectMapper.Map, List>(locations); return dtos; } + [HttpGet("list/by-types-and-erp-code")] + public virtual async Task> GetListByTypesAndErpCodeAsync(List types, string erpCode,string locCode) + { + var locations = await _repository.GetListAsync(c => types.Contains(c.Type) && c.ErpLocationCode == erpCode&&c.Code==locCode).ConfigureAwait(false); + var dtos = ObjectMapper.Map, List>(locations); + return dtos; + } + + [HttpGet("list/by-location-group-code-and-location-type")] public virtual async Task> GeListByLocationGroupCodeAndLocationType(List locationGroupCodes, List locationTypes) diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/ProductReceiptNoteEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/ProductReceiptNoteEventHandler.cs index d20477238..e000b4e8a 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/ProductReceiptNoteEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/ProductReceiptNoteEventHandler.cs @@ -77,15 +77,6 @@ public class ProductReceiptNoteEventHandler var transaction = ObjectMapper.Map(detail); var itemBasicDto= await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); - var locationDtos = await _locationAppService.GetListByTypesAndErpCodeAsync( - new List { EnumLocationType.WIP }, - detail.LocationErpCode).ConfigureAwait(false); - - if (locationDtos == null||locationDtos.Count<1) - { - throw new UserFriendlyException( - $"Erp储位为【{detail.LocationErpCode}】,库位类型为{EnumLocationType.WIP.GetDisplayName()}的库位不存在。"); - } if (itemBasicDto == null) { @@ -97,11 +88,6 @@ public class ProductReceiptNoteEventHandler detail.ItemDesc2 = itemBasicDto.Desc2; detail.ItemName=itemBasicDto.Name; detail.StdPackQty=itemBasicDto.StdPackQty; - var erpLocationDto = locationDtos.First(); - detail.LocationArea = erpLocationDto.Code; - detail.LocationGroup = erpLocationDto.LocationGroupCode; - detail.LocationErpCode= erpLocationDto.Code; - detail.LocationCode= erpLocationDto.Code; transaction.TransType = TransType; transaction.TransInOut = TransInOut;