diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/CoatingIssueJobs/ICoatingIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/CoatingIssueJobs/ICoatingIssueJobAppService.cs index ac9476fe8..79234fd72 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/CoatingIssueJobs/ICoatingIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/CoatingIssueJobs/ICoatingIssueJobAppService.cs @@ -28,6 +28,6 @@ public interface ICoatingIssueJobAppService Task GetByNumber2Async(string number); Task GetJobByPackingCodeAsync(string packingCode); - Task CallBackAgvAsync(AgvRequestDto request); - Task CallAgvAsync(CoatingIssueJobDTO input); + + } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/InjectionJobs/IInjectionIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/InjectionJobs/IInjectionIssueJobAppService.cs index 08cd707f0..1763aa9ed 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/InjectionJobs/IInjectionIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/InjectionJobs/IInjectionIssueJobAppService.cs @@ -30,6 +30,6 @@ public interface IInjectionIssueJobAppService Task CallBackAgvAsync(AgvRequestDto request); - Task CallAgvAsync(InjectionIssueJobDTO input); + } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/KittingIssueJobs/IKittingIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/KittingIssueJobs/IKittingIssueJobAppService.cs index a6cae3f8d..8a845bd64 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/KittingIssueJobs/IKittingIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/KittingIssueJobs/IKittingIssueJobAppService.cs @@ -28,5 +28,5 @@ public interface IKittingIssueJobAppService Task GetByNumber2Async(string number); Task GetJobByPackingCodeAsync(string packingCode); Task CallBackAgvAsync(AgvRequestDto request); - Task CallAgvAsync(KittingIssueJobDTO input); + } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/SparePartIssueJobs/ISparePartIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/SparePartIssueJobs/ISparePartIssueJobAppService.cs index a82a31739..3caa12107 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/SparePartIssueJobs/ISparePartIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/SparePartIssueJobs/ISparePartIssueJobAppService.cs @@ -29,5 +29,5 @@ public interface ISparePartIssueJobAppService Task GetJobByPackingCodeAsync(string packingCode); Task CallBackAgvAsync(AgvRequestDto request); - Task CallAgvAsync(SparePartIssueJobDTO input); + } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobOutputService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobOutputService.cs index ce95c679c..c219299d0 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobOutputService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobOutputService.cs @@ -77,169 +77,169 @@ public class AgvJobOutputService : ApplicationService - /// - /// 装配闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("assemble-test-callagv-id")] - public async Task Assemble_CallAgvAsync(Guid id) - { - var jobdto= await _assembleIssueJobAppService.GetAsync(id).ConfigureAwait(false); - var ret= await _assembleIssueJobAppService.CallAgvAsync(jobdto,"123","321").ConfigureAwait(false); - return ret; - } - - /// - /// 装配闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("assemble-test-callagv1")] - public async Task Assemble_CallAgvAsync1(AssembleIssueJobDTO jobdto) - { - var ret = await _assembleIssueJobAppService.CallAgvAsync(jobdto, "123", "321").ConfigureAwait(false); - return ret; - } - /// - /// 喷涂闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("coating-test-callagv-id")] - public async Task Coating_CallAgvAsync(Guid id) - { - var jobdto= await _coatingIssueJobAppService.GetAsync(id).ConfigureAwait(false); - var ret = await _coatingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 喷涂闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("coating-test-callagv")] - public async Task Coating_CallAgvAsync(CoatingIssueJobDTO jobdto) - { - var ret = await _coatingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 注塑闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("injection-test-callagv-id")] - public async Task Injection_CallAgvAsync(Guid id) - { - var jobdto = await _injectionIssueJobAppService.GetAsync(id).ConfigureAwait(false); - var ret = await _injectionIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 注塑闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("injection-test-callagv")] - public async Task Injection_CallAgvAsync1(InjectionIssueJobDTO jobdto) - { - var ret = await _injectionIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 注塑闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("kitting-test-callagv-id")] - public async Task Kitting_CallAgvAsync(Guid id) - { - var jobdto=await _kittingIssueJobAppService.GetAsync(id).ConfigureAwait(false); - var ret = await _kittingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// Kitting闻荫调用海康AGV接口测试 - /// - /// - /// - - [HttpPost("kitting-test-callagv")] - public async Task Kitting_CallAgvAsync1(KittingIssueJobDTO jobdto) - { - var ret = await _kittingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 备件闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("sparePart-test-callagv-id")] - public async Task SparePart_CallAgvAsync(Guid id) - { - var jobdto = await _sparePartIssueJobAppService.GetAsync(id).ConfigureAwait(false); - var ret = await _sparePartIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 备件闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("sparePart-test-callagv")] - public async Task SparePart_CallAgvAsync1(SparePartIssueJobDTO jobdto) - { - var ret = await _sparePartIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 非生产领料闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("unplannedIssue-test-callagv-id")] - public async Task UnplannedIssue_CallAgvAsync(Guid id) - { - var jobdto = await _unplannedIssueJobAppService.GetAsync(id).ConfigureAwait(false); - var ret = await _unplannedIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 非生产领料闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("unplannedIssue-test-callagv")] - public async Task UnplannedIssue_CallAgvAsync1(UnplannedIssueJobDTO jobdto) - { - var ret = await _unplannedIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 非生产退料闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("unplannedReceipt-test-callagv-id")] - public async Task UnplannedReceipt_CallAgvAsync(Guid id) - { - var jobdto = await _unplannedReceiptJobAppService.GetAsync(id).ConfigureAwait(false); - var ret = await _unplannedReceiptJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } - /// - /// 非生产退料闻荫调用海康AGV接口测试 - /// - /// - /// - [HttpPost("unplannedReceipt-test-callagv")] - public async Task UnplannedReceipt_CallAgvAsync1(UnplannedReceiptJobDTO jobdto) - { - var ret = await _unplannedReceiptJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); - return ret; - } + ///// + ///// 装配闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("assemble-test-callagv-id")] + //public async Task Assemble_CallAgvAsync(Guid id) + //{ + // var jobdto= await _assembleIssueJobAppService.GetAsync(id).ConfigureAwait(false); + // var ret= await _assembleIssueJobAppService.CallAgvAsync(jobdto,"123","321").ConfigureAwait(false); + // return ret; + //} + + ///// + ///// 装配闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("assemble-test-callagv1")] + //public async Task Assemble_CallAgvAsync1(AssembleIssueJobDTO jobdto) + //{ + // var ret = await _assembleIssueJobAppService.CallAgvAsync(jobdto, "123", "321").ConfigureAwait(false); + // return ret; + //} + ///// + ///// 喷涂闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("coating-test-callagv-id")] + //public async Task Coating_CallAgvAsync(Guid id) + //{ + // var jobdto= await _coatingIssueJobAppService.GetAsync(id).ConfigureAwait(false); + // var ret = await _coatingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 喷涂闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("coating-test-callagv")] + //public async Task Coating_CallAgvAsync(CoatingIssueJobDTO jobdto) + //{ + // var ret = await _coatingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 注塑闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("injection-test-callagv-id")] + //public async Task Injection_CallAgvAsync(Guid id) + //{ + // var jobdto = await _injectionIssueJobAppService.GetAsync(id).ConfigureAwait(false); + // var ret = await _injectionIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 注塑闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("injection-test-callagv")] + //public async Task Injection_CallAgvAsync1(InjectionIssueJobDTO jobdto) + //{ + // var ret = await _injectionIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 注塑闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("kitting-test-callagv-id")] + //public async Task Kitting_CallAgvAsync(Guid id) + //{ + // var jobdto=await _kittingIssueJobAppService.GetAsync(id).ConfigureAwait(false); + // var ret = await _kittingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// Kitting闻荫调用海康AGV接口测试 + ///// + ///// + ///// + + //[HttpPost("kitting-test-callagv")] + //public async Task Kitting_CallAgvAsync1(KittingIssueJobDTO jobdto) + //{ + // var ret = await _kittingIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 备件闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("sparePart-test-callagv-id")] + //public async Task SparePart_CallAgvAsync(Guid id) + //{ + // var jobdto = await _sparePartIssueJobAppService.GetAsync(id).ConfigureAwait(false); + // var ret = await _sparePartIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 备件闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("sparePart-test-callagv")] + //public async Task SparePart_CallAgvAsync1(SparePartIssueJobDTO jobdto) + //{ + // var ret = await _sparePartIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 非生产领料闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("unplannedIssue-test-callagv-id")] + //public async Task UnplannedIssue_CallAgvAsync(Guid id) + //{ + // var jobdto = await _unplannedIssueJobAppService.GetAsync(id).ConfigureAwait(false); + // var ret = await _unplannedIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 非生产领料闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("unplannedIssue-test-callagv")] + //public async Task UnplannedIssue_CallAgvAsync1(UnplannedIssueJobDTO jobdto) + //{ + // var ret = await _unplannedIssueJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 非生产退料闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("unplannedReceipt-test-callagv-id")] + //public async Task UnplannedReceipt_CallAgvAsync(Guid id) + //{ + // var jobdto = await _unplannedReceiptJobAppService.GetAsync(id).ConfigureAwait(false); + // var ret = await _unplannedReceiptJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} + ///// + ///// 非生产退料闻荫调用海康AGV接口测试 + ///// + ///// + ///// + //[HttpPost("unplannedReceipt-test-callagv")] + //public async Task UnplannedReceipt_CallAgvAsync1(UnplannedReceiptJobDTO jobdto) + //{ + // var ret = await _unplannedReceiptJobAppService.CallAgvAsync(jobdto).ConfigureAwait(false); + // return ret; + //} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs index 8ef0aeed8..d0e81a446 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs @@ -55,6 +55,7 @@ public class CoatingIssueJobAppService private readonly IPostionLocationAppService _postionLocationAppService; private readonly IItemBasicAppService _itemBasicAppService; private readonly ITransferNoteAppService _transferNoteAppService; + private readonly ILocationDeliveryAppService _locationDeliveryAppService; protected ICoatingIssueRequestAppService CoatingIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -68,7 +69,10 @@ public class CoatingIssueJobAppService , IHttpClientFactory httpClientFactory , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, IOptions agvOptions , UnitOfWorkManager unitOfWorkManager - , IPostionLocationAppService postionLocationAppService, IItemBasicAppService _itemBasicAppService, ITransferNoteAppService transferNoteAppService + , IPostionLocationAppService postionLocationAppService, IItemBasicAppService _itemBasicAppService, + ITransferNoteAppService transferNoteAppService, + ILocationDeliveryAppService locationDeliveryAppService + ) : base( repository, coatingIssueJobManager) { @@ -86,6 +90,7 @@ public class CoatingIssueJobAppService _agvOptions = agvOptions; _postionLocationAppService = postionLocationAppService; _transferLibRequestAppService= transferLibRequestAppService; + _locationDeliveryAppService= locationDeliveryAppService; } [HttpPost("get-by-number-2")] @@ -102,28 +107,66 @@ public class CoatingIssueJobAppService foreach (var input in inputs) { await CheckMinRowAndSetStatusAsync(input).ConfigureAwait(false); - await CheckDimensionalStorehouseAsync(input).ConfigureAwait(false); + //如果是立库 就给直接承接了 + var dimensionalStorehouseflag = await UpdateJobStatusWaitByDimensionalStorehouseAsync(input).ConfigureAwait(false); + if (dimensionalStorehouseflag) + { + input.IsClaims = true; + input.ClaimsUserId = string.IsNullOrEmpty(_options.Value.StereosUser) + ? "LYF" + : _options.Value.StereosUser; + input.ClaimsUserName = string.IsNullOrEmpty(_options.Value.StereosPassword) + ? "LYF" + : _options.Value.StereosPassword; + } + + if (dimensionalStorehouseflag == false) + { + //如果是Agv + var agvFlag = await UpdateJobStatusWaitByAgvAsync(input).ConfigureAwait(false); + if (agvFlag) + { + input.IsClaims = true; + input.ClaimsUserId = string.IsNullOrEmpty(_options.Value.StereosUser) + ? "AGV" + : _options.Value.StereosUser; + input.ClaimsUserName = string.IsNullOrEmpty(_options.Value.StereosPassword) + ? "AGV" + : _options.Value.StereosPassword; + } + } } - var coatingIssueJobDtos = await base.CreateManyAsync(inputs).ConfigureAwait(false); - foreach (var coatingIssueJobDto in coatingIssueJobDtos) + var assembleIssueJobDtos = await base.CreateManyAsync(inputs).ConfigureAwait(false); + foreach (var assembleIssueJobDto in assembleIssueJobDtos) { - await DoingDimensionalStorehouseAsync(coatingIssueJobDto).ConfigureAwait(false); + await DoingDimensionalStorehouseAsync(assembleIssueJobDto).ConfigureAwait(false); + var firstDetail = assembleIssueJobDto.Details.First(); + await DoingAgvAsync(assembleIssueJobDto, firstDetail.RecommendFromLocationCode, firstDetail.RecommendToLocationCode).ConfigureAwait(false); } - return coatingIssueJobDtos; + return assembleIssueJobDtos; } [HttpPost("")] public override async Task CreateAsync(CoatingIssueJobEditInput input) { await CheckMinRowAndSetStatusAsync(input).ConfigureAwait(false); - await CheckDimensionalStorehouseAsync(input).ConfigureAwait(false); + var flagDimensionalStorehouse = await UpdateJobStatusWaitByDimensionalStorehouseAsync(input).ConfigureAwait(false); + if (flagDimensionalStorehouse == false) + { + await UpdateJobStatusWaitByAgvAsync(input).ConfigureAwait(false); + } - var coatingIssueJobDto = await base.CreateAsync(input).ConfigureAwait(false); - await DoingDimensionalStorehouseAsync(coatingIssueJobDto).ConfigureAwait(false); + var assembleIssueJobDto = await base.CreateAsync(input).ConfigureAwait(false); + await DoingDimensionalStorehouseAsync(assembleIssueJobDto).ConfigureAwait(false); + if (flagDimensionalStorehouse == false) + { + var firstDetail = assembleIssueJobDto.Details.First(); + await DoingAgvAsync(assembleIssueJobDto, firstDetail.RecommendFromLocationCode, firstDetail.RecommendToLocationCode).ConfigureAwait(false); + } - return coatingIssueJobDto; + return assembleIssueJobDto; } [HttpPost("invalid")] @@ -214,7 +257,23 @@ public class CoatingIssueJobAppService jobDetail.TransferLibToSupplierBatch = transferLibNoteDetail.HandledToSupplierBatch; jobDetail.TransferLibToWarehouseCode = transferLibNoteDetail.HandledToWarehouseCode; - await _repository.UpdateAsync(job).ConfigureAwait(false); + var jobDto = ObjectMapper.Map(job); + + var isDoingAgv = await DoingAgvAsync(jobDto, jobDetail.TransferLibToLocationCode, jobDetail.RecommendToLocationCode).ConfigureAwait(false); + + if (isDoingAgv) + { + job.JobStatus = EnumJobStatus.WaitAgv; + job.IsClaims = true; + job.ClaimsUserId = string.IsNullOrEmpty(_options.Value.StereosUser) + ? "AGV" + : _options.Value.StereosUser; + job.ClaimsUserName = string.IsNullOrEmpty(_options.Value.StereosPassword) + ? "AGV" + : _options.Value.StereosPassword; + } + + job = await _repository.UpdateAsync(job).ConfigureAwait(false); } /// @@ -475,6 +534,50 @@ public class CoatingIssueJobAppService #region 立库 + /// + /// 调用立体库 + /// + /// + /// + private async Task DoingDimensionalStorehouseAsync(CoatingIssueJobDTO CoatingIssueJobDto) + { + var jobDetailInputdetail = CoatingIssueJobDto.Details.FirstOrDefault(); + var loctionDto = await _locationAppService.GetByCodeAsync(jobDetailInputdetail.RecommendFromLocationCode) + .ConfigureAwait(false); + + if (loctionDto.Type == EnumLocationType.DimensionalStorehouse) + { + //TODO 立体库 + var ret = await SyncIssueJobStereoAsync(new List { CoatingIssueJobDto }, + jobDetailInputdetail.RecommendToLocationCode, CoatingIssueJobDto.Id).ConfigureAwait(false); + if (ret.Code != 0) + { + throw new UserFriendlyException($"调用立体库不成功!原因:{ret.Message}"); + } + } + } + + /// + /// 判断是不是在立体库 + /// + /// + /// + private async Task UpdateJobStatusWaitByDimensionalStorehouseAsync(CoatingIssueJobEditInput input) + { + var jobDetailInputdetail = input.Details.FirstOrDefault(); + + var loctionDto = await _locationAppService.GetByCodeAsync(jobDetailInputdetail.RecommendFromLocationCode) + .ConfigureAwait(false); + + if (loctionDto.Type == EnumLocationType.DimensionalStorehouse) + { + input.JobStatus = EnumJobStatus.Wait; + return true; + } + + return false; + } + /// /// 立体库同步 /// @@ -482,27 +585,29 @@ public class CoatingIssueJobAppService /// /// [HttpPost("sync-issue-job-stereo")] - public async Task SyncIssueJobStereoAsync(List input, string pLoc) + public async Task SyncIssueJobStereoAsync(List input, string pLoc, Guid uid) { var ret = new ReusltObject(); - ret.Code = int.Parse(GaoTongResultStatus.Success); + ret.Code = 0; ret.Message = "操作成功"; - ret.OperateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + ret.OperateTime = DateTime.Now.ToString("yyyy-MM-dd"); + using var unitOfWork = _unitOfWorkManager.Begin(); try { var IssueJobToRestoDetailDTOs = new List(); var main = new IssueJobToRestoDTO(); - main.OperatorName = CurrentUser.UserName; + main.Uuid = uid; + main.OperatorName = string.IsNullOrEmpty(CurrentUser.UserName) ? "admin" : CurrentUser.UserName; foreach (var job in input) { foreach (var jobitem in job.Details) { IssueJobToRestoDetailDTOs.Add(new IssueJobToRestoDetailDTO { - Count = jobitem.HandledToQty, + Count = jobitem.RecommendFromQty, ProductNo = jobitem.ItemCode, NeedSite = pLoc, - WorkNo = job.Number, + WorkNo = job.CoatingRequestNumber, TaskNo = job.Number }); } @@ -513,26 +618,31 @@ public class CoatingIssueJobAppService #if DEBUG var json = JsonSerializer.Serialize(main); - _options.Value.Address = "http://7e42682n64.goho.co:21171/"; //测试地址 + _options.Value.Address = "http://localhost:59094/"; //测试地址 _options.Value.Token = ""; //测试token _options.Value.UserName = ""; //测试用户名 _options.Value.Password = ""; //测试密码 - _options.Value.Path = "zozocnApi/custom/receiveProductionPlan"; //测试密码 #endif //var json = JsonSerializer.Serialize(main); - _options.Value.Address = "http://7e42682n64.goho.co:21171/"; //测试地址 - _options.Value.Token = ""; //测试token - _options.Value.UserName = ""; //测试用户名 - _options.Value.Password = ""; //测试密码 - _options.Value.Path = "zozocnApi/custom/receiveProductionPlan"; //测试密码 - - _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize(_options)); - - + _options.Value.Address = string.IsNullOrEmpty(_options.Value.Address) + ? "http://7e42682n64.goho.co:21171/" + : _options.Value.Address; //测试地址 + _options.Value.Token = + string.IsNullOrEmpty(_options.Value.Token) ? string.Empty : _options.Value.Token; //测试token + _options.Value.UserName = + string.IsNullOrEmpty(_options.Value.UserName) ? "" : _options.Value.UserName; //测试用户名 + _options.Value.Password = + string.IsNullOrEmpty(_options.Value.Password) ? "" : _options.Value.Password; //测试密码 + _options.Value.Path = string.IsNullOrEmpty(_options.Value.Path) + ? "zozocnApi/custom/receiveProductionPlan" + : _options.Value.Path; //测试密码 + _logger.LogInformation(JsonSerializer.Serialize(_options)); + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + _logger.LogInformation($"标志{flag}开始调用高通WMS:传递值{JsonSerializer.Serialize(main)}"); if (!string.IsNullOrEmpty(_options.Value.Token)) @@ -550,24 +660,17 @@ public class CoatingIssueJobAppService } var client = new IssueJobToRestoClient(_options.Value.Address, httpclient, _options.Value.Path); - - var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); - _logger.LogInformation($"标志{flag}开始调用高通WMS:传递值{System.Text.Json.JsonSerializer.Serialize(main)}"); - - //_logger.LogInformation(MakeGrid($"标志{flag}开始调用高通WMS明细", main.Details.ToList())); - - ret = await client.SyncIssueJobStereoAsync(main).ConfigureAwait(false); - _logger.LogInformation($"标志{flag}调用高通WMS:返回值{ret}"); - + _logger.LogInformation($"标志{flag}调用高通WMS:返回值{JsonSerializer.Serialize(ret)}"); } catch (Exception ex) { ret = new ReusltObject(); - ret.Code = int.Parse(GaoTongResultStatus.Failure); + ret.Code = 1; ret.Message = ex.Message; - ret.OperateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + ret.OperateTime = DateTime.Now.ToString("yyyy-MM-dd"); + await unitOfWork.RollbackAsync().ConfigureAwait(false); } return ret; @@ -576,11 +679,19 @@ public class CoatingIssueJobAppService [HttpPost("receive-issue-job-stereo")] public virtual async Task SyncReciveIssueJobStereoAsync(IssueRequestFromRestoDTO input) { -#if DEBUG var json = JsonSerializer.Serialize(input); + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + _logger.LogInformation($"{flag}接收到立体库确认单据内容:" + json); +#if DEBUG #endif var errors = new List(); - var ret = new ReusltObject { Code = 1, OperateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Message = "操作成功" }; + var ret = new ReusltObject + { + Code = int.Parse(GaoTongResultStatus.Success), + OperateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + Message = "操作成功" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); try { if (input.Jobs.Count > 0) @@ -588,40 +699,102 @@ public class CoatingIssueJobAppService var jobs = input.Jobs; var numbers = jobs.Select(p => p.JobNumber); var query = _repository.WithDetails() - .Where(p => numbers.Contains(p.Number)); + .Where(p => numbers.Contains(p.Number) && p.JobStatus != EnumJobStatus.Done); + + var entities = query.ToList(); - var dtos = ObjectMapper.Map, List>(entities); if (entities.Count == 0) { errors.Add($"任务号{string.Join(",", numbers)}不存在!"); } - if (input.Jobs.Count == entities.Count) + + var dtos = ObjectMapper.Map, List>(entities); + + + if (input.Jobs.Count != entities.Count) { errors.Add("立体库提交出库任务和WMS任务不符,请核对! \n"); } foreach (var itm in dtos) { + var first = jobs.FirstOrDefault(p => p.JobNumber == itm.Number); var itmDetails = itm.Details.ToList(); var details = new List(); foreach (var detail in first.Details) { + var fromloc = await _locationAppService.GetByCodeAsync(detail.FromLocationCode) + .ConfigureAwait(false); + if (fromloc == null) + { + errors.Add($"来源库位{detail.FromLocationCode}没查到"); + } + var toloc = await _locationAppService.GetByCodeAsync(detail.ToLocationCode) + .ConfigureAwait(false); + if (toloc == null) + { + errors.Add($"目标库位{detail.ToLocationCode}没查到"); + } var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.ItemCode); + if (entity == null) + { + errors.Add($"物料号{detail.ItemCode}不在任务明细内!"); + } + var dto = new CoatingIssueJobDetailDTO(); - dto.HandledFromLocationCode = entity.HandledFromLocationCode; - dto.HandledToLocationCode = entity.HandledToLocationCode; - dto.ItemCode = detail.ItemCode; + dto.InjectFrom(entity); + + /* 客户说整单完成后才回传 dto.RecommendFromQty = detail.Qty; dto.RecommendToQty = detail.Qty; dto.HandledFromQty = detail.Qty; dto.HandledToQty = detail.Qty; - dto.Status = entity.Status; + */ + //dto.RecommendFromQty = detail.Qty; + //dto.RecommendToQty = detail.Qty; + //dto.HandledFromQty = detail.Qty; + //dto.HandledToQty = detail.Qty; + + dto.HandledToLocationCode = toloc.Code; + dto.HandledToLocationGroup = toloc.LocationGroupCode; + dto.HandledToLocationArea = toloc.AreaCode; + dto.HandledToLocationErpCode = toloc.ErpLocationCode; + dto.HandledToLot = string.Empty; + dto.HandledToWarehouseCode = toloc.WarehouseCode; + dto.HandledToQty = detail.Qty; + dto.HandledToLot = string.Empty; + dto.HandledToPackingCode = string.Empty; + + + dto.HandledFromWarehouseCode = fromloc.WarehouseCode; + dto.HandledFromLocationCode = fromloc.Code; + dto.HandledFromLocationGroup = fromloc.LocationGroupCode; + dto.HandledFromLocationArea = fromloc.AreaCode; + dto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + dto.HandledFromQty = detail.Qty; + dto.HandledFromLot = string.Empty; + dto.HandledFromPackingCode = string.Empty; + + details.Add(dto); + await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false); } + if (errors.Count > 0) + { + ret = new ReusltObject + { + Code = int.Parse(GaoTongResultStatus.Failure), + OperateTime = DateTime.Now.ToString("yyyy-MM-dd"), + Message = string.Join(",", errors.ToArray()), + Data = json + }; + } + itm.Worker = "LITK"; itm.Details = details; - await CompleteAsync(itm.Id, itm).ConfigureAwait(false); + // await CompleteAsync(itm.Id, itm).ConfigureAwait(false); + _logger.LogInformation($"{flag}接收到立体库确认单据内容:" + json + "立体库任务完成"); } } else @@ -635,8 +808,10 @@ public class CoatingIssueJobAppService { Code = int.Parse(GaoTongResultStatus.Failure), OperateTime = DateTime.Now.ToString("yyyy-MM-dd"), - Message = ex.Message + Message = ex.Message, + Data = json }; + await unitOfWork.RollbackAsync(); return ret; } @@ -646,7 +821,8 @@ public class CoatingIssueJobAppService { Code = int.Parse(GaoTongResultStatus.Failure), OperateTime = DateTime.Now.ToString("yyyy-MM-dd"), - Message = string.Join(",", errors.ToArray()) + Message = string.Join(",", errors.ToArray()), + Data = json }; } @@ -655,6 +831,7 @@ public class CoatingIssueJobAppService #endregion + #region 私有 /// @@ -739,34 +916,7 @@ public class CoatingIssueJobAppService } } - /// - /// 调用立体库 - /// - /// - /// - private async Task DoingDimensionalStorehouseAsync(CoatingIssueJobDTO coatingIssueJobDto) - { - var jobDetailInputdetail = coatingIssueJobDto.Details.FirstOrDefault(); - - var loctionDto = await _locationAppService.GetByCodeAsync(jobDetailInputdetail.RecommendFromLocationCode) - .ConfigureAwait(false); - var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); - _logger.LogInformation($"立体库任务检查开始{flag}"); - if (loctionDto.Type == EnumLocationType.DimensionalStorehouse) - { - - _logger.LogInformation($"立体库任务开始标记{flag}"); - //TODO 立体库 - var ret = await SyncIssueJobStereoAsync(new List { coatingIssueJobDto }, - loctionDto.Code).ConfigureAwait(false); - - _logger.LogInformation($"立体库任务结束标记{flag},返回值{ret}"); - if (ret.Code != 0) - { - throw new UserFriendlyException($"调用立体库不成功!原因:{ret.Message}"); - } - } - } + /// /// 修改当前任务状态 和 该任务的请求状态 @@ -826,21 +976,77 @@ public class CoatingIssueJobAppService handledToQty).ConfigureAwait(false); } + + /// + /// 调用AGV + /// + /// + /// + /// + /// + private async Task DoingAgvAsync(CoatingIssueJobDTO assembleIssueJobDto, string fromLocationCode, string toLocationCode) + { + var jobDetailInputdetail = assembleIssueJobDto.Details.FirstOrDefault(); + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + fromLocationCode, toLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + //TODO AGV + //来源永远是库位 目标永远是工位 + var ret = await CallAgvAsync(assembleIssueJobDto, fromLocationCode, jobDetailInputdetail.Remark).ConfigureAwait(false); + +#if DEBUG + + return true; + +#endif + + if (ret.Code != 0) + { + throw new UserFriendlyException($"调用AGV不成功!原因:{ret.Message}"); + } + } + + return false; + } + + /// + /// 判断是不是有Agv + /// + /// + /// + private async Task UpdateJobStatusWaitByAgvAsync(CoatingIssueJobEditInput input) + { + var jobDetailInputdetail = input.Details.FirstOrDefault(); + + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + jobDetailInputdetail.RecommendFromLocationCode, jobDetailInputdetail.RecommendToLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + input.JobStatus = EnumJobStatus.WaitAgv; + return true; + } + + return false; + } + /// /// 调用 Agv 接口 /// /// - /// - /// + /// + /// /// [HttpPost("call-agv")] - public async Task CallAgvAsync(CoatingIssueJobDTO input) + public async Task CallAgvAsync(CoatingIssueJobDTO input, string beginPosition, string endPosition) { var res = new ReusltObject(); List errors = new List(); List successList = new List(); - var jobres = await SendInterFaceAsync(input).ConfigureAwait(false); + var jobres = await SendInterFaceAsync(input, beginPosition, endPosition).ConfigureAwait(false); if (jobres.Code != "0") { _logger.LogInformation(jobres.Message); @@ -868,170 +1074,74 @@ public class CoatingIssueJobAppService [HttpPost("call-back-agv")] public async Task 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(); - 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.CoatingRequestNumber, - }; - 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>(entities); - foreach (var itm in dtos) - { - var arys = jobs.Where(p => p.OrderNum == itm.Number); - var itmDetails = itm.Details.ToList(); - var details = new List(); - 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 entity = await _repository.FindAsync(p => p.Number == request.Data.First().OrderNum).ConfigureAwait(false); + var dto = ObjectMapper.Map(entity); - 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 CoatingIssueJobDetailDTO(); - 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 : string.Empty; - 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 : string.Empty; - 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任务完成"); - } + foreach (var detail in entity.Details) + { + var detailDto = new CoatingIssueJobDetailDTO(); + if (!string.IsNullOrEmpty(detail.TransferLibFromLocationCode)) + { + //库移的最终目标 挪到 推荐的目标 + var fromloc = await _locationAppService.GetByCodeAsync(detail.TransferLibToLocationCode).ConfigureAwait(false); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.TransferLibToLot; + detailDto.HandledToPackingCode = detail.TransferLibToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.TransferLibToLot; + detailDto.HandledFromPackingCode = detail.TransferLibToPackingCode; } else { - errors.Add("Agv确认单据里无数据! \n"); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + var fromloc = await _locationAppService.GetByCodeAsync(detail.RecommendFromLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.RecommendToLot; + detailDto.HandledToPackingCode = detail.RecommendToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.RecommendToLot; + detailDto.HandledFromPackingCode = detail.RecommendToPackingCode; } - } - catch (Exception ex) - { - ret = new AgvResultObject - { - Code = "-1", - ReqCode = job.CoatingRequestNumber, - Message = ex.Message - }; - await unitOfWork.RollbackAsync().ConfigureAwait(false); - return ret; + + await ExecuteDetailExtAsync(entity.Id, entity.Details.First().Id, detailDto).ConfigureAwait(false); } - if (errors.Count > 0) + return new AgvResultObject { - ret = new AgvResultObject - { - Code = "-1", - Message = string.Join(",", errors.ToArray()), - ReqCode = job.CoatingRequestNumber - }; - } - return ret; + Code = "0", + Message = "OK", + ReqCode = "", + }; } /// @@ -1188,12 +1298,12 @@ public class CoatingIssueJobAppService - /// - /// 调用Agv接口实现 - /// - /// - /// - private async Task SendInterFaceAsync(CoatingIssueJobDTO job) + /// + /// 调用Agv接口实现 + /// + /// + /// + private async Task SendInterFaceAsync(CoatingIssueJobDTO job, string beginPosition, string endPosition) { #if DEBUG @@ -1225,8 +1335,9 @@ public class CoatingIssueJobAppService request.MatQty = first.HandledToQty; request.OrderNum = job.Number; request.OrderType = EnumJobType.CoatingIssueJob.ToString(); - + request.BeginPosition = beginPosition; + request.EndPosition = endPosition; var httpclient = _httpClientFactory.CreateClient(); _agvOptions.Value.Address = string.IsNullOrEmpty(_agvOptions.Value.Address) ? "http://7e42682n64.goho.co:21171/" diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs index 1060b8209..5e7c7e7c5 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs @@ -53,6 +53,7 @@ public class InjectionIssueJobAppService private readonly ILogger _logger; private readonly IItemBasicAppService _itemBasicAppService; private readonly ITransferNoteAppService _transferNoteAppService; + private readonly ILocationDeliveryAppService _locationDeliveryAppService; protected IInjectionIssueRequestAppService InjectionIssueRequestAppService => @@ -64,7 +65,7 @@ public class InjectionIssueJobAppService ILocationAppService locationAppService, IInjectionIssueNoteAppService injectionIssueNoteAppService, IExpectOutAppService expectOutAppService , IHttpClientFactory httpClientFactory - , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser + , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, ILocationDeliveryAppService locationDeliveryAppService , IOptions agvOptions , UnitOfWorkManager unitOfWorkManager , IItemBasicAppService itemBasicAppService @@ -84,6 +85,7 @@ public class InjectionIssueJobAppService _agvOptions = agvOptions; _logger = logger; _itemBasicAppService = itemBasicAppService; + _locationDeliveryAppService = locationDeliveryAppService; } [HttpPost("get-by-number-2")] public async Task GetByNumber2Async(string number) @@ -106,6 +108,8 @@ public class InjectionIssueJobAppService foreach (var injectionIssueJobDto in injectionIssueJobDtos) { await DoingDimensionalStorehouseAsync(injectionIssueJobDto).ConfigureAwait(false); + var firstDetail = injectionIssueJobDto.Details.First(); + await DoingAgvAsync(injectionIssueJobDto, firstDetail.RecommendFromLocationCode, firstDetail.RecommendToLocationCode).ConfigureAwait(false); } return injectionIssueJobDtos; @@ -119,6 +123,8 @@ public class InjectionIssueJobAppService var injectionIssueJobDto = await base.CreateAsync(input).ConfigureAwait(false); await DoingDimensionalStorehouseAsync(injectionIssueJobDto).ConfigureAwait(false); + var firstDetail = injectionIssueJobDto.Details.First(); + await DoingAgvAsync(injectionIssueJobDto, firstDetail.RecommendFromLocationCode, firstDetail.RecommendToLocationCode).ConfigureAwait(false); return injectionIssueJobDto; } @@ -765,23 +771,80 @@ public class InjectionIssueJobAppService injectionIssueJobDetailDto.Status, injectionIssueJobDetailDto.HandledToLot, handledToQty).ConfigureAwait(false); } - + + + #region Agv + + /// + /// 调用AGV + /// + /// + /// + /// + /// + private async Task DoingAgvAsync(InjectionIssueJobDTO InjectionIssueJobDto, string fromLocationCode, string toLocationCode) + { + var jobDetailInputdetail = InjectionIssueJobDto.Details.FirstOrDefault(); + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + fromLocationCode, toLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + //TODO AGV + //来源永远是库位 目标永远是工位 + var ret = await CallAgvAsync(InjectionIssueJobDto, fromLocationCode, jobDetailInputdetail.Remark).ConfigureAwait(false); + +#if DEBUG + + return true; + +#endif + + if (ret.Code != 0) + { + throw new UserFriendlyException($"调用AGV不成功!原因:{ret.Message}"); + } + } + + return false; + } + + /// + /// 判断是不是有Agv + /// + /// + /// + private async Task UpdateJobStatusWaitByAgvAsync(InjectionIssueJobEditInput input) + { + var jobDetailInputdetail = input.Details.FirstOrDefault(); + + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + jobDetailInputdetail.RecommendFromLocationCode, jobDetailInputdetail.RecommendToLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + input.JobStatus = EnumJobStatus.WaitAgv; + return true; + } + + return false; + } /// /// 调用 Agv 接口 /// /// - /// - /// + /// + /// /// [HttpPost("call-agv")] - public async Task CallAgvAsync(InjectionIssueJobDTO input) + public async Task CallAgvAsync(InjectionIssueJobDTO input, string beginPosition, string endPosition) { var res = new ReusltObject(); List errors = new List(); List successList = new List(); - var jobres = await SendInterFaceAsync(input).ConfigureAwait(false); + var jobres = await SendInterFaceAsync(input, beginPosition, endPosition).ConfigureAwait(false); if (jobres.Code != "0") { _logger.LogInformation(jobres.Message); @@ -809,169 +872,75 @@ public class InjectionIssueJobAppService [HttpPost("call-back-agv")] public async Task 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(); - 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.InjectionRequestNumber, - }; - using var unitOfWork = _unitOfWorkManager.Begin(); - try + var entity = await _repository.FindAsync(p => p.Number == request.Data.First().OrderNum).ConfigureAwait(false); + var dto = ObjectMapper.Map(entity); + + foreach (var detail in entity.Details) { - if (request.Data.Count > 0) + var detailDto = new InjectionIssueJobDetailDTO(); + if (!string.IsNullOrEmpty(detail.TransferLibFromLocationCode)) { - 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>(entities); - - foreach (var itm in dtos) - { - var arys = jobs.Where(p => p.OrderNum == itm.Number); - var itmDetails = itm.Details.ToList(); - var details = new List(); - 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 InjectionIssueJobDetailDTO(); - 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 : string.Empty; - 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 : string.Empty; - 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任务完成"); - } + //库移的最终目标 挪到 推荐的目标 + var fromloc = await _locationAppService.GetByCodeAsync(detail.TransferLibToLocationCode).ConfigureAwait(false); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.TransferLibToLot; + detailDto.HandledToPackingCode = detail.TransferLibToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.TransferLibToLot; + detailDto.HandledFromPackingCode = detail.TransferLibToPackingCode; } else { - errors.Add("Agv确认单据里无数据! \n"); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + var fromloc = await _locationAppService.GetByCodeAsync(detail.RecommendFromLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.RecommendToLot; + detailDto.HandledToPackingCode = detail.RecommendToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.RecommendToLot; + detailDto.HandledFromPackingCode = detail.RecommendToPackingCode; } - } - catch (Exception ex) - { - ret = new AgvResultObject - { - Code = "-1", - ReqCode = job.InjectionRequestNumber, - Message = ex.Message - }; - await unitOfWork.RollbackAsync().ConfigureAwait(false); - return ret; + + await ExecuteDetailExtAsync(entity.Id, entity.Details.First().Id, detailDto).ConfigureAwait(false); } - if (errors.Count > 0) + return new AgvResultObject { - ret = new AgvResultObject - { - Code = "-1", - Message = string.Join(",", errors.ToArray()), - ReqCode = job.InjectionRequestNumber - }; - } - return ret; + Code = "0", + Message = "OK", + ReqCode = "", + }; } + /// /// Agv 回库 接口 /// @@ -1121,15 +1090,14 @@ public class InjectionIssueJobAppService } - - - /// /// 调用Agv接口实现 /// /// + /// + /// /// - private async Task SendInterFaceAsync(InjectionIssueJobDTO job) + private async Task SendInterFaceAsync(InjectionIssueJobDTO job, string beginPosition, string endPosition) { #if DEBUG @@ -1153,15 +1121,14 @@ public class InjectionIssueJobAppService { throw new UserFriendlyException($"任务{job.Number}没有推荐库存!"); } - - - var first = job.Details.FirstOrDefault(); var request = new AgvRequest(); request.MatCode = first.ItemCode; request.MatQty = first.HandledToQty; request.OrderNum = job.Number; request.OrderType = EnumJobType.InjectionIssueJob.ToString(); + request.BeginPosition = beginPosition; + request.EndPosition = endPosition; var httpclient = _httpClientFactory.CreateClient(); _agvOptions.Value.Address = string.IsNullOrEmpty(_agvOptions.Value.Address) @@ -1208,6 +1175,7 @@ public class InjectionIssueJobAppService return ret; } + #endregion diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs index 261e9aed9..ae47315c5 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs @@ -54,6 +54,7 @@ public class KittingIssueJobAppService private readonly ILogger _logger; private readonly IItemBasicAppService _itemBasicAppService; private readonly ITransferNoteAppService _transferNoteAppService; + private readonly ILocationDeliveryAppService _locationDeliveryAppService; protected IKittingIssueRequestAppService KittingIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -67,7 +68,7 @@ public class KittingIssueJobAppService , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, IItemBasicAppService itemBasicAppService ,IOptions agvOptions, - + ILocationDeliveryAppService locationDeliveryAppService, UnitOfWorkManager unitOfWorkManager ) : base( repository, kittingIssueJobManager) @@ -85,6 +86,7 @@ public class KittingIssueJobAppService _unitOfWorkManager = unitOfWorkManager; _agvOptions = agvOptions; _itemBasicAppService = itemBasicAppService; + _locationDeliveryAppService = locationDeliveryAppService; } [HttpPost("get-by-number-2")] @@ -219,7 +221,23 @@ public class KittingIssueJobAppService jobDetail.TransferLibToSupplierBatch = transferLibNoteDetail.HandledToSupplierBatch; jobDetail.TransferLibToWarehouseCode = transferLibNoteDetail.HandledToWarehouseCode; - await _repository.UpdateAsync(job).ConfigureAwait(false); + var jobDto = ObjectMapper.Map(job); + + var isDoingAgv = await DoingAgvAsync(jobDto, jobDetail.TransferLibToLocationCode, jobDetail.RecommendToLocationCode).ConfigureAwait(false); + + if (isDoingAgv) + { + job.JobStatus = EnumJobStatus.WaitAgv; + job.IsClaims = true; + job.ClaimsUserId = string.IsNullOrEmpty(_options.Value.StereosUser) + ? "AGV" + : _options.Value.StereosUser; + job.ClaimsUserName = string.IsNullOrEmpty(_options.Value.StereosPassword) + ? "AGV" + : _options.Value.StereosPassword; + } + + job = await _repository.UpdateAsync(job).ConfigureAwait(false); } /// @@ -774,21 +792,85 @@ public class KittingIssueJobAppService kittingIssueJobDetailDto.Status, kittingIssueJobDetailDto.HandledToLot, handledToQty).ConfigureAwait(false); } + + + + + #endregion + + + #region Agv + + /// + /// 调用AGV + /// + /// + /// + /// + /// + private async Task DoingAgvAsync(KittingIssueJobDTO KittingIssueJobDto, string fromLocationCode, string toLocationCode) + { + var jobDetailInputdetail = KittingIssueJobDto.Details.FirstOrDefault(); + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + fromLocationCode, toLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + //TODO AGV + //来源永远是库位 目标永远是工位 + var ret = await CallAgvAsync(KittingIssueJobDto, fromLocationCode, jobDetailInputdetail.Remark).ConfigureAwait(false); + +#if DEBUG + + return true; + +#endif + + if (ret.Code != 0) + { + throw new UserFriendlyException($"调用AGV不成功!原因:{ret.Message}"); + } + } + + return false; + } + + /// + /// 判断是不是有Agv + /// + /// + /// + private async Task UpdateJobStatusWaitByAgvAsync(KittingIssueJobEditInput input) + { + var jobDetailInputdetail = input.Details.FirstOrDefault(); + + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + jobDetailInputdetail.RecommendFromLocationCode, jobDetailInputdetail.RecommendToLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + input.JobStatus = EnumJobStatus.WaitAgv; + return true; + } + + return false; + } + /// /// 调用 Agv 接口 /// /// - /// - /// + /// + /// /// [HttpPost("call-agv")] - public async Task CallAgvAsync(KittingIssueJobDTO input) + public async Task CallAgvAsync(KittingIssueJobDTO input, string beginPosition, string endPosition) { var res = new ReusltObject(); List errors = new List(); List successList = new List(); - var jobres = await SendInterFaceAsync(input).ConfigureAwait(false); + var jobres = await SendInterFaceAsync(input, beginPosition, endPosition).ConfigureAwait(false); if (jobres.Code != "0") { _logger.LogInformation(jobres.Message); @@ -816,168 +898,73 @@ public class KittingIssueJobAppService [HttpPost("call-back-agv")] public async Task 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(); - 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.KittingRequestNumber, - }; - using var unitOfWork = _unitOfWorkManager.Begin(); - try + var entity = await _repository.FindAsync(p => p.Number == request.Data.First().OrderNum).ConfigureAwait(false); + var dto = ObjectMapper.Map(entity); + + foreach (var detail in entity.Details) { - if (request.Data.Count > 0) + var detailDto = new KittingIssueJobDetailDTO(); + if (!string.IsNullOrEmpty(detail.TransferLibFromLocationCode)) { - 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>(entities); - - foreach (var itm in dtos) - { - var arys = jobs.Where(p => p.OrderNum == itm.Number); - var itmDetails = itm.Details.ToList(); - var details = new List(); - 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 KittingIssueJobDetailDTO(); - 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 : string.Empty; - 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 : string.Empty; - 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任务完成"); - } + //库移的最终目标 挪到 推荐的目标 + var fromloc = await _locationAppService.GetByCodeAsync(detail.TransferLibToLocationCode).ConfigureAwait(false); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.TransferLibToLot; + detailDto.HandledToPackingCode = detail.TransferLibToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.TransferLibToLot; + detailDto.HandledFromPackingCode = detail.TransferLibToPackingCode; } else { - errors.Add("Agv确认单据里无数据! \n"); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + var fromloc = await _locationAppService.GetByCodeAsync(detail.RecommendFromLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.RecommendToLot; + detailDto.HandledToPackingCode = detail.RecommendToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.RecommendToLot; + detailDto.HandledFromPackingCode = detail.RecommendToPackingCode; } - } - catch (Exception ex) - { - ret = new AgvResultObject - { - Code = "-1", - ReqCode = job.KittingRequestNumber, - Message = ex.Message - }; - await unitOfWork.RollbackAsync().ConfigureAwait(false); - return ret; + + await ExecuteDetailExtAsync(entity.Id, entity.Details.First().Id, detailDto).ConfigureAwait(false); } - if (errors.Count > 0) + return new AgvResultObject { - ret = new AgvResultObject - { - Code = "-1", - Message = string.Join(",", errors.ToArray()), - ReqCode = job.KittingRequestNumber - }; - } - return ret; + Code = "0", + Message = "OK", + ReqCode = "", + }; } /// @@ -1133,8 +1120,10 @@ public class KittingIssueJobAppService /// 调用Agv接口实现 /// /// + /// + /// /// - private async Task SendInterFaceAsync(KittingIssueJobDTO job) + private async Task SendInterFaceAsync(KittingIssueJobDTO job, string beginPosition, string endPosition) { #if DEBUG @@ -1164,8 +1153,8 @@ public class KittingIssueJobAppService request.MatQty = first.HandledToQty; request.OrderNum = job.Number; request.OrderType = EnumJobType.KittingIssueJob.ToString(); - request.BeginPosition = first.HandledFromLocationCode; - request.EndPosition = first.HandledToLocationCode; + request.BeginPosition = beginPosition; + request.EndPosition = endPosition; var httpclient = _httpClientFactory.CreateClient(); _agvOptions.Value.Address = string.IsNullOrEmpty(_agvOptions.Value.Address) @@ -1211,8 +1200,6 @@ public class KittingIssueJobAppService } return ret; } - - #endregion } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs index 590b08475..dc887aa81 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs @@ -53,6 +53,7 @@ public class SparePartIssueJobAppService private readonly ILogger _logger; private readonly IItemBasicAppService _itemBasicAppService; private readonly ITransferNoteAppService _transferNoteAppService; + private readonly ILocationDeliveryAppService _locationDeliveryAppService; protected ISparePartIssueRequestAppService SparePartIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -64,7 +65,10 @@ public class SparePartIssueJobAppService ISparePartIssueNoteAppService sparePartIssueNoteAppService, IExpectOutAppService expectOutAppService , IHttpClientFactory httpClientFactory , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, ILogger logger - , UnitOfWorkManager unitOfWorkManager, IOptions agvOptions, IItemBasicAppService itemBasicAppService, ITransferNoteAppService transferNoteAppService + , UnitOfWorkManager unitOfWorkManager, IOptions agvOptions, + IItemBasicAppService itemBasicAppService, + ITransferNoteAppService transferNoteAppService, + ILocationDeliveryAppService locationDeliveryAppService ) : base( repository, sparePartIssueJobManager) { @@ -82,6 +86,7 @@ public class SparePartIssueJobAppService _logger = logger; _itemBasicAppService = itemBasicAppService; _transferNoteAppService = transferNoteAppService; + _locationDeliveryAppService = locationDeliveryAppService; } [HttpPost("get-by-number-2")] @@ -210,7 +215,23 @@ public class SparePartIssueJobAppService jobDetail.TransferLibToSupplierBatch = transferLibNoteDetail.HandledToSupplierBatch; jobDetail.TransferLibToWarehouseCode = transferLibNoteDetail.HandledToWarehouseCode; - await _repository.UpdateAsync(job).ConfigureAwait(false); + var jobDto = ObjectMapper.Map(job); + + var isDoingAgv = await DoingAgvAsync(jobDto, jobDetail.TransferLibToLocationCode, jobDetail.RecommendToLocationCode).ConfigureAwait(false); + + if (isDoingAgv) + { + job.JobStatus = EnumJobStatus.WaitAgv; + job.IsClaims = true; + job.ClaimsUserId = string.IsNullOrEmpty(_options.Value.StereosUser) + ? "AGV" + : _options.Value.StereosUser; + job.ClaimsUserName = string.IsNullOrEmpty(_options.Value.StereosPassword) + ? "AGV" + : _options.Value.StereosPassword; + } + + job = await _repository.UpdateAsync(job).ConfigureAwait(false); } /// @@ -750,21 +771,82 @@ public class SparePartIssueJobAppService handledToQty).ConfigureAwait(false); } + + + + #endregion + #region Agv + + /// + /// 调用AGV + /// + /// + /// + /// + /// + private async Task DoingAgvAsync(SparePartIssueJobDTO SparePartIssueJobDto, string fromLocationCode, string toLocationCode) + { + var jobDetailInputdetail = SparePartIssueJobDto.Details.FirstOrDefault(); + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + fromLocationCode, toLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + //TODO AGV + //来源永远是库位 目标永远是工位 + var ret = await CallAgvAsync(SparePartIssueJobDto, fromLocationCode, jobDetailInputdetail.Remark).ConfigureAwait(false); + +#if DEBUG + + return true; + +#endif + + if (ret.Code != 0) + { + throw new UserFriendlyException($"调用AGV不成功!原因:{ret.Message}"); + } + } + + return false; + } + + /// + /// 判断是不是有Agv + /// + /// + /// + private async Task UpdateJobStatusWaitByAgvAsync(SparePartIssueJobEditInput input) + { + var jobDetailInputdetail = input.Details.FirstOrDefault(); + + var locationDeliveryDto = await _locationDeliveryAppService.GetByFromLocationCodeAndToLocationCodeAsync( + jobDetailInputdetail.RecommendFromLocationCode, jobDetailInputdetail.RecommendToLocationCode).ConfigureAwait(false); + + if (locationDeliveryDto != null && locationDeliveryDto.EnumLocationDeliveryType == EnumLocationDeliveryType.Agv) + { + input.JobStatus = EnumJobStatus.WaitAgv; + return true; + } + + return false; + } + /// /// 调用 Agv 接口 /// /// - /// - /// + /// + /// /// [HttpPost("call-agv")] - public async Task CallAgvAsync(SparePartIssueJobDTO input) + public async Task CallAgvAsync(SparePartIssueJobDTO input, string beginPosition, string endPosition) { var res = new ReusltObject(); List errors = new List(); List successList = new List(); - var jobres = await SendInterFaceAsync(input).ConfigureAwait(false); + var jobres = await SendInterFaceAsync(input, beginPosition, endPosition).ConfigureAwait(false); if (jobres.Code != "0") { _logger.LogInformation(jobres.Message); @@ -792,169 +874,75 @@ public class SparePartIssueJobAppService [HttpPost("call-back-agv")] public async Task 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(); - 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.SparePartRequestNumber, - }; - using var unitOfWork = _unitOfWorkManager.Begin(); - try + var entity = await _repository.FindAsync(p => p.Number == request.Data.First().OrderNum).ConfigureAwait(false); + var dto = ObjectMapper.Map(entity); + + foreach (var detail in entity.Details) { - if (request.Data.Count > 0) + var detailDto = new SparePartIssueJobDetailDTO(); + if (!string.IsNullOrEmpty(detail.TransferLibFromLocationCode)) { - 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>(entities); - - foreach (var itm in dtos) - { - var arys = jobs.Where(p => p.OrderNum == itm.Number); - var itmDetails = itm.Details.ToList(); - var details = new List(); - 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 SparePartIssueJobDetailDTO(); - 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 : string.Empty; - 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 : string.Empty; - 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任务完成"); - } + //库移的最终目标 挪到 推荐的目标 + var fromloc = await _locationAppService.GetByCodeAsync(detail.TransferLibToLocationCode).ConfigureAwait(false); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.TransferLibToLot; + detailDto.HandledToPackingCode = detail.TransferLibToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.TransferLibToLot; + detailDto.HandledFromPackingCode = detail.TransferLibToPackingCode; } else { - errors.Add("Agv确认单据里无数据! \n"); + var toloc = await _locationAppService.GetByCodeAsync(detail.RecommendToLocationCode).ConfigureAwait(false); + var fromloc = await _locationAppService.GetByCodeAsync(detail.RecommendFromLocationCode).ConfigureAwait(false); + + detailDto.InjectFrom(detail); + + detailDto.HandledToLocationCode = toloc.Code; + detailDto.HandledToLocationGroup = toloc.LocationGroupCode; + detailDto.HandledToLocationArea = toloc.AreaCode; + detailDto.HandledToLocationErpCode = toloc.ErpLocationCode; + detailDto.HandledToWarehouseCode = toloc.WarehouseCode; + detailDto.HandledToQty = request.Data.First().MatQty; + detailDto.HandledToLot = detail.RecommendToLot; + detailDto.HandledToPackingCode = detail.RecommendToPackingCode; + + detailDto.HandledFromLocationCode = fromloc.Code; + detailDto.HandledFromLocationGroup = fromloc.LocationGroupCode; + detailDto.HandledFromLocationArea = fromloc.AreaCode; + detailDto.HandledFromLocationErpCode = fromloc.ErpLocationCode; + detailDto.HandledFromWarehouseCode = fromloc.WarehouseCode; + detailDto.HandledFromQty = request.Data.First().MatQty;//2024-12-16 和励 张旭确认的 因为没有人工干预 也没校验 一托就直接顶走了 + detailDto.HandledFromLot = detail.RecommendToLot; + detailDto.HandledFromPackingCode = detail.RecommendToPackingCode; } - } - catch (Exception ex) - { - ret = new AgvResultObject - { - Code = "-1", - ReqCode = job.SparePartRequestNumber, - Message = ex.Message - }; - await unitOfWork.RollbackAsync().ConfigureAwait(false); - return ret; + + await ExecuteDetailExtAsync(entity.Id, entity.Details.First().Id, detailDto).ConfigureAwait(false); } - if (errors.Count > 0) + return new AgvResultObject { - ret = new AgvResultObject - { - Code = "-1", - Message = string.Join(",", errors.ToArray()), - ReqCode = job.SparePartRequestNumber - }; - } - return ret; + Code = "0", + Message = "OK", + ReqCode = "", + }; } + /// /// Agv 回库 接口 /// @@ -1061,7 +1049,7 @@ public class SparePartIssueJobAppService detailInput.ToStatus = fromlocation.DefaultInventoryStatus; detailInput.Qty = detail.MatQty; detailInput.FromLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; - detailInput.FromPackingCode =detail.PakingCode; + detailInput.FromPackingCode = detail.PakingCode; transfer.Details.Add(detailInput); @@ -1104,13 +1092,14 @@ public class SparePartIssueJobAppService } - /// /// 调用Agv接口实现 /// /// + /// + /// /// - private async Task SendInterFaceAsync(SparePartIssueJobDTO job) + private async Task SendInterFaceAsync(SparePartIssueJobDTO job, string beginPosition, string endPosition) { #if DEBUG @@ -1121,7 +1110,6 @@ public class SparePartIssueJobAppService ReqCode = job.SparePartRequestNumber, Message = "OK" }; - using var unitOfWork = _unitOfWorkManager.Begin(); try { @@ -1130,6 +1118,7 @@ public class SparePartIssueJobAppService { throw new UserFriendlyException($"任务{job.Number}为已完成状态,不能发起AGV任务!"); } + if (job.Details.Count == 0) { throw new UserFriendlyException($"任务{job.Number}没有推荐库存!"); @@ -1140,6 +1129,8 @@ public class SparePartIssueJobAppService request.MatQty = first.HandledToQty; request.OrderNum = job.Number; request.OrderType = EnumJobType.SparePartIssueJob.ToString(); + request.BeginPosition = beginPosition; + request.EndPosition = endPosition; var httpclient = _httpClientFactory.CreateClient(); _agvOptions.Value.Address = string.IsNullOrEmpty(_agvOptions.Value.Address) @@ -1186,6 +1177,5 @@ public class SparePartIssueJobAppService return ret; } - #endregion }