299 lines
9.0 KiB
C#
299 lines
9.0 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;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
|
|
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
|
|
|
|
public IActionResult Out(int id)
|
|
{
|
|
var inv = _unitwork.FindById<Inventory>(id);
|
|
if (inv == null)
|
|
{
|
|
return FFResult().RefreshGrid().Alert("选定库存不存在!请检查后再执行出库任务!");
|
|
}
|
|
|
|
if (_unitwork.IsExit<TaskHeader>(x => x.ContainerCode.Equals(inv.ContainerCode)))
|
|
{
|
|
return FFResult().RefreshGrid().Alert("选定库存已存在任务!请检查后再执行出库任务!");
|
|
}
|
|
var location = _unitwork.FindSingle<Location>(x => x.Code == inv.LocationCode);
|
|
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 FFResult().RefreshGrid().Message("任务创建成功!");
|
|
|
|
}
|
|
}
|
|
}
|