using System; using System.Collections.Generic; using System.Text.Json; using System.Threading; 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.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(); await DictBasicAppService.UpdateAsync(Dict).ConfigureAwait(false); } 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); //try //{ // Thread thread = new Thread(thead); // thread.Start(); // var BalanceAppService = workerContext.ServiceProvider.GetRequiredService(); // BalanceUpdateItemBasicInfoDto balan = new BalanceUpdateItemBasicInfoDto(); // List bala = new List(); // BalanceUpdateItemBasicInfo ba = new BalanceUpdateItemBasicInfo(); // ba.ItemCode = item.Code; // ba.ItemDesc1 = item.Desc1; // ba.ItemDesc2 = item.Desc2; // ba.ItemName = item.Name; // bala.Add(ba); // balan.BalanceUpdateItemBasicInfos = bala; // await BalanceAppService.UpdateItemBasicInfoAsync(balan).ConfigureAwait(false); //} //catch (Exception ex) //{ //} } public static void thead() { } 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(); var itemBasicAppService = workerContext.ServiceProvider.GetRequiredService(); await itemPackAppService.UpsertAsync(itemPack).ConfigureAwait(false); await itemBasicAppService.UpsertStdPackQtyAsync(itemPack.ItemCode, itemPack.Qty).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.CreateManyByNoCodeAsync(new List { inventoryLabel }).ConfigureAwait(false); } public static async Task HandleBackFlushsAsync(this IncomingToWms incomingConverted, PeriodicBackgroundWorkerContext workerContext) { var backFlush = JsonSerializer.Deserialize(incomingConverted.DataContent); var backFlushAppService = workerContext.ServiceProvider.GetRequiredService(); List back = new List(); back.Add(backFlush); await backFlushAppService.CreateManyAsync(back).ConfigureAwait(false); } }