|
|
@ -1,13 +1,19 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Net.Http.Headers; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Text; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Omu.ValueInjecter; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Win_in.Sfs.Basedata.Application; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Basedata.Domain.Shared; |
|
|
|
using Win_in.Sfs.Basedata.SplitPackings.Commons; |
|
|
@ -18,6 +24,10 @@ using Win_in.Sfs.Wms.Inventory.Application.Contracts; |
|
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|
|
|
using Win_in.Sfs.Wms.Store.Domain; |
|
|
|
using Win_in.Sfs.Wms.Store.Domain.Shared; |
|
|
|
using Win_in.Sfs.Wms.Store.Jobs.IssueJobs.proxy; |
|
|
|
using Win_in.Sfs.Wms.Store.Options; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.Store.Application; |
|
|
|
|
|
|
@ -42,6 +52,13 @@ public class TransferNoteAppService : SfsStoreWithDetailsAppServiceBase |
|
|
|
|
|
|
|
private readonly IExpectOutAppService _expectOutAppService; //
|
|
|
|
private readonly IInventoryLabelAppService _inventoryLabelAppService; |
|
|
|
private readonly IHttpClientFactory _httpClientFactory; |
|
|
|
|
|
|
|
private readonly IOptions<AgvOptions> _agvOptions; |
|
|
|
|
|
|
|
private readonly ILogger<AssembleIssueJobAppService> _logger; |
|
|
|
|
|
|
|
private readonly IPostionLocationAppService _postionLocationAppService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -57,7 +74,8 @@ public class TransferNoteAppService : SfsStoreWithDetailsAppServiceBase |
|
|
|
IInspectJobAppService inspectJobAppService, |
|
|
|
IIssueJobAppService issueJobAppService, |
|
|
|
IInventoryLabelAppService inventoryLabelAppService, |
|
|
|
IExpectOutAppService expectOutAppService) : base(repository) |
|
|
|
IHttpClientFactory _httpClientFactory, |
|
|
|
IExpectOutAppService expectOutAppService) : base(repository) |
|
|
|
{ |
|
|
|
_transferNoteManager = transferNoteManager; |
|
|
|
_balanceAppService = balanceAppService; |
|
|
@ -598,4 +616,268 @@ public class TransferNoteAppService : SfsStoreWithDetailsAppServiceBase |
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 调用 Agv 接口
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <param name="pLoc"></param>
|
|
|
|
/// <param name="uid"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("call-agv")] |
|
|
|
public async Task<ReusltObject> CallAgvAsync(List<TransferNoteDTO> inputs) |
|
|
|
{ |
|
|
|
|
|
|
|
var res = new ReusltObject(); |
|
|
|
List<string> errors = new List<string>(); |
|
|
|
List<string> successList = new List<string>(); |
|
|
|
foreach (var itm in inputs) |
|
|
|
{ |
|
|
|
var jobres = await SendInterFaceAsync(itm).ConfigureAwait(false); |
|
|
|
if (jobres.Code != "0") |
|
|
|
{ |
|
|
|
_logger.LogInformation(jobres.Message); |
|
|
|
errors.Add(jobres.Message); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
successList.Add(jobres.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
res.Code = -1; |
|
|
|
res.Message = string.Join(",", errors); |
|
|
|
res.Data = ""; |
|
|
|
return res; |
|
|
|
} |
|
|
|
return res; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost("call-back-agv")] |
|
|
|
public async Task<AgvResultObject> CallBackAgvAsync(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 first = request.Data.FirstOrDefault(); |
|
|
|
var job = await _repository.GetAsync(p => p.Number == first.OrderNum).ConfigureAwait(false); |
|
|
|
var ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "0", |
|
|
|
Message = "OK", |
|
|
|
ReqCode = job.RequestNumber, |
|
|
|
}; |
|
|
|
// using var unitOfWork = _unitOfWorkManager.Begin();
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (request.Data.Count > 0) |
|
|
|
{ |
|
|
|
var jobs = request.Data; |
|
|
|
var numbers = jobs.Select(p => p.OrderNum); |
|
|
|
var query = _repository.WithDetails() |
|
|
|
.Where(p => numbers.Contains(p.Number) ); |
|
|
|
var entities = query.ToList(); |
|
|
|
if (entities.Count == 0) |
|
|
|
{ |
|
|
|
errors.Add($"任务号{string.Join(",", numbers)}不存在!"); |
|
|
|
} |
|
|
|
var dtos = ObjectMapper.Map<List<TransferNote>, List<TransferNoteDTO>>(entities); |
|
|
|
|
|
|
|
foreach (var itm in dtos) |
|
|
|
{ |
|
|
|
var arys = jobs.Where(p => p.OrderNum == itm.Number); |
|
|
|
var itmDetails = itm.Details.ToList(); |
|
|
|
var details = new List<TransferNoteDetailDTO>(); |
|
|
|
foreach (var detail in arys) |
|
|
|
{ |
|
|
|
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 entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
errors.Add($"物料号{detail.MatCode}不在任务明细内!"); |
|
|
|
} |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
return ret = new AgvResultObject() |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
ReqCode = "", |
|
|
|
Message = string.Join(",", errors.ToArray()) |
|
|
|
}; |
|
|
|
} |
|
|
|
var dto = new TransferNoteDetailDTO(); |
|
|
|
dto.InjectFrom(entity); |
|
|
|
dto.ToLocationCode = toloc.Code; |
|
|
|
dto.ToLocationGroup = tolocation.LocationGroupCode; |
|
|
|
dto.ToLocationArea = tolocation.AreaCode; |
|
|
|
dto.ToLocationErpCode = tolocation.ErpLocationCode; |
|
|
|
|
|
|
|
dto.ToWarehouseCode = tolocation.WarehouseCode; |
|
|
|
dto.Qty = detail.MatQty; |
|
|
|
dto.ToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; |
|
|
|
dto.ToPackingCode = string.Empty; |
|
|
|
|
|
|
|
dto.FromWarehouseCode = fromlocation.WarehouseCode; |
|
|
|
dto.FromLocationCode = fromlocation.Code; |
|
|
|
dto.FromLocationGroup = fromlocation.LocationGroupCode; |
|
|
|
dto.FromLocationArea = fromlocation.AreaCode; |
|
|
|
dto.FromLocationErpCode = fromlocation.ErpLocationCode; |
|
|
|
dto.Qty = detail.MatQty; |
|
|
|
dto.FromLot = string.Empty; |
|
|
|
dto.FromPackingCode = string.Empty; |
|
|
|
details.Add(dto); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false);
|
|
|
|
} |
|
|
|
|
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
ret = new AgvResultObject() |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
ReqCode = "", |
|
|
|
Message = string.Join(",", errors.ToArray()) |
|
|
|
}; |
|
|
|
} |
|
|
|
itm.Worker = "AGV"; |
|
|
|
itm.Details = details; |
|
|
|
|
|
|
|
_logger.LogInformation($"{flag}接收Agv确认单据内容:" + json + "Agv任务完成"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
errors.Add("Agv确认单据里无数据! \n"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
ReqCode = job.RequestNumber, |
|
|
|
Message = ex.Message, |
|
|
|
}; |
|
|
|
//await unitOfWork.RollbackAsync();
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
Message = string.Join(",", errors.ToArray()), |
|
|
|
ReqCode = job.RequestNumber |
|
|
|
}; |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
private async Task<AgvResultObject> SendInterFaceAsync(TransferNoteDTO job) |
|
|
|
{ |
|
|
|
var ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "0", |
|
|
|
ReqCode = job.RequestNumber, |
|
|
|
Message = "OK" |
|
|
|
}; |
|
|
|
//using var unitOfWork = _unitOfWorkManager.Begin();
|
|
|
|
try |
|
|
|
{ |
|
|
|
var first = job.Details.FirstOrDefault(); |
|
|
|
var request = new AgvRequest(); |
|
|
|
request.MatCode = first.ItemCode; |
|
|
|
request.MatQty = first.Qty; |
|
|
|
request.OrderNum = job.Number; |
|
|
|
request.OrderType = EnumJobType.AssembleIssueJob.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"); |
|
|
|
// _logger.LogInformation($"标志{flag}开始调用高通WMS:传递值{JsonSerializer.Serialize(main)}");
|
|
|
|
if (!string.IsNullOrEmpty(_agvOptions.Value.Token)) |
|
|
|
{ |
|
|
|
var token = _agvOptions.Value.Token; |
|
|
|
httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_agvOptions.Value.UserName) && !string.IsNullOrEmpty(_agvOptions.Value.Password)) |
|
|
|
{ |
|
|
|
var username = _agvOptions.Value.UserName; |
|
|
|
var password = _agvOptions.Value.Password; |
|
|
|
httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", |
|
|
|
Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"))); |
|
|
|
} |
|
|
|
|
|
|
|
var client = new AgvJobClient(_agvOptions.Value.Address, httpclient, _agvOptions.Value.Path); |
|
|
|
ret = await client.PushOutTask4FWAsync(request).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
ret = new AgvResultObject(); |
|
|
|
ret.Code = "1"; |
|
|
|
ret.Message = e.Message; |
|
|
|
ret.ReqCode = job.RequestNumber; |
|
|
|
//await unitOfWork.RollbackAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|