168 lines
5.7 KiB
C#
168 lines
5.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AutoMapper;
|
|
using HHWMS.Web.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using WalkingTec.Mvvm.Core;
|
|
|
|
namespace HHWMS.Web
|
|
{
|
|
/// <summary>
|
|
/// 提供给WCS调用接口
|
|
/// 调用方向 WCS --> WMS
|
|
/// </summary>
|
|
[Public]
|
|
[ActionDescription("HHWMS.WCSApi")]
|
|
[ApiController]
|
|
[Route("api/[controller]/[action]"), ApiExplorerSettings(GroupName = "User")]
|
|
public class IWCSController : ApiController
|
|
{
|
|
private readonly IUnitWork _unitWork;
|
|
private readonly IMapper _mapper;
|
|
|
|
public IWCSController(IUnitWork unitWork, IMapper mapper)
|
|
{
|
|
_unitWork = unitWork;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 请求入库
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public IActionResult RequestIn(WcsRequest request)
|
|
{
|
|
return ApiResult();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 状态返回
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public IActionResult TaskStatusResult(WcsRequest request)
|
|
{
|
|
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 });
|
|
}
|
|
|
|
}
|
|
}
|