From 6752c3756674830fd35ce8af961246c313960a8a Mon Sep 17 00:00:00 2001 From: zhaoxinyu <89237069@qq.com> Date: Tue, 16 Apr 2024 11:50:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Incoming/InjectionMoldingRequestReader.cs | 90 +++++++++++++------ .../PublishProfiles/FolderProfile2.pubxml | 17 ++++ 2 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/Properties/PublishProfiles/FolderProfile2.pubxml diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent/Incoming/InjectionMoldingRequestReader.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent/Incoming/InjectionMoldingRequestReader.cs index b4e8d7c3e..6ae2b1616 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent/Incoming/InjectionMoldingRequestReader.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent/Incoming/InjectionMoldingRequestReader.cs @@ -59,10 +59,12 @@ public class InjectionMoldingRequestReader : IReader /// 读取注塑叫料任务 /// /// + public virtual async Task> ReadAsync() { try { + // 创建 SfsStoreRequestInputBase 对象以设定作业条件 var jobCondition = new SfsStoreRequestInputBase(); Filter filter = new Filter() { @@ -71,6 +73,7 @@ public class InjectionMoldingRequestReader : IReader Logic = EnumFilterLogic.And.ToString(), Value = (EnumRequestStatus.Completed).ToString() }; + // 添加筛选条件:请求状态不等于已完成 jobCondition.Condition.Filters.Add(filter); filter = new Filter() { @@ -79,26 +82,32 @@ public class InjectionMoldingRequestReader : IReader Logic = EnumFilterLogic.And.ToString(), Value = "Vision" }; + // 添加筛选条件:类型为 Vision jobCondition.Condition.Filters.Add(filter); + // 通过筛选条件获取作业列表 var jobs = await _injectionRequest.GetAllListByFilterAsync(jobCondition).ConfigureAwait(false); List joblist = new List(); if (jobs.Count == 0) { - string camera =await ReaderCameraApi().ConfigureAwait(false); + // 调用 ReaderCameraApi 方法获取摄像头信息 + string camera = await ReaderCameraApi().ConfigureAwait(false); List cameraList = new List(); if (camera == "Error occured") { + // 记录错误日志并返回空列表 _logger.LogError($"没有读取到摄像头信息{DateTime.Now},请检查网络"); return new List(); } - cameraList = System.Text.Json.JsonSerializer.Deserialize>(camera);//camera转注塑叫料明细任务数据 + // 将摄像头信息转换为注塑叫料明细任务数据 + cameraList = System.Text.Json.JsonSerializer.Deserialize>(camera); - InjectionRequestEditInput input=new InjectionRequestEditInput(); + InjectionRequestEditInput input = new InjectionRequestEditInput(); List injectionRequestDetails = new List(); - foreach (var job in cameraList) { + foreach (var job in cameraList) + { var detailInput = new InjectionRequestDetailInput() { @@ -106,24 +115,30 @@ public class InjectionMoldingRequestReader : IReader ToLocationCode = job.ToLocCode, Qty = job.Qty, }; + // 添加注塑叫料明细任务数据 injectionRequestDetails.Add(detailInput); } input.Details.AddRange(injectionRequestDetails); - var errors=await BindAsync(input.Details).ConfigureAwait(false);//零件仓库赋值 + // 通过 BindAsync 方法对零件仓库进行赋值 + var errors = await BindAsync(input.Details).ConfigureAwait(false); if (errors.Count > 0) { - foreach (var error in errors) { + // 记录错误日志并返回空列表 + foreach (var error in errors) + { _logger.LogError(error); } return new List(); } + // 创建新的注塑请求并将数据写入数据库 await _injectionRequest.CreateAsync(input).ConfigureAwait(false); } } + // 捕获特定异常并记录日志 catch (AbpException ex) { - _logger.LogError(ex.Message); + _logger.LogError(ex.Message); } catch (JsonException ex) { @@ -133,32 +148,45 @@ public class InjectionMoldingRequestReader : IReader { _logger.LogError(ex.Message); } + // 返回空列表 return new List(); } + + /// + /// 绑定零件库位信息,如果对错误返回错误新列表 + /// + /// + /// private async Task> BindAsync(List p_list) { + // 异步方法,将输入的请求绑定到对应的零件和库位信息,返回错误列表 List errors = new List(); foreach (var request in p_list) { - var itm =await _itemService.GetByCodeAsync(request.ItemCode).ConfigureAwait(false); - if(itm == null) { errors.Add($"编号:{request.ItemCode}零件表中没找到!" ); } + // 获取对应零件信息 + var itm = await _itemService.GetByCodeAsync(request.ItemCode).ConfigureAwait(false); + if (itm == null) { errors.Add($"编号:{request.ItemCode}零件表中没找到!"); } else { + // 更新请求中的零件描述和名称 request.ItemDesc1 = itm.Desc1; request.ItemDesc2 = itm.Desc2; request.ItemName = itm.Name; } + // 获取对应库位信息 var loc = await _locService.GetByCodeAsync(request.ToLocationCode).ConfigureAwait(false); if (loc == null) { errors.Add($"编号:{request.ToLocationCode}库位表中没找到!"); } else { + // 更新请求中的库位相关信息 request.ToLocationCode = loc.Code; request.ToLocationGroup = loc.LocationGroupCode; request.ToLocationErpCode = loc.ErpLocationCode; - request.ToWarehouseCode= loc.WarehouseCode; + request.ToWarehouseCode = loc.WarehouseCode; } } + // 返回错误列表 return errors; } @@ -169,28 +197,34 @@ public class InjectionMoldingRequestReader : IReader /// public async Task ReaderCameraApi() { - - var address = _options.Value.AutoRemote.IpAddress; - var username = _options.Value.AutoRemote.UserName; - var password = _options.Value.AutoRemote.Password; - var token = _options.Value.AutoRemote.Token; - var client = _httpClientFactory.CreateClient(); - var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}")); - client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials); - var response = await client.GetAsync(address).ConfigureAwait(false); - if (response.IsSuccessStatusCode) - { - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - + // 从配置中获取远程摄像头的地址、用户名、密码和令牌 + var address = _options.Value.AutoRemote.IpAddress; + var username = _options.Value.AutoRemote.UserName; + var password = _options.Value.AutoRemote.Password; + var token = _options.Value.AutoRemote.Token; + + // 创建一个HttpClient实例 + var client = _httpClientFactory.CreateClient(); + + // 将用户名和密码转换为Base64编码的凭据,并设置请求的身份验证信息 + var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}")); + client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials); + + // 发送GET请求到远程摄像头地址并等待响应 + var response = await client.GetAsync(address).ConfigureAwait(false); + + // 如果请求成功,则返回响应内容,否则返回错误信息 + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + return "Error occurred"; } + private List Parse(string p_str) { - List requests = new List(); - - - + List requests = new List(); return System.Text.Json.JsonSerializer.Deserialize>(p_str); } diff --git a/be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/Properties/PublishProfiles/FolderProfile2.pubxml b/be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/Properties/PublishProfiles/FolderProfile2.pubxml new file mode 100644 index 000000000..d5b645c0e --- /dev/null +++ b/be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/Properties/PublishProfiles/FolderProfile2.pubxml @@ -0,0 +1,17 @@ + + + + + false + false + true + Release + Any CPU + FileSystem + C:\wms + FileSystem + <_TargetId>Folder + + \ No newline at end of file