Browse Source

Merge branch 'dev_DY_CC' of http://dev.ccwin-in.com:3000/BoXu.Zheng/WZC2 into dev_DY_CC

dev_DY_CC
周红军 1 year ago
parent
commit
2bb73a9fb3
  1. 90
      be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent/Incoming/InjectionMoldingRequestReader.cs
  2. 17
      be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/Properties/PublishProfiles/FolderProfile2.pubxml

90
be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent/Incoming/InjectionMoldingRequestReader.cs

@ -59,10 +59,12 @@ public class InjectionMoldingRequestReader : IReader
/// 读取注塑叫料任务
/// </summary>
/// <returns></returns>
public virtual async Task<List<IncomingFromExternal>> 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<InjectionRequestEditInput> joblist = new List<InjectionRequestEditInput>();
if (jobs.Count == 0)
{
string camera =await ReaderCameraApi().ConfigureAwait(false);
// 调用 ReaderCameraApi 方法获取摄像头信息
string camera = await ReaderCameraApi().ConfigureAwait(false);
List<InjectionRequest> cameraList = new List<InjectionRequest>();
if (camera == "Error occured")
{
// 记录错误日志并返回空列表
_logger.LogError($"没有读取到摄像头信息{DateTime.Now},请检查网络");
return new List<IncomingFromExternal>();
}
cameraList = System.Text.Json.JsonSerializer.Deserialize<List<InjectionRequest>>(camera);//camera转注塑叫料明细任务数据
// 将摄像头信息转换为注塑叫料明细任务数据
cameraList = System.Text.Json.JsonSerializer.Deserialize<List<InjectionRequest>>(camera);
InjectionRequestEditInput input=new InjectionRequestEditInput();
InjectionRequestEditInput input = new InjectionRequestEditInput();
List<InjectionRequestDetailInput> injectionRequestDetails = new List<InjectionRequestDetailInput>();
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<IncomingFromExternal>();
}
// 创建新的注塑请求并将数据写入数据库
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<IncomingFromExternal>();
}
/// <summary>
/// 绑定零件库位信息,如果对错误返回错误新列表
/// </summary>
/// <param name="p_list"></param>
/// <returns></returns>
private async Task<List<string>> BindAsync(List<InjectionRequestDetailInput> p_list)
{
// 异步方法,将输入的请求绑定到对应的零件和库位信息,返回错误列表
List<string> errors = new List<string>();
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
/// <returns></returns>
public async Task<string> 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<InjectionRequest> Parse(string p_str)
{
List<InjectionRequest> requests = new List<InjectionRequest>();
List<InjectionRequest> requests = new List<InjectionRequest>();
return System.Text.Json.JsonSerializer.Deserialize<List<InjectionRequest>>(p_str);
}

17
be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/Properties/PublishProfiles/FolderProfile2.pubxml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>false</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>C:\wms</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
</PropertyGroup>
</Project>
Loading…
Cancel
Save