将查找仓位方法移到LocationVM
This commit is contained in:
1 parent
2bfda34103
commit
45bc46a828
3 files changed
+354
-109
No files matched your search
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user