133 lines
3.9 KiB
C#
133 lines
3.9 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("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; }
|
||
}
|
||
|
||
}
|