优化同步接口

This commit is contained in:
tongfei
2024-04-25 15:17:23 +08:00
parent 9b8483f08a
commit 9dc8de71f7
4 changed files with 54 additions and 31 deletions

View File

@@ -771,7 +771,7 @@
生成单据号
</summary>
</member>
<member name="M:WMS.Web.Domain.Entitys.InStock.SyncSuccess(System.Int32,System.Int32,System.String)">
<member name="M:WMS.Web.Domain.Entitys.InStock.SyncSuccess(System.Int32,System.Int32,System.String,System.String)">
<summary>
同步金蝶(成功)
</summary>
@@ -779,7 +779,7 @@
<param name="operateId"></param>
<param name="erpBillNo"></param>
</member>
<member name="M:WMS.Web.Domain.Entitys.InStock.SyncFail(System.String,System.Int32,System.Int32,WMS.Web.Domain.Values.SyncStatus)">
<member name="M:WMS.Web.Domain.Entitys.InStock.SyncFail(System.String,System.Int32,System.Int32,WMS.Web.Domain.Values.SyncStatus,System.String)">
<summary>
同步金蝶(失败)
</summary>
@@ -935,6 +935,11 @@
箱唛编号-末尾序号
</summary>
</member>
<member name="P:WMS.Web.Domain.Entitys.InStockErpDetails.ErpInStockDetailId">
<summary>
erp入库单的明细ID
</summary>
</member>
<member name="M:WMS.Web.Domain.Entitys.InStockErpDetails.GenerateBatchBillNo(System.Int32,System.Int32,System.Boolean)">
<summary>
生成批号

View File

@@ -149,13 +149,15 @@ namespace WMS.Web.Domain.Entitys
/// <param name="erpDetailId"></param>
/// <param name="operateId"></param>
/// <param name="erpBillNo"></param>
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
/// <param name="erpDetailId"></param>
/// <param name="operateId"></param>
/// <param name="syncStatus"></param>
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;

View File

@@ -70,6 +70,11 @@ namespace WMS.Web.Domain.Entitys
/// </summary>
public int? LastBillNo { get; set; }
/// <summary>
/// erp入库单的明细ID
/// </summary>
public int? ErpInStockDetailId { get; set; }
/// <summary>
/// 生成批号
/// </summary>

View File

@@ -854,7 +854,7 @@ 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);
@@ -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
/// <param name="erpDetail"></param>
/// <param name="billNo"></param>
/// <returns></returns>
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
/// <param name="erpDetail"></param>
/// <param name="sc_erpService"></param>
/// <returns></returns>
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,7 +1075,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.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);
}
}