230 lines
8.7 KiB
C#
230 lines
8.7 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("receipt")]
|
|
[ActionDescription("散料操作")]
|
|
public class ReceiptSLInController : BaseController
|
|
{
|
|
private readonly IUnitWork _unitWork;
|
|
|
|
public ReceiptSLInController(IUnitWork unitWork)
|
|
{
|
|
_unitWork = unitWork;
|
|
}
|
|
|
|
#region Search
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
return PartialView("Index");
|
|
}
|
|
#endregion
|
|
|
|
[HttpPost]
|
|
public ActionResult CallBox()
|
|
{
|
|
// 查询站台占用
|
|
var stations = _unitWork.Find<Location>(x => (x.Code == StationCode.散料库左抽屉
|
|
|| x.Code == StationCode.散料库右抽屉)
|
|
&& x.Status != LocationStatus.任务锁).ToList();
|
|
if (stations.Count == 0) return JsonMore(null, 500, "无可用站台!");
|
|
|
|
// 查找没任务的仓位,分两边查,那边站台能用 查哪边
|
|
var box = _unitWork.Find<Location>(x => (x.ZoneCode == ZoneCodeEnum.散料库)
|
|
& (x.Status != LocationStatus.任务锁)
|
|
&& x.Status != LocationStatus.满货
|
|
&& x.Status != LocationStatus.空仓位
|
|
&& x.Row == stations.First().Row).FirstOrDefault();
|
|
if (box == null && stations.Count == 2)
|
|
box = _unitWork.Find<Location>(x => (x.ZoneCode == ZoneCodeEnum.散料库)
|
|
& (x.Status != LocationStatus.任务锁)
|
|
&& x.Status != LocationStatus.满货
|
|
&& x.Status != LocationStatus.空仓位
|
|
&& x.Row == stations.Last().Row).FirstOrDefault();
|
|
|
|
if (box == null) return JsonMore(null, 500, "库内没有可用散料箱!");
|
|
|
|
var toLocation = box.Row == 1 ? StationCode.散料库右抽屉 : StationCode.散料库左抽屉;
|
|
// 创建任务
|
|
var task = new TaskHeader
|
|
{
|
|
ZoneCode = ZoneCodeEnum.散料库,
|
|
TaskNo = _unitWork.GetSerialNumber("SOut"),
|
|
TaskType = TaskTypeEnum.散料盒出库,
|
|
ContainerCode = box.ContainerCode,
|
|
FromLocation = box.Code,
|
|
ToLocation = toLocation,
|
|
Status = TaskStatusEnum.新建,
|
|
CreateTime = DateTime.Now,
|
|
CreateBy = Wtm.LoginUserInfo.ITCode
|
|
};
|
|
_unitWork.Add(task);
|
|
return JsonMore(null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扫描散料箱
|
|
/// </summary>
|
|
/// <param name="boxCode"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ActionResult ScanBox(string boxCode)
|
|
{
|
|
// 判断任务重复
|
|
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}不在站台,无法入库!");
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
else
|
|
{
|
|
return JsonMore(null, 500, $"{boxCode}不正确!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扫描唯一码,并验证,返回入库单明细
|
|
/// </summary>
|
|
/// <param name="uniqueCode"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ActionResult ScanUniqueCode(string uniqueCode)
|
|
{
|
|
var receiptDetail = _unitWork.FindSingle<ReceiptDetail>(x => x.UniqueCode.Equals(uniqueCode));
|
|
if (receiptDetail != null)
|
|
{
|
|
if (receiptDetail.Status == ReceiptStatusEnum.收完)
|
|
{
|
|
return JsonMore(null, 500, $"{uniqueCode}已全部收完,无需重新绑定!");
|
|
}
|
|
return JsonMore(receiptDetail);
|
|
}
|
|
return JsonMore(null, 500, $"{uniqueCode}不存在!");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ActionResult BindingData(List<Binding> data)
|
|
{
|
|
var receiptHeaderList = _unitWork.Find<ReceiptHeader>(x =>
|
|
data.Select(x => x.ReceiptCode).ToList().Contains(x.ID.ToString()))
|
|
.Include(x => x.ReceiptDetails).ToList();
|
|
// 查找明细,修改对应状态,并且 绑定物料周转箱
|
|
foreach (Binding item in data.OrderBy(x => x.ReceiptCode))
|
|
{
|
|
// 更新入库单明细状态
|
|
var header = receiptHeaderList.Find(x => x.ID.ToString().Equals(item.ReceiptCode));
|
|
var receipt = header.ReceiptDetails.First(x => x.UniqueCode.Equals(item.UniqueCode));
|
|
if (receipt != null)
|
|
{
|
|
if (receipt.Status == ReceiptStatusEnum.收完) continue;
|
|
receipt.CompletedQty += item.BindQty;
|
|
}
|
|
if(receipt.CompletedQty == receipt.Qty)
|
|
{
|
|
receipt.Status = ReceiptStatusEnum.收完;
|
|
if (!header.ReceiptDetails.Any(x => x.Status < ReceiptStatusEnum.收完))
|
|
{
|
|
header.FirstStatus = ReceiptStatusEnum.收完;
|
|
}
|
|
}
|
|
// 新建库存
|
|
var inventory = new Inventory
|
|
{
|
|
ZoneCode = ZoneCodeEnum.散料库,
|
|
UniqueCode = item.UniqueCode,
|
|
Qty = item.BindQty,
|
|
Lot = item.Size.ToString(),
|
|
ContainerCode = item.BoxCode,
|
|
TaskStatus = InventoryTaskStatus.任务中
|
|
};
|
|
_unitWork.Add(inventory);
|
|
}
|
|
_unitWork.BatchUpdate(receiptHeaderList.ToArray());
|
|
return JsonMore(null);
|
|
}
|
|
/// <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.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}不正确!");
|
|
}
|
|
}
|
|
}
|