|
|
@ -23,6 +23,9 @@ using System.Net.NetworkInformation; |
|
|
|
using Win_in.Sfs.Shared.Domain.Shared.Enums.Store; |
|
|
|
using System.Threading; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Reflection; |
|
|
|
using Microsoft.Extensions.Primitives; |
|
|
|
using Win_in.Sfs.Shared.Application; |
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent.Incoming; |
|
|
|
public class InjectionMoldingRequestReader : IReader |
|
|
@ -67,55 +70,89 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
#if DEBUG
|
|
|
|
_options.Value.AutoRemote.TimeCycle = 1; |
|
|
|
_options.Value.AutoRemote.Interval = 2; |
|
|
|
|
|
|
|
#endif
|
|
|
|
// var sleepTime = (_options.Value.AutoRemote.TimeCycle*60/ _options.Value.AutoRemote.Interval)-10;
|
|
|
|
var invterval = _options.Value.AutoRemote.Interval; |
|
|
|
|
|
|
|
var guid = DateTime.Now.ToString("yyyyMMddHHmmssfff"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Stopwatch sw = Stopwatch.StartNew(); |
|
|
|
|
|
|
|
Client client = new Client(_options.Value.AutoRemote.IpAddress, _httpClientFactory.CreateClient());//调用客户记录
|
|
|
|
|
|
|
|
var flag = await client.GetMacStaticAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
if (flag != 1) |
|
|
|
{ |
|
|
|
// 记录错误日志并返回空列表
|
|
|
|
_logger.LogInformation($"读取到摄像头信息为不可用{DateTime.Now},请检查摄像头"); |
|
|
|
|
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
} |
|
|
|
if (string.IsNullOrEmpty(_options.Value.AutoRemote.AreaIDs)) |
|
|
|
{ |
|
|
|
_logger.LogInformation($"没有设置指定区域AutoRemote->AreaIDs"); |
|
|
|
|
|
|
|
|
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
} |
|
|
|
var ids = _options.Value.AutoRemote.AreaIDs.Split(","); |
|
|
|
List<ResponCargoItem> camralist = new List<ResponCargoItem>(); |
|
|
|
List<ResponCargoItem1> camralist1 = new List<ResponCargoItem1>(); |
|
|
|
for (int i = 1; i <= invterval; i++) |
|
|
|
{ |
|
|
|
foreach (var itm in ids)//遍历区域查找所有货物
|
|
|
|
{ |
|
|
|
var idsList = await client.GetCargoStaticAsync(itm).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(1000);//设备读取50ms延时,设置延时时间为1000ms保证读取更新到信息
|
|
|
|
//flag 1-有货 0-空闲
|
|
|
|
foreach (var respon in idsList.Where(r => r.Flag == 0)) |
|
|
|
{ |
|
|
|
var response = new ResponCargoItem1(); |
|
|
|
response.FromObject(respon); |
|
|
|
response.Number = $"第{i.ToString()}次读取"; |
|
|
|
camralist1.Add(response); |
|
|
|
} |
|
|
|
|
|
|
|
camralist.AddRange(idsList.Where(r => r.Flag == 0)); |
|
|
|
} |
|
|
|
|
|
|
|
_logger.LogInformation($"读取标识{guid}读取成功次数{i},耗时 {sw.ElapsedMilliseconds}毫秒"); |
|
|
|
} |
|
|
|
_logger.LogInformation($"标识{guid}读取{invterval}次接口表:{System.Text.Json.JsonSerializer.Serialize(camralist1)}"); |
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation(MakeGrid($"标识{guid}读取{invterval}次接口表",camralist1)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sw.Stop(); |
|
|
|
Thread.Sleep(1000); |
|
|
|
|
|
|
|
//按区域、货位号、零件、标志
|
|
|
|
var group= camralist.GroupBy(r => new { r.AreaID, r.CargoID, r.PartCode, r.Flag }); |
|
|
|
//获取和次数相等的空闲数据
|
|
|
|
var list = group.Where(r => r.Count() == invterval).ToList(); |
|
|
|
|
|
|
|
var errorlist= group.Where(r => r.Count() != invterval).ToList(); |
|
|
|
|
|
|
|
if (errorlist.Count > 0) |
|
|
|
{ |
|
|
|
_logger.LogInformation($"标识{guid}不能同步内容JSON:{System.Text.Json.JsonSerializer.Serialize(errorlist.Select(r => r.Key).ToList())}"); |
|
|
|
_logger.LogInformation(MakeGrid($"标识{guid}不能同步内容", errorlist)); |
|
|
|
} |
|
|
|
|
|
|
|
//如果有货位空闲
|
|
|
|
if (list.Count>0) |
|
|
|
{ |
|
|
|
|
|
|
|
sw = Stopwatch.StartNew(); |
|
|
|
|
|
|
|
sw = Stopwatch.StartNew(); |
|
|
|
_logger.LogInformation($"开始标识{guid}同步WMS开始"); |
|
|
|
List<UnCompletedRequestDto> inputdetail = new List<UnCompletedRequestDto>(); |
|
|
|
foreach (var item in list.Select(r=>r.Key).ToList()) |
|
|
@ -137,11 +174,15 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
select itm; |
|
|
|
var injectionList = query.ToList();//已经完成的记录
|
|
|
|
|
|
|
|
_logger.LogInformation($"标识{guid}同步WMS内容:{System.Text.Json.JsonSerializer.Serialize(injectionList)}"); |
|
|
|
|
|
|
|
_logger.LogInformation(MakeGrid($"{guid}同步WMS内容", injectionList)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var inject in injectionList) |
|
|
|
{ |
|
|
|
List<InjectionRequest> cameraList = new List<InjectionRequest>(); |
|
|
|
|
|
|
|
InjectionIssueRequestEditInput input = new InjectionIssueRequestEditInput(); |
|
|
|
input.Worker = "Vision"; |
|
|
|
input.IssueRequestType = EnumIssueRequestType.Vision; |
|
|
@ -249,7 +290,7 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
{ |
|
|
|
// 获取对应零件信息
|
|
|
|
var itm = await _itemService.GetByCodeAsync(request.ItemCode).ConfigureAwait(false); |
|
|
|
if (itm == null) { errors.Add($"编号:{request.ItemCode}零件表中没找到!"); } |
|
|
|
if (itm == null) { errors.Add($"编号:{request.ItemCode}零件表中没找到,请维护零件表!"); } |
|
|
|
else |
|
|
|
{ |
|
|
|
// 更新请求中的零件描述和名称
|
|
|
@ -260,7 +301,7 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
} |
|
|
|
// 获取对应库位信息
|
|
|
|
var loc = await _locService.GetByCodeAsync(request.ToLocationCode).ConfigureAwait(false); |
|
|
|
if (loc == null) { errors.Add($"编号:{request.ToLocationCode}库位表中没找到!"); } |
|
|
|
if (loc == null) { errors.Add($"编号:{request.ToLocationCode}库位表中没找到,请维护库位表!"); } |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
@ -357,14 +398,79 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
public decimal Qty { get; set; } |
|
|
|
|
|
|
|
} |
|
|
|
private string MakeGrid<T>(string header,List<T> p_list) where T : class |
|
|
|
{ |
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
sb.AppendLine(header); |
|
|
|
|
|
|
|
int rows = p_list.Count; |
|
|
|
var first = p_list.First(); |
|
|
|
|
|
|
|
var properties = first.GetType().GetProperties(); |
|
|
|
|
|
|
|
int columns = properties.Length; |
|
|
|
var columNames = first.GetType().GetProperties().ToList().Select(p => p.Name).ToList(); |
|
|
|
int cellWidth = 20; // 每个单元格的宽度
|
|
|
|
|
|
|
|
|
|
|
|
List<string> contents = new List<string>(); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rows; i++) |
|
|
|
{ |
|
|
|
var row = p_list[i]; |
|
|
|
foreach (PropertyInfo property in properties) |
|
|
|
{ |
|
|
|
// 使用反射获取属性值
|
|
|
|
contents.Add(property.GetValue(row).ToString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 输出列头
|
|
|
|
for (int j = 0; j < columns; j++) |
|
|
|
{ |
|
|
|
sb.Append("|"); |
|
|
|
sb.Append(FormatCell(columNames[j], cellWidth)); |
|
|
|
} |
|
|
|
sb.Append("|"); |
|
|
|
sb.AppendLine(); |
|
|
|
|
|
|
|
// 输出列头分隔线
|
|
|
|
for (int k = 0; k < columns * (cellWidth + 1) + 1; k++) |
|
|
|
{ |
|
|
|
sb.Append("-"); |
|
|
|
} |
|
|
|
sb.AppendLine(); |
|
|
|
|
|
|
|
// 输出网格内容
|
|
|
|
for (int i = 0; i < rows; i++) |
|
|
|
{ |
|
|
|
for (int j = 0; j < columns; j++) |
|
|
|
{ |
|
|
|
sb.Append("|"); |
|
|
|
sb.Append(FormatCell(contents[i * columns + j], cellWidth)); |
|
|
|
} |
|
|
|
sb.Append("|"); |
|
|
|
sb.AppendLine(); |
|
|
|
} |
|
|
|
return sb.ToString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string FormatCell(object value, int width) |
|
|
|
{ |
|
|
|
return value.ToString().PadLeft(width); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|