累计下发出库任务, 判断料塔是否存在可用层,有就下发出库任务

This commit is contained in:
zgf committed 2023-11-30 18:44:01 +08:00
1 parent 8e11aa092b
commit 11ea24c544
2 files changed
+42 -23

No files matched your search

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -174,11 +175,19 @@ namespace HHWMS.Web
&& x.Type.Equals(LocationTypeEnum.堆垛机工位)).FirstOrDefault(); && x.Type.Equals(LocationTypeEnum.堆垛机工位)).FirstOrDefault();
var cTask = _unitwork.Find<TaskHeader>(x => x.ContainerCode == item.Key var cTask = _unitwork.Find<TaskHeader>(x => x.ContainerCode == item.Key
&& x.TaskType == TaskTypeEnum.盘料盒出库).FirstOrDefault(); && x.TaskType == TaskTypeEnum.盘料盒出库).FirstOrDefault();
if (gLoc != null || cTask != null) //查找料塔工位 T
var tLoc = _unitwork.Find<Location>(x => x.Row == row
&& x.Type.Equals(LocationTypeEnum.料塔))
.FirstOrDefault();
if(_unitwork.IsExit<TaskHeader>(x => x.FromLocation.Equals(tLoc.Code)))
{ {
//盘料箱已在堆垛机工位,或者有此料箱的出库任务,直接生成盘料出库任务 continue;
} }
else //if (gLoc != null || cTask != null)
//{
// //盘料箱已在堆垛机工位,或者有此料箱的出库任务,直接生成盘料出库任务
//}
if (gLoc == null && cTask == null)
{ {
// 盘料箱在库内,工位为空,先生成料盘箱出库任务 // 盘料箱在库内,工位为空,先生成料盘箱出库任务
@@ -212,14 +221,8 @@ namespace HHWMS.Web
} }
} }
if (gLoc != null) if (gLoc != null || cTask != null)
{ {
//查找料塔工位 T
var tLoc = _unitwork.Find<Location>(x => string.IsNullOrEmpty(x.ContainerCode)
&& x.Row == row
&& x.Type.Equals(LocationTypeEnum.料塔))
.FirstOrDefault();
//判断是否存在此托盘的出库任务 //判断是否存在此托盘的出库任务
var containerTask = _unitwork.Find<TaskHeader>(x => x.Status < TaskStatusEnum.已下发 var containerTask = _unitwork.Find<TaskHeader>(x => x.Status < TaskStatusEnum.已下发
&& x.ContainerCode == item.Key && x.ContainerCode == item.Key
@@ -231,9 +234,10 @@ namespace HHWMS.Web
tLoc = _unitwork.Find<Location>(x => x.Code == containerTask.ToLocation tLoc = _unitwork.Find<Location>(x => x.Code == containerTask.ToLocation
&& x.Type.Equals(LocationTypeEnum.料塔)) && x.Type.Equals(LocationTypeEnum.料塔))
.FirstOrDefault(); .FirstOrDefault();
var canUse = CalCanUse(Convert.ToInt32(tLoc.Length), containerTask.ToLocation,_unitwork);
foreach (var inventory in item) foreach (var inventory in item)
{ {
if (tLoc.Height < tLoc.Length) if (canUse.Length > 0)
{ {
// 库存不在已建任务明细中,新增任务明细 // 库存不在已建任务明细中,新增任务明细
if (!containerTask.TaskDetails.Any(x => x.UniqueCode.Equals(inventory.UniqueCode))) if (!containerTask.TaskDetails.Any(x => x.UniqueCode.Equals(inventory.UniqueCode)))
@@ -243,24 +247,25 @@ namespace HHWMS.Web
UniqueCode = inventory.UniqueCode, UniqueCode = inventory.UniqueCode,
Lot = $"{Convert.ToInt32(location.Length)}-{tLoc.Code}", Lot = $"{Convert.ToInt32(location.Length)}-{tLoc.Code}",
FromLocation = inventory.Lot, FromLocation = inventory.Lot,
ToLocation = (Convert.ToInt32(tLoc.Height) + 1).ToString(), ToLocation = canUse.First().ToString(),
Status = TaskStatusEnum.待下发, Status = TaskStatusEnum.待下发,
ContainerCode = inventory.ContainerCode, ContainerCode = inventory.ContainerCode,
CreateTime = DateTime.Now CreateTime = DateTime.Now
}); });
tLoc.Height += 1; canUse = canUse.Where(x => x != canUse.First()).ToArray();
} }
//存在 //存在
else else
{ {
var i = containerTask.TaskDetails.Where(x => x.Status == TaskStatusEnum.新建 var i = containerTask.TaskDetails.Where(x => x.UniqueCode == inventory.UniqueCode)
&& x.UniqueCode == inventory.UniqueCode)
.FirstOrDefault(); .FirstOrDefault();
if (string.IsNullOrEmpty(i.ToLocation))
i.Lot = $"{Convert.ToInt32(location.Length)}-{tLoc.Code}"; {
i.ToLocation = (Convert.ToInt32(tLoc.Height) + 1).ToString(); i.Lot = $"{Convert.ToInt32(location.Length)}-{tLoc.Code}";
i.Status = TaskStatusEnum.待下发; i.ToLocation = canUse.First().ToString();
tLoc.Height += 1; i.Status = TaskStatusEnum.待下发;
canUse = canUse.Where(x => x != canUse.First()).ToArray();
}
} }
} }
else else
@@ -297,22 +302,23 @@ namespace HHWMS.Web
task.ToLocation = tLoc.Code; task.ToLocation = tLoc.Code;
task.CreateTime = DateTime.Now; task.CreateTime = DateTime.Now;
task.CreateBy = "wmsjob"; task.CreateBy = "wmsjob";
var canUse = CalCanUse(Convert.ToInt32(tLoc.Length), tLoc.Code, _unitwork);
foreach (var inventory in item) foreach (var inventory in item)
{ {
if (tLoc.Height < tLoc.Length) if (canUse.Length > 0)
{ {
var detail = new TaskDetail var detail = new TaskDetail
{ {
UniqueCode = inventory.UniqueCode, UniqueCode = inventory.UniqueCode,
Lot = $"{Convert.ToInt32(location.Length)}-{tLoc.Code}", Lot = $"{Convert.ToInt32(location.Length)}-{tLoc.Code}",
FromLocation = inventory.Lot, FromLocation = inventory.Lot,
ToLocation = (Convert.ToInt32(tLoc.Height) + 1).ToString(), ToLocation = canUse.First().ToString(),
Status = TaskStatusEnum.新建, Status = TaskStatusEnum.新建,
ContainerCode = inventory.ContainerCode, ContainerCode = inventory.ContainerCode,
CreateTime = DateTime.Now CreateTime = DateTime.Now
}; };
task.TaskDetails.Add(detail); task.TaskDetails.Add(detail);
tLoc.Height += 1; canUse = canUse.Where(x => x != canUse.First()).ToArray();
} }
else else
{ {
@@ -551,5 +557,17 @@ namespace HHWMS.Web
} }
} }
} }
public int[] CalCanUse(int length, string code, UnitWork _unitwork)
{
var used1 = _unitwork.Find<Inventory>(x => x.LocationCode.Equals(code))
.Select(x => int.Parse(x.Lot)).ToArray();
var used2 = _unitwork.Find<TaskDetail>(x => x.Lot.Contains(code))
.Select(x => int.Parse(x.ToLocation)).ToArray();
var used = used1.Union(used2);
var caseList = Enumerable.Range(1, length).ToArray();
var canUse = caseList.Except(used).ToArray<int>();
return canUse;
}
} }
} }
@@ -26,6 +26,7 @@ namespace HHWMS.Web.Models
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")] [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string MaterialCode { get; set; } public string MaterialCode { get; set; }
[Required]
[Display(Name = "Inventory.UniqueCode", Description = "唯一编码")] [Display(Name = "Inventory.UniqueCode", Description = "唯一编码")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")] [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string UniqueCode { get; set; } public string UniqueCode { get; set; }