Files
8357WMS/HHWMS.Web/Areas/Shipment/Controllers/ShipOutController.cs
T
2023-10-26 09:55:15 +08:00

182 lines
6.2 KiB
C#

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
/// <summary>
/// 扫描散料箱/盘料周转箱 返回待出库明细
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
[HttpPost]
public ActionResult ScanBox(string code)
{
Location box = new Location();
if (code.Contains("C"))
{
box = _unitWork.FindSingle<Location>(x => x.ContainerCode.Equals(code) && x.Type == LocationTypeEnum.散料库站台);
}
else if (code.Contains("L"))
{
box = _unitWork.FindSingle<Location>(x => x.Code.Equals(code));
}
// 判断箱号是否合理
if (box != null)
{
if (box.Type == LocationTypeEnum.散料库站台 || box.Type == LocationTypeEnum.料塔)
{
var inv = _unitWork.Find<Inventory>(x => x.LocationCode.Equals(code));
if (code.Contains("C"))
{
inv = _unitWork.Find<Inventory>(x => x.ContainerCode.Equals(code));
}
return JsonMore(inv);
}
else
{
return JsonMore(null, 500, $"{code}不在站台!");
}
}
else
{
return JsonMore(null, 500, $"{code}不正确!");
}
}
/// <summary>
/// 扫描唯一码,并验证
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
[HttpPost]
public ActionResult ScanUniqueCode(string code)
{
// 判断唯一码是否在 出库站台 料塔 或 抽屉
var stationList = _unitWork.Find<Location>(x => x.Type.Equals(LocationTypeEnum.散料库站台)
|| x.Type.Equals(LocationTypeEnum.料塔))
.Select(x => x.Code).ToList();
var inv = _unitWork.FindSingle<Inventory>(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<Inventory>(x => x.UniqueCode.Equals(uniqueCode) && x.LocationCode == station);
if (inv != null)
{
// 删除库存,扣账,记录库存交易 todo,根据站台查询是否还有未拣货的物料,如果没有就清空站台占用
_unitWork.Delete(inv);
List<Inventory> list = _unitWork.Find<Inventory>(x => x.LocationCode == station).ToList();
if (list.Count() == 0)
{
var Sation = _unitWork.Find<Location>(x => x.Code == station).FirstOrDefault();
if (Sation != null)
{
Sation.ContainerCode = "";
_unitWork.Update(Sation);
}
}
return JsonMore(inv);
}
return JsonMore(null, 500, $"站台{station}上的{uniqueCode}不存在!");
}
/// <summary>
/// 散料箱回库,捡完回库
/// </summary>
/// <param name="boxCode"></param>
/// <param name="isFull"></param>
/// <returns></returns>
[HttpPost]
public ActionResult BoxBack(string boxCode, bool isFull)
{
// 判断任务重复
if(!_unitWork.IsExit<TaskHeader>(x => x.ZoneCode.Equals(ZoneCodeEnum.散料库) && x.ContainerCode.Equals(boxCode))){
return JsonMore(null, 500, $"库内已存在{boxCode}的任务,请勿重复操作!");
};
// 判断箱号是否合理
var box = _unitWork.FindSingle<Location>(x => x.ContainerCode.Equals(boxCode));
if (box != null)
{
if(box.Type != LocationTypeEnum.散料库站台)
{
return JsonMore(null, 500, $"{boxCode}不在站台,无法入库!");
}
else
{
// 查找目标库位
var toLocation = _unitWork.FindSingle<Location>(x => x.Status.Equals(LocationStatus.空仓位)
&& x.Type.Equals(LocationTypeEnum.散料库位)
&& x.Code == boxCode
&& 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}不正确!");
}
}
}