|
|
@ -7,6 +7,7 @@ using System.Text; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Castle.Components.DictionaryAdapter; |
|
|
|
using DocumentFormat.OpenXml.Bibliography; |
|
|
|
using DocumentFormat.OpenXml.Office2016.Excel; |
|
|
|
using DocumentFormat.OpenXml.Spreadsheet; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
@ -892,168 +893,182 @@ public class AssembleIssueJobAppService |
|
|
|
[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); |
|
|
|
using var unitOfWork = _unitOfWorkManager.Begin(); |
|
|
|
var ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "0", |
|
|
|
Message = "OK", |
|
|
|
ReqCode = job.AssembleRequestNumber, |
|
|
|
Code = "1", |
|
|
|
Message = "Json转换错误", |
|
|
|
ReqCode = "Json转换错误" |
|
|
|
}; |
|
|
|
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) && p.JobStatus != EnumJobStatus.Done); |
|
|
|
var entities = query.ToList(); |
|
|
|
if (entities.Count == 0) |
|
|
|
{ |
|
|
|
errors.Add($"任务号{string.Join(",", numbers)}不存在!"); |
|
|
|
} |
|
|
|
var dtos = ObjectMapper.Map<List<AssembleIssueJob>, List<AssembleIssueJobDTO>>(entities); |
|
|
|
|
|
|
|
foreach (var itm in dtos) |
|
|
|
{ |
|
|
|
var arys = jobs.Where(p => p.OrderNum == itm.Number); |
|
|
|
var itmDetails = itm.Details.ToList(); |
|
|
|
var details = new List<AssembleIssueJobDetailDTO>(); |
|
|
|
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 item=await _itemBasicAppService.GetByCodeAsync(detail.MatCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (item == null) |
|
|
|
{ |
|
|
|
errors.Add($"零件号{detail.MatCode}不存在!"); |
|
|
|
} |
|
|
|
var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
errors.Add($"零件号{detail.MatCode}不在任务明细内!"); |
|
|
|
} |
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
await unitOfWork.RollbackAsync().ConfigureAwait(false); |
|
|
|
return ret = new AgvResultObject() |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
ReqCode = "", |
|
|
|
Message = string.Join(",", errors.ToArray()) |
|
|
|
}; |
|
|
|
} |
|
|
|
var dto = new AssembleIssueJobDetailDTO(); |
|
|
|
dto.InjectFrom(entity); |
|
|
|
dto.HandledToLocationCode = tolocation.Code; |
|
|
|
dto.HandledToLocationGroup = tolocation.LocationGroupCode; |
|
|
|
dto.HandledToLocationArea = tolocation.AreaCode; |
|
|
|
dto.HandledToLocationErpCode = tolocation.ErpLocationCode; |
|
|
|
|
|
|
|
dto.HandledToWarehouseCode = tolocation.WarehouseCode; |
|
|
|
dto.HandledToQty = detail.MatQty; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dto.HandledToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : entity.RecommendFromLot; |
|
|
|
dto.HandledToPackingCode = string.Empty; |
|
|
|
|
|
|
|
dto.HandledFromWarehouseCode = fromlocation.WarehouseCode; |
|
|
|
dto.HandledFromLocationCode = fromlocation.Code; |
|
|
|
dto.HandledFromLocationGroup = fromlocation.LocationGroupCode; |
|
|
|
dto.HandledFromLocationArea = fromlocation.AreaCode; |
|
|
|
dto.HandledFromLocationErpCode = fromlocation.ErpLocationCode; |
|
|
|
dto.HandledFromQty = detail.MatQty; |
|
|
|
dto.HandledFromLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : entity.RecommendToLot; |
|
|
|
dto.HandledFromPackingCode = string.Empty; |
|
|
|
details.Add(dto); |
|
|
|
await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
await unitOfWork.RollbackAsync().ConfigureAwait(false); |
|
|
|
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.AssembleRequestNumber, |
|
|
|
Message = ex.Message |
|
|
|
}; |
|
|
|
await unitOfWork.RollbackAsync().ConfigureAwait(false); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
if (errors.Count > 0) |
|
|
|
{ |
|
|
|
ret = new AgvResultObject |
|
|
|
{ |
|
|
|
Code = "-1", |
|
|
|
Message = string.Join(",", errors.ToArray()), |
|
|
|
ReqCode = job.AssembleRequestNumber |
|
|
|
}; |
|
|
|
} |
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// var json = JsonSerializer.Serialize(request);
|
|
|
|
// var flag = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
|
// _logger.LogInformation($"{flag}接收到AGV确认单据内容:" + json);
|
|
|
|
//#if DEBUG
|
|
|
|
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
// foreach (var agvRequestDetailDto in request.Data)
|
|
|
|
// {
|
|
|
|
// var job = await _repository.FindAsync(p => p.Number == agvRequestDetailDto.OrderNum).ConfigureAwait(false);
|
|
|
|
// if (job == null)
|
|
|
|
// {
|
|
|
|
// ret.ReqCode = agvRequestDetailDto.OrderNum;
|
|
|
|
// throw new UserFriendlyException($"未找到{agvRequestDetailDto.OrderNum}单号");
|
|
|
|
// }
|
|
|
|
// if (job.JobStatus != EnumJobStatus.WaitAgv)
|
|
|
|
// {
|
|
|
|
// throw new UserFriendlyException($"{agvRequestDetailDto.OrderNum}单号的任务状态错误");
|
|
|
|
// }
|
|
|
|
// var postionLocationDtoFrom= await _postionLocationAppService.GetByCodeAsync(agvRequestDetailDto.BeginPosition).ConfigureAwait(false);
|
|
|
|
// if (postionLocationDtoFrom == null)
|
|
|
|
// {
|
|
|
|
// throw new UserFriendlyException($"{agvRequestDetailDto.BeginPosition}起始点位未找到");
|
|
|
|
// }
|
|
|
|
// var postionLocationDtoEnd=await _postionLocationAppService.GetByCodeAsync(agvRequestDetailDto.EndPosition).ConfigureAwait(false);
|
|
|
|
// if (postionLocationDtoEnd==null)
|
|
|
|
// {
|
|
|
|
// throw new UserFriendlyException($"{agvRequestDetailDto.EndPosition}目标点位未找到");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync(
|
|
|
|
// jobDetailInputdetail.RecommendFromLocationCode, jobDetailInputdetail.RecommendToLocationCode).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv)
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (var itm in dtos)
|
|
|
|
// {
|
|
|
|
// var arys = jobs.Where(p => p.OrderNum == itm.Number);
|
|
|
|
// var itmDetails = itm.Details.ToList();
|
|
|
|
// var details = new List<AssembleIssueJobDetailDTO>();
|
|
|
|
// foreach (var detail in arys)
|
|
|
|
// {
|
|
|
|
|
|
|
|
// 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}不存在!");
|
|
|
|
// }
|
|
|
|
// var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode);
|
|
|
|
// if (entity == null)
|
|
|
|
// {
|
|
|
|
// errors.Add($"零件号{detail.MatCode}不在任务明细内!");
|
|
|
|
// }
|
|
|
|
// if (errors.Count > 0)
|
|
|
|
// {
|
|
|
|
// await unitOfWork.RollbackAsync().ConfigureAwait(false);
|
|
|
|
// return ret = new AgvResultObject()
|
|
|
|
// {
|
|
|
|
// Code = "-1",
|
|
|
|
// ReqCode = "",
|
|
|
|
// Message = string.Join(",", errors.ToArray())
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// var dto = new AssembleIssueJobDetailDTO();
|
|
|
|
// dto.InjectFrom(entity);
|
|
|
|
// dto.HandledToLocationCode = tolocation.Code;
|
|
|
|
// dto.HandledToLocationGroup = tolocation.LocationGroupCode;
|
|
|
|
// dto.HandledToLocationArea = tolocation.AreaCode;
|
|
|
|
// dto.HandledToLocationErpCode = tolocation.ErpLocationCode;
|
|
|
|
|
|
|
|
// dto.HandledToWarehouseCode = tolocation.WarehouseCode;
|
|
|
|
// dto.HandledToQty = detail.MatQty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// dto.HandledToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : entity.RecommendFromLot;
|
|
|
|
// dto.HandledToPackingCode = string.Empty;
|
|
|
|
|
|
|
|
// dto.HandledFromWarehouseCode = fromlocation.WarehouseCode;
|
|
|
|
// dto.HandledFromLocationCode = fromlocation.Code;
|
|
|
|
// dto.HandledFromLocationGroup = fromlocation.LocationGroupCode;
|
|
|
|
// dto.HandledFromLocationArea = fromlocation.AreaCode;
|
|
|
|
// dto.HandledFromLocationErpCode = fromlocation.ErpLocationCode;
|
|
|
|
// dto.HandledFromQty = detail.MatQty;
|
|
|
|
// dto.HandledFromLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : entity.RecommendToLot;
|
|
|
|
// dto.HandledFromPackingCode = string.Empty;
|
|
|
|
// details.Add(dto);
|
|
|
|
// await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (errors.Count > 0)
|
|
|
|
// {
|
|
|
|
// await unitOfWork.RollbackAsync().ConfigureAwait(false);
|
|
|
|
// ret = new AgvResultObject()
|
|
|
|
// {
|
|
|
|
// Code = "-1",
|
|
|
|
// ReqCode = "",
|
|
|
|
// Message = string.Join(",", errors.ToArray())
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// itm.Worker = "AGV";
|
|
|
|
// itm.Details = details;
|
|
|
|
|
|
|
|
// _logger.LogInformation($"{flag}接收Agv确认单据内容:" + json + "Agv任务完成");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// catch (Exception ex)
|
|
|
|
// {
|
|
|
|
// await unitOfWork.RollbackAsync().ConfigureAwait(false);
|
|
|
|
// return ret;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (errors.Count > 0)
|
|
|
|
// {
|
|
|
|
// ret = new AgvResultObject
|
|
|
|
// {
|
|
|
|
// Code = "-1",
|
|
|
|
// Message = string.Join(",", errors.ToArray()),
|
|
|
|
// ReqCode = first.OrderNum
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|