|
|
@ -34,10 +34,10 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
private readonly ILogger<InjectionMoldingRequestReader> _logger; |
|
|
|
private readonly IOptions<InjectionMoldingTaskOptions> _options; |
|
|
|
private readonly IHttpClientFactory _httpClientFactory; |
|
|
|
|
|
|
|
|
|
|
|
public InjectionMoldingRequestReader( |
|
|
|
IInjectionIssueRequestAppService injectionRequest |
|
|
|
|
|
|
|
|
|
|
|
, ILogger<InjectionMoldingRequestReader> logger |
|
|
|
, IOptions<InjectionMoldingTaskOptions> options |
|
|
|
, IHttpClientFactory httpClientFactory |
|
|
@ -47,21 +47,21 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
) |
|
|
|
{ |
|
|
|
_injectionRequest = injectionRequest; |
|
|
|
|
|
|
|
|
|
|
|
_logger = logger; |
|
|
|
_options = options; |
|
|
|
_httpClientFactory = httpClientFactory; |
|
|
|
_itemService=itemService; |
|
|
|
_itemService = itemService; |
|
|
|
_locService = locService; |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 读取注塑叫料任务
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <summary>
|
|
|
|
/// 读取注塑叫料任务
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public virtual async Task<List<IncomingFromExternal>> ReadAsync() |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
#if DEBUG
|
|
|
@ -69,130 +69,131 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
_options.Value.AutoRemote.Interval = 2; |
|
|
|
|
|
|
|
#endif
|
|
|
|
// var sleepTime = (_options.Value.AutoRemote.TimeCycle*60/ _options.Value.AutoRemote.Interval)-10;
|
|
|
|
// var sleepTime = (_options.Value.AutoRemote.TimeCycle*60/ _options.Value.AutoRemote.Interval)-10;
|
|
|
|
var invterval = _options.Value.AutoRemote.Interval; |
|
|
|
|
|
|
|
var successTime = 0; |
|
|
|
|
|
|
|
var guid = DateTime.Now.ToString("yyyyMMddHHmmssfff"); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i <invterval; i++) |
|
|
|
{ |
|
|
|
Stopwatch sw = Stopwatch.StartNew(); |
|
|
|
|
|
|
|
Client client = new Client(_options.Value.AutoRemote.IpAddress, _httpClientFactory.CreateClient());//调用客户记录
|
|
|
|
Stopwatch sw = Stopwatch.StartNew(); |
|
|
|
|
|
|
|
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>(); |
|
|
|
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>(); |
|
|
|
for (int i = 1; i <= invterval; i++) |
|
|
|
{ |
|
|
|
foreach (var itm in ids)//遍历区域查找所有货物
|
|
|
|
{ |
|
|
|
var idsList = await client.GetCargoStaticAsync(itm).ConfigureAwait(false); |
|
|
|
camralist.AddRange(idsList); |
|
|
|
//flag 1-有货 0-空闲
|
|
|
|
camralist.AddRange(idsList.Where(r => r.Flag == 0)); |
|
|
|
} |
|
|
|
successTime++; |
|
|
|
sw.Stop(); |
|
|
|
_logger.LogInformation($"读取标识{guid}读取成功次数{successTime},耗时 {sw.ElapsedMilliseconds}毫秒"); |
|
|
|
Thread.Sleep(1000); |
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"读取标识{guid}读取成功次数{i},耗时 {sw.ElapsedMilliseconds}毫秒"); |
|
|
|
} |
|
|
|
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(); |
|
|
|
//如果有货位空闲
|
|
|
|
if (list.Count>0) |
|
|
|
{ |
|
|
|
|
|
|
|
sw = Stopwatch.StartNew(); |
|
|
|
|
|
|
|
if (successTime == invterval) |
|
|
|
_logger.LogInformation($"开始标识{guid}同步WMS开始"); |
|
|
|
List<UnCompletedRequestDto> inputdetail = new List<UnCompletedRequestDto>(); |
|
|
|
foreach (var item in list.Select(r=>r.Key).ToList()) |
|
|
|
{ |
|
|
|
sw = Stopwatch.StartNew(); |
|
|
|
|
|
|
|
_logger.LogInformation($"开始标识{guid}同步WMS开始"); |
|
|
|
List<UnCompletedRequestDto> inputdetail = new List<UnCompletedRequestDto>(); |
|
|
|
foreach (var item in camralist) |
|
|
|
{ |
|
|
|
UnCompletedRequestDto jobrequestinput = new UnCompletedRequestDto(); |
|
|
|
jobrequestinput.ItemCode = item.PartCode; |
|
|
|
jobrequestinput.LocCode = item.AreaID.ToString(); |
|
|
|
jobrequestinput.PositionCode = item.CargoID.ToString(); |
|
|
|
inputdetail.Add(jobrequestinput); |
|
|
|
} |
|
|
|
UnCompletedRequestDto jobrequestinput = new UnCompletedRequestDto(); |
|
|
|
jobrequestinput.ItemCode = item.PartCode; |
|
|
|
jobrequestinput.LocCode = item.AreaID.ToString(); |
|
|
|
jobrequestinput.PositionCode = item.CargoID.ToString(); |
|
|
|
inputdetail.Add(jobrequestinput); |
|
|
|
} |
|
|
|
|
|
|
|
var uncompletelist = await _injectionRequest.GetUnCompletedRequestAsync(inputdetail).ConfigureAwait(false);//将所有库位零件信息查找未完成记录
|
|
|
|
var uncompletelist = await _injectionRequest.Getlist(inputdetail).ConfigureAwait(false);//将所有库位零件信息查找未完成记录
|
|
|
|
|
|
|
|
var query = from itm in camralist |
|
|
|
join itm1 in uncompletelist on new { locCode = itm.AreaID.ToString(), itmCode = itm.PartCode, PositionCode = itm.CargoID.ToString() } |
|
|
|
equals new { locCode = itm1.LocCode, itmCode = itm1.ItemCode, PositionCode = itm1.PositionCode } into temp |
|
|
|
from tm in temp.DefaultIfEmpty() |
|
|
|
where tm == null |
|
|
|
select itm; |
|
|
|
var injectionList = query.ToList();//已经完成的记录
|
|
|
|
var query = from itm in list.Select(r => r.Key).ToList() |
|
|
|
join itm1 in uncompletelist on new { locCode = itm.AreaID.ToString(), itmCode = itm.PartCode, PositionCode = itm.CargoID.ToString() } |
|
|
|
equals new { locCode = itm1.LocCode, itmCode = itm1.ItemCode, PositionCode = itm1.PositionCode } into temp |
|
|
|
from tm in temp.DefaultIfEmpty() |
|
|
|
where tm == null |
|
|
|
select itm; |
|
|
|
var injectionList = query.ToList();//已经完成的记录
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var inject in injectionList) |
|
|
|
foreach (var inject in injectionList) |
|
|
|
{ |
|
|
|
List<InjectionRequest> cameraList = new List<InjectionRequest>(); |
|
|
|
|
|
|
|
InjectionIssueRequestEditInput input = new InjectionIssueRequestEditInput(); |
|
|
|
input.Worker = "Vision"; |
|
|
|
input.IssueRequestType = EnumIssueRequestType.Vision; |
|
|
|
input.AutoSubmit = true; |
|
|
|
input.ActiveDate = DateTime.Now; |
|
|
|
input.UseOnTheWayLocation = false; |
|
|
|
input.Remark = "视觉叫料"; |
|
|
|
List<InjectionIssueRequestDetailInput> injectionRequestDetails = new List<InjectionIssueRequestDetailInput>(); |
|
|
|
//foreach (var job in cameraList)
|
|
|
|
//{
|
|
|
|
var detailInput = new InjectionIssueRequestDetailInput() |
|
|
|
{ |
|
|
|
List<InjectionRequest> cameraList = new List<InjectionRequest>(); |
|
|
|
|
|
|
|
InjectionIssueRequestEditInput input = new InjectionIssueRequestEditInput(); |
|
|
|
input.Worker = "Vision"; |
|
|
|
input.IssueRequestType = EnumIssueRequestType.Vision; |
|
|
|
input.AutoSubmit = true; |
|
|
|
input.ActiveDate = DateTime.Now; |
|
|
|
input.UseOnTheWayLocation = false; |
|
|
|
input.Remark = "视觉叫料"; |
|
|
|
List<InjectionIssueRequestDetailInput> injectionRequestDetails = new List<InjectionIssueRequestDetailInput>(); |
|
|
|
//foreach (var job in cameraList)
|
|
|
|
//{
|
|
|
|
var detailInput = new InjectionIssueRequestDetailInput() |
|
|
|
{ |
|
|
|
ItemCode = inject.PartCode, |
|
|
|
ToLocationCode = inject.AreaID.ToString(), |
|
|
|
PositionCode = inject.CargoID, |
|
|
|
Qty = 1, |
|
|
|
RecommendType = EnumRecommendType.RAW, |
|
|
|
IssuedQty = 0, |
|
|
|
ReceivedQty = 0, |
|
|
|
Status = EnumStatus.Open, |
|
|
|
RequestStatus = EnumRequestStatus.New, |
|
|
|
BoxQty = 1 |
|
|
|
}; |
|
|
|
// 添加注塑叫料明细任务数据
|
|
|
|
injectionRequestDetails.Add(detailInput); |
|
|
|
//}
|
|
|
|
input.Details.AddRange(injectionRequestDetails); |
|
|
|
// 通过 BindAsync 方法对零件仓库进行赋值
|
|
|
|
var errors = await BindAsync(input.Details).ConfigureAwait(false); |
|
|
|
if (errors.Count > 0) |
|
|
|
ItemCode = inject.PartCode, |
|
|
|
ToLocationCode = inject.AreaID.ToString(), |
|
|
|
PositionCode = inject.CargoID, |
|
|
|
Qty = 1, |
|
|
|
RecommendType = EnumRecommendType.RAW, |
|
|
|
IssuedQty = 0, |
|
|
|
ReceivedQty = 0, |
|
|
|
Status = EnumStatus.Open, |
|
|
|
RequestStatus = EnumRequestStatus.New, |
|
|
|
BoxQty = 1 |
|
|
|
}; |
|
|
|
// 添加注塑叫料明细任务数据
|
|
|
|
injectionRequestDetails.Add(detailInput); |
|
|
|
//}
|
|
|
|
input.Details.AddRange(injectionRequestDetails); |
|
|
|
// 通过 BindAsync 方法对零件仓库进行赋值
|
|
|
|
var errors = await BindAsync(input.Details).ConfigureAwait(false); |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
// 记录错误日志并返回空列表
|
|
|
|
foreach (var error in errors) |
|
|
|
{ |
|
|
|
// 记录错误日志并返回空列表
|
|
|
|
foreach (var error in errors) |
|
|
|
{ |
|
|
|
_logger.LogInformation(error); |
|
|
|
} |
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
_logger.LogInformation(error); |
|
|
|
} |
|
|
|
// 创建新的注塑请求并将数据写入数据库
|
|
|
|
await _injectionRequest.CreateAsync(input).ConfigureAwait(false); |
|
|
|
|
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
} |
|
|
|
_logger.LogInformation($"标识{guid}同步WMS结束,耗时{sw.ElapsedMilliseconds }毫秒"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(1000); |
|
|
|
// 创建新的注塑请求并将数据写入数据库
|
|
|
|
await _injectionRequest.CreateAsync(input).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"标识{guid}同步WMS结束,耗时{sw.ElapsedMilliseconds}毫秒"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(1000); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Client client = new Client(_options.Value.AutoRemote.IpAddress, _httpClientFactory.CreateClient());//调用客户记录
|
|
|
|
|
|
|
|
//var flag= await client.GetMacStaticAsync().ConfigureAwait(false);
|
|
|
@ -219,13 +220,13 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
//camralist = camralist.Where(p=>p.Flag==0).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
// 捕获特定异常并记录日志
|
|
|
|
|
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
_logger.LogInformation(ex.Message); |
|
|
@ -262,7 +263,7 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
if (loc == null) { errors.Add($"编号:{request.ToLocationCode}库位表中没找到!"); } |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
// 更新请求中的库位相关信息
|
|
|
|
request.ToLocationCode = loc.Code; |
|
|
|
request.ToLocationGroup = loc.LocationGroupCode; |
|
|
|