增加线边仓取消任务
This commit is contained in:
1 parent
7c2722c88d
commit
db202e16e1
5 files changed
+471
No files matched your search
@@ -146,6 +146,169 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
#endregion Delete
|
||||
|
||||
#region Cancel
|
||||
|
||||
[ActionDescription("TaskHeader.Cancel")]
|
||||
public ActionResult Cancel(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<TaskHeaderVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("TaskHeader.Cancel")]
|
||||
public ActionResult Cancel(string id, IFormCollection nouse)
|
||||
{
|
||||
if (!int.TryParse(id, out var taskId))
|
||||
{
|
||||
return FFResult().CloseDialog().Alert("任务参数错误").RefreshGrid();
|
||||
}
|
||||
|
||||
using (var transaction = DC.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
var task = DC.Set<TaskHeader>()
|
||||
.FromSqlRaw("SELECT * FROM `TaskHeader` WHERE `ID` = {0} FOR UPDATE", taskId)
|
||||
.AsNoTracking()
|
||||
.SingleOrDefault();
|
||||
if (task == null)
|
||||
{
|
||||
return FFResult().CloseDialog().Alert("任务不存在或已被处理").RefreshGrid();
|
||||
}
|
||||
|
||||
if (task.ZoneId != 1027
|
||||
|| task.RoadWay != 1
|
||||
|| task.TaskType != TaskTypeEnum.入库)
|
||||
{
|
||||
return FFResult().CloseDialog().Alert("仅允许取消线边库入库任务").RefreshGrid();
|
||||
}
|
||||
|
||||
if (task.Status != TaskStatusEnum.新建
|
||||
&& task.Status != TaskStatusEnum.待下发
|
||||
&& task.Status != TaskStatusEnum.已下发)
|
||||
{
|
||||
return FFResult().CloseDialog().Alert("当前任务状态不允许取消").RefreshGrid();
|
||||
}
|
||||
|
||||
if (_unitwork.IsExit<TaskDetail>(x => x.HeaderId == task.ID))
|
||||
{
|
||||
return FFResult().CloseDialog().Alert("任务存在明细,不能使用此功能取消").RefreshGrid();
|
||||
}
|
||||
|
||||
var inventories = _unitwork.Find<Inventory>(x =>
|
||||
x.ContainerCode == task.ContainerCode)
|
||||
.ToList();
|
||||
if (inventories.Any(x =>
|
||||
x.ZoneId != task.ZoneId
|
||||
|| !SameCode(x.LocationCode, task.ToLocation)
|
||||
|| x.TaskStatus != InventoryTaskStatusEnum.Locked
|
||||
|| (x.Qty ?? 0) != 0))
|
||||
{
|
||||
return FFResult().CloseDialog()
|
||||
.Alert("托盘存在非零库存或库存状态不一致,不能取消")
|
||||
.RefreshGrid();
|
||||
}
|
||||
|
||||
var container = _unitwork.FindSingle<Container>(x => x.Code == task.ContainerCode);
|
||||
var location = _unitwork.FindSingle<Location>(x => x.Code == task.ToLocation);
|
||||
var hasInventory = inventories.Any();
|
||||
if (container == null
|
||||
|| location == null
|
||||
|| container.IsLock != ContainerLockEnum.任务锁
|
||||
|| container.Status != (hasInventory ? ContainerStatus.有 : ContainerStatus.空)
|
||||
|| !SameCode(container.LocationCode, task.ToLocation)
|
||||
|| location.Status != LocationStatusEnum.锁定
|
||||
|| location.ContainerStatus != (hasInventory ? LocationStatus.有货 : LocationStatus.空仓位)
|
||||
|| !SameCode(location.ContainerCode, task.ContainerCode))
|
||||
{
|
||||
return FFResult().CloseDialog()
|
||||
.Alert("托盘或库位状态与任务不一致,请先排查")
|
||||
.RefreshGrid();
|
||||
}
|
||||
|
||||
if (task.Status == TaskStatusEnum.已下发
|
||||
&& !TryCancelWcsTask(task, out var wcsError))
|
||||
{
|
||||
return FFResult().CloseDialog().Alert(wcsError).RefreshGrid();
|
||||
}
|
||||
|
||||
var operatorCode = Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
var now = DateTime.Now;
|
||||
if (inventories.Any())
|
||||
{
|
||||
_unitwork.BatchDelete(inventories);
|
||||
}
|
||||
|
||||
container.LocationCode = string.Empty;
|
||||
container.IsLock = ContainerLockEnum.未锁;
|
||||
container.Status = hasInventory ? ContainerStatus.有 : ContainerStatus.空;
|
||||
container.UpdateBy = operatorCode;
|
||||
container.UpdateTime = now;
|
||||
_unitwork.Update(container);
|
||||
|
||||
location.ContainerCode = string.Empty;
|
||||
location.Status = LocationStatusEnum.未锁;
|
||||
location.ContainerStatus = LocationStatus.空仓位;
|
||||
location.Version = Guid.NewGuid();
|
||||
location.UpdateBy = operatorCode;
|
||||
location.UpdateTime = now;
|
||||
_unitwork.Update(location);
|
||||
|
||||
_unitwork.Delete(task);
|
||||
transaction.Commit();
|
||||
|
||||
Wtm.DoLog("取消线边库入库任务", ActionLogTypesEnum.Normal,
|
||||
"CancelInboundTask", request: task.TaskNo,
|
||||
result: $"取消成功,清理库存{inventories.Count}条");
|
||||
return FFResult().CloseDialog().Alert("任务取消成功").RefreshGrid();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return FFResult().CloseDialog()
|
||||
.Alert(ex.InnerException?.Message ?? ex.Message)
|
||||
.RefreshGrid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SameCode(string left, string right)
|
||||
{
|
||||
return string.Equals(left, right, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private bool TryCancelWcsTask(TaskHeader task, out string errorMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new { TaskNo = task.TaskNo };
|
||||
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCSXB", "TaskCancel",
|
||||
HttpMethodEnum.POST, request).Result.Data;
|
||||
if (wcsResult == null)
|
||||
{
|
||||
errorMessage = "WCS取消任务无响应,WMS未清理数据";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!wcsResult.Success)
|
||||
{
|
||||
errorMessage = $"WCS取消任务失败:{wcsResult.Msg}";
|
||||
return false;
|
||||
}
|
||||
|
||||
errorMessage = null;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = $"调用WCS取消任务接口异常:{ex.InnerException?.Message ?? ex.Message}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Cancel
|
||||
|
||||
#region Details
|
||||
|
||||
[ActionDescription("Sys.Details")]
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
@model HHWMS.Web.TaskHeaderVM
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:quote>
|
||||
确认取消该线边库入库任务?取消后将删除未完成的零库存记录,并释放托盘和目标库位。
|
||||
已下发任务仅在WCS尚未开始执行时允许取消。
|
||||
</wt:quote>
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:display field="Entity.TaskNo"/>
|
||||
<wt:display field="Entity.ContainerCode"/>
|
||||
<wt:display field="Entity.ToLocation"/>
|
||||
<wt:display field="Entity.Status"/>
|
||||
</wt:row>
|
||||
<wt:hidden field="Entity.ID"/>
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:submitbutton theme="ButtonThemeEnum.Warm" text="确认取消"/>
|
||||
<wt:closebutton/>
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
Reference in new issue
Block a user