|
|
@ -21,6 +21,8 @@ using System.IdentityModel.Tokens.Jwt; |
|
|
|
using Volo.Abp; |
|
|
|
using System.Net.NetworkInformation; |
|
|
|
using Win_in.Sfs.Shared.Domain.Shared.Enums.Store; |
|
|
|
using System.Threading; |
|
|
|
using System.Diagnostics; |
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent.Incoming; |
|
|
|
public class InjectionMoldingRequestReader : IReader |
|
|
@ -62,113 +64,150 @@ public class InjectionMoldingRequestReader : IReader |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
// 获取注塑叫料任务数量
|
|
|
|
//var count = await _injectionRequest.GetCountAsync().ConfigureAwait(false);
|
|
|
|
//List<InjectionIssueRequestEditInput> joblist = new List<InjectionIssueRequestEditInput>();
|
|
|
|
//if (count == 0)
|
|
|
|
//{
|
|
|
|
// 调用 ReaderCameraApi 方法获取摄像头信息
|
|
|
|
var sleepTime = (_options.Value.AutoRemote.TimeCycle*60/ _options.Value.AutoRemote.Interval)-10; |
|
|
|
var invterval = _options.Value.AutoRemote.Interval; |
|
|
|
|
|
|
|
var successTime = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i <invterval; i++) |
|
|
|
{ |
|
|
|
Stopwatch sw = Stopwatch.StartNew(); |
|
|
|
|
|
|
|
Client client = new Client(_options.Value.AutoRemote.IpAddress, _httpClientFactory.CreateClient());//调用客户记录
|
|
|
|
|
|
|
|
var flag= await client.GetMacStaticAsync().ConfigureAwait(false); |
|
|
|
if (flag!=1) |
|
|
|
var flag = await client.GetMacStaticAsync().ConfigureAwait(false); |
|
|
|
if (flag != 1) |
|
|
|
{ |
|
|
|
// 记录错误日志并返回空列表
|
|
|
|
_logger.LogInformation($"读取到摄像头信息为不可用{DateTime.Now},请检查摄像头"); |
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
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(","); |
|
|
|
var ids = _options.Value.AutoRemote.AreaIDs.Split(","); |
|
|
|
List<ResponCargoItem> camralist = new List<ResponCargoItem>(); |
|
|
|
foreach (var itm in ids)//遍历区域查找所有货物
|
|
|
|
{ |
|
|
|
var idsList= await client.GetCargoStaticAsync(itm).ConfigureAwait(false); |
|
|
|
camralist.AddRange(idsList); |
|
|
|
var idsList = await client.GetCargoStaticAsync(itm).ConfigureAwait(false); |
|
|
|
camralist.AddRange(idsList); |
|
|
|
} |
|
|
|
camralist = camralist.Where(p=>p.Flag==0).ToList(); |
|
|
|
|
|
|
|
successTime++; |
|
|
|
if (successTime == invterval) |
|
|
|
{ |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
var uncompletelist= await _injectionRequest.GetUnCompletedRequestAsync(inputdetail).ConfigureAwait(false);//将所有库位零件信息查找未完成记录
|
|
|
|
var uncompletelist = await _injectionRequest.GetUnCompletedRequestAsync(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 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();//已经完成的记录
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
//{
|
|
|
|
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() |
|
|
|
{ |
|
|
|
ItemCode = inject.PartCode, |
|
|
|
ToLocationCode = inject.AreaID.ToString(), |
|
|
|
PositionCode=inject.CargoID, |
|
|
|
PositionCode = inject.CargoID, |
|
|
|
Qty = 1, |
|
|
|
RecommendType = EnumRecommendType.RAW, |
|
|
|
IssuedQty = 0, |
|
|
|
ReceivedQty = 0, |
|
|
|
Status = EnumStatus.Open, |
|
|
|
RequestStatus = EnumRequestStatus.New, |
|
|
|
BoxQty=1 |
|
|
|
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) |
|
|
|
//}
|
|
|
|
input.Details.AddRange(injectionRequestDetails); |
|
|
|
// 通过 BindAsync 方法对零件仓库进行赋值
|
|
|
|
var errors = await BindAsync(input.Details).ConfigureAwait(false); |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
_logger.LogInformation(error); |
|
|
|
// 记录错误日志并返回空列表
|
|
|
|
foreach (var error in errors) |
|
|
|
{ |
|
|
|
_logger.LogInformation(error); |
|
|
|
} |
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
} |
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
// 创建新的注塑请求并将数据写入数据库
|
|
|
|
await _injectionRequest.CreateAsync(input).ConfigureAwait(false); |
|
|
|
} |
|
|
|
// 创建新的注塑请求并将数据写入数据库
|
|
|
|
await _injectionRequest.CreateAsync(input).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(sleepTime * 1000); |
|
|
|
} |
|
|
|
sw.Stop(); |
|
|
|
_logger.LogInformation($"读取成功次数{successTime},耗时 ${sw.ElapsedMilliseconds / 1000 / 60}分钟"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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>();
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
|
|
|
|
//if (string.IsNullOrEmpty(_options.Value.AutoRemote.AreaIDs))
|
|
|
|
//{
|
|
|
|
// _logger.LogInformation("注塑叫料任务已存在,无需读取");
|
|
|
|
// _logger.LogInformation($"没有设置指定区域AutoRemote->AreaIDs");
|
|
|
|
// return new List<IncomingFromExternal>();
|
|
|
|
//}
|
|
|
|
|
|
|
|
//var ids=_options.Value.AutoRemote.AreaIDs.Split(",");
|
|
|
|
//List<ResponCargoItem> camralist = new List<ResponCargoItem>();
|
|
|
|
//foreach (var itm in ids)//遍历区域查找所有货物
|
|
|
|
//{
|
|
|
|
// var idsList= await client.GetCargoStaticAsync(itm).ConfigureAwait(false);
|
|
|
|
// camralist.AddRange(idsList);
|
|
|
|
//}
|
|
|
|
//camralist = camralist.Where(p=>p.Flag==0).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
// 捕获特定异常并记录日志
|
|
|
|
|
|
|
|