Files
WMS/HHWMS.Web/Areas/Receipt/Controllers/ReceiptInController.cs
T
zhougf a3e91357ee 容器出库
库位禁用
演示逻辑修改 task station=1的出库任务需要自动下发入库任务和AGv任务
2024-05-29 17:09:03 +08:00

154 lines
5.2 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;
private readonly WTMContext _context;
public ReceiptInController(IUnitWork unitWork, WTMContext wtmContext)
{
_unitWork = unitWork;
_context = wtmContext;
}
#region Index
[ActionDescription("Sys.Search")]
public ActionResult Index()
{
return PartialView("Index");
}
#endregion Index
[HttpPost]
public ActionResult TaskIn(string containerCode, bool inv, bool agv)
{
if (Wtm == null)
{
Wtm = _context;
}
// 判断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.空仓位
&& u.Type == container.Type
&& !u.IsStop)
.OrderByDescending(x => x.Layer)
.ThenByDescending(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
};
try
{
var res = Wtm.CallAPI<ApiJsonResult<dynamic>>("WCS", "TaskAssign", HttpMethodEnum.POST, postData)
.Result.Data;
if (res.Success)
{
task.Status = TaskStatusEnum.已下发;
}
else
{
task.ErrorMsg = res.Msg;
}
}
catch (Exception ex)
{
task.ErrorMsg = ex.Message;
}
task.UpdateTime = DateTime.Now;
task.UpdateBy = "WMS";
_unitWork.Update(task);
if (agv)
{
// 调用AGV接口
var task_id = Wtm.ConfigInfo.AppSettings
.FirstOrDefault(x => x.Key == "OutIn").Value;
var res2 = Wtm.CallAPI<ShipOutController.agvResult>("ACS", "task_mould_do", HttpMethodEnum.POST, new
{
task_id = task_id
});
}
return JsonMore(null);
}
}
}