using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.BackgroundWorkers; using Win_in.Sfs.Auth.Application.Contracts; using Win_in.Sfs.Auth.Users; using Win_in.Sfs.Auth.Users.Inputs; using Win_in.Sfs.Basedata.Application.Contracts; using Win_in.Sfs.Label.Application.Contracts; using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Wms.DataExchange.Domain; using Win_in.Sfs.Wms.Inventory.Application.Contracts; using Win_in.Sfs.Wms.Store.Application.Contracts; namespace Win_in.Sfs.Wms.DataExchange.Agent; public static class IncomingToWmsExtensions { public static async Task HandlePurchaseOrdersAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var purchaseOrder = JsonSerializer.Deserialize(incomingConverted.DataContent); var purchaseOrderAppService = workerContext.ServiceProvider.GetRequiredService(); await purchaseOrderAppService.CreateAsync(purchaseOrder).ConfigureAwait(false); } public static async Task HandleAsnsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var supplierAsn = JsonSerializer.Deserialize(incomingConverted.DataContent); var supplierAsnAppService = workerContext.ServiceProvider.GetRequiredService(); await supplierAsnAppService.CreateAsync(supplierAsn).ConfigureAwait(false); } public static async Task HandleDictsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var Dict = JsonSerializer.Deserialize(incomingConverted.DataContent); var DictBasicAppService = workerContext.ServiceProvider.GetRequiredService(); try { await DictBasicAppService.UpdateAsync(Dict).ConfigureAwait(false); } catch (System.Exception ex) { throw; } } public static async Task HandleUsersAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var user = JsonSerializer.Deserialize(incomingConverted.DataContent); var userBasicAppService = workerContext.ServiceProvider.GetRequiredService(); await userBasicAppService.UpdateByNmaeAsync(user).ConfigureAwait(false); } public static async Task HandleDepartmentsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var Department = JsonSerializer.Deserialize(incomingConverted.DataContent); var DepartmentBasicAppService = workerContext.ServiceProvider.GetRequiredService(); await DepartmentBasicAppService.UpdateAsync(Department).ConfigureAwait(false); } public static async Task HandleItemsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var item = JsonSerializer.Deserialize(incomingConverted.DataContent); var itemBasicAppService = workerContext.ServiceProvider.GetRequiredService(); await itemBasicAppService.UpsertAsyncByInterface(item).ConfigureAwait(false); } public static async Task HandleErpLocationsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var erpLocation = JsonSerializer.Deserialize(incomingConverted.DataContent); var erpLocationAppService = workerContext.ServiceProvider.GetRequiredService(); await erpLocationAppService.UpsertAsync(erpLocation).ConfigureAwait(false); } public static async Task HandleBomsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var bom = JsonSerializer.Deserialize(incomingConverted.DataContent); var bomAppService = workerContext.ServiceProvider.GetRequiredService(); await bomAppService.UpsertAsyncByInterface(bom).ConfigureAwait(false); } public static async Task HandleSuppliersAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var supplier = JsonSerializer.Deserialize(incomingConverted.DataContent); var supplierAppService = workerContext.ServiceProvider.GetRequiredService(); await supplierAppService.UpsertAsyncByInterface(supplier).ConfigureAwait(false); } public static async Task HandleSupplierItemsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var supplierItem = JsonSerializer.Deserialize(incomingConverted.DataContent); var supplierItemAppService = workerContext.ServiceProvider.GetRequiredService(); await supplierItemAppService.UpsertAsync(supplierItem).ConfigureAwait(false); } public static async Task HandleItemPacksAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var itemPack = JsonSerializer.Deserialize(incomingConverted.DataContent); var itemPackAppService = workerContext.ServiceProvider.GetRequiredService(); await itemPackAppService.UpsertAsync(itemPack).ConfigureAwait(false); } public static async Task HandleCustomersAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var customer = JsonSerializer.Deserialize(incomingConverted.DataContent); var customerAppService = workerContext.ServiceProvider.GetRequiredService(); await customerAppService.UpsertAsyncByInterface(customer).ConfigureAwait(false); } public static async Task HandleCustomerItemsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var customerItem = JsonSerializer.Deserialize(incomingConverted.DataContent); var customerItemAppService = workerContext.ServiceProvider.GetRequiredService(); await customerItemAppService.UpsertAsync(customerItem).ConfigureAwait(false); } public static async Task HandleInterfaceCalendarsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var interfaceCalendar = JsonSerializer.Deserialize(incomingConverted.DataContent); var interfaceCalendarAppService = workerContext.ServiceProvider.GetRequiredService(); await interfaceCalendarAppService.UpsertAsync(interfaceCalendar).ConfigureAwait(false); } public static async Task HandleSaleOrdersAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var saleOrder = JsonSerializer.Deserialize(incomingConverted.DataContent); var saleOrderAppService = workerContext.ServiceProvider.GetRequiredService(); await saleOrderAppService.UpsertAsync(saleOrder).ConfigureAwait(false); } public static async Task HandleProductReceiptsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var productReceipt = JsonSerializer.Deserialize(incomingConverted.DataContent); var productReceiptAppService = workerContext.ServiceProvider.GetRequiredService(); await productReceiptAppService.CreateAsync(productReceipt).ConfigureAwait(false); } public static async Task HandleMaterialRequestsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var materialRequest = JsonSerializer.Deserialize(incomingConverted.DataContent); var materialRequestAppService = workerContext.ServiceProvider.GetRequiredService(); await materialRequestAppService.CreateAndHandleByAPIAsync(materialRequest).ConfigureAwait(false); } public static async Task HandleScrapsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var scrap = JsonSerializer.Deserialize(incomingConverted.DataContent); var scrapAppService = workerContext.ServiceProvider.GetRequiredService(); await scrapAppService.CreateAsync(scrap).ConfigureAwait(false); } public static async Task HandleIssueNoteConfirmAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var number = incomingConverted.DataIdentityCode; var issueNoteAppService = workerContext.ServiceProvider.GetRequiredService(); await issueNoteAppService.ConfirmAsync(number).ConfigureAwait(false); } public static async Task HandleInventoryLabelsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var inventoryLabel = JsonSerializer.Deserialize(incomingConverted.DataContent); var inventoryLabelAppService = workerContext.ServiceProvider.GetRequiredService(); await inventoryLabelAppService.CreateAsync(inventoryLabel).ConfigureAwait(false); } public static async Task HandleBackFlushsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var backFlush = JsonSerializer.Deserialize(incomingConverted.DataContent); var balanceAppService = workerContext.ServiceProvider.GetRequiredService(); var balanceDtos = await balanceAppService.GetRecommendBalancesAsync(new RecommendBalanceRequestInput() { Qty = backFlush.Qty, ItemCode = backFlush.ItemCode, LocationAreas = new List() { backFlush.LocationArea }, LocationTypes = new List() { EnumLocationType.WIP, }, Statuses = new List() { EnumInventoryStatus.OK, } }).ConfigureAwait(false); foreach (var balanceDto in balanceDtos) { backFlush.Details.Add(new BackFlushNoteDetailInput() { Qty = balanceDto.Qty, ItemCode = balanceDto.ItemCode, ArriveDate = balanceDto.ArriveDate, BomVersion = string.Empty, ContainerCode = string.Empty, ExpireDate = balanceDto.ExpireDate, Lot = balanceDto.Lot, LocationCode = balanceDto.LocationCode, LocationErpCode = balanceDto.LocationErpCode, LocationArea = balanceDto.LocationArea, LocationGroup = balanceDto.LocationGroup }); } var backFlushAppService = workerContext.ServiceProvider.GetRequiredService(); // await backFlushAppService.CreateAsync(backFlush); } }