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