diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 0abb9ef3..aa94f5e9 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -771,7 +771,7 @@ 生成单据号 - + 同步金蝶(成功) @@ -779,7 +779,7 @@ - + 同步金蝶(失败) @@ -935,6 +935,11 @@ 箱唛编号-末尾序号 + + + erp入库单的明细ID + + 生成批号 diff --git a/src/WMS.Web.Domain/Entitys/InStock.cs b/src/WMS.Web.Domain/Entitys/InStock.cs index 7ae7f374..90b920d5 100644 --- a/src/WMS.Web.Domain/Entitys/InStock.cs +++ b/src/WMS.Web.Domain/Entitys/InStock.cs @@ -149,13 +149,15 @@ namespace WMS.Web.Domain.Entitys /// /// /// - public void SyncSuccess(int erpDetailId, int operateId, string erpBillNo) + public void SyncSuccess(int erpDetailId, int operateId, string erpBillNo,string erpInStockDetailId) { var erpd = this.ErpDetails.Where(s=>s.ErpDetailId==erpDetailId).ToList(); erpd.ForEach(det => { det.SuccessSync = SyncStatus.Success; det.ErpSyncBillNo = erpBillNo; + if (!string.IsNullOrEmpty(erpInStockDetailId)) + det.ErpInStockDetailId = Convert.ToInt32(erpInStockDetailId); }); //所有erp明细同步成功才是整个单据成功 @@ -177,12 +179,14 @@ namespace WMS.Web.Domain.Entitys /// /// /// - public void SyncFail(string remark, int erpDetailId, int operateId, SyncStatus syncStatus) + public void SyncFail(string remark, int erpDetailId, int operateId, SyncStatus syncStatus, string erpInStockDetailId) { var erpd = this.ErpDetails.Where(w => w.ErpDetailId == erpDetailId).ToList(); erpd.ForEach(det => { det.SuccessSync = syncStatus; + if (!string.IsNullOrEmpty(erpInStockDetailId)) + det.ErpInStockDetailId = Convert.ToInt32(erpInStockDetailId); }); this.SuccessSync = SyncStatus.Fail; this.Remark = remark; diff --git a/src/WMS.Web.Domain/Entitys/InStockErpDetails.cs b/src/WMS.Web.Domain/Entitys/InStockErpDetails.cs index fa13bf4b..769d1ccc 100644 --- a/src/WMS.Web.Domain/Entitys/InStockErpDetails.cs +++ b/src/WMS.Web.Domain/Entitys/InStockErpDetails.cs @@ -70,6 +70,11 @@ namespace WMS.Web.Domain.Entitys /// public int? LastBillNo { get; set; } + /// + /// erp入库单的明细ID + /// + public int? ErpInStockDetailId { get; set; } + /// /// 生成批号 /// diff --git a/src/WMS.Web.Domain/Services/InStockService.cs b/src/WMS.Web.Domain/Services/InStockService.cs index a70a48c5..28f63f1b 100644 --- a/src/WMS.Web.Domain/Services/InStockService.cs +++ b/src/WMS.Web.Domain/Services/InStockService.cs @@ -854,12 +854,12 @@ namespace WMS.Web.Domain.Services erpDetails.Add(item); } - var sourceBillNos= entity.ErpDetails.GroupBy(x => x.SourceBillNo).Select(x => x.Key).ToList(); + var sourceBillNos = entity.ErpDetails.GroupBy(x => x.SourceBillNo).Select(x => x.Key).ToList(); var erp_InStockErpDetails = await sc_inStockRepositories.GetErpDetails(sourceBillNos); foreach (var det in erpDetails) - { + { var erpDto = new ErpPushDto() { RuleId = "PUR_PurchaseOrder-STK_InStock",//转换规则内码 采购订单下推采购入库单 @@ -876,25 +876,28 @@ namespace WMS.Web.Domain.Services details = resPurchaseInStockDetails_result.Data; //金蝶已有的单;进行金蝶不同操作处理:保存,提交,审核 - var currentDet = details.Where(x => x.Qty == det.Qty).FirstOrDefault(); + ErpPurchaseInStockDetailsDto currentDet = null; + if (det.ErpInStockDetailId.HasValue) + currentDet = details.Where(x => x.DetailId == det.ErpInStockDetailId.Value.ToString()).FirstOrDefault(); if (currentDet != null) { var res = await this.QueryFirst(currentDet, erpDto.TargetFormId, entity.BillNo, det, sc_erpService); if (res.result.IsSuccess) - entity.SyncSuccess(det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.erpBillNo); + entity.SyncSuccess(det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.erpBillNo, res.instockDetailId); else - entity.SyncFail(res.result.Message, det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus); + entity.SyncFail(res.result.Message, det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus, res.instockDetailId); } else { //下推金蝶 var res = await this.Push(erpDto, det, entity.BillNo, sc_erpService, sc_inStockRepositories); if (res.result.IsSuccess) - entity.SyncSuccess(det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.erpBillNo); + entity.SyncSuccess(det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.erpBillNo, res.instockDetailId); else - entity.SyncFail(res.result.Message, det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus); + entity.SyncFail(res.result.Message, det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus, res.instockDetailId); } + } //最好一条一条执行,否则执行失败 但是金蝶那边又同步成功 就会造成数据比价乱 var isSuccess = await sc_InStockRepositories.Update(entity, true); @@ -909,8 +912,9 @@ namespace WMS.Web.Domain.Services /// /// /// - private async Task<(Result result, SyncStatus syncStatus, string erpBillNo)> Push(ErpPushDto dto, InStockErpDetails erpDetail, string billNo, IErpService sc_erpService, IInStockRepositories sc_inStockRepositories) + private async Task<(Result result, SyncStatus syncStatus, string erpBillNo, string instockDetailId)> Push(ErpPushDto dto, InStockErpDetails erpDetail, string billNo, IErpService sc_erpService, IInStockRepositories sc_inStockRepositories) { + var erp_instock_detId = string.Empty; try { _logger.LogInformation($"入库单->开始下推 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 数据: {JsonConvert.SerializeObject(dto)}"); @@ -919,13 +923,14 @@ namespace WMS.Web.Domain.Services if (!res.IsSuccess) { _logger.LogInformation($"入库单->下推失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{res.Message}"); - return (Result.ReFailure(res.Message, res.Status), SyncStatus.Fail, ""); + return (Result.ReFailure(res.Message, res.Status), SyncStatus.Fail, "", null); } string id = res.Data; var resPurchaseInStock = await sc_erpService.BillQueryForPurchaseInStock(id); var purchaseInStock = resPurchaseInStock.Data; purchaseInStock.Details[0].Qty = erpDetail.Qty; string formId = dto.TargetFormId.ToString(); + erp_instock_detId = purchaseInStock.Details[0].DetailId; //批号生成和同步 if (string.IsNullOrEmpty(erpDetail.BatchBillNo)) { @@ -959,7 +964,7 @@ namespace WMS.Web.Domain.Services if (!res_s.IsSuccess) { _logger.LogInformation($"入库单->保存失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{res_s.Message}"); - return (Result.ReFailure(res_s.Message, res_s.Status), SyncStatus.SubmitFail, id); + return (Result.ReFailure(res_s.Message, res_s.Status), SyncStatus.SubmitFail, "", purchaseInStock.Details[0].DetailId); } //提交 _logger.LogInformation($"入库单->保存成功 开始提交 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}"); @@ -968,7 +973,7 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->提交失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First(), purchaseInStock.Details[0].DetailId); } //审核 _logger.LogInformation($"入库单->提交成功 开始审核 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}"); @@ -976,16 +981,16 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First(), purchaseInStock.Details[0].DetailId); } _logger.LogInformation($"入库单->同步金蝶成功->单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}"); - return (Result.ReSuccess(), SyncStatus.Success, o_dto.Numbers.First()); + return (Result.ReSuccess(), SyncStatus.Success, o_dto.Numbers.First(), purchaseInStock.Details[0].DetailId); } catch (Exception ex) { _logger.LogInformation($"入库单-同步:错误:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{ex.Message}"); var result = Result.ReFailure(ex.Message, 50001); - return (result, SyncStatus.Fail, ""); + return (result, SyncStatus.Fail, "", erp_instock_detId); } } @@ -999,8 +1004,10 @@ namespace WMS.Web.Domain.Services /// /// /// - private async Task<(Result result, SyncStatus syncStatus, string erpBillNo)> QueryFirst(ErpPurchaseInStockDetailsDto currentDet, string formId, string billNo, InStockErpDetails erpDetail, IErpService sc_erpService) + private async Task<(Result result, SyncStatus syncStatus, string erpBillNo, string instockDetailId)> QueryFirst(ErpPurchaseInStockDetailsDto currentDet, string formId, string billNo, InStockErpDetails erpDetail, IErpService sc_erpService) { + + var erp_instock_detId = string.Empty; try { var purchaseInstock = new ErpPurchaseInStockSaveDto(currentDet.OrderId); @@ -1008,6 +1015,8 @@ namespace WMS.Web.Domain.Services det.DetailId = currentDet.DetailId; det.Qty = currentDet.Qty; purchaseInstock.Details.Add(det); + + erp_instock_detId = det.DetailId; ErpOperateDto o_dto = new ErpOperateDto(formId, currentDet.OrderBillNo);//res_s.Data if (currentDet.DocumentStatus == ErpOrderStatus.Z.ToString()) { @@ -1017,7 +1026,7 @@ namespace WMS.Web.Domain.Services if (!res_s.IsSuccess) { _logger.LogInformation($"入库单->保存失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{res_s.Message}"); - return (Result.ReFailure(res_s.Message, res_s.Status), SyncStatus.SubmitFail, currentDet.OrderId); + return (Result.ReFailure(res_s.Message, res_s.Status), SyncStatus.SubmitFail, currentDet.OrderId, det.DetailId); } //提交 @@ -1026,7 +1035,7 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->提交失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First(), det.DetailId); } //审核 @@ -1035,7 +1044,7 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First(), det.DetailId); } } else if (currentDet.DocumentStatus == ErpOrderStatus.A.ToString()) @@ -1046,7 +1055,7 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->提交失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First(), det.DetailId); } //审核 @@ -1055,7 +1064,7 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First(), det.DetailId); } } else if (currentDet.DocumentStatus == ErpOrderStatus.B.ToString()) @@ -1066,9 +1075,9 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First(), det.DetailId); } - } + } else if (currentDet.DocumentStatus == ErpOrderStatus.D.ToString()) { //提交 @@ -1077,7 +1086,7 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->提交失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First(), det.DetailId); } //审核 @@ -1086,23 +1095,23 @@ namespace WMS.Web.Domain.Services if (!resSubmit.IsSuccess) { _logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}"); - return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First()); + return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First(), det.DetailId); } } else if (currentDet.DocumentStatus == ErpOrderStatus.C.ToString()) { _logger.LogInformation($"入库单->存在已审核的ERP入库单 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:存在已审核的ERP入库单"); - return (Result.ReFailure("存在已审核的ERP入库单", 2001), SyncStatus.CheckFail, o_dto.Numbers.First()); + return (Result.ReFailure("存在已审核的ERP入库单", 2001), SyncStatus.CheckFail, o_dto.Numbers.First(), det.DetailId); } _logger.LogInformation($"入库单->同步金蝶成功->单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}"); - return (Result.ReSuccess(), SyncStatus.Success, o_dto.Numbers.First()); + return (Result.ReSuccess(), SyncStatus.Success, o_dto.Numbers.First(), det.DetailId); } catch (Exception ex) { _logger.LogInformation($"入库单-同步:错误:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{ex.Message}"); var result = Result.ReFailure(ex.Message, 50001); - return (result, SyncStatus.Fail, ""); + return (result, SyncStatus.Fail, "", erp_instock_detId); } }