495 lines
17 KiB
C#
495 lines
17 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using WalkingTec.Mvvm.Core;
|
|
using WalkingTec.Mvvm.Mvc;
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
using HHWMS.Web;
|
|
using HHWMS.Web.Models;
|
|
|
|
namespace HHWMS.Web.Controllers
|
|
{
|
|
[Area("inventory")]
|
|
[ActionDescription("库存管理")]
|
|
public partial class InventoryController : BaseController
|
|
{
|
|
private readonly IUnitWork _unitWork;
|
|
|
|
public InventoryController(IUnitWork unitWork)
|
|
{
|
|
_unitWork = unitWork;
|
|
}
|
|
|
|
#region Search
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryListVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost]
|
|
public string Search(InventorySearcher searcher)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryListVM>(passInit: true);
|
|
if (ModelState.IsValid)
|
|
{
|
|
vm.Searcher = searcher;
|
|
return vm.GetJson(false);
|
|
}
|
|
else
|
|
{
|
|
return vm.GetError();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Create
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create()
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Create")]
|
|
public ActionResult Create(InventoryVM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoAdd();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Edit
|
|
[ActionDescription("Sys.Edit")]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
[HttpPost]
|
|
[ValidateFormItemOnly]
|
|
public ActionResult Edit(InventoryVM vm)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
vm.DoEdit();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
vm.DoReInit();
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Delete
|
|
[ActionDescription("Sys.Delete")]
|
|
public ActionResult Delete(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
[HttpPost]
|
|
public ActionResult Delete(string id, IFormCollection nouse)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryVM>(id);
|
|
vm.DoDelete();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Details
|
|
[ActionDescription("Sys.Details")]
|
|
public ActionResult Details(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryVM>(id);
|
|
return PartialView(vm);
|
|
}
|
|
#endregion
|
|
|
|
#region BatchEdit
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult BatchEdit(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
public ActionResult DoBatchEdit(InventoryBatchVM vm, IFormCollection nouse)
|
|
{
|
|
if (!ModelState.IsValid || !vm.DoBatchEdit())
|
|
{
|
|
return PartialView("BatchEdit",vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region BatchDelete
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult BatchDelete(string[] IDs)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryBatchVM>(Ids: IDs);
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
public ActionResult DoBatchDelete(InventoryBatchVM vm, IFormCollection nouse)
|
|
{
|
|
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
|
{
|
|
return PartialView("BatchDelete",vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Import
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import()
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryImportVM>();
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("Sys.Import")]
|
|
public ActionResult Import(InventoryImportVM vm, IFormCollection nouse)
|
|
{
|
|
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
|
{
|
|
return PartialView(vm);
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Export
|
|
[ActionDescription("Sys.Export")]
|
|
[HttpPost]
|
|
public IActionResult ExportExcel(InventoryListVM vm)
|
|
{
|
|
return vm.GetExportData();
|
|
}
|
|
#endregion
|
|
|
|
#region InvOut 出库
|
|
[ActionDescription("TaskType.Out")]
|
|
public ActionResult InvOut(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryVM>(id);
|
|
if (vm.Entity.TaskStatus == InventoryTaskStatusEnum.Locked)
|
|
{
|
|
return FFResult().Alert("所选库存已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("TaskType.Out")]
|
|
public ActionResult InvOut(InventoryVM vm)
|
|
{
|
|
var id = vm.Entity.ID;
|
|
// 校验参数
|
|
if (string.IsNullOrWhiteSpace(vm.OutPort))
|
|
{
|
|
return FFResult().Alert("出口必选,请选择后重试!");
|
|
}
|
|
// 校验库存
|
|
var inv = _unitWork.FindSingle<Inventory>(x => x.ID == id);
|
|
if (inv == null)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存不存在,请检查后重试!").RefreshGrid();
|
|
}
|
|
if (inv.TaskStatus == InventoryTaskStatusEnum.Locked)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
// 校验容器
|
|
var container = _unitWork.FindSingle<Container>(x => x.Code == inv.ContainerCode);
|
|
if (container == null)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存的容器不存在,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
if (container.IsLock == ContainerLockEnum.任务锁)
|
|
{
|
|
return FFResult().CloseDialog().Alert("库存所在容器已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
// 校验库位
|
|
var location = _unitWork.FindSingle<Location>(x => x.Code == inv.LocationCode);
|
|
if (location == null)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存不在库内,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
if (location.Status == LocationStatusEnum.锁定)
|
|
{
|
|
return FFResult().CloseDialog().Alert("库存所在仓位已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
// 创建任务
|
|
var task = new TaskHeader()
|
|
{
|
|
TaskNo = _unitWork.GetSerialNumber("Out", 6),
|
|
ZoneId = inv.ZoneId,
|
|
TaskType = TaskTypeEnum.出库,
|
|
FromLocation = inv.LocationCode,
|
|
ToLocation = vm.OutPort,
|
|
ContainerCode = inv.ContainerCode,
|
|
RoadWay = 1,
|
|
Status = TaskStatusEnum.新建,
|
|
CreateBy = Wtm.LoginUserInfo.ITCode,
|
|
CreateTime = DateTime.Now
|
|
};
|
|
|
|
// 6. 调用WCS接口下发任务
|
|
var wcsTaskModel = new WCSTaskModel
|
|
{
|
|
TaskNo = task.TaskNo,
|
|
PalletNo = task.ContainerCode,
|
|
FromLocation = task.FromLocation, // 入库任务起始位置为空
|
|
ToLocation = task.ToLocation,
|
|
};
|
|
|
|
//调用WCS任务下发接口
|
|
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
|
|
|
if (wcsResult != null && wcsResult.Success)
|
|
{
|
|
// WCS任务下发成功
|
|
task.Status = TaskStatusEnum.已下发;
|
|
_unitWork.Add(task);
|
|
|
|
// 更新库存
|
|
inv.TaskStatus = InventoryTaskStatusEnum.Locked;
|
|
inv.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(inv);
|
|
|
|
// 更新容器
|
|
// _unitWork.BatchUpdate<Container>(x => x.Code == task.ContainerCode, x => new Container()
|
|
// {
|
|
// IsLock = ContainerLockEnum.任务锁,
|
|
// UpdateTime = DateTime.Now
|
|
// });
|
|
container.IsLock = ContainerLockEnum.任务锁;
|
|
container.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(container);
|
|
|
|
// 更新库位
|
|
location.Status = LocationStatusEnum.锁定;
|
|
location.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(location);
|
|
|
|
return FFResult().CloseDialog().Message("出库任务创建成功").RefreshGrid();
|
|
}
|
|
else
|
|
{
|
|
// WCS任务下发失败
|
|
return FFResult().CloseDialog().Message(wcsResult?.Msg ?? "WCS任务下发失败").RefreshGrid();
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region InvOut 成品出库
|
|
[ActionDescription("TaskType.Out")]
|
|
public ActionResult InvOut2(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<InventoryVM>(id);
|
|
if (vm.Entity.TaskStatus == InventoryTaskStatusEnum.Locked)
|
|
{
|
|
return FFResult().Alert("所选库存已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
return PartialView(vm);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ActionDescription("TaskType.Out")]
|
|
public ActionResult InvOut2(InventoryVM vm)
|
|
{
|
|
var id = vm.Entity.ID;
|
|
// 校验参数
|
|
if (string.IsNullOrWhiteSpace(vm.OutPort))
|
|
{
|
|
return FFResult().Alert("出口必选,请选择后重试!");
|
|
}
|
|
// 校验库存
|
|
var inv = _unitWork.FindSingle<Inventory>(x => x.ID == id);
|
|
if (inv == null)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存不存在,请检查后重试!").RefreshGrid();
|
|
}
|
|
if (inv.TaskStatus == InventoryTaskStatusEnum.Locked)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
// 校验容器
|
|
var container = _unitWork.FindSingle<Container>(x => x.Code == inv.ContainerCode);
|
|
if (container == null)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存的容器不存在,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
if (container.IsLock == ContainerLockEnum.任务锁)
|
|
{
|
|
return FFResult().CloseDialog().Alert("库存所在容器已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
// 校验库位
|
|
var location = _unitWork.FindSingle<Location>(x => x.Code == inv.LocationCode);
|
|
if (location == null)
|
|
{
|
|
return FFResult().CloseDialog().Alert("所选库存不在库内,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
if (location.Status == LocationStatusEnum.锁定)
|
|
{
|
|
return FFResult().CloseDialog().Alert("库存所在仓位已被锁定!,请检查后重试!").RefreshGrid();
|
|
}
|
|
|
|
// 创建任务
|
|
var task = new TaskHeader()
|
|
{
|
|
TaskNo = _unitWork.GetSerialNumber("Out", 6),
|
|
ZoneId = inv.ZoneId,
|
|
TaskType = TaskTypeEnum.出库,
|
|
FromLocation = inv.LocationCode,
|
|
ToLocation = vm.OutPort,
|
|
ContainerCode = inv.ContainerCode,
|
|
RoadWay = 2,
|
|
Status = TaskStatusEnum.新建,
|
|
CreateBy = Wtm.LoginUserInfo.ITCode,
|
|
CreateTime = DateTime.Now
|
|
};
|
|
|
|
var locationVm = Wtm.CreateVM<LocationVM>();
|
|
var result = locationVm.SendWcsTask(task);
|
|
if (result.Status)
|
|
{
|
|
// 更新库存
|
|
inv.TaskStatus = InventoryTaskStatusEnum.Locked;
|
|
inv.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(inv);
|
|
|
|
// 更新容器
|
|
container.IsLock = ContainerLockEnum.任务锁;
|
|
container.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(container);
|
|
|
|
// 更新库位
|
|
location.Status = LocationStatusEnum.锁定;
|
|
location.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(location);
|
|
return FFResult().CloseDialog().Message("出库任务创建成功").RefreshGrid();
|
|
}
|
|
else
|
|
{
|
|
return FFResult().CloseDialog().Message(result.Message?? "WCS任务下发失败").RefreshGrid();
|
|
}
|
|
/*// 6. 调用WCS接口下发任务
|
|
var wcsTaskModel = new WCSTaskModel
|
|
{
|
|
TaskNo = task.TaskNo,
|
|
PalletNo = task.ContainerCode,
|
|
FromLocation = task.FromLocation, // 入库任务起始位置为空
|
|
ToLocation = task.ToLocation,
|
|
};
|
|
|
|
//调用WCS任务下发接口
|
|
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCSCP", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
|
|
|
if (wcsResult != null && wcsResult.Success)
|
|
{
|
|
// WCS任务下发成功
|
|
task.Status = TaskStatusEnum.已下发;
|
|
_unitWork.Add(task);
|
|
|
|
// 更新库存
|
|
inv.TaskStatus = InventoryTaskStatusEnum.Locked;
|
|
inv.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(inv);
|
|
|
|
// 更新容器
|
|
// _unitWork.BatchUpdate<Container>(x => x.Code == task.ContainerCode, x => new Container()
|
|
// {
|
|
// IsLock = ContainerLockEnum.任务锁,
|
|
// UpdateTime = DateTime.Now
|
|
// });
|
|
container.IsLock = ContainerLockEnum.任务锁;
|
|
container.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(container);
|
|
|
|
// 更新库位
|
|
location.Status = LocationStatusEnum.锁定;
|
|
location.UpdateTime = DateTime.Now;
|
|
_unitWork.Update(location);
|
|
|
|
return FFResult().CloseDialog().Message("出库任务创建成功").RefreshGrid();
|
|
}
|
|
else
|
|
{
|
|
// WCS任务下发失败
|
|
return FFResult().CloseDialog().Message(wcsResult?.Msg ?? "WCS任务下发失败").RefreshGrid();
|
|
}*/
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
}
|