130 lines
4.3 KiB
C#
130 lines
4.3 KiB
C#
using System;
|
||
using System.Linq;
|
||
using HHWMS.Web.Models;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using WalkingTec.Mvvm.Core;
|
||
using WalkingTec.Mvvm.Mvc;
|
||
|
||
namespace HHWMS.Web.Controllers
|
||
{
|
||
[Area("receipt")]
|
||
[ActionDescription("入库操作")]
|
||
public partial class ReceiptInController : BaseController
|
||
{
|
||
private readonly IUnitWork _unitWork;
|
||
|
||
public ReceiptInController(IUnitWork unitWork)
|
||
{
|
||
_unitWork = unitWork;
|
||
}
|
||
|
||
#region Index
|
||
|
||
[ActionDescription("Sys.Search")]
|
||
public ActionResult Index()
|
||
{
|
||
return PartialView("Index");
|
||
}
|
||
|
||
#endregion Index
|
||
|
||
[HttpPost]
|
||
public ActionResult TaskIn(string containerCode, bool inv)
|
||
{
|
||
// 判断containerCode是否为空
|
||
if (string.IsNullOrEmpty(containerCode))
|
||
{
|
||
return JsonMore(null, 500, "容器编码为空!请检查后重新提交!");
|
||
}
|
||
// 查询container表code为containercode的值
|
||
var container = _unitWork.FindSingle<Container>(u => u.Code == containerCode);
|
||
if (container == null)
|
||
{
|
||
return JsonMore(null, 500, $"库内没有编码为 {containerCode} 的容器!");
|
||
}
|
||
// 如果 container的库位不为空,或者islock为true,则返回错误信息
|
||
if (!string.IsNullOrEmpty(container.LocationCode) || container.IsLock == ContainerLockEnum.任务锁)
|
||
{
|
||
return JsonMore(null, 500, $"容器 {containerCode} 已被占用!");
|
||
}
|
||
|
||
|
||
container.IsLock = ContainerLockEnum.任务锁;
|
||
container.UpdateTime = DateTime.Now;
|
||
container.UpdateBy = Wtm.LoginUserInfo?.ITCode??"WMS";
|
||
// _unitWork.Update(container);
|
||
|
||
//查找仓位
|
||
var location = _unitWork.Find<Location>(u => u.Status == LocationStatus.空仓位)
|
||
.OrderBy(x => x.Layer)
|
||
.ThenBy(x => x.Line)
|
||
.FirstOrDefault();
|
||
|
||
// 判断location是否为空
|
||
if (location == null)
|
||
{
|
||
return JsonMore(null, 500, "库内没有空闲仓位!");
|
||
}
|
||
location.Status = LocationStatus.任务锁;
|
||
location.UpdateTime = DateTime.Now;
|
||
location.UpdateBy = Wtm.LoginUserInfo?.ITCode??"WMS";
|
||
_unitWork.Update(location);
|
||
|
||
if (inv) //有货
|
||
{
|
||
_unitWork.Add<Inventory>(new Inventory()
|
||
{
|
||
ZoneCode = ZoneCodeEnum.立库,
|
||
ContainerCode = containerCode,
|
||
LocationCode = location.Code,
|
||
MaterialCode = "123456",
|
||
MaterialName = "矿泉水",
|
||
Qty = 1,
|
||
TaskStatus = InventoryTaskStatus.任务中,
|
||
CreateTime = DateTime.Now
|
||
});
|
||
}
|
||
_unitWork.Update(container);
|
||
//创建容器编码为containercode的任务
|
||
var task = new TaskHeader
|
||
{
|
||
ZoneCode = ZoneCodeEnum.立库,
|
||
TaskNo = _unitWork.GetSerialNumber("In"),
|
||
TaskType = TaskTypeEnum.立库入库,
|
||
ContainerCode = containerCode,
|
||
FromLocation = "",
|
||
ToLocation = location.Code,
|
||
Status = TaskStatusEnum.待下发,
|
||
CreateBy = Wtm.LoginUserInfo?.ITCode??"WMS",
|
||
CreateTime = DateTime.Now
|
||
};
|
||
_unitWork.Add(task);
|
||
|
||
// 下发任务到wcs
|
||
var postData = new
|
||
{
|
||
TaskNo = task.TaskNo,
|
||
PalletNo = task.ContainerCode,
|
||
FromLocation = task.FromLocation,
|
||
ToLocation = task.ToLocation
|
||
};
|
||
var res = Wtm.CallAPI<ApiJsonResult<dynamic>>("WCS", "TaskAssign", HttpMethodEnum.POST, postData)
|
||
.Result.Data;
|
||
|
||
if (res.Success)
|
||
{
|
||
task.Status = TaskStatusEnum.已下发;
|
||
}
|
||
else
|
||
{
|
||
task.ErrorMsg = res.Msg;
|
||
}
|
||
task.UpdateTime = DateTime.Now;
|
||
task.UpdateBy = "WMS";
|
||
_unitWork.Update(task);
|
||
|
||
return JsonMore(null);
|
||
}
|
||
}
|
||
}
|