using CMS.Plugin.HIAWms.Application.Contracts.Dtos.CommonDto; using CMS.Plugin.HIAWms.Application.Contracts.Dtos.OutStockDto; using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsInOutStockOrder; using CMS.Plugin.HIAWms.Application.Contracts.Services; using CMS.Plugin.HIAWms.Domain.Shared.Enums; using CMS.Plugin.HIAWms.Domain.WmsMaterials; using CMS.Plugin.HIAWms.Domain.WmsTask; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Uow; namespace CMS.Plugin.HIAWms.Application.Implements { /// /// LMES操作服务 /// public class LMesOperateAppService : CMSPluginAppService, ILMesOperateAppService { private readonly IWmsTaskRepository _wmsTaskRepository; private readonly IWmsMaterialRepository _wmsMaterialRepository; private readonly IWmsCommonAppService _wmsCommonAppService; private readonly IWmsInOutStockOrderAppService _wmsInOutStockOrderAppService; private readonly IWmsOutStockAppService _wmsOutStockOrderAppService; private readonly IServiceProvider _serviceProvider; public LMesOperateAppService(IWmsTaskRepository wmsTaskRepository, IWmsMaterialRepository wmsMaterialRepository, IWmsInOutStockOrderAppService wmsInOutStockOrderAppService, IWmsOutStockAppService wmsOutStockOrderAppService , IServiceProvider serviceProvider, IWmsCommonAppService wmsCommonAppService) { _wmsTaskRepository = wmsTaskRepository; _wmsMaterialRepository = wmsMaterialRepository; _wmsInOutStockOrderAppService = wmsInOutStockOrderAppService; _wmsOutStockOrderAppService = wmsOutStockOrderAppService; _serviceProvider = serviceProvider; _wmsCommonAppService = wmsCommonAppService; } /// /// lmes叫料. /// /// /// /// public async Task> LMesCallMaterialAsync(List input) { if (input == null || input.Count == 0) { throw new UserFriendlyException("叫料参数错误"); } using var scope = _serviceProvider.CreateScope(); var unitOfWorkManager = scope.ServiceProvider.GetRequiredService(); using var uow = unitOfWorkManager.Begin(requiresNew: true); var result = new List(); foreach (var item in input) { if (string.IsNullOrEmpty(item.MaterialMode)) { throw new UserFriendlyException("叫料型号不能为空"); } var task = await _wmsTaskRepository.QueryWmsTaskByDataIdentifierAasync(item.DataIdentifier); if (task != null) { throw new UserFriendlyException($"原料标识{item.DataIdentifier}已生成任务,任务号{task.TaskNo},无需重复操作"); } // 生成出库单 var materiaL = await _wmsMaterialRepository.FindByModelAsync(item.MaterialMode); if (materiaL == null) { throw new UserFriendlyException("该型号物料信息不存在"); } var createOrderInput = new WmsInOutStockOrderCreateDto { OrderType = Domain.Shared.Enums.OrderTypeEnum.PRODUCTCALL, MaterialNo = materiaL.MaterialNo, MaterialName = materiaL.MaterialName, MaterialModel = item.MaterialMode, MaterialNumber = 1, MaterialBatch = item.MaterialMode, OrderStatus = Domain.Shared.Enums.OrderStatusEnum.Executing, OperateTime = DateTime.Now, DistributeNumber = 1, }; var createResult = await _wmsInOutStockOrderAppService.CreateAsync(createOrderInput); // 叫料 var callInput = new List { new CallMaterialInput { OrderNo = createResult.OrderNo, MaterialModel = item.MaterialMode, MaterialNumber = 1, MaterialNo = materiaL.MaterialNo, MaterialName = materiaL.MaterialName, DataIdentifier = item.DataIdentifier, IgnoreOrder = true, OrderType = createResult.OrderType, Priority = createResult.Priority }, }; var callresult = await _wmsOutStockOrderAppService.CallMaterialAsync(callInput); result.AddRange(callresult); } await uow.SaveChangesAsync(); return result; } /// /// LMes出库 /// /// public async Task LMesOutStockAsync(ReduceInput input) { if (input == null) { throw new UserFriendlyException("出库参数错误"); } using var scope = _serviceProvider.CreateScope(); var unitOfWorkManager = scope.ServiceProvider.GetRequiredService(); using var uow = unitOfWorkManager.Begin(requiresNew: true); if (string.IsNullOrEmpty(input.MaterialMode)) { throw new UserFriendlyException("出库型号不能为空"); } var reduceInput = new ReduceStockInput { MaterialModel = input.MaterialMode, StockNumber = input.Quantity, PlaceNo = input.PlaceNo, }; await _wmsCommonAppService.ReduceMaterialStockAsync(reduceInput); await uow.SaveChangesAsync(); } } }