diff --git a/HHWMS.Web/Areas/Api/IWCSController.cs b/HHWMS.Web/Areas/Api/IWCSController.cs
index 888314a..0fbc08d 100644
--- a/HHWMS.Web/Areas/Api/IWCSController.cs
+++ b/HHWMS.Web/Areas/Api/IWCSController.cs
@@ -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();
}
+
+ ///
+ /// 请求空闲库位
+ ///
+ /// 包含容器编码的请求
+ /// 返回空闲库位信息
+ [HttpPost]
+ /*public IActionResult RequestLocation(WcsRequest request)
+ {
+ if (string.IsNullOrEmpty(request?.PalletNo))
+ {
+ return ApiResultError("容器编码不能为空");
+ }
+
+ // 1. 优先查找里外仓位都为空的里仓位
+ var innerLocation = _unitwork.Find(x => 1 == 1)
+ .Join(_unitwork.Find(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(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(x => 1 == 1)
+ .Join(_unitwork.Find(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(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();
+ 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(x => x.Code == locationCode).FirstOrDefault();
+ location.ContainerCode = palletNo;
+ location.Status = LocationStatus.任务锁;
+ _unitwork.Update(location);
+
+ var container = _unitwork.Find(x => x.Code == palletNo).FirstOrDefault();
+ if (container != null)
+ {
+ container.LocationCode = location.Code;
+ _unitwork.Update(container);
+ }
+
+ return ApiResult(new { LocationCode = location.Code });
+ }
+
}
}
diff --git a/HHWMS.Web/Areas/Configs/Controllers/LocationController.cs b/HHWMS.Web/Areas/Configs/Controllers/LocationController.cs
index 9b0b862..0c277f8 100644
--- a/HHWMS.Web/Areas/Configs/Controllers/LocationController.cs
+++ b/HHWMS.Web/Areas/Configs/Controllers/LocationController.cs
@@ -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.空仓位,
diff --git a/HHWMS.Web/Areas/Configs/ViewModels/LocationVMs/LocationVM.cs b/HHWMS.Web/Areas/Configs/ViewModels/LocationVMs/LocationVM.cs
index 64c80ed..f270752 100644
--- a/HHWMS.Web/Areas/Configs/ViewModels/LocationVMs/LocationVM.cs
+++ b/HHWMS.Web/Areas/Configs/ViewModels/LocationVMs/LocationVM.cs
@@ -11,6 +11,10 @@ namespace HHWMS.Web
{
public partial class LocationVM : BaseCRUDVM
{
+ public LocationVM()
+ {
+ }
+
public InventoryListVM Inventorys { get; set; } = new InventoryListVM();
[Display(Name = "Location.BeginLine", Description = "起始列")]
@@ -32,10 +36,6 @@ namespace HHWMS.Web
public List Types { get; set; }
public List LocationStatus { get; set; }
- public LocationVM()
- {
- }
-
protected override void InitVM()
{
Inventorys.CopyContext(this);
@@ -88,123 +88,250 @@ namespace HHWMS.Web
}
///
- /// 查找库位
+ /// 查找单伸位巷道的空仓位
+ ///
+ private string GetEmptyLocationBySingle(int? roadway)
+ {
+ var locations = DC.Set()
+ .Where(l => l.RoadWay == roadway
+ && l.Status == "empty"
+ && l.RowFlag == 0) // 单伸位只查找外仓位
+ .OrderBy(l => l.Layer)
+ .ThenBy(l => l.Line)
+ .FirstOrDefault();
+
+ return locations?.Code;
+ }
+
+ ///
+ /// 查找双伸位巷道的空仓位
+ ///
+ private string GetEmptyLocationByDouble(int roadway)
+ {
+ // 一次性获取所需的所有数据,避免多次查询数据库
+ var locationPairs = DC.Set()
+ .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;
+ }
+
+ ///
+ /// 根据巷道类型查找可用仓位
///
- ///
public ResponseResult GetLocation(WcsRequest request)
{
- var res = ResponseResult.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.Error("巷道号不能为空");
+ }
+
+ // 获取巷道类型
+ var roadwayType = GetRoadwayType(request.RoadWay);
+ if (roadwayType == null)
+ {
+ return ResponseResult.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.Error("未知的巷道类型");
+ }
+
+ if (locationCode == null)
+ {
+ return ResponseResult.Error("未找到可用的空仓位");
+ }
+
+ return ResponseResult.Success(new { LocationCode = locationCode });
+ }
+
+ ///
+ /// 根据巷道名称获取巷道类型
+ ///
+ /// 巷道名称
+ /// 巷道类型(2代表单伸位,4代表双伸位)
+ private int? GetRoadwayType(int? roadwayName)
+ {
+ var dictData = DC.Set()
+ .FirstOrDefault(x => x.DictType == "RoadwayConfig" && x.DictLabel == roadwayName.ToString());
+
+ if (dictData != null)
+ {
+ if (int.TryParse(dictData.DictValue, out int roadwayType))
{
- return ResponseResult.Error("未找到可用巷道!");
+ return roadwayType;
}
}
- else
+
+ return null;
+ }
+
+ ///
+ /// 获取所有巷道的可用仓位
+ ///
+ public ResponseResult GetAllAvailableLocations()
+ {
+ // 获取所有巷道配置
+ var roadwayConfigs = DC.Set()
+ .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.Error("未找到巷道配置");
}
- return "";*/
- }
- ///
- /// 单伸位 查找仓位
- ///
- ///
- public string GetLocationByOne(WcsRequest request)
- {
- // 根据托盘类型/传入的长宽高 查找库位
- var locationList = _unitWork.Find(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;
- }
-
- ///
- /// 双伸位 查找仓位
- ///
- ///
- public string GetLocationByTwo(WcsRequest request)
- {
- // 根据托盘类型 查找库位 todo
- return "";
- }
-
- ///
- /// 双伸位,获取里仓位有货,外仓位无货的仓位
- ///
- ///
- public string GetOutEmptyLocation(WcsRequest request)
- {
- int roadWay = (int)request.RoadWay;
- var locationList = _unitWork.Find(x => x.RoadWay == roadWay)
- .Join(_unitWork.Find(x => x.RoadWay == roadWay),
- a => a.ContiguousCode, g => g.Code,
- (a, g) => new
+ // 一次性获取所有库位数据
+ var allLocations = DC.Set()
+ .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);
- ///
- /// 双伸位,获取里外仓位都为空的仓位
- ///
- ///
- /// 0 返回外仓位,1返回里仓位
- ///
- public string GetAllEmptyLocation(WcsRequest request, int rowFlag)
- {
- int roadWay = (int)request.RoadWay;
- var locationList = _unitWork.Find(x => x.RoadWay == roadWay)
- .Join(_unitWork.Find(x => x.RoadWay == roadWay),
- a => a.ContiguousCode, g => g.Code,
- (a, g) => new
+ var availableLocations = new List