成品库入库页面

库纯出库相关 location添加sendwcstask
This commit is contained in:
zhougf committed 2025-07-23 22:33:45 +08:00
1 parent b12ed2d5e5
commit 2435176f77
13 files changed
+1727 -98

No files matched your search

+180 -55
View File
@@ -57,7 +57,8 @@ namespace HHWMS.Web
var timeSinceLastRequest = DateTime.Now - lastRequestTime;
if (timeSinceLastRequest.TotalMilliseconds < DEBOUNCE_INTERVAL_MS)
{
var remainingSeconds = Math.Ceiling((DEBOUNCE_INTERVAL_MS - timeSinceLastRequest.TotalMilliseconds) / 1000);
var remainingSeconds =
Math.Ceiling((DEBOUNCE_INTERVAL_MS - timeSinceLastRequest.TotalMilliseconds) / 1000);
return ApiResultError($"请求过于频繁,请等待{remainingSeconds}秒后重试");
}
}
@@ -115,18 +116,17 @@ namespace HHWMS.Web
/// <summary>
/// 状态返回(带防抖)
/// </summary>
[Public]
[HttpPost]
public Task<IActionResult> TaskStatusResult(WcsRequest request)
{
if (request == null || string.IsNullOrEmpty(request.PalletNo))
if (request == null || string.IsNullOrEmpty(request.TaskNo))
{
return Task.FromResult<IActionResult>(ApiResultError("请求参数无效"));
}
return WithDebounce($"TaskStatus_{request.PalletNo}", async () =>
{
return await ProcessTaskStatusResult(request);
});
return WithDebounce($"TaskStatus_{request.PalletNo}",
async () => { return await ProcessTaskStatusResult(request); });
}
/// <summary>
@@ -135,14 +135,14 @@ namespace HHWMS.Web
private async Task<IActionResult> ProcessTaskStatusResult(WcsRequest request)
{
// 1. 根据托盘号查找对应的任务
var task = _unitWork.FindSingle<TaskHeader>(x => x.TaskNo == request.TaskNo
var task = _unitWork.FindSingle<TaskHeader>(x => x.TaskNo == request.TaskNo
&& x.Status != TaskStatusEnum.完成);
if (task == null)
{
return ApiResultError("未找到对应的任务");
}
/* 根据任务的巷道号来判断
* 1.线边库1号巷道只有任务完成,任务下发的时候已经分配仓位
* 2.成品库2号巷道有任务请求(10)和任务完成(100)
@@ -151,7 +151,7 @@ namespace HHWMS.Web
* 任务完成(100):完成任务,更新库存,更新容器状态,更新库位状态,更新任务状态(线边库需要根据重量计算库存的数量),更新对应的工单
* 任务完成后,删除任务并放到历史任务中
*/
// 根据任务的巷道号和状态来执行不同的逻辑
if (task.RoadWay == 1) // 线边库1号巷道
{
@@ -165,9 +165,24 @@ namespace HHWMS.Web
{
if (request.State == 10) // 任务请求,需要分配仓位
{
if (!string.IsNullOrWhiteSpace(task.ToLocation))
{
return ApiResult(new { LocationCode = task.ToLocation });
}
// 根据请求的高度,分配仓位
var locationVm = Wtm.CreateVM<LocationVM>();
request.RoadWay = 2;
// 默认1 模具2 低仓位3 高仓位4 成品大于4 超限 模具大于2 超限
if(request.Height == 2)
request.Height = 999;
else if (request.Height == 3)
request.Height = 1100;
else
request.Height = 0;
var container = _unitWork.FindSingle<Container>(x => x.Code == task.ContainerCode);
if (container != null)
{
@@ -179,16 +194,29 @@ namespace HHWMS.Web
_ => request.LocationType
};
}
var location = await locationVm.GetLocation(request).Data;
// 模具库 高度超限直接返回失败
if (request.LocationType == LocationTypeEnum.M && request.Height >= 2)
{
return ApiResultError(msg: "模具超高,未找到合适的仓位");
}
var location = locationVm.GetLocation(request).Data;
if (location != null)
{
// 更新任务的目标仓位
task.ToLocation = location.LocationCode;
_unitWork.Update(task);
var loc = _unitWork.FindSingle<Location>(x => x.Code == task.ToLocation);
loc.Status = LocationStatusEnum.锁定;
loc.Version = Guid.NewGuid();
loc.UpdateTime = DateTime.Now;
_unitWork.Update(loc);
return ApiResult(new { LocationCode = location.LocationCode });
}
else
{
return ApiResultError("未找到合适的仓位");
return ApiResultError(msg: "未找到合适的仓位");
}
}
else if (request.State == 100) // 任务完成
@@ -215,30 +243,76 @@ namespace HHWMS.Web
var invTrans = new List<InventoryTransaction>();
foreach (var inventory in inventories)
{
var material = _unitWork.FindSingle<Material>(x => x.MaterialCode == inventory.MaterialCode);
inventory.LocationCode = task.ToLocation;
if(task.TaskType == TaskTypeEnum.入库)
inventory.Qty = (request.Weight - ContainerWeight) / material.Qty;
inventory.TaskStatus = InventoryTaskStatusEnum.Idle;
// 创建库存交易记录 放到任务完成,计算数量信息
var invTransaction = new InventoryTransaction
// 线边库
if (inventory.ZoneId == 1027)
{
Type = task.TaskType == TaskTypeEnum.入库 ? InventoryTranType.入库 : InventoryTranType.出库,
ContainerCode = task.ContainerCode,
LocationCode = task.ToLocation,
MaterialCode = inventory.MaterialCode,
MaterialName = inventory.MaterialName,
MaterialSpec = inventory.MaterialSpec,
MaterialUnit = inventory.MaterialUnit,
Qty = inventory.Qty,
CreateTime = DateTime.Now
};
invTrans.Add(invTransaction);
if (task.TaskType == TaskTypeEnum.入库)
{
var material =
_unitWork.FindSingle<Material>(x => x.MaterialCode == inventory.MaterialCode);
inventory.Qty = (request.Weight - ContainerWeight) / material.Qty;
}
if (task.TaskType != TaskTypeEnum.移库)
{
// 创建库存交易记录 放到任务完成,计算数量信息
var invTransaction = new InventoryTransaction
{
Type = task.TaskType == TaskTypeEnum.入库
? InventoryTranType.入库
: InventoryTranType.出库,
ContainerCode = task.ContainerCode,
LocationCode = task.ToLocation,
MaterialCode = inventory.MaterialCode,
MaterialName = inventory.MaterialName,
MaterialSpec = inventory.MaterialSpec,
MaterialUnit = inventory.MaterialUnit,
Qty = inventory.Qty,
CreateTime = DateTime.Now
};
invTrans.Add(invTransaction);
}
else
{
// 创建库存交易记录 放到任务完成,计算数量信息
var invTransaction = new InventoryTransaction
{
Type = InventoryTranType.入库,
ContainerCode = task.ContainerCode,
LocationCode = task.ToLocation,
MaterialCode = inventory.MaterialCode,
MaterialName = inventory.MaterialName,
MaterialSpec = inventory.MaterialSpec,
MaterialUnit = inventory.MaterialUnit,
Qty = inventory.Qty,
CreateTime = DateTime.Now
};
invTrans.Add(invTransaction);
var invTransaction2 = new InventoryTransaction
{
Type = InventoryTranType.出库,
ContainerCode = task.ContainerCode,
LocationCode = task.ToLocation,
MaterialCode = inventory.MaterialCode,
MaterialName = inventory.MaterialName,
MaterialSpec = inventory.MaterialSpec,
MaterialUnit = inventory.MaterialUnit,
Qty = inventory.Qty,
CreateTime = DateTime.Now
};
invTrans.Add(invTransaction2);
}
}
inventory.TaskStatus = InventoryTaskStatusEnum.Idle;
}
if (invTrans.Any())
{
_unitWork.BatchAdd(invTrans);
}
_unitWork.BatchAdd(invTrans);
_unitWork.BatchUpdate(inventories);
@@ -246,24 +320,73 @@ namespace HHWMS.Web
var container = _unitWork.FindSingle<Container>(x => x.Code == task.ContainerCode);
if (container != null)
{
container.LocationCode = task.ToLocation;
container.LocationCode = task.TaskType == TaskTypeEnum.出库 ? "" : task.ToLocation;
container.IsLock = ContainerLockEnum.未锁;
container.UpdateTime = DateTime.Now;
}
_unitWork.Update(container);
// 更新库位状态
var location = task.TaskType == TaskTypeEnum.入库
? _unitWork.FindSingle<Location>(x => x.Code == task.ToLocation)
: _unitWork.FindSingle<Location>(x => x.Code == task.FromLocation);
if (location != null)
// 更新库位状态(区分入库、出库、移库)
switch (task.TaskType)
{
location.ContainerCode = task.TaskType == TaskTypeEnum.入库 ? request.PalletNo : "";
location.Status = LocationStatusEnum.未锁;
location.ContainerStatus = LocationStatus.空仓位;
location.UpdateTime = DateTime.Now;
case TaskTypeEnum.入库:
// 处理入库:更新目标库位
var inLocation = _unitWork.FindSingle<Location>(x => x.Code == task.ToLocation);
if (inLocation != null)
{
inLocation.ContainerCode = task.ContainerCode; // 绑定容器编码
inLocation.Status = LocationStatusEnum.未锁; // 标记为未锁状态
inLocation.ContainerStatus = inventories.Any() ? LocationStatus.有货 : LocationStatus.空容器;
inLocation.UpdateTime = DateTime.Now;
_unitWork.Update(inLocation);
}
break;
case TaskTypeEnum.出库:
// 处理出库:更新源库位
var outLocation = _unitWork.FindSingle<Location>(x => x.Code == task.FromLocation);
if (outLocation != null)
{
outLocation.ContainerCode = ""; // 清空容器编码
outLocation.Status = LocationStatusEnum.未锁; // 标记为未锁状态
outLocation.ContainerStatus = LocationStatus.空仓位; // 标记为空仓位
outLocation.UpdateTime = DateTime.Now;
_unitWork.Update(outLocation);
}
break;
case TaskTypeEnum.移库:
// 处理移库:同时更新源库位和目标库位
// 1. 更新源库位(移出后变为空)
var sourceLocation = _unitWork.FindSingle<Location>(x => x.Code == task.FromLocation);
if (sourceLocation != null)
{
sourceLocation.ContainerCode = "";
sourceLocation.Status = LocationStatusEnum.未锁;
sourceLocation.ContainerStatus = LocationStatus.空仓位;
sourceLocation.UpdateTime = DateTime.Now;
_unitWork.Update(sourceLocation);
}
// 2. 更新目标库位(移入后有容器)
var targetLocation = _unitWork.FindSingle<Location>(x => x.Code == task.ToLocation);
if (targetLocation != null)
{
targetLocation.ContainerCode = task.ContainerCode;
targetLocation.Status = LocationStatusEnum.未锁;
targetLocation.UpdateTime = DateTime.Now;
_unitWork.Update(targetLocation);
}
break;
default:
// 处理未定义的任务类型(可选)
throw new ArgumentOutOfRangeException($"未处理的任务类型:{task.TaskType}");
}
_unitWork.Update(location);
// 更新任务状态为完成
task.Status = TaskStatusEnum.完成;
@@ -285,7 +408,7 @@ namespace HHWMS.Web
}
}
}
/// <summary>
/// 请求空闲库位(带防抖)
@@ -297,7 +420,7 @@ namespace HHWMS.Web
{
return Task.FromResult<IActionResult>(ApiResultError("容器编码不能为空"));
}
if (!request.RoadWay.HasValue)
{
return Task.FromResult<IActionResult>(ApiResultError("巷道不能为空"));
@@ -312,10 +435,11 @@ namespace HHWMS.Web
var updateResult = UpdateLocationAndContainer(code.Data.LocationCode, request.PalletNo);
return Task.FromResult<IActionResult>(updateResult);
}
return Task.FromResult<IActionResult>(ApiResultError("没有符合条件的可用库位"));
});
}
/// <summary>
/// 更新库位和容器
/// </summary>
@@ -325,15 +449,16 @@ namespace HHWMS.Web
private IActionResult UpdateLocationAndContainer(string locationCode, string palletNo)
{
var location = _unitWork.Find<Location>(x => x.Code == locationCode).FirstOrDefault();
var resultNum = _unitWork.BatchUpdate<Location>(x => x.Code == locationCode && x.Version == location.Version,
var resultNum = _unitWork.BatchUpdate<Location>(
x => x.Code == locationCode && x.Version == location.Version,
x => new Location()
{
ContainerCode = palletNo,
// Status = LocationStatus.任务锁,
UpdateTime = DateTime.Now,
UpdateBy = "WMS",
Version = Guid.NewGuid()
});
{
ContainerCode = palletNo,
// Status = LocationStatus.任务锁,
UpdateTime = DateTime.Now,
UpdateBy = "WMS",
Version = Guid.NewGuid()
});
if (resultNum == 0)
{
//失败
@@ -350,4 +475,4 @@ namespace HHWMS.Web
return ApiResult(new { LocationCode = location?.Code });
}
}
}
}