|
|
@ -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 |
|
|
@ -92,26 +95,46 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
} |
|
|
|
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}读取全部空闲内容:{System.Text.Json.JsonSerializer.Serialize(camralist)}"); |
|
|
|
_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 }); |
|
|
|
//获取和次数相等的空闲数据
|
|
|
@ -121,7 +144,8 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
|
|
|
|
if (errorlist.Count > 0) |
|
|
|
{ |
|
|
|
_logger.LogInformation($"标识{guid}不能在规定次数内完成读取的{System.Text.Json.JsonSerializer.Serialize(errorlist.Select(r => r.Key).ToList())}"); |
|
|
|
_logger.LogInformation($"标识{guid}不能同步内容JSON:{System.Text.Json.JsonSerializer.Serialize(errorlist.Select(r => r.Key).ToList())}"); |
|
|
|
_logger.LogInformation(MakeGrid($"标识{guid}不能同步内容", errorlist)); |
|
|
|
} |
|
|
|
|
|
|
|
//如果有货位空闲
|
|
|
@ -150,12 +174,9 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
select itm; |
|
|
|
var injectionList = query.ToList();//已经完成的记录
|
|
|
|
|
|
|
|
_logger.LogInformation($"标识{guid}同步WMS未完成记录:{System.Text.Json.JsonSerializer.Serialize(injectionList)}"); |
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"标识{guid}同步WMS内容:{System.Text.Json.JsonSerializer.Serialize(injectionList)}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation(MakeGrid($"{guid}同步WMS内容", injectionList)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -377,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); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|