fix: 查询库存接口,按照入库时间降序返回
This commit is contained in:
parent
471300768e
commit
57ce5eb5a2
@ -26,10 +26,11 @@ namespace HHWMS.Web.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<InventoryApiListVM>(passInit: true);
|
||||
// 默认按入库时间倒序:最新入库的库存排在最前
|
||||
searcher.SortInfo = new SortInfo()
|
||||
{
|
||||
Property = "MaterialCode",
|
||||
Direction = SortDir.Asc
|
||||
Property = "Createtime",
|
||||
Direction = SortDir.Desc
|
||||
};
|
||||
searcher.IsPlainText = false;
|
||||
searcher.IsEnumToString = true;
|
||||
|
||||
@ -75,7 +75,7 @@ namespace HHWMS.Web
|
||||
NextBatch = x.Lot,
|
||||
UpdateTime = x.UpdateTime,
|
||||
UploadFlag = x.UploadErpFlag
|
||||
}).OrderBy(x => x.MaterialCode);
|
||||
}).OrderByDescending(x => x.Createtime); // 按入库时间倒序,最新入库排在最前
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Support;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
@ -688,6 +689,10 @@ namespace HHWMS.Web.Controllers
|
||||
if (!result.Status)
|
||||
{
|
||||
task.Status = TaskStatusEnum.待下发;
|
||||
// 记录最后一次下发失败原因,列表中可直接看出"从未下发成功"的任务
|
||||
task.ErrorMsg = string.IsNullOrWhiteSpace(result.Message)
|
||||
? "WCS任务下发失败"
|
||||
: result.Message;
|
||||
_unitwork.Update(task);
|
||||
transaction.Commit();
|
||||
return JsonMore(null, 500, result.Message ?? "WCS任务下发失败");
|
||||
@ -805,82 +810,30 @@ namespace HHWMS.Web.Controllers
|
||||
|
||||
private void RecalculateShipmentDetail(int shipmentDetailId)
|
||||
{
|
||||
var detail = _unitwork.FindSingle<ShipmentDetail>(x => x.ID == shipmentDetailId);
|
||||
if (detail == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RecalculateShipmentDetail(detail);
|
||||
ShipmentStatusCalculator.RecalculateDetail(_unitwork, shipmentDetailId, GetOperatorCode());
|
||||
}
|
||||
|
||||
private void RecalculateShipmentDetail(ShipmentDetail detail)
|
||||
{
|
||||
|
||||
detail.DividedQty = _unitwork.Find<TaskDetail>(x =>
|
||||
x.OrderDetailId == detail.ID
|
||||
&& x.Status != TaskStatusEnum.完成)
|
||||
.Sum(x => x.Qty) ?? 0;
|
||||
var qty = detail.Qty ?? 0;
|
||||
var completedQty = detail.CompletedQty ?? 0;
|
||||
var dividedQty = detail.DividedQty ?? 0;
|
||||
detail.Status = completedQty >= qty
|
||||
? ShipStatusEnum.拣货完成
|
||||
: completedQty > 0
|
||||
? ShipStatusEnum.拣货中
|
||||
: dividedQty >= qty && qty > 0
|
||||
? ShipStatusEnum.分配完成
|
||||
: dividedQty > 0
|
||||
? ShipStatusEnum.分配中
|
||||
: ShipStatusEnum.新建;
|
||||
detail.UpdateTime = DateTime.Now;
|
||||
detail.UpdateBy = Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
_unitwork.Update(detail);
|
||||
ShipmentStatusCalculator.RecalculateDetail(_unitwork, detail, GetOperatorCode());
|
||||
}
|
||||
|
||||
private void RecalculateShipmentHeader(int shipmentHeaderId)
|
||||
{
|
||||
var header = _unitwork.FindSingle<ShipmentHeader>(x => x.ID == shipmentHeaderId);
|
||||
if (header == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RecalculateShipmentHeader(header);
|
||||
ShipmentStatusCalculator.RecalculateHeader(_unitwork, shipmentHeaderId, GetOperatorCode());
|
||||
}
|
||||
|
||||
private void RecalculateShipmentHeader(ShipmentHeader header)
|
||||
{
|
||||
ShipmentStatusCalculator.RecalculateHeader(_unitwork, header, GetOperatorCode());
|
||||
}
|
||||
|
||||
var details = _unitwork.Find<ShipmentDetail>(x => x.HeaderId == header.ID).ToList();
|
||||
ShipStatusEnum status;
|
||||
if (details.Any() && details.All(x => (x.CompletedQty ?? 0) >= (x.Qty ?? 0)))
|
||||
{
|
||||
status = ShipStatusEnum.拣货完成;
|
||||
}
|
||||
else if (details.Any(x => (x.CompletedQty ?? 0) > 0))
|
||||
{
|
||||
status = ShipStatusEnum.拣货中;
|
||||
}
|
||||
else if (details.Any() && details.All(x =>
|
||||
(x.CompletedQty ?? 0) + (x.DividedQty ?? 0) >= (x.Qty ?? 0)))
|
||||
{
|
||||
status = ShipStatusEnum.分配完成;
|
||||
}
|
||||
else if (details.Any(x => (x.DividedQty ?? 0) > 0))
|
||||
{
|
||||
status = ShipStatusEnum.分配中;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ShipStatusEnum.新建;
|
||||
}
|
||||
|
||||
header.FirstStatus = status;
|
||||
header.LastStatus = status;
|
||||
header.UpdateTime = DateTime.Now;
|
||||
header.UpdateBy = Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
_unitwork.Update(header);
|
||||
/// <summary>
|
||||
/// 当前操作人账号,用于写更新人
|
||||
/// </summary>
|
||||
private string GetOperatorCode()
|
||||
{
|
||||
return Wtm.LoginUserInfo?.ITCode ?? "WMS";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -2,8 +2,20 @@
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:quote>
|
||||
确认取消该线边库入库任务?取消后将删除未完成的零库存记录,并释放托盘和目标库位。
|
||||
已下发任务仅在WCS尚未开始执行时允许取消。
|
||||
@if (Model.Entity.ZoneId != 1027)
|
||||
{
|
||||
<text>
|
||||
确认取消该成品库未下发的出库任务?取消后将删除任务及明细,解锁库存、托盘和起始库位,并回退出库单的已分配数量与状态。
|
||||
已下发到 WCS 的任务不能在此取消,请在 WCS 侧处理。
|
||||
</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>
|
||||
确认取消该线边库入库任务?取消后将删除未完成的零库存记录,并释放托盘和目标库位。
|
||||
已下发任务仅在WCS尚未开始执行时允许取消。
|
||||
</text>
|
||||
}
|
||||
</wt:quote>
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:display field="Entity.TaskNo"/>
|
||||
|
||||
115
HHWMS.Web/Support/ShipmentStatusCalculator.cs
Normal file
115
HHWMS.Web/Support/ShipmentStatusCalculator.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using HHWMS.Web.Models;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
namespace HHWMS.Web.Support
|
||||
{
|
||||
/// <summary>
|
||||
/// 出库单(ERP发货通知单)状态重算。
|
||||
/// 统一「出库单页取消分配」与「任务管理页取消任务」两处的重算口径,
|
||||
/// 避免同一业务出现两套状态规则。
|
||||
/// </summary>
|
||||
public static class ShipmentStatusCalculator
|
||||
{
|
||||
/// <summary>
|
||||
/// 按明细ID重算已分配数量与明细状态
|
||||
/// </summary>
|
||||
/// <param name="unitWork">工作单元</param>
|
||||
/// <param name="shipmentDetailId">出库明细ID</param>
|
||||
/// <param name="operatorCode">操作人账号</param>
|
||||
public static void RecalculateDetail(IUnitWork unitWork, int shipmentDetailId, string operatorCode)
|
||||
{
|
||||
var detail = unitWork.FindSingle<ShipmentDetail>(x => x.ID == shipmentDetailId);
|
||||
if (detail != null)
|
||||
{
|
||||
RecalculateDetail(unitWork, detail, operatorCode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重算单条出库明细:已分配数量取自未完成的任务明细,状态按完成量/分配量推导
|
||||
/// </summary>
|
||||
/// <param name="unitWork">工作单元</param>
|
||||
/// <param name="detail">出库明细</param>
|
||||
/// <param name="operatorCode">操作人账号</param>
|
||||
public static void RecalculateDetail(IUnitWork unitWork, ShipmentDetail detail, string operatorCode)
|
||||
{
|
||||
// 已分配数量 = 该明细下未完成任务明细的数量合计
|
||||
detail.DividedQty = unitWork.Find<TaskDetail>(x =>
|
||||
x.OrderDetailId == detail.ID
|
||||
&& x.Status != TaskStatusEnum.完成)
|
||||
.Sum(x => x.Qty) ?? 0;
|
||||
|
||||
var qty = detail.Qty ?? 0;
|
||||
var completedQty = detail.CompletedQty ?? 0;
|
||||
var dividedQty = detail.DividedQty ?? 0;
|
||||
detail.Status = completedQty >= qty
|
||||
? ShipStatusEnum.拣货完成
|
||||
: completedQty > 0
|
||||
? ShipStatusEnum.拣货中
|
||||
: dividedQty >= qty && qty > 0
|
||||
? ShipStatusEnum.分配完成
|
||||
: dividedQty > 0
|
||||
? ShipStatusEnum.分配中
|
||||
: ShipStatusEnum.新建;
|
||||
detail.UpdateTime = DateTime.Now;
|
||||
detail.UpdateBy = operatorCode;
|
||||
unitWork.Update(detail);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按表头ID重算出库单主表状态
|
||||
/// </summary>
|
||||
/// <param name="unitWork">工作单元</param>
|
||||
/// <param name="shipmentHeaderId">出库单ID</param>
|
||||
/// <param name="operatorCode">操作人账号</param>
|
||||
public static void RecalculateHeader(IUnitWork unitWork, int shipmentHeaderId, string operatorCode)
|
||||
{
|
||||
var header = unitWork.FindSingle<ShipmentHeader>(x => x.ID == shipmentHeaderId);
|
||||
if (header != null)
|
||||
{
|
||||
RecalculateHeader(unitWork, header, operatorCode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重算出库单主表:按全部明细的完成量/分配量汇总推导
|
||||
/// </summary>
|
||||
/// <param name="unitWork">工作单元</param>
|
||||
/// <param name="header">出库单主表</param>
|
||||
/// <param name="operatorCode">操作人账号</param>
|
||||
public static void RecalculateHeader(IUnitWork unitWork, ShipmentHeader header, string operatorCode)
|
||||
{
|
||||
var details = unitWork.Find<ShipmentDetail>(x => x.HeaderId == header.ID).ToList();
|
||||
ShipStatusEnum status;
|
||||
if (details.Any() && details.All(x => (x.CompletedQty ?? 0) >= (x.Qty ?? 0)))
|
||||
{
|
||||
status = ShipStatusEnum.拣货完成;
|
||||
}
|
||||
else if (details.Any(x => (x.CompletedQty ?? 0) > 0))
|
||||
{
|
||||
status = ShipStatusEnum.拣货中;
|
||||
}
|
||||
else if (details.Any() && details.All(x =>
|
||||
(x.CompletedQty ?? 0) + (x.DividedQty ?? 0) >= (x.Qty ?? 0)))
|
||||
{
|
||||
status = ShipStatusEnum.分配完成;
|
||||
}
|
||||
else if (details.Any(x => (x.DividedQty ?? 0) > 0))
|
||||
{
|
||||
status = ShipStatusEnum.分配中;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ShipStatusEnum.新建;
|
||||
}
|
||||
|
||||
header.FirstStatus = status;
|
||||
header.LastStatus = status;
|
||||
header.UpdateTime = DateTime.Now;
|
||||
header.UpdateBy = operatorCode;
|
||||
unitWork.Update(header);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,7 @@ namespace HHWMS.Web.Support
|
||||
new QuartzService(sp, gd, dc).AddJob(job).Wait();
|
||||
}
|
||||
|
||||
var test = gd.AllAssembly.FirstOrDefault(x => x.FullName.Contains("HHWMS.Web"));
|
||||
var test = gd.AllAssembly.FirstOrDefault(x => x.FullName.Contains("HHWMS.Web"));
|
||||
var t = test.GetExportedTypes().Where(x => typeof(WtmJob).IsAssignableFrom(x) && x.Name != "WtmJob");
|
||||
foreach (var item in t)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user