feat: 支持ERP主动下发成品发货通知单并复用导入逻辑
This commit is contained in:
1 parent
80d1b201b0
commit
ede6d32608
9 files changed
+555
-103
No files matched your search
@@ -698,7 +698,7 @@ namespace HHWMS.Web.Controllers
|
||||
if (apiResult.Data.Data != null)
|
||||
{
|
||||
fetchedCount += apiResult.Data.Data.Count;
|
||||
items.AddRange(apiResult.Data.Data.Where(x => !x.BReturnFlag));
|
||||
items.AddRange(apiResult.Data.Data.Where(x => x == null || !x.BReturnFlag));
|
||||
}
|
||||
page++;
|
||||
} while (fetchedCount < total && page <= 100);
|
||||
@@ -708,20 +708,12 @@ namespace HHWMS.Web.Controllers
|
||||
return new ApiJsonResult<int> { Success = false, Msg = "未查询到发货通知单" };
|
||||
}
|
||||
|
||||
using (var transaction = DC.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessDispatchItems(items);
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return new ApiJsonResult<int> { Success = true, Data = items.Count };
|
||||
if (fetchedCount < total)
|
||||
return new ApiJsonResult<int> { Success = false, Msg = "ERP分页数据未获取完整,请稍后重试" };
|
||||
if (items.Any(x => x == null || x.DLCode != dispatchCode))
|
||||
return new ApiJsonResult<int> { Success = false, Msg = "ERP返回的通知单号与请求不一致" };
|
||||
var count = await _dispatchImport.ImportAsync(items, Wtm.LoginUserInfo?.ITCode ?? "WMS");
|
||||
return new ApiJsonResult<int> { Success = true, Status = true, Data = count };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -731,93 +723,6 @@ namespace HHWMS.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessDispatchItems(List<DispatchItem> items)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var operatorCode = Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
foreach (var group in items.Where(x => !string.IsNullOrWhiteSpace(x.DLCode) && x.DLsID > 0)
|
||||
.GroupBy(x => x.DLCode))
|
||||
{
|
||||
var header = _unitwork.FindSingle<ShipmentHeader>(x => x.SourceCode == group.Key);
|
||||
if (header == null)
|
||||
{
|
||||
header = new ShipmentHeader
|
||||
{
|
||||
SourceCode = group.Key,
|
||||
Code = _unitwork.GetSerialNumber("SO"),
|
||||
BillType = "sout",
|
||||
CompanyCode = group.First().CusCode,
|
||||
SupplierCode = group.First().CusCode,
|
||||
TotalQty = group.Sum(x => x.DeliveryQty),
|
||||
TotalLines = group.Select(x => x.DLsID).Distinct().Count(),
|
||||
FirstStatus = ShipStatusEnum.新建,
|
||||
LastStatus = ShipStatusEnum.新建,
|
||||
Remark = group.First().CusName,
|
||||
UpdateVersion = 1,
|
||||
CreateBy = operatorCode,
|
||||
CreateTime = now
|
||||
};
|
||||
_unitwork.Add(header);
|
||||
}
|
||||
else
|
||||
{
|
||||
header.CompanyCode = group.First().CusCode;
|
||||
header.SupplierCode = group.First().CusCode;
|
||||
header.Remark = group.First().CusName;
|
||||
header.UpdateVersion++;
|
||||
header.UpdateBy = operatorCode;
|
||||
header.UpdateTime = now;
|
||||
_unitwork.Update(header);
|
||||
}
|
||||
|
||||
foreach (var item in group.GroupBy(x => x.DLsID).Select(x => x.First()))
|
||||
{
|
||||
var detail = _unitwork.FindSingle<ShipmentDetail>(x => x.DLsID == item.DLsID);
|
||||
if (detail == null)
|
||||
{
|
||||
detail = new ShipmentDetail
|
||||
{
|
||||
HeaderId = header.ID,
|
||||
DLsID = item.DLsID,
|
||||
ZoneCode = "cp",
|
||||
MaterialCode = item.InvCode,
|
||||
MaterialName = item.InvName,
|
||||
MaterialType = item.InvDefine1,
|
||||
Qty = item.DeliveryQty,
|
||||
CompletedQty = 0,
|
||||
DividedQty = 0,
|
||||
Status = ShipStatusEnum.新建,
|
||||
UpdateVersion = 1,
|
||||
CreateBy = operatorCode,
|
||||
CreateTime = now
|
||||
};
|
||||
_unitwork.Add(detail);
|
||||
}
|
||||
else
|
||||
{
|
||||
detail.HeaderId = header.ID;
|
||||
detail.MaterialCode = item.InvCode;
|
||||
detail.MaterialName = item.InvName;
|
||||
detail.MaterialType = item.InvDefine1;
|
||||
if ((detail.CompletedQty ?? 0) == 0 && (detail.DividedQty ?? 0) == 0)
|
||||
{
|
||||
// ERP累计出库数量存在回写延迟,WMS执行量只使用发货通知数量和本地记录。
|
||||
detail.Qty = item.DeliveryQty;
|
||||
}
|
||||
detail.UpdateVersion++;
|
||||
detail.UpdateBy = operatorCode;
|
||||
detail.UpdateTime = now;
|
||||
_unitwork.Update(detail);
|
||||
}
|
||||
}
|
||||
|
||||
var localDetails = _unitwork.Find<ShipmentDetail>(x => x.HeaderId == header.ID).ToList();
|
||||
header.TotalQty = localDetails.Sum(x => x.Qty ?? 0);
|
||||
header.TotalLines = localDetails.Count;
|
||||
_unitwork.Update(header);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleasePendingPallet(TaskHeader task)
|
||||
{
|
||||
var operatorCode = Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
|
||||
@@ -19,9 +19,11 @@ namespace HHWMS.Web.Controllers
|
||||
public partial class ShipmentHeaderController : BaseController
|
||||
{
|
||||
private readonly IUnitWork _unitwork;
|
||||
public ShipmentHeaderController(IUnitWork unitwork)
|
||||
private readonly HHWMS.Web.Support.DispatchImportService _dispatchImport;
|
||||
public ShipmentHeaderController(IUnitWork unitwork, HHWMS.Web.Support.DispatchImportService dispatchImport)
|
||||
{
|
||||
_unitwork = unitwork;
|
||||
_dispatchImport = dispatchImport;
|
||||
}
|
||||
#region Search
|
||||
[ActionDescription("Sys.Search")]
|
||||
|
||||
Reference in new issue
Block a user