fix: 查询库存接口,按照入库时间降序返回
This commit is contained in:
1 parent
471300768e
commit
57ce5eb5a2
7 files changed
+273
-71
No files matched your search
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Support;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -177,8 +178,21 @@ namespace HHWMS.Web.Controllers
|
||||
return FFResult().CloseDialog().Alert("任务不存在或已被处理").RefreshGrid();
|
||||
}
|
||||
|
||||
if (task.ZoneId != 1027
|
||||
|| task.RoadWay != 1
|
||||
// 非线边库(成品库等)走"未下发出库任务取消",只回滚 WMS 数据,不调用 WCS
|
||||
if (task.ZoneId != 1027)
|
||||
{
|
||||
var outboundError = CancelPendingOutboundTask(task);
|
||||
if (outboundError != null)
|
||||
{
|
||||
return FFResult().CloseDialog().Alert(outboundError).RefreshGrid();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
return FFResult().CloseDialog().Alert("任务取消成功").RefreshGrid();
|
||||
}
|
||||
|
||||
// 线边库仅允许取消入库任务,其余逻辑保持不变
|
||||
if (task.RoadWay != 1
|
||||
|| task.TaskType != TaskTypeEnum.入库)
|
||||
{
|
||||
return FFResult().CloseDialog().Alert("仅允许取消线边库入库任务").RefreshGrid();
|
||||
@@ -273,6 +287,113 @@ namespace HHWMS.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消成品库未下发的出库任务(含下发失败、始终未下发到 WCS 的任务)。
|
||||
/// 只回滚 WMS 数据,不调用 WCS。返回 null 表示成功,否则返回提示信息。
|
||||
/// </summary>
|
||||
/// <param name="task">任务主表(已加行锁的快照)</param>
|
||||
private string CancelPendingOutboundTask(TaskHeader task)
|
||||
{
|
||||
if (task.TaskType != TaskTypeEnum.出库)
|
||||
{
|
||||
return "成品库仅支持取消未下发的出库任务,入库任务请在 WCS 侧处理";
|
||||
}
|
||||
|
||||
if (task.Status != TaskStatusEnum.待下发)
|
||||
{
|
||||
return "任务已下发 WCS,不能在此取消,请在 WCS 侧处理";
|
||||
}
|
||||
|
||||
var taskDetails = _unitwork.Find<TaskDetail>(x => x.HeaderId == task.ID).ToList();
|
||||
var shipmentDetailIds = taskDetails
|
||||
.Where(x => x.OrderDetailId.HasValue)
|
||||
.Select(x => x.OrderDetailId.Value)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// 1. 先删任务明细,避免后面重算已分配数量时仍把它们统计进去
|
||||
if (taskDetails.Any())
|
||||
{
|
||||
_unitwork.BatchDelete(taskDetails);
|
||||
}
|
||||
|
||||
// 2. 释放托盘:库存解锁、容器解锁、起始库位解锁(库存数量不变)
|
||||
ReleaseTaskPallet(task);
|
||||
|
||||
// 3. 删除任务主表
|
||||
_unitwork.Delete(task);
|
||||
|
||||
// 4. 回退出库单已分配数量与单据状态
|
||||
var operatorCode = Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
var shipmentHeaderIds = new List<int>();
|
||||
foreach (var shipmentDetailId in shipmentDetailIds)
|
||||
{
|
||||
var shipmentDetail = _unitwork.FindSingle<ShipmentDetail>(x => x.ID == shipmentDetailId);
|
||||
if (shipmentDetail == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ShipmentStatusCalculator.RecalculateDetail(_unitwork, shipmentDetail, operatorCode);
|
||||
if (!shipmentHeaderIds.Contains(shipmentDetail.HeaderId))
|
||||
{
|
||||
shipmentHeaderIds.Add(shipmentDetail.HeaderId);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var shipmentHeaderId in shipmentHeaderIds)
|
||||
{
|
||||
ShipmentStatusCalculator.RecalculateHeader(_unitwork, shipmentHeaderId, operatorCode);
|
||||
}
|
||||
|
||||
Wtm.DoLog("取消成品库未下发出库任务", ActionLogTypesEnum.Normal,
|
||||
"CancelPendingOutboundTask", request: task.TaskNo,
|
||||
result: $"取消成功,清理任务明细{taskDetails.Count}条,回退出库明细{shipmentDetailIds.Count}条");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放任务占用的托盘资源:库存解锁、容器解锁、起始库位解锁(不改变库存数量)
|
||||
/// </summary>
|
||||
/// <param name="task">任务主表</param>
|
||||
private void ReleaseTaskPallet(TaskHeader task)
|
||||
{
|
||||
var operatorCode = Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
var now = DateTime.Now;
|
||||
|
||||
var inventories = _unitwork.Find<Inventory>(x => x.ContainerCode == task.ContainerCode).ToList();
|
||||
foreach (var inventory in inventories)
|
||||
{
|
||||
inventory.TaskStatus = InventoryTaskStatusEnum.Idle;
|
||||
inventory.UpdateBy = operatorCode;
|
||||
inventory.UpdateTime = now;
|
||||
}
|
||||
|
||||
if (inventories.Any())
|
||||
{
|
||||
_unitwork.BatchUpdate(inventories);
|
||||
}
|
||||
|
||||
var container = _unitwork.FindSingle<Container>(x => x.Code == task.ContainerCode);
|
||||
if (container != null)
|
||||
{
|
||||
container.IsLock = ContainerLockEnum.未锁;
|
||||
container.UpdateBy = operatorCode;
|
||||
container.UpdateTime = now;
|
||||
_unitwork.Update(container);
|
||||
}
|
||||
|
||||
// 出库任务取消时托盘仍在原库位,只解除库位锁,不修改库位与托盘的绑定关系
|
||||
var location = _unitwork.FindSingle<Location>(x => x.Code == task.FromLocation);
|
||||
if (location != null && location.Status == LocationStatusEnum.锁定)
|
||||
{
|
||||
location.Status = LocationStatusEnum.未锁;
|
||||
location.UpdateBy = operatorCode;
|
||||
location.UpdateTime = now;
|
||||
_unitwork.Update(location);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SameCode(string left, string right)
|
||||
{
|
||||
return string.Equals(left, right, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
Reference in new issue
Block a user