将查找仓位方法移到LocationVM
This commit is contained in:
parent
2bfda34103
commit
45bc46a828
@ -4,6 +4,7 @@ using AutoMapper;
|
||||
using HHWMS.Web.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SqlSugar;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
namespace HHWMS.Web
|
||||
@ -46,5 +47,122 @@ namespace HHWMS.Web
|
||||
{
|
||||
return ApiResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求空闲库位
|
||||
/// </summary>
|
||||
/// <param name="request">包含容器编码的请求</param>
|
||||
/// <returns>返回空闲库位信息</returns>
|
||||
[HttpPost]
|
||||
/*public IActionResult RequestLocation(WcsRequest request)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request?.PalletNo))
|
||||
{
|
||||
return ApiResultError("容器编码不能为空");
|
||||
}
|
||||
|
||||
// 1. 优先查找里外仓位都为空的里仓位
|
||||
var innerLocation = _unitwork.Find<Location>(x => 1 == 1)
|
||||
.Join(_unitwork.Find<Location>(x => 1 == 1),
|
||||
inner => inner.ContiguousCode,
|
||||
outer => outer.Code,
|
||||
(inner, outer) => new { Inner = inner, Outer = outer })
|
||||
.Where(x => x.Inner.RowFlag == 1
|
||||
&& x.Inner.Status == "empty"
|
||||
&& x.Outer.Status == "empty")
|
||||
.Select(x => x.Inner)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (innerLocation != null)
|
||||
{
|
||||
// 更新库位表的ContainerCode为请求的PalletNo
|
||||
innerLocation.ContainerCode = request.PalletNo;
|
||||
_unitwork.Update(innerLocation);
|
||||
|
||||
// 更新容器表的LocationCode为分配到的库位编码
|
||||
var container = _unitwork.Find<Container>(x => x.Code == request.PalletNo).FirstOrDefault();
|
||||
if (container != null)
|
||||
{
|
||||
container.LocationCode = innerLocation.Code;
|
||||
_unitwork.Update(container);
|
||||
}
|
||||
|
||||
return ApiResult(new
|
||||
{
|
||||
LocationCode = innerLocation.Code
|
||||
});
|
||||
}
|
||||
|
||||
// 2. 查找里仓位有货,外仓位无货的外仓位
|
||||
var outerLocation = _unitwork.Find<Location>(x => 1 == 1)
|
||||
.Join(_unitwork.Find<Location>(x => 1 == 1),
|
||||
outer => outer.ContiguousCode,
|
||||
inner => inner.Code,
|
||||
(outer, inner) => new { Outer = outer, Inner = inner })
|
||||
.Where(x => x.Outer.RowFlag == 0
|
||||
&& x.Outer.Status == "empty"
|
||||
&& x.Inner.Status == "some")
|
||||
.Select(x => x.Outer)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (outerLocation != null)
|
||||
{
|
||||
// 更新库位表的ContainerCode为请求的PalletNo
|
||||
outerLocation.ContainerCode = request.PalletNo;
|
||||
_unitwork.Update(outerLocation);
|
||||
|
||||
// 更新容器表的LocationCode为分配到的库位编码
|
||||
var container = _unitwork.Find<Container>(x => x.Code == request.PalletNo).FirstOrDefault();
|
||||
if (container != null)
|
||||
{
|
||||
container.LocationCode = outerLocation.Code;
|
||||
_unitwork.Update(container);
|
||||
}
|
||||
|
||||
return ApiResult(new
|
||||
{
|
||||
LocationCode = outerLocation.Code
|
||||
});
|
||||
}
|
||||
|
||||
return ApiResultError("没有符合条件的可用库位");
|
||||
}
|
||||
*/
|
||||
public IActionResult RequestLocation(WcsRequest request)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request?.PalletNo))
|
||||
{
|
||||
return ApiResultError("容器编码不能为空");
|
||||
}
|
||||
|
||||
var vm = Wtm.CreateVM<LocationVM>();
|
||||
var code = vm.GetLocation(request);
|
||||
if (code.Status)
|
||||
{
|
||||
UpdateLocationAndContainer(code.Data.LocationCode, request.PalletNo);
|
||||
return ApiResult(code.Data);
|
||||
}
|
||||
|
||||
return ApiResultError("没有符合条件的可用库位");
|
||||
|
||||
}
|
||||
|
||||
private IActionResult UpdateLocationAndContainer(string locationCode, string palletNo)
|
||||
{
|
||||
var location = _unitwork.Find<Location>(x => x.Code == locationCode).FirstOrDefault();
|
||||
location.ContainerCode = palletNo;
|
||||
location.Status = LocationStatus.任务锁;
|
||||
_unitwork.Update(location);
|
||||
|
||||
var container = _unitwork.Find<Container>(x => x.Code == palletNo).FirstOrDefault();
|
||||
if (container != null)
|
||||
{
|
||||
container.LocationCode = location.Code;
|
||||
_unitwork.Update(container);
|
||||
}
|
||||
|
||||
return ApiResult(new { LocationCode = location.Code });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ namespace HHWMS.Web.Controllers
|
||||
Row = row,
|
||||
Line = line,
|
||||
Layer = layer,
|
||||
RowFlag = (short?)(row == 1 || row == 4 ? 1 : 0),
|
||||
RowFlag = (short?)(vm.RoadwayType == 1 || vm.RoadwayType == 2 ? 0 : (row == 1 || row == 4 ? 1 : 0)),
|
||||
ContiguousCode = vm.RoadwayType == 4 ? $"{vm.Entity.Type}{vm.Entity.RoadWay.ToString().PadLeft(2, '0')}-{(row % 2 == 0?row-1:row+1) .ToString().PadLeft(2, '0')}-{line.ToString().PadLeft(2, '0')}-{layer.ToString().PadLeft(2, '0')}" : null,
|
||||
IsStop = false,
|
||||
Status = LocationStatus.空仓位,
|
||||
|
||||
@ -11,6 +11,10 @@ namespace HHWMS.Web
|
||||
{
|
||||
public partial class LocationVM : BaseCRUDVM<Location>
|
||||
{
|
||||
public LocationVM()
|
||||
{
|
||||
}
|
||||
|
||||
public InventoryListVM Inventorys { get; set; } = new InventoryListVM();
|
||||
|
||||
[Display(Name = "Location.BeginLine", Description = "起始列")]
|
||||
@ -32,10 +36,6 @@ namespace HHWMS.Web
|
||||
public List<ComboSelectListItem> Types { get; set; }
|
||||
public List<ComboSelectListItem> LocationStatus { get; set; }
|
||||
|
||||
public LocationVM()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitVM()
|
||||
{
|
||||
Inventorys.CopyContext(this);
|
||||
@ -88,123 +88,250 @@ namespace HHWMS.Web
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找库位
|
||||
/// 查找单伸位巷道的空仓位
|
||||
/// </summary>
|
||||
private string GetEmptyLocationBySingle(int? roadway)
|
||||
{
|
||||
var locations = DC.Set<Location>()
|
||||
.Where(l => l.RoadWay == roadway
|
||||
&& l.Status == "empty"
|
||||
&& l.RowFlag == 0) // 单伸位只查找外仓位
|
||||
.OrderBy(l => l.Layer)
|
||||
.ThenBy(l => l.Line)
|
||||
.FirstOrDefault();
|
||||
|
||||
return locations?.Code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找双伸位巷道的空仓位
|
||||
/// </summary>
|
||||
private string GetEmptyLocationByDouble(int roadway)
|
||||
{
|
||||
// 一次性获取所需的所有数据,避免多次查询数据库
|
||||
var locationPairs = DC.Set<Location>()
|
||||
.Where(l => l.RoadWay == roadway)
|
||||
.Select(l => new
|
||||
{
|
||||
l.Code,
|
||||
l.ContiguousCode,
|
||||
l.Status,
|
||||
l.RowFlag,
|
||||
l.Layer,
|
||||
l.Line
|
||||
})
|
||||
.ToDictionary(l => l.Code);
|
||||
|
||||
// 1. 优先查找里外仓位都为空的里仓位
|
||||
var emptyInnerLocation = locationPairs.Values
|
||||
.Where(l => l.RowFlag == 1
|
||||
&& l.Status == "empty"
|
||||
&& locationPairs.TryGetValue(l.ContiguousCode, out var outer)
|
||||
&& outer.Status == "empty")
|
||||
.OrderBy(l => l.Layer)
|
||||
.ThenBy(l => l.Line)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (emptyInnerLocation != null)
|
||||
{
|
||||
return emptyInnerLocation.Code;
|
||||
}
|
||||
|
||||
// 2. 查找里仓位有货,外仓位为空的外仓位
|
||||
var availableOuterLocation = locationPairs.Values
|
||||
.Where(l => l.RowFlag == 0
|
||||
&& l.Status == "empty"
|
||||
&& locationPairs.TryGetValue(l.ContiguousCode, out var inner)
|
||||
&& inner.Status == "some")
|
||||
.OrderBy(l => l.Layer)
|
||||
.ThenBy(l => l.Line)
|
||||
.FirstOrDefault();
|
||||
|
||||
return availableOuterLocation?.Code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据巷道类型查找可用仓位
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ResponseResult<dynamic> GetLocation(WcsRequest request)
|
||||
{
|
||||
var res = ResponseResult<dynamic>.Success(new {LocationCode = "test"});
|
||||
return res;
|
||||
//return GetOutEmptyLocation(request);
|
||||
/*if (request.RoadWay == null)
|
||||
if (!request.RoadWay.HasValue)
|
||||
{
|
||||
// 根据条件查询巷道 (巷道均分,根据托盘类型分)
|
||||
request.RoadWay = SelectRoadWay(request);
|
||||
if(SelectRoadWay(request) == 0)
|
||||
return ResponseResult<dynamic>.Error("巷道号不能为空");
|
||||
}
|
||||
|
||||
// 获取巷道类型
|
||||
var roadwayType = GetRoadwayType(request.RoadWay);
|
||||
if (roadwayType == null)
|
||||
{
|
||||
return ResponseResult<dynamic>.Error("未找到对应的巷道类型");
|
||||
}
|
||||
|
||||
string locationCode;
|
||||
switch (roadwayType)
|
||||
{
|
||||
case 1: // 单边位
|
||||
case 2: // 单伸位
|
||||
locationCode = GetEmptyLocationBySingle(request.RoadWay.Value);
|
||||
break;
|
||||
case 4: // 双伸位
|
||||
locationCode = GetEmptyLocationByDouble(request.RoadWay.Value);
|
||||
break;
|
||||
default:
|
||||
return ResponseResult<dynamic>.Error("未知的巷道类型");
|
||||
}
|
||||
|
||||
if (locationCode == null)
|
||||
{
|
||||
return ResponseResult<dynamic>.Error("未找到可用的空仓位");
|
||||
}
|
||||
|
||||
return ResponseResult<dynamic>.Success(new { LocationCode = locationCode });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据巷道名称获取巷道类型
|
||||
/// </summary>
|
||||
/// <param name="roadwayName">巷道名称</param>
|
||||
/// <returns>巷道类型(2代表单伸位,4代表双伸位)</returns>
|
||||
private int? GetRoadwayType(int? roadwayName)
|
||||
{
|
||||
var dictData = DC.Set<SysDictData>()
|
||||
.FirstOrDefault(x => x.DictType == "RoadwayConfig" && x.DictLabel == roadwayName.ToString());
|
||||
|
||||
if (dictData != null)
|
||||
{
|
||||
if (int.TryParse(dictData.DictValue, out int roadwayType))
|
||||
{
|
||||
return ResponseResult<dynamic>.Error("未找到可用巷道!");
|
||||
return roadwayType;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有巷道的可用仓位
|
||||
/// </summary>
|
||||
public ResponseResult<dynamic> GetAllAvailableLocations()
|
||||
{
|
||||
// 获取所有巷道配置
|
||||
var roadwayConfigs = DC.Set<SysDictData>()
|
||||
.Where(x => x.DictType == "RoadwayConfig")
|
||||
.Select(x => new
|
||||
{
|
||||
Roadway = x.DictLabel,
|
||||
Type = x.DictValue
|
||||
})
|
||||
.ToDictionary(x => x.Roadway, x => x.Type);
|
||||
|
||||
if (!roadwayConfigs.Any())
|
||||
{
|
||||
// 查询该巷道类型 调用不同的方法
|
||||
return GetLocationByOne(request);
|
||||
return ResponseResult<dynamic>.Error("未找到巷道配置");
|
||||
}
|
||||
return "";*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单伸位 查找仓位
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetLocationByOne(WcsRequest request)
|
||||
{
|
||||
// 根据托盘类型/传入的长宽高 查找库位
|
||||
var locationList = _unitWork.Find<Location>(x => x.RoadWay == request.RoadWay);
|
||||
locationList = locationList.WhereIf(request.Length > 0, x => x.Length == request.Length)
|
||||
.WhereIf(request.Width > 0, x => x.Width == request.Width)
|
||||
.WhereIf(request.Height > 0, x => x.Height >= request.Height)
|
||||
.OrderBy(x => x.Height);
|
||||
var location = locationList.OrderBy(x => x.Layer)
|
||||
.ThenBy(x => x.Line)
|
||||
.FirstOrDefault();
|
||||
return location?.Code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 双伸位 查找仓位
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetLocationByTwo(WcsRequest request)
|
||||
{
|
||||
// 根据托盘类型 查找库位 todo
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 双伸位,获取里仓位有货,外仓位无货的仓位
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetOutEmptyLocation(WcsRequest request)
|
||||
{
|
||||
int roadWay = (int)request.RoadWay;
|
||||
var locationList = _unitWork.Find<Location>(x => x.RoadWay == roadWay)
|
||||
.Join(_unitWork.Find<Location>(x => x.RoadWay == roadWay),
|
||||
a => a.ContiguousCode, g => g.Code,
|
||||
(a, g) => new
|
||||
// 一次性获取所有库位数据
|
||||
var allLocations = DC.Set<Location>()
|
||||
.Select(l => new
|
||||
{
|
||||
a.Code,
|
||||
a.Status,
|
||||
a.RowFlag,
|
||||
a.Layer,
|
||||
a.Line,
|
||||
ContiguousCode = g.Code,
|
||||
Status1 = g.Status
|
||||
}).ToList();
|
||||
var location = locationList.Where(x => x.RowFlag == 0 && x.Status == "empty" && x.Status1 == "some")
|
||||
.OrderBy(x => x.Layer)
|
||||
.ThenBy(x => x.Line)
|
||||
.FirstOrDefault()?.Code;
|
||||
return location;
|
||||
}
|
||||
l.Code,
|
||||
l.ContiguousCode,
|
||||
l.Status,
|
||||
l.RowFlag,
|
||||
l.Layer,
|
||||
l.Line,
|
||||
l.RoadWay,
|
||||
l.ZoneCode
|
||||
})
|
||||
.ToDictionary(l => l.Code);
|
||||
|
||||
/// <summary>
|
||||
/// 双伸位,获取里外仓位都为空的仓位
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="rowFlag">0 返回外仓位,1返回里仓位</param>
|
||||
/// <returns></returns>
|
||||
public string GetAllEmptyLocation(WcsRequest request, int rowFlag)
|
||||
{
|
||||
int roadWay = (int)request.RoadWay;
|
||||
var locationList = _unitWork.Find<Location>(x => x.RoadWay == roadWay)
|
||||
.Join(_unitWork.Find<Location>(x => x.RoadWay == roadWay),
|
||||
a => a.ContiguousCode, g => g.Code,
|
||||
(a, g) => new
|
||||
var availableLocations = new List<object>();
|
||||
|
||||
// 按巷道类型分组处理
|
||||
foreach (var config in roadwayConfigs)
|
||||
{
|
||||
var roadway = int.Parse(config.Key);
|
||||
var locationType = config.Value;
|
||||
|
||||
// 获取当前巷道的所有仓位
|
||||
var roadwayLocations = allLocations.Values
|
||||
.Where(l => l.RoadWay == roadway)
|
||||
.ToList();
|
||||
|
||||
if (!roadwayLocations.Any()) continue;
|
||||
|
||||
// 根据巷道类型处理
|
||||
switch (locationType)
|
||||
{
|
||||
a.Code,
|
||||
a.Status,
|
||||
a.RowFlag,
|
||||
a.Layer,
|
||||
a.Line,
|
||||
ContiguousCode = g.Code,
|
||||
Status1 = g.Status
|
||||
}).ToList();
|
||||
var location = locationList.Where(x => x.RowFlag == rowFlag && x.Status == "empty" && x.Status1 == "empty")
|
||||
.OrderBy(x => x.Layer)
|
||||
.ThenBy(x => x.Line)
|
||||
.FirstOrDefault()?.Code;
|
||||
return location;
|
||||
}
|
||||
case "2": // 单伸位
|
||||
var singleLocations = roadwayLocations
|
||||
.Where(l => l.RowFlag == 0 && l.Status == "empty")
|
||||
.OrderBy(l => l.Layer)
|
||||
.ThenBy(l => l.Line)
|
||||
.Select(l => new
|
||||
{
|
||||
LocationCode = l.Code,
|
||||
l.ZoneCode,
|
||||
l.RoadWay,
|
||||
l.Layer,
|
||||
l.Line,
|
||||
Type = "单伸位"
|
||||
});
|
||||
availableLocations.AddRange(singleLocations);
|
||||
break;
|
||||
|
||||
/// <summary>
|
||||
/// 根据传入条件,查找可利用巷道
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public int SelectRoadWay(WcsRequest request)
|
||||
{
|
||||
return 1;
|
||||
case "4": // 双伸位
|
||||
// 1. 查找里外都为空的里仓位
|
||||
var emptyInnerLocations = roadwayLocations
|
||||
.Where(l => l.RowFlag == 1
|
||||
&& l.Status == "empty"
|
||||
&& allLocations.TryGetValue(l.ContiguousCode, out var outer)
|
||||
&& outer.Status == "empty")
|
||||
.OrderBy(l => l.Layer)
|
||||
.ThenBy(l => l.Line)
|
||||
.Select(l => new
|
||||
{
|
||||
LocationCode = l.Code,
|
||||
l.ZoneCode,
|
||||
l.RoadWay,
|
||||
l.Layer,
|
||||
l.Line,
|
||||
Type = "双伸位-里仓位"
|
||||
});
|
||||
availableLocations.AddRange(emptyInnerLocations);
|
||||
|
||||
// 2. 查找里仓位有货,外仓位为空的外仓位
|
||||
var availableOuterLocations = roadwayLocations
|
||||
.Where(l => l.RowFlag == 0
|
||||
&& l.Status == "empty"
|
||||
&& allLocations.TryGetValue(l.ContiguousCode, out var inner)
|
||||
&& inner.Status == "some")
|
||||
.OrderBy(l => l.Layer)
|
||||
.ThenBy(l => l.Line)
|
||||
.Select(l => new
|
||||
{
|
||||
LocationCode = l.Code,
|
||||
l.ZoneCode,
|
||||
l.RoadWay,
|
||||
l.Layer,
|
||||
l.Line,
|
||||
Type = "双伸位-外仓位"
|
||||
});
|
||||
availableLocations.AddRange(availableOuterLocations);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!availableLocations.Any())
|
||||
{
|
||||
return ResponseResult<dynamic>.Error("未找到可用的空仓位");
|
||||
}
|
||||
|
||||
return ResponseResult<dynamic>.Success(new
|
||||
{
|
||||
Locations = availableLocations,
|
||||
Total = availableLocations.Count
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user