优化接口

This commit is contained in:
tongfei
2024-04-24 10:27:56 +08:00
parent 7f110d3dfd
commit f2e2ae8aa0
10 changed files with 350 additions and 21 deletions

View File

@@ -124,7 +124,7 @@ namespace WMS.Web.Domain.Services
// 构建 Redis 锁的值,用于标识锁的持有者
string lockValue = Guid.NewGuid().ToString();
// 获取 Redis 锁,设置超时时间为 10 秒
if (await _redisDb.LockTakeAsync(lockKey, lockValue, TimeSpan.FromSeconds(10)))
if (await _redisDb.LockTakeAsync(lockKey, lockValue, TimeSpan.FromSeconds(10)))
{
try
{
@@ -203,7 +203,7 @@ namespace WMS.Web.Domain.Services
await _redisDb.LockReleaseAsync(lockKey, lockValue);
}
}
else
else
{
return Result.ReFailure(ResultCodes.Concurrent_Instock);
}
@@ -856,30 +856,50 @@ namespace WMS.Web.Domain.Services
if (erpDetails.Count != 0)
{
foreach (var s in erpDetails)
foreach (var det in erpDetails)
{
var erp_details = entity.ErpDetails
.Where(w => w.SourceBillNo.Equals(s)).Select(s => s.ErpDetailId).ToList();
.Where(w => w.SourceBillNo.Equals(det)).Select(t => t.ErpDetailId).ToList();
var erpDto = new ErpPushDto()
{
RuleId = "PUR_PurchaseOrder-STK_InStock",//转换规则内码 采购订单下推采购入库单
FormId = FormIdParam.PUR_PurchaseOrder.ToString(),
TargetFormId = FormIdParam.STK_InStock.ToString(),
DetailsId = s.ErpDetailId.ToString(),
DetailsId = det.ErpDetailId.ToString(),
IsDraftWhenSaveFail = true//是否需要暂存
};
//下推金蝶
var res = await this.Push(erpDto, s, entity.BillNo, sc_erpService, sc_inStockRepositories);
if (res.result.IsSuccess)
entity.SyncSuccess(s.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.erpBillNo);
List<ErpPurchaseInStockDetailsDto> details = new List<ErpPurchaseInStockDetailsDto>();
var resPurchaseInStockDetails_result = await sc_erpService.BillQueryForPurchaseInStockBy(det.ErpDetailId.ToString());
if (resPurchaseInStockDetails_result.IsSuccess)
details = resPurchaseInStockDetails_result.Data;
//金蝶已有的单;进行金蝶不同操作处理:保存,提交,审核
var currentDet = details.Where(x => x.Qty == det.Qty).FirstOrDefault();
if (currentDet != null)
{
var res= await this.QueryFirst(currentDet, erpDto.FormId, entity.BillNo, det, sc_erpService);
if (res.result.IsSuccess)
entity.SyncSuccess(det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.erpBillNo);
else
entity.SyncFail(res.result.Message, det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus);
}
else
entity.SyncFail(res.result.Message, s.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus);
{
//下推金蝶
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);
else
entity.SyncFail(res.result.Message, det.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus);
}
}
}
else
{
erpDetails_tags.ForEach(x => { x.SuccessSync = SyncStatus.Fail; });
entity.SyncFailAll("同步金蝶失败,金蝶存在已审核的采购入库单", loginInfo?.UserInfo?.StaffId ?? 0);
entity.SyncFailAll("同步金蝶失败,该采购单已存在采购入库单", loginInfo?.UserInfo?.StaffId ?? 0);
}
//最好一条一条执行,否则执行失败 但是金蝶那边又同步成功 就会造成数据比价乱
var isSuccess = await sc_InStockRepositories.Update(entity, true);
@@ -975,6 +995,102 @@ namespace WMS.Web.Domain.Services
}
/// <summary>
/// 金蝶已有的入库单进行不同处理:保存、提交、审核
/// </summary>
/// <param name="currentDet"></param>
/// <param name="formId"></param>
/// <param name="billNo"></param>
/// <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)
{
try
{
var purchaseInstock = new ErpPurchaseInStockSaveDto(currentDet.OrderId);
var det = new ErpPurchaseInStockDetailsSaveDto();
det.DetailId = currentDet.DetailId;
det.Qty = currentDet.Qty;
purchaseInstock.Details.Add(det);
ErpOperateDto o_dto = new ErpOperateDto(formId, currentDet.OrderBillNo);//res_s.Data
if (currentDet.DocumentStatus == ErpOrderStatus.Z.ToString())
{
//保存
_logger.LogInformation($"入库单->查询到已有暂存的入库单 开始保存 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 数据: {JsonConvert.SerializeObject(purchaseInstock)}");
var res_s = await sc_erpService.Save<ErpPurchaseInStockSaveDto>(purchaseInstock, formId);
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);
}
//提交
_logger.LogInformation($"入库单->保存成功 开始提交 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}");
var resSubmit = await sc_erpService.Submit(o_dto, formId);
if (!resSubmit.IsSuccess)
{
_logger.LogInformation($"入库单->提交失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}");
return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First());
}
//审核
_logger.LogInformation($"入库单->提交成功 开始审核 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}");
resSubmit = await sc_erpService.Audit(o_dto, formId);
if (!resSubmit.IsSuccess)
{
_logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}");
return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First());
}
}
else if (currentDet.DocumentStatus == ErpOrderStatus.A.ToString())
{
//提交
_logger.LogInformation($"入库单->查询到已有保存的入库单 开始提交 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}");
var resSubmit = await sc_erpService.Submit(o_dto, formId);
if (!resSubmit.IsSuccess)
{
_logger.LogInformation($"入库单->提交失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}");
return (resSubmit, SyncStatus.SubmitFail, o_dto.Numbers.First());
}
//审核
_logger.LogInformation($"入库单->提交成功 开始审核 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}");
resSubmit = await sc_erpService.Audit(o_dto, formId);
if (!resSubmit.IsSuccess)
{
_logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}");
return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First());
}
}
else if (currentDet.DocumentStatus == ErpOrderStatus.B.ToString())
{
//审核
_logger.LogInformation($"入库单->查询到已有提交的入库单 开始审核 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}");
var resSubmit = await sc_erpService.Audit(o_dto, formId);
if (!resSubmit.IsSuccess)
{
_logger.LogInformation($"入库单->审核失败 单号:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{resSubmit.Message}");
return (resSubmit, SyncStatus.CheckFail, o_dto.Numbers.First());
}
}
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());
}
_logger.LogInformation($"入库单->同步金蝶成功->单号:{billNo} erp明细Id:{erpDetail.ErpDetailId}");
return (Result.ReSuccess(), SyncStatus.Success, o_dto.Numbers.First());
}
catch (Exception ex)
{
_logger.LogInformation($"入库单-同步:错误:{billNo} erp明细Id:{erpDetail.ErpDetailId} 错误:{ex.Message}");
var result = Result.ReFailure(ex.Message, 50001);
return (result, SyncStatus.Fail, "");
}
}
}
}