WMS/HHWMS.Web/Areas/Shipment/Controllers/ShipOutController.cs
zhougf a6168a75bf 设计出库口入库流程
托盘、周转箱分区存放
2024-04-30 23:18:05 +08:00

133 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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("shipment")]
[ActionDescription("出库操作")]
public class ShipOutController : BaseController
{
private readonly IUnitWork _unitWork;
public ShipOutController(IUnitWork unitWork)
{
_unitWork = unitWork;
}
#region Index
[ActionDescription("Sys.Search")]
public ActionResult Index()
{
return PartialView("Index");
}
#endregion
[HttpPost]
public IActionResult CallBox()
{
// 查找库位状态为空容器的库位
var location = _unitWork.FindSingle<Location>(x => x.Status == LocationStatus.空容器);
if (location != null)
{
location.Status = LocationStatus.任务锁;
location.UpdateTime = DateTime.Now;
location.UpdateBy = Wtm.LoginUserInfo?.ITCode ?? "WMS";
_unitWork.Update(location);
// 查找container,并更新状态
var container = _unitWork.FindSingle<Container>(x => x.Code == location.ContainerCode);
container.IsLock = ContainerLockEnum.任务锁;
container.UpdateTime = DateTime.Now;
container.UpdateBy = Wtm.LoginUserInfo?.ITCode ?? "WMS";
_unitWork.Update(container);
//创建出库任务
var task = new TaskHeader
{
ZoneCode = ZoneCodeEnum.立库,
TaskNo = _unitWork.GetSerialNumber("Out"),
TaskType = TaskTypeEnum.立库出库,
ContainerCode = location.ContainerCode,
FromLocation = location.Code,
ToLocation = "",
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);
}
else
{
return JsonMore(null, 500, "库内无可用容器!");
}
}
public IActionResult AgvTask(string type)
{
try
{
var ids = Wtm.ConfigInfo.AppSettings.ToList();
var task_id = type switch
{
"In" => ids.FirstOrDefault(x => x.Key == "In").Value,
"Out" => ids.FirstOrDefault(x => x.Key == "Out").Value,
"Charge" => ids.FirstOrDefault(x => x.Key == "Charge").Value,
"OutIn" => ids.FirstOrDefault(x => x.Key == "OutIn").Value,
_ => throw new Exception("参数错误!")
};
var res = Wtm.CallAPI<agvResult>("ACS", "task_mould_do", HttpMethodEnum.POST, new
{
task_id = task_id
});
if (res.Result.Data.ack != 0)
{
return JsonMore(null, 500, res.Result.Data.msg);
}
return JsonMore(null);
}
catch (Exception ex)
{
return JsonMore(null, 500, ex.Message);
}
}
public class agvResult
{
public int ack { get; set; }
public string msg { get; set; }
public dynamic data { get; set; }
}
}