|
|
@ -54,7 +54,7 @@ public class CoatingIssueJobAppService |
|
|
|
private readonly IOptions<AgvOptions> _agvOptions; |
|
|
|
private readonly IPostionLocationAppService _postionLocationAppService; |
|
|
|
private readonly IItemBasicAppService _itemBasicAppService; |
|
|
|
|
|
|
|
private readonly ITransferNoteAppService _transferNoteAppService; |
|
|
|
|
|
|
|
protected ICoatingIssueRequestAppService CoatingIssueRequestAppService => |
|
|
|
LazyServiceProvider.LazyGetRequiredService<ICoatingIssueRequestAppService>(); |
|
|
@ -68,7 +68,7 @@ public class CoatingIssueJobAppService |
|
|
|
, IHttpClientFactory httpClientFactory |
|
|
|
, IOptions<RestoOptions> options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, IOptions<AgvOptions> agvOptions |
|
|
|
, UnitOfWorkManager unitOfWorkManager |
|
|
|
, IPostionLocationAppService postionLocationAppService, IItemBasicAppService _itemBasicAppService |
|
|
|
, IPostionLocationAppService postionLocationAppService, IItemBasicAppService _itemBasicAppService, ITransferNoteAppService transferNoteAppService |
|
|
|
) : base( |
|
|
|
repository, coatingIssueJobManager) |
|
|
|
{ |
|
|
@ -85,6 +85,7 @@ public class CoatingIssueJobAppService |
|
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
|
_agvOptions = agvOptions; |
|
|
|
_postionLocationAppService = postionLocationAppService; |
|
|
|
_transferLibRequestAppService= transferLibRequestAppService; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost("get-by-number-2")] |
|
|
@ -1034,96 +1035,169 @@ public class CoatingIssueJobAppService |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 调用Agv接口实现
|
|
|
|
/// Agv 回库 接口
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="job"></param>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<AgvResultObject> SendInterFaceAsync(CoatingIssueJobDTO job) |
|
|
|
[HttpPost("call-return-back-agv")] |
|
|
|
public async Task<AgvResultObject> CallReturnBackAgvAsync(AgvRequestDto request) |
|
|
|
{ |
|
|
|
var json = JsonSerializer.Serialize(request); |
|
|
|
var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); |
|
|
|
_logger.LogInformation($"{flag}接收到AGV确认单据内容:" + json); |
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
#endif
|
|
|
|
var errors = new List<string>(); |
|
|
|
var ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "0", |
|
|
|
ReqCode = job.CoatingRequestNumber, |
|
|
|
Message = "OK" |
|
|
|
Message = "OK", |
|
|
|
ReqCode = "", |
|
|
|
}; |
|
|
|
using var unitOfWork = _unitOfWorkManager.Begin(); |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
if (job.JobStatus == EnumJobStatus.Done) |
|
|
|
if (request.Data.Count > 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"任务{job.Number}为已完成状态,不能发起AGV任务!"); |
|
|
|
} |
|
|
|
var notes = request.Data; |
|
|
|
|
|
|
|
if (job.Details.Count == 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"任务{job.Number}没有推荐库存!"); |
|
|
|
} |
|
|
|
foreach (var detail in notes) |
|
|
|
{ |
|
|
|
TransferNoteEditInput transfer = new TransferNoteEditInput(); |
|
|
|
transfer.CallJobNumber = detail.OrderNum; |
|
|
|
transfer.Type = EnumTransSubType.Agv_Return_Coating.ToString(); |
|
|
|
transfer.Worker = "Agv"; |
|
|
|
transfer.UseOnTheWayLocation = false; |
|
|
|
List<TransferNoteDetailInput> transferNoteDetailInputs = new List<TransferNoteDetailInput>(); |
|
|
|
TransferNoteDetailInput detailInput = new TransferNoteDetailInput(); |
|
|
|
var fromloc = await _postionLocationAppService.GetByCodeAsync(detail.BeginPosition).ConfigureAwait(false); |
|
|
|
if (fromloc == null) |
|
|
|
{ |
|
|
|
errors.Add($"来源起始点{detail.BeginPosition}没查到"); |
|
|
|
} |
|
|
|
LocationDTO fromlocation = null; |
|
|
|
if (fromloc != null) |
|
|
|
{ |
|
|
|
fromlocation = await _locationAppService.GetByCodeAsync(fromloc.LocationCode).ConfigureAwait(false); |
|
|
|
} |
|
|
|
if (fromlocation == null) |
|
|
|
{ |
|
|
|
errors.Add($"来源起始点{detail.BeginPosition}库位没查到"); |
|
|
|
} |
|
|
|
var toloc = await _postionLocationAppService.GetByCodeAsync(detail.EndPosition) |
|
|
|
.ConfigureAwait(false); |
|
|
|
if (toloc == null) |
|
|
|
{ |
|
|
|
errors.Add($"结束点{detail.EndPosition}没查到"); |
|
|
|
} |
|
|
|
LocationDTO tolocation = null; |
|
|
|
if (toloc != null) |
|
|
|
{ |
|
|
|
tolocation = await _locationAppService.GetByCodeAsync(toloc.LocationCode).ConfigureAwait(false); |
|
|
|
} |
|
|
|
if (tolocation == null) |
|
|
|
{ |
|
|
|
errors.Add($"结束点{detail.EndPosition}库位没查到"); |
|
|
|
} |
|
|
|
var item = await _itemBasicAppService.GetByCodeAsync(detail.MatCode).ConfigureAwait(false); |
|
|
|
if (item == null) |
|
|
|
{ |
|
|
|
errors.Add($"零件号{detail.MatCode}的零件不存在!"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
detailInput.ItemCode = item.Code; |
|
|
|
detailInput.Uom = item.BasicUom; |
|
|
|
detailInput.ItemName = item.Name; |
|
|
|
detailInput.ItemDesc1 = !string.IsNullOrEmpty(item.Desc1) ? item.Desc1 : string.Empty; |
|
|
|
} |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
return ret = new AgvResultObject() |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
ReqCode = "", |
|
|
|
Message = string.Join(",", errors.ToArray()) |
|
|
|
}; |
|
|
|
} |
|
|
|
detailInput.ToLocationCode = tolocation.Code; |
|
|
|
detailInput.ToLocationGroup = tolocation.LocationGroupCode; |
|
|
|
detailInput.ToLocationArea = tolocation.AreaCode; |
|
|
|
detailInput.ToLocationErpCode = tolocation.ErpLocationCode; |
|
|
|
detailInput.ToWarehouseCode = tolocation.WarehouseCode; |
|
|
|
detailInput.FromStatus = tolocation.DefaultInventoryStatus; |
|
|
|
|
|
|
|
|
|
|
|
var first = job.Details.FirstOrDefault(); |
|
|
|
var request = new AgvRequest(); |
|
|
|
request.MatCode = first.ItemCode; |
|
|
|
request.MatQty = first.HandledToQty; |
|
|
|
request.OrderNum = job.Number; |
|
|
|
request.OrderType = EnumJobType.CoatingIssueJob.ToString(); |
|
|
|
|
|
|
|
|
|
|
|
var httpclient = _httpClientFactory.CreateClient(); |
|
|
|
_agvOptions.Value.Address = string.IsNullOrEmpty(_agvOptions.Value.Address) |
|
|
|
? "http://7e42682n64.goho.co:21171/" |
|
|
|
: _agvOptions.Value.Address; //测试地址
|
|
|
|
_agvOptions.Value.Token = |
|
|
|
string.IsNullOrEmpty(_agvOptions.Value.Token) ? string.Empty : _agvOptions.Value.Token; //测试token
|
|
|
|
_agvOptions.Value.UserName = |
|
|
|
string.IsNullOrEmpty(_agvOptions.Value.UserName) ? "" : _agvOptions.Value.UserName; //测试用户名
|
|
|
|
_agvOptions.Value.Password = |
|
|
|
string.IsNullOrEmpty(_agvOptions.Value.Password) ? "" : _agvOptions.Value.Password; //测试密码
|
|
|
|
_agvOptions.Value.Path = string.IsNullOrEmpty(_agvOptions.Value.Path) |
|
|
|
? "zozocnApi/custom/receiveProductionPlan" |
|
|
|
: _agvOptions.Value.Path; //测试密码
|
|
|
|
var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); |
|
|
|
detailInput.Qty = detail.MatQty; |
|
|
|
detailInput.ToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; |
|
|
|
detailInput.ToPackingCode = detail.PakingCode; |
|
|
|
detailInput.FromWarehouseCode = fromlocation.WarehouseCode; |
|
|
|
detailInput.FromLocationCode = fromlocation.Code; |
|
|
|
detailInput.FromLocationGroup = fromlocation.LocationGroupCode; |
|
|
|
detailInput.FromLocationArea = fromlocation.AreaCode; |
|
|
|
detailInput.FromLocationErpCode = fromlocation.ErpLocationCode; |
|
|
|
detailInput.ToStatus = fromlocation.DefaultInventoryStatus; |
|
|
|
detailInput.Qty = detail.MatQty; |
|
|
|
detailInput.FromLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; |
|
|
|
detailInput.FromPackingCode = detail.PakingCode; |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_agvOptions.Value.Token)) |
|
|
|
{ |
|
|
|
var token = _agvOptions.Value.Token; |
|
|
|
httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); |
|
|
|
} |
|
|
|
transfer.Details.Add(detailInput); |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_agvOptions.Value.UserName) && !string.IsNullOrEmpty(_agvOptions.Value.Password)) |
|
|
|
|
|
|
|
await _transferNoteAppService.CreateAsync(transfer).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var username = _agvOptions.Value.UserName; |
|
|
|
var password = _agvOptions.Value.Password; |
|
|
|
httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", |
|
|
|
Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"))); |
|
|
|
errors.Add("Agv确认单据里无数据! \n"); |
|
|
|
} |
|
|
|
|
|
|
|
var client = new AgvJobClient(_agvOptions.Value.Address, httpclient, _agvOptions.Value.Path); |
|
|
|
ret = await client.PushOutTask4FWAsync(request).ConfigureAwait(false); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
ReqCode = "", |
|
|
|
Message = ex.Message |
|
|
|
}; |
|
|
|
await unitOfWork.RollbackAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
|
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
ret = new AgvResultObject(); |
|
|
|
ret.Code = "1"; |
|
|
|
ret.Message = e.Message; |
|
|
|
ret.ReqCode = job.CoatingRequestNumber; |
|
|
|
ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
Message = string.Join(",", errors.ToArray()), |
|
|
|
ReqCode = "" |
|
|
|
}; |
|
|
|
await unitOfWork.RollbackAsync().ConfigureAwait(false); |
|
|
|
throw new UserFriendlyException($"接口报错 错误信息{e.Message}"); |
|
|
|
} |
|
|
|
return ret; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 回库调用
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="job"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
private async Task<AgvResultObject> ReturnBackAsync(CoatingIssueJobDTO job) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 调用Agv接口实现
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="job"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<AgvResultObject> SendInterFaceAsync(CoatingIssueJobDTO job) |
|
|
|
{ |
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
#endif
|
|
|
|
var ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "0", |
|
|
@ -1133,12 +1207,25 @@ public class CoatingIssueJobAppService |
|
|
|
using var unitOfWork = _unitOfWorkManager.Begin(); |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
if (job.JobStatus == EnumJobStatus.Done) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"任务{job.Number}为已完成状态,不能发起AGV任务!"); |
|
|
|
} |
|
|
|
|
|
|
|
if (job.Details.Count == 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"任务{job.Number}没有推荐库存!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var first = job.Details.FirstOrDefault(); |
|
|
|
var request = new AgvRequestBack(); |
|
|
|
var request = new AgvRequest(); |
|
|
|
request.MatCode = first.ItemCode; |
|
|
|
request.ReturnQty = first.HandledToQty; |
|
|
|
request.EndPosition = first.HandledToLocationCode; |
|
|
|
|
|
|
|
request.MatQty = first.HandledToQty; |
|
|
|
request.OrderNum = job.Number; |
|
|
|
request.OrderType = EnumJobType.CoatingIssueJob.ToString(); |
|
|
|
|
|
|
|
|
|
|
|
var httpclient = _httpClientFactory.CreateClient(); |
|
|
|
_agvOptions.Value.Address = string.IsNullOrEmpty(_agvOptions.Value.Address) |
|
|
@ -1170,7 +1257,7 @@ public class CoatingIssueJobAppService |
|
|
|
} |
|
|
|
|
|
|
|
var client = new AgvJobClient(_agvOptions.Value.Address, httpclient, _agvOptions.Value.Path); |
|
|
|
ret = await client.NotifyOutTaskBack4FWAsync(request).ConfigureAwait(false); |
|
|
|
ret = await client.PushOutTask4FWAsync(request).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
@ -1184,5 +1271,6 @@ public class CoatingIssueJobAppService |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|