| | |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsInOutStockRecord; |
| | | using Volo.Abp.Uow; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using NPOI.SS.Formula.Functions; |
| | | using System.Collections.Generic; |
| | | |
| | | namespace CMS.Plugin.HIAWms.Application.Implements; |
| | | |
| | |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="UserFriendlyException"></exception> |
| | | public async Task FinishTaskAsync(WmsTaskStatusDto input) |
| | | public async Task<WmsTaskDto> FinishTaskAsync(WmsTaskStatusDto input) |
| | | { |
| | | if (string.IsNullOrEmpty(input.TaskNo)) |
| | | { |
| | | throw new UserFriendlyException("任务号不能为空"); |
| | | } |
| | | using var scope = _serviceProvider.CreateScope(); |
| | | var unitOfWorkManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>(); |
| | | using var uow = unitOfWorkManager.Begin(requiresNew: true); |
| | |
| | | |
| | | await uow.SaveChangesAsync(); |
| | | await uow.CompleteAsync(); |
| | | |
| | | return ObjectMapper.Map<WmsTask, WmsTaskDto>(task); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <exception cref="UserFriendlyException"></exception> |
| | | public async Task CancelTaskAysnc(WmsTaskStatusDto input) |
| | | { |
| | | |
| | | if (string.IsNullOrEmpty(input.TaskNo)) |
| | | { |
| | | throw new UserFriendlyException("任务号不能为空"); |
| | | } |
| | | using var scope = _serviceProvider.CreateScope(); |
| | | var unitOfWorkManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>(); |
| | | using var uow = unitOfWorkManager.Begin(requiresNew: true); |
| | |
| | | /// <exception cref="UserFriendlyException"></exception> |
| | | public async Task ChangeTaskToPlaceAsync(ChangeTaskToPlaceInput input) |
| | | { |
| | | var task = await wmsTaskRepository.FindByNameAsync(input.TaskNo); |
| | | |
| | | if (string.IsNullOrEmpty(input.TaskNo)) |
| | | { |
| | | throw new UserFriendlyException("任务号不能为空"); |
| | | } |
| | | |
| | | var task = await wmsTaskRepository.FindByNameAsync(input.TaskNo); |
| | | if (task == null) |
| | | { |
| | | throw new UserFriendlyException("任务信息不存在"); |
| | |
| | | throw new UserFriendlyException("目标库位信息不存在"); |
| | | } |
| | | |
| | | if(toPlaceInfo.IsDisabled) |
| | | if (toPlaceInfo.IsDisabled) |
| | | { |
| | | throw new UserFriendlyException("目标库位已被禁用"); |
| | | } |
| | | |
| | | var toplaceStock = await _wmsMaterialStockRepository.GetStockListAsync(new WmsMaterialStock { PlaceNo = input.ToPlace }); |
| | | if (toplaceStock != null && toplaceStock.Count>0) |
| | | if (toplaceStock != null && toplaceStock.Count > 0) |
| | | { |
| | | var model = toplaceStock.FirstOrDefault(); |
| | | if (model.MaterialModel != input.MutableParam1) |
| | |
| | | |
| | | await wmsTaskRepository.UpdateAsync(task); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取需要执行的任务 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<WmsTaskDto> GetToExecuteTaskAsync(QueryTaskTypeInput input) |
| | | { |
| | | var queryInput = new GetWmsTaskInput |
| | | { |
| | | TaskStatus = WmsTaskStatus.WEIZHIXING, |
| | | }; |
| | | var whereConditions = DynamicGetQueryParams(queryInput); |
| | | |
| | | var NoStartTaskList = await wmsTaskRepository.GetTaskListAsync(whereConditions); |
| | | |
| | | |
| | | if (NoStartTaskList.Count <= 0) return null; |
| | | |
| | | var executeTaskList = NoStartTaskList.WhereIf(input.TaskType > 0, x => x.TaskType == input.TaskType).OrderBy(x => x.TaskType).ThenBy(x => x.TaskLevel).ToList(); |
| | | |
| | | var executeTask = executeTaskList.FirstOrDefault(); |
| | | if (input.OutStockHasGood) |
| | | { |
| | | executeTask = NoStartTaskList.OrderByDescending(x => x.TaskType == TaskTypeEnum.RUKU).ThenBy(x => x.TaskLevel).FirstOrDefault(); |
| | | } |
| | | |
| | | if (executeTask == null) |
| | | { |
| | | return ObjectMapper.Map<WmsTask, WmsTaskDto>(NoStartTaskList.FirstOrDefault()); |
| | | } |
| | | |
| | | if (executeTask.TaskType == TaskTypeEnum.CHUKU && input.OutStockHasGood) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | if(executeTask.TaskType == TaskTypeEnum.RUKU && !input.InStockHasGood) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return ObjectMapper.Map<WmsTask, WmsTaskDto>(executeTask); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 更新任务为执行中 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<WmsTaskDto> StartExecuteTaskAsync(ExcecuteTaskInput input) |
| | | { |
| | | if (string.IsNullOrEmpty(input.TaskNo)) |
| | | { |
| | | throw new UserFriendlyException("任务号不能为空"); |
| | | } |
| | | var task = await wmsTaskRepository.FindByNameAsync(input.TaskNo); |
| | | if(task == null) |
| | | { |
| | | return null; |
| | | } |
| | | task.TaskStatus = WmsTaskStatus.ZHIXINGZHONG; |
| | | task.TaskDodeviceStatus = TaskDodeviceStatus.SrmProgress; |
| | | await wmsTaskRepository.UpdateAsync(task); |
| | | return ObjectMapper.Map<WmsTask, WmsTaskDto>(task); |
| | | } |
| | | } |