From 28cdb9e9b13079a1ee3d62accc3df87764c21d94 Mon Sep 17 00:00:00 2001 From: tongfei <244188119@qq.com> Date: Tue, 12 Mar 2024 10:53:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/InStockTaskController.cs | 5 +- src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml | 10 +- .../Services/BoxInventoryService.cs | 4 +- .../Services/InStockTaskService.cs | 283 ++++++++++++++---- 4 files changed, 243 insertions(+), 59 deletions(-) diff --git a/src/WMS.Web.Api/Controllers/InStockTaskController.cs b/src/WMS.Web.Api/Controllers/InStockTaskController.cs index fefc5eb8..3bae980f 100644 --- a/src/WMS.Web.Api/Controllers/InStockTaskController.cs +++ b/src/WMS.Web.Api/Controllers/InStockTaskController.cs @@ -134,7 +134,10 @@ namespace WMS.Web.Api.Controllers var sourcesBillNos = tasks.Select(x => x.SourceBillNo).ToList(); //2.同步金蝶 - return await _inStockTaskService.Sysn(sourcesBillNos); + await _inStockTaskService.Sysn(sourcesBillNos); + + //再刷新3天内所有的 + return await _inStockTaskService.Sysn(null); } /// diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 533c1b85..f19c666e 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -4531,7 +4531,15 @@ - ERP数据同步到WMS数据库 + ERP数据同步到WMS数据库-旧代码 + + + + + + + + ERP数据同步到WMS数据库-新代码 diff --git a/src/WMS.Web.Domain/Services/BoxInventoryService.cs b/src/WMS.Web.Domain/Services/BoxInventoryService.cs index 984a683b..6dd19d01 100644 --- a/src/WMS.Web.Domain/Services/BoxInventoryService.cs +++ b/src/WMS.Web.Domain/Services/BoxInventoryService.cs @@ -1140,8 +1140,8 @@ namespace WMS.Web.Domain.Services var isAllNoInventory = update_entity.Details.All(x => x.Qty == 0); if (isAllNoInventory) { - //给改箱服务用:按箱的话,就要把明细里的数量修改为0 - changeBox_inventoryList.Add(GenerateBoxInventory(update_entity.Clone())); + //给改箱服务用:按箱的话,就要把明细里的数量修改为0;备注:当数量为0后就不要改箱了 + //changeBox_inventoryList.Add(GenerateBoxInventory(update_entity.Clone())); delete_ids.Add(update_entity.Id); } diff --git a/src/WMS.Web.Domain/Services/InStockTaskService.cs b/src/WMS.Web.Domain/Services/InStockTaskService.cs index ce74d7fb..df4d0f74 100644 --- a/src/WMS.Web.Domain/Services/InStockTaskService.cs +++ b/src/WMS.Web.Domain/Services/InStockTaskService.cs @@ -98,7 +98,7 @@ namespace WMS.Web.Domain.Services return Result.ReFailure(ResultCodes.AdjustError); return Result.ReSuccess(); - } + } /// /// 同步:采购入库类型单据 @@ -114,7 +114,7 @@ namespace WMS.Web.Domain.Services return Result.ReFailure(erp_result.Message, erp_result.Status); var erp_list = erp_result.Data; - return await this.SysnData(erp_list.ToList(), isTransaction); + return await this.SysnDataNew(erp_list.ToList(), isTransaction); } /// @@ -123,7 +123,7 @@ namespace WMS.Web.Domain.Services /// /// /// - public async Task SysnMiscellaneous(List billNos = null, bool isTransaction = true) + public async Task SysnMiscellaneous(List billNos = null, bool isTransaction = true) { //1.获取金蝶数据:其他入库订单数据 var erp_result = await _erpService.BillQueryForMiscellaneous(billNos); @@ -131,7 +131,7 @@ namespace WMS.Web.Domain.Services return Result.ReFailure(erp_result.Message, erp_result.Status); var erp_list = erp_result.Data; - return await this.SysnData(erp_list.ToList(), isTransaction); + return await this.SysnDataNew(erp_list.ToList(), isTransaction); } /// @@ -140,7 +140,7 @@ namespace WMS.Web.Domain.Services /// /// /// - public async Task SysnTransferDirect(List billNos = null, bool isTransaction = true) + public async Task SysnTransferDirect(List billNos = null, bool isTransaction = true) { //1.获取金蝶数据:直接调拨入库订单数据 var erp_result = await _erpService.BillQueryForTransferDirect(billNos); @@ -148,7 +148,7 @@ namespace WMS.Web.Domain.Services return Result.ReFailure(erp_result.Message, erp_result.Status); var erp_list = erp_result.Data; - return await this.SysnData(erp_list.ToList(), isTransaction); + return await this.SysnDataNew(erp_list.ToList(), isTransaction); } /// @@ -157,14 +157,14 @@ namespace WMS.Web.Domain.Services /// /// /// - public async Task SysnTransferin(List billNos = null, bool isTransaction = true) + public async Task SysnTransferin(List billNos = null, bool isTransaction = true) { //1.获取金蝶数据:分步式入库订单数据 var erp_result = await _erpService.BillQueryForTransferin(billNos); if (!erp_result.IsSuccess) return Result.ReFailure(erp_result.Message, erp_result.Status); var erp_list = erp_result.Data; - return await this.SysnData(erp_list.ToList(), isTransaction); + return await this.SysnDataNew(erp_list.ToList(), isTransaction); } /// @@ -173,9 +173,9 @@ namespace WMS.Web.Domain.Services /// /// /// - public async Task SysnAssembledApp(List billNos = null, bool isTransaction = true) + public async Task SysnAssembledApp(List billNos = null, bool isTransaction = true) { - var erp_list = new List(); + var erp_list = new List(); //1.获取金蝶数据:组装成品入库订单数据 var erp_result_ass = await _erpService.BillQueryForAssembledApp_Assembly(billNos); @@ -190,7 +190,7 @@ namespace WMS.Web.Domain.Services var erp_list_disass = erp_result_disass.Data; erp_list.AddRange(erp_list_disass); - return await this.SysnData(erp_list, isTransaction); + return await this.SysnDataNew(erp_list, isTransaction); } /// @@ -198,7 +198,7 @@ namespace WMS.Web.Domain.Services /// /// /// - public async Task Sysn(List billNos = null) + public async Task Sysn(List billNos = null) { //1.事务 IDbContextTransaction _transaction = _basicsRepositories.GetTransaction(); @@ -223,43 +223,104 @@ namespace WMS.Web.Domain.Services /// /// /// - public async Task InStock(List billNos,bool isTransaction) + public async Task InStock(List billNos, bool isTransaction) { - //1.同步数据:采购订单 - var purchase_result = await this.SsynPurchaseInStock(billNos, isTransaction); - if (!purchase_result.IsSuccess) - return Result.ReFailure(purchase_result.Message, purchase_result.Status); + if (billNos == null || billNos.Count == 0) + { + //1.同步数据:采购订单 + var purchase_result = await this.SsynPurchaseInStock(null, isTransaction); + if (!purchase_result.IsSuccess) + return Result.ReFailure(purchase_result.Message, purchase_result.Status); - //2.同步数据:其他入库单 - var miscellaneou_result = await this.SysnMiscellaneous(billNos, isTransaction); - if (!miscellaneou_result.IsSuccess) - return Result.ReFailure(miscellaneou_result.Message, miscellaneou_result.Status); + //2.同步数据:其他入库单 + var miscellaneou_result = await this.SysnMiscellaneous(null, isTransaction); + if (!miscellaneou_result.IsSuccess) + return Result.ReFailure(miscellaneou_result.Message, miscellaneou_result.Status); - //3.同步数据:直接调拨入库单 - var TransferDirect_result = await this.SysnTransferDirect(billNos, isTransaction); - if (!TransferDirect_result.IsSuccess) - return Result.ReFailure(TransferDirect_result.Message, TransferDirect_result.Status); + //3.同步数据:直接调拨入库单 + var TransferDirect_result = await this.SysnTransferDirect(null, isTransaction); + if (!TransferDirect_result.IsSuccess) + return Result.ReFailure(TransferDirect_result.Message, TransferDirect_result.Status); - //4.同步数据:分步式入库单 - var Transferin_result = await this.SysnTransferin(billNos, isTransaction); - if (!Transferin_result.IsSuccess) - return Result.ReFailure(Transferin_result.Message, Transferin_result.Status); + //4.同步数据:分步式入库单 + var Transferin_result = await this.SysnTransferin(null, isTransaction); + if (!Transferin_result.IsSuccess) + return Result.ReFailure(Transferin_result.Message, Transferin_result.Status); - //5.同步数据:组装拆卸单 - var AssembledApp_result = await this.SysnAssembledApp(billNos, isTransaction); - if (!AssembledApp_result.IsSuccess) - return Result.ReFailure(AssembledApp_result.Message, AssembledApp_result.Status); + //5.同步数据:组装拆卸单 + var AssembledApp_result = await this.SysnAssembledApp(null, isTransaction); + if (!AssembledApp_result.IsSuccess) + return Result.ReFailure(AssembledApp_result.Message, AssembledApp_result.Status); + } + else + { + List Instock_sourceBillNos = new List(); + List Miscellaneous_sourceBillNos = new List(); + List TransferDirect_sourceBillNos = new List(); + List Transferin_sourceBillNos = new List(); + List AssembledApp_sourceBillNos = new List(); + var taskList = await _inStockTaskRepositories.GetListBy(billNos); + foreach (var entity in taskList) + { + if (entity.Type == InstockType.Purchase) + Instock_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.Stkdirecttransfers) + TransferDirect_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.StktransferInst) + Transferin_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.Assembled) + AssembledApp_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.Miscellaneous) + Miscellaneous_sourceBillNos.Add(entity.SourceBillNo); + } + + if (Instock_sourceBillNos.Count() > 0) + { + //1.同步数据:采购订单 + var purchase_result = await this.SsynPurchaseInStock(Instock_sourceBillNos, isTransaction); + if (!purchase_result.IsSuccess) + return Result.ReFailure(purchase_result.Message, purchase_result.Status); + } + if (Miscellaneous_sourceBillNos.Count() > 0) + { + //2.同步数据:其他入库单 + var miscellaneou_result = await this.SysnMiscellaneous(Miscellaneous_sourceBillNos, isTransaction); + if (!miscellaneou_result.IsSuccess) + return Result.ReFailure(miscellaneou_result.Message, miscellaneou_result.Status); + } + if (TransferDirect_sourceBillNos.Count() > 0) + { + //3.同步数据:直接调拨入库单 + var TransferDirect_result = await this.SysnTransferDirect(TransferDirect_sourceBillNos, isTransaction); + if (!TransferDirect_result.IsSuccess) + return Result.ReFailure(TransferDirect_result.Message, TransferDirect_result.Status); + } + if (Transferin_sourceBillNos.Count() > 0) + { + //4.同步数据:分步式入库单 + var Transferin_result = await this.SysnTransferin(Transferin_sourceBillNos, isTransaction); + if (!Transferin_result.IsSuccess) + return Result.ReFailure(Transferin_result.Message, Transferin_result.Status); + } + if (AssembledApp_sourceBillNos.Count() > 0) + { + //5.同步数据:组装拆卸单 + var AssembledApp_result = await this.SysnAssembledApp(AssembledApp_sourceBillNos, isTransaction); + if (!AssembledApp_result.IsSuccess) + return Result.ReFailure(AssembledApp_result.Message, AssembledApp_result.Status); + } + } return Result.ReSuccess(); } /// - /// ERP数据同步到WMS数据库 + /// ERP数据同步到WMS数据库-旧代码 /// /// /// /// - public async Task SysnData(List erp_list, bool isTransaction) + public async Task SysnData(List erp_list, bool isTransaction) { var type = (InstockType)erp_list.GroupBy(x => x.Type).Select(x => x.Key).FirstOrDefault(); var totalCount = erp_list.Count; @@ -271,14 +332,14 @@ namespace WMS.Web.Domain.Services var data_list = await _inStockTaskRepositories.GetListBy(SourceBillNo_list); if (data_list.Count != 0) { - data_list.ForEach(x => + data_list.ForEach(x => { - var erp_list_dets= erp_list.Where(t => t.BillNo == x.SourceBillNo).ToList(); - if (erp_list_dets != null && erp_list_dets.Count != 0 && erp_list_dets.Count > x.Details.Count) + var erp_list_dets = erp_list.Where(t => t.BillNo == x.SourceBillNo).ToList(); + if (erp_list_dets != null && erp_list_dets.Count != 0 && erp_list_dets.Count > x.Details.Count) { - var xd_detids=x.Details.Select(xd => xd.ErpDetailId).ToList(); - var task_no_materials= erp_list_dets.Where(ed => !xd_detids.Contains(ed.ErpDetailId)).ToList(); - var Add_task_no_materials= _mapper.Map>(task_no_materials); + var xd_detids = x.Details.Select(xd => xd.ErpDetailId).ToList(); + var task_no_materials = erp_list_dets.Where(ed => !xd_detids.Contains(ed.ErpDetailId)).ToList(); + var Add_task_no_materials = _mapper.Map>(task_no_materials); x.Details.AddRange(Add_task_no_materials); } }); @@ -292,18 +353,18 @@ namespace WMS.Web.Domain.Services continue; //2.1.1对比erp的物料信息 - var erp_data = erp_list.Where(x =>x.ErpDetailId==item.ErpDetailId).FirstOrDefault(); + var erp_data = erp_list.Where(x => x.ErpDetailId == item.ErpDetailId).FirstOrDefault(); if (erp_data != null) { //2.1.2修改数量 - if (erp_data.Qty > item.AccruedQty && (erp_data.Qty>item.RealityQty && item.RealityQty!=0)) + if (erp_data.Qty > item.AccruedQty && (erp_data.Qty > item.RealityQty && item.RealityQty != 0)) data.Status = InstockStatus.Part; - else if(erp_data.Qty<=item.AccruedQty && erp_data.Qty<=item.RealityQty) + else if (erp_data.Qty <= item.AccruedQty && erp_data.Qty <= item.RealityQty) data.Status = InstockStatus.Already; item.Remark = erp_data.Remark; item.AccruedQty = erp_data.Qty; item.FactoryPrice = erp_data.FactoryPrice; - item.DeliveredQty = erp_data.DeliveredQty; + item.DeliveredQty = erp_data.DeliveredQty; //打印日志:需要的修改条数 totalUpdateCount++; erp_remove_billNo.Add(data.SourceBillNo); @@ -324,7 +385,7 @@ namespace WMS.Web.Domain.Services x.AccruedQty = 0; } } - else if(erp_data==null) + else if (erp_data == null) { x.AccruedQty = 0; } @@ -336,9 +397,9 @@ namespace WMS.Web.Domain.Services if (local_data_order != null) { var local_data = data_list_details_new.Where(t => t.ErpDetailId == item.ErpDetailId).ToList(); - if (local_data != null && local_data.Count!=0) + if (local_data != null && local_data.Count != 0) { - var isHaveMater_detail= local_data.Where(t => t.MaterialId == item.MaterialId).Any(); + var isHaveMater_detail = local_data.Where(t => t.MaterialId == item.MaterialId).Any(); if (!isHaveMater_detail) { //明细的物料改变了:新的物料重新添加一条明细 @@ -362,15 +423,15 @@ namespace WMS.Web.Domain.Services if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError); - + //要剔除的来源单据编号:去重 - erp_remove_billNo= erp_remove_billNo.GroupBy(x => x).Select(x => x.Key).ToList(); + erp_remove_billNo = erp_remove_billNo.GroupBy(x => x).Select(x => x.Key).ToList(); //2.3剔除:已修改的单据 foreach (var item in erp_remove_billNo) { erp_list.RemoveAll(x => x.BillNo == item); } - + } //打印日志 @@ -383,10 +444,10 @@ namespace WMS.Web.Domain.Services { var add_entitys = new List(); var current_billNos = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList(); - + foreach (var item in current_billNos) { - var current_order= erp_list.Where(x => x.BillNo == item).FirstOrDefault(); + var current_order = erp_list.Where(x => x.BillNo == item).FirstOrDefault(); var dto = new InStockTask(); dto.Create((InstockType)current_order.Type, current_order.BillNo, current_order.CreateTime); @@ -405,6 +466,118 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } + /// + /// ERP数据同步到WMS数据库-新代码 + /// + /// + /// + /// + public async Task SysnDataNew(List erp_list, bool isTransaction) + { + + //1.通过单据编号找到wms系统现有的任务单;并修改 + var erp_removeList = new List(); + var SourceBillNo_list = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList(); + var data_list = await _inStockTaskRepositories.GetListBy(SourceBillNo_list); + + //要新增的明细 + var erp_addDetailsList = new List(); + //2.遍历已有的任务单 + if (data_list.Count != 0) + { + //2.1遍历任务单明细:改变已有的值和要添加的明细 + data_list.SelectMany(s => s.Details).ToList().ForEach(det => + { + //2.1去当前erp的明细 + var erp_data = erp_list.Where(x => x.ErpDetailId == det.ErpDetailId).FirstOrDefault(); + if (erp_data != null) + { + //2.1.1当物料相同,仓库不同或者物料不同,就新增一条明细 + //2.1.2物料相同的,就改变数值 + if (det.MaterialId != erp_data.MaterialId || (det.MaterialId == erp_data.MaterialId && det.StockCode != erp_data.StockCode)) + { + //老物料,应收数量修改为0 + det.AccruedQty = 0; + //当物料相同,仓库不同或者物料不同,就新增一条明细 + erp_addDetailsList.Add(erp_data); + } + else if (det.MaterialId == erp_data.MaterialId) + { + //物料相同的,就改变数值 + det.Remark = erp_data.Remark; + det.AccruedQty = erp_data.Qty; + det.FactoryPrice = erp_data.FactoryPrice; + det.DeliveredQty = erp_data.DeliveredQty; + } + //操作完后剔除 + erp_removeList.Add(erp_data); + } + }); + + //2.2遍历任务单:添加新的明细 + data_list.ForEach(order => + { + //2.1.任务单添加明细 + var addErpDetails= erp_addDetailsList.Where(x => x.BillNo == order.SourceBillNo).ToList(); + if (addErpDetails.Count != 0) + { + var addDetails = _mapper.Map>(addErpDetails); + order.Details.AddRange(addDetails); + } + }); + + //2.3遍历任务单:改变任务单的状态 + data_list.ForEach(order => + { + //当应入库数量大于实际入库数量:状态就部分入库 + //当应入库数量小于等于实际入库数量:状态就已入库 + var AccruedQtyTotal = order.Details.Sum(x => x.AccruedQty); + var RealityQtyTotal = order.Details.Sum(x => x.RealityQty); + if(AccruedQtyTotal> RealityQtyTotal) + order.Status = InstockStatus.Part; + else if(AccruedQtyTotal<= RealityQtyTotal) + order.Status = InstockStatus.Already; + }); + } + + //2.3.提交任务单的修改 + var isSuccess = await _inStockTaskRepositories.UpdateRange(data_list, isTransaction); + if (!isSuccess) + return Result.ReFailure(ResultCodes.DateWriteError); + + //2.4剔除:已修改的单据 + foreach (var item in erp_removeList) + erp_list.Remove(item); + + //3.wms任务单的来源单据编号不存在于erp中,那么就新增 + if (erp_list.Count != 0) + { + var add_entitys = new List(); + var current_billNos = erp_list.GroupBy(x => x.BillNo).Select(x => x.Key).ToList(); + + foreach (var item in current_billNos) + { + var current_order = erp_list.Where(x => x.BillNo == item).FirstOrDefault(); + var dto = new InStockTask(); + dto.Create((InstockType)current_order.Type, current_order.BillNo, current_order.CreateTime); + + //找到当前对应来源单据编号的集合数据 + var current_erp_details = erp_list.Where(x => x.BillNo == item).ToList(); + //给到dto的实体明细中 + dto.Details = _mapper.Map>(current_erp_details); + add_entitys.Add(dto); + } + //3.1提交新增 + isSuccess = await _inStockTaskRepositories.AddRange(add_entitys, isTransaction); + if (!isSuccess) + return Result.ReFailure(ResultCodes.DateWriteError); + } + + return Result.ReSuccess(); + + } + + /// /// 作废 /// @@ -432,9 +605,9 @@ namespace WMS.Web.Domain.Services /// /// /// - public void LogInfomation(InstockType type, int totalCount,int updateCount,int addCount) + public void LogInfomation(InstockType type, int totalCount, int updateCount, int addCount) { - _logger.LogInformation($"《{type.GetRemark()}总条数:" + totalCount+",修改条数:"+updateCount+",新增条数:"+addCount+"》"); + _logger.LogInformation($"《{type.GetRemark()}总条数:" + totalCount + ",修改条数:" + updateCount + ",新增条数:" + addCount + "》"); } } }