using System; using System.Collections.Generic; using System.Linq; using HHWMS.Web.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; 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 Search [ActionDescription("Sys.Search")] public ActionResult Index() { return PartialView("Index"); } #endregion /// /// 扫描散料箱/盘料周转箱 返回待出库明细 /// /// /// [HttpPost] public ActionResult ScanBox(string code) { // 判断箱号是否合理 var box = _unitWork.FindSingle(x => x.Code.Equals(code)); if (box != null) { if (box.Type == LocationTypeEnum.散料库站台 || box.Type == LocationTypeEnum.料塔) { var inv = _unitWork.Find(x => x.LocationCode.Equals(code)); return JsonMore(inv); } else { return JsonMore(null, 500, $"{code}不在站台!"); } } else { return JsonMore(null, 500, $"{code}不正确!"); } } /// /// 扫描唯一码,并验证 /// /// /// [HttpPost] public ActionResult ScanUniqueCode(string code) { // 判断唯一码是否在 出库站台 料塔 或 抽屉 var stationList = _unitWork.Find(x => x.Type.Equals(LocationTypeEnum.散料库站台) || x.Type.Equals(LocationTypeEnum.料塔)) .Select(x => x.Code).ToList(); var inv = _unitWork.FindSingle(x => x.UniqueCode.Equals(code) && stationList.Contains(x.LocationCode)); if (inv != null) { return JsonMore(inv); } return JsonMore(null, 500, $"{code}不存在!"); } [HttpPost] public ActionResult Pick(string uniqueCode, decimal qty,string station) { var inv = _unitWork.FindSingle(x => x.UniqueCode.Equals(uniqueCode) && x.LocationCode == station); if (inv != null) { // 删除库存,扣账,记录库存交易 todo,根据站台查询是否还有未拣货的物料,如果没有就清空站台占用 _unitWork.Delete(inv); List list = _unitWork.Find(x => x.LocationCode == station).ToList(); if (list.Count() == 0) { var Sation = _unitWork.Find(x => x.Code == station).FirstOrDefault(); if (Sation != null) { Sation.ContainerCode = ""; _unitWork.Update(Sation); } } return JsonMore(inv); } return JsonMore(null, 500, $"站台{station}上的{uniqueCode}不存在!"); } /// /// 散料箱回库,捡完回库 /// /// /// /// [HttpPost] public ActionResult BoxBack(string boxCode, bool isFull) { // 判断任务重复 if(!_unitWork.IsExit(x => x.ZoneCode.Equals(ZoneCodeEnum.散料库) && x.ContainerCode.Equals(boxCode))){ return JsonMore(null, 500, $"库内已存在{boxCode}的任务,请勿重复操作!"); }; // 判断箱号是否合理 var box = _unitWork.FindSingle(x => x.ContainerCode.Equals(boxCode)); if (box != null) { if(box.Type != LocationTypeEnum.散料库站台) { return JsonMore(null, 500, $"{boxCode}不在站台,无法入库!"); } else { // 查找目标库位 var toLocation = _unitWork.FindSingle(x => x.Status.Equals(LocationStatus.空仓位) && x.Type.Equals(LocationTypeEnum.散料库位) && x.Row.Equals(box.Row)); if (toLocation != null) { // 创建任务 var task = new TaskHeader { ZoneCode = ZoneCodeEnum.散料库, TaskNo = _unitWork.GetSerialNumber("CIn"), TaskType = TaskTypeEnum.散料盒入库, ContainerCode = boxCode, FromLocation = box.Code, ToLocation = toLocation.Code, Status = TaskStatusEnum.新建, CreateBy = Wtm.LoginUserInfo.ITCode, CreateTime = DateTime.Now }; _unitWork.Add(task); toLocation.Status = LocationStatus.任务锁; toLocation.Length = isFull ? 1 : 0; // 是否满盘 _unitWork.Update(toLocation); } else { return JsonMore(null, 500, $"库内无可用仓位,无法入库!"); } } return JsonMore(data: null); } else { return JsonMore(null, 500, $"{boxCode}不正确!"); } } }