成品库入库页面

库纯出库相关 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

@@ -87,62 +87,90 @@ namespace HHWMS.Web
/// <summary>
/// 查找双伸位巷道的空仓位
/// </summary>
private string GetEmptyLocationByDouble(int roadway, LocationTypeEnum locationType, decimal? height = 0)
private string GetEmptyLocationByDouble(int roadway, LocationTypeEnum locationType, string inPort,
decimal? height = 0)
{
// 一次性获取所需的所有数据,避免多次查询数据库
var locationPairs = DC.Set<Location>()
.Where(l => l.RoadWay == roadway
&& l.Type == locationType
.Where(l => l.Type == locationType
&& l.Status == LocationStatusEnum.未锁
&& !l.IsStop
&& l.Height >= height)
.Select(l => new
{
l.Code,
l.ContiguousCode,
l.Status,
l.ContainerStatus,
l.RowFlag,
l.Height,
l.Layer,
l.Line
})
.AsNoTracking()
.ToDictionary(l => l.Code);
if (locationPairs.Count <= 20)
{
return "";
}
// 1. 优先查找里外仓位都为空的里仓位
var emptyInnerLocation = locationPairs.Values
/// 1 7 8 优先1巷道
/// 4 9 10 优先2 巷道
var availableLocation = locationPairs.Values
.Where(l => l.RowFlag == RowFlagEnum.Inner
&& l.Status == LocationStatusEnum.未锁
&& l.ContainerStatus == LocationStatus.空仓位
&& locationPairs.TryGetValue(l.ContiguousCode, out var outer)
&& outer.Status == LocationStatusEnum.未锁
&& outer.ContainerStatus == LocationStatus.空仓位)
.OrderBy(l => l.Height)
.ThenBy(l => l.Layer)
.ThenBy(l => l.Line)
.FirstOrDefault();
.ToList();
if (emptyInnerLocation != null)
if (availableLocation.Any())
{
return emptyInnerLocation.Code;
return GetSortedLocationCode(availableLocation, inPort) ?? availableLocation.First().Code;
}
// 2. 查找里仓位有货,外仓位为空的外仓位
var availableOuterLocation = locationPairs.Values
.Where(l => l.RowFlag == 0
availableLocation = locationPairs.Values
.Where(l => l.RowFlag == RowFlagEnum.Outer
&& l.Status == LocationStatusEnum.未锁
&& l.ContainerStatus == LocationStatus.空仓位
&& locationPairs.TryGetValue(l.ContiguousCode, out var inner)
&& inner.Status == LocationStatusEnum.未锁
&& inner.ContainerStatus == LocationStatus.有货)
.OrderBy(l => l.Height)
.ThenBy(l => l.Layer)
.ThenBy(l => l.Line)
.FirstOrDefault();
return availableOuterLocation?.Code;
.ToList();
return GetSortedLocationCode(availableLocation, inPort) ?? availableLocation.First().Code;
}
private string GetSortedLocationCode(List<Location> locations, string inPort)
{
if (locations == null || !locations.Any())
return null;
// 定义端口组与排序规则的映射(键:端口数组,值:排序函数)
var portSortMappings = new Dictionary<string[], Func<IEnumerable<Location>, IOrderedEnumerable<Location>>>
{
{
new[] { "EnterExit_P1001" },
locs => locs.OrderBy(x => x.Height).ThenBy(x => x.RoadWay).ThenBy(l => l.Layer).ThenByDescending(x => x.Line)
},
{
new[] { "EnterExit_P1007", "EnterExit_P1008" },
locs => locs.OrderBy(x => x.Height).ThenBy(x => x.RoadWay).ThenBy(l => l.Layer).ThenBy(x => x.Line)
},
{
new[] { "EnterExit_P1004" },
locs => locs.OrderBy(x => x.Height).ThenByDescending(x => x.RoadWay).ThenBy(l => l.Layer).ThenByDescending(x => x.Line)
},
{
new[] { "EnterExit_P1009", "EnterExit_P1010" },
locs => locs.OrderBy(x => x.Height).ThenByDescending(x => x.RoadWay).ThenBy(l => l.Layer).ThenBy(x => x.Line)
}
};
// 查找匹配的端口组,应用排序规则
foreach (var (ports, sortFunc) in portSortMappings)
{
if (ports.Contains(inPort))
{
return sortFunc(locations).FirstOrDefault()?.Code;
}
}
// 无匹配端口时,返回默认排序的第一个
return locations.FirstOrDefault()?.Code;
}
/// <summary>
/// 根据巷道类型查找可用仓位
/// </summary>
@@ -169,7 +197,8 @@ namespace HHWMS.Web
break;
case 4: // 双伸位
locationCode =
GetEmptyLocationByDouble(request.RoadWay.Value, request.LocationType, request.Height);
GetEmptyLocationByDouble(request.RoadWay.Value, request.LocationType, request.InPort,
request.Height);
break;
default:
return ResponseResult<dynamic>.Error("未知的巷道类型");
@@ -364,5 +393,181 @@ namespace HHWMS.Web
Total = availableLocations.Count
});
}
/// <summary>
/// 下发任务到wcs
/// </summary>
/// <param name="taskHeader"></param>
/// <returns></returns>
public ResponseResult<dynamic> SendWcsTask(TaskHeader task)
{
// 下发任务到wcs
// 1.入库任务直接下发
// 2.出库任务 判断是否为双伸位库位
// 2.1 单伸位:直接下发
// 2.2 双伸位:判断出库库位是否为里仓位
// 2.2.1 里仓位,判断是否需要移库,先生成移库任务,再下发出库任务
// 2.2.2 外仓位,直接下发
var _unitWork = new UnitWork(Wtm);
if (task.TaskType != TaskTypeEnum.入库)
{
var loc = DC.Set<Location>().Where(x => x.Code == task.FromLocation)
.AsNoTracking()
.FirstOrDefault();
// 双伸位 并且里仓位
if (loc != null && loc.RowFlag == RowFlagEnum.Inner && !string.IsNullOrWhiteSpace(loc.ContiguousCode))
{
var outter = DC.Set<Location>().FirstOrDefault(x => x.Code == loc.ContiguousCode);
if (outter != null && outter.Status == LocationStatusEnum.未锁 &&
outter.ContainerStatus != LocationStatus.空仓位)
{
// 查找移库仓位
var moveloc = GetMoveLocation(outter);
if (moveloc.Status)
{
string code = moveloc.Data.Code;
var movelocation = _unitWork.FindSingle<Location>(x => x.Code == code);
// 生成outter移库任务
var outterTask = new TaskHeader()
{
ZoneId = outter.ZoneId,
TaskNo = _unitWork.GetSerialNumber("Move"),
TaskType = TaskTypeEnum.移库,
ContainerCode = outter.ContainerCode,
FromLocation = outter.Code,
ToLocation = movelocation.Code,
Status = TaskStatusEnum.待下发,
CreateTime = DateTime.Now,
CreateBy = Wtm?.LoginUserInfo?.ITCode ?? "WMS",
};
var result = SendWcsTask(outterTask);
if (result.Status)
{
movelocation.Status = LocationStatusEnum.锁定;
_unitWork.Update(movelocation);
outter.Status = LocationStatusEnum.锁定;
_unitWork.Update(outter);
}
else
{
return result;
}
}
else
{
return moveloc;
}
}
}
}
// 下发任务到wcs
var postData = new
{
TaskNo = task.TaskNo,
PalletNo = task.ContainerCode,
FromLocation = task.FromLocation,
ToLocation = task.ToLocation
};
task.Status = TaskStatusEnum.已下发;
task.UpdateTime = DateTime.Now;
task.UpdateBy = "WMS";
_unitWork.Add(task);
/*try
{
var domain = task.ZoneId == 1027 ? "WCSXB" : "WCSCP";
var res = Wtm.CallAPI<ApiJsonResult<dynamic>>(domain, "TaskAssign", HttpMethodEnum.POST, postData)
.Result?.Data;
if (res != null && res.Success)
{
task.Status = TaskStatusEnum.已下发;
task.UpdateTime = DateTime.Now;
task.UpdateBy = "WMS";
_unitWork.Add(task);
}
else
{
task.ErrorMsg = res?.Msg;
return ResponseResult<dynamic>.Error(res?.Msg);
}
}
catch (Exception ex)
{
task.ErrorMsg = ex.Message;
return ResponseResult<dynamic>.Error("任务下发失败!");
}*/
return ResponseResult<dynamic>.Success();
}
public ResponseResult<dynamic> GetMoveLocation(Location outter)
{
// 查找移库仓位
// 一次性获取所需的所有数据,避免多次查询数据库
var locationPairs = DC.Set<Location>()
.Where(l => l.Type == outter.Type
&& !l.IsStop
&& l.Status == LocationStatusEnum.未锁
&& l.Height >= outter.Height)
.Select(l => new
{
l.RoadWay,
l.Code,
l.ContiguousCode,
l.Status,
l.ContainerStatus,
l.RowFlag,
l.Height,
l.Layer,
l.Line
})
.AsNoTracking()
.ToDictionary(l => l.Code);
// 1. 优先查找里外仓位都为空的里仓位
var moveloc = locationPairs.Values
.Where(l => l.RowFlag == RowFlagEnum.Inner
&& l.ContainerStatus == LocationStatus.空仓位
&& locationPairs.TryGetValue(l.ContiguousCode, out var outer)
&& outer.ContainerStatus == LocationStatus.空仓位)
.OrderBy(l => l.Height)
.ThenBy(l => Math.Abs(outter.RoadWay - l.RoadWay))
.ThenBy(l => Math.Abs(outter.Line - l.Line))
.ThenBy(l => l.Layer)
.FirstOrDefault();
if (moveloc == null)
{
// 2. 查找里仓位有货,外仓位为空的外仓位
moveloc = locationPairs.Values
.Where(l => l.RowFlag == RowFlagEnum.Outer
&& l.ContainerStatus == LocationStatus.空仓位
&& locationPairs.TryGetValue(l.ContiguousCode, out var inner)
&& inner.Status == LocationStatusEnum.未锁
&& inner.ContainerStatus == LocationStatus.有货)
.OrderBy(l => Math.Abs((decimal)outter.Height - (decimal)l.Height))
.ThenBy(l => Math.Abs(outter.RoadWay - l.RoadWay))
.ThenBy(l => Math.Abs(outter.Line - l.Line))
.ThenBy(l => l.Layer)
.FirstOrDefault();
if (moveloc == null)
{
return ResponseResult<dynamic>.Error("找不到可用的移库仓位!");
}
else
{
return ResponseResult<dynamic>.Success(new { LocationCode = moveloc.Code });
}
}
else
{
return ResponseResult<dynamic>.Success(new { LocationCode = moveloc.Code });
}
}
}
}