319 lines
12 KiB
C#
319 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using HHWMS.Web.Models;
|
|
using MESTOWMSService;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using ServiceReference1;
|
|
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>
|
|
/// <param name="type"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ActionResult ScanBox(string code, string type)
|
|
{
|
|
Location box = new Location();
|
|
if (type.Contains("slbox"))
|
|
{
|
|
box = _unitWork.FindSingle<Location>(x => x.Code.Equals(code) && x.Type == LocationTypeEnum.散料库站台);
|
|
}
|
|
else if (type.Contains("lt"))
|
|
{
|
|
box = _unitWork.FindSingle<Location>(x => x.Code.Equals(code) && x.Type == LocationTypeEnum.料塔);
|
|
}
|
|
// 判断箱号是否合理
|
|
if (box != null)
|
|
{
|
|
var inv = _unitWork.Find<Inventory>(x => x.LocationCode.Equals(code)
|
|
&& x.TaskStatus == InventoryTaskStatus.任务中);
|
|
return JsonMore(inv);
|
|
|
|
}
|
|
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 shipment = _unitWork.Find<ShipmentDetail>(x => x.UniqueCode.Equals(uniqueCode))
|
|
.FirstOrDefault();
|
|
using (var tran = Wtm.DC.Database.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
if (shipment == null)
|
|
{
|
|
return JsonMore(null, 500, "未找到该出库单!");
|
|
}
|
|
|
|
shipment.Status = ShipStatusEnum.拣货完成;
|
|
shipment.UpdateTime = DateTime.Now;
|
|
shipment.UpdateBy = Wtm.LoginUserInfo?.ITCode??"WMS";
|
|
_unitWork.Update(shipment);
|
|
|
|
var header = _unitWork.Find<ShipmentHeader>(x => x.ID.Equals(shipment.ShipmentHeaderId))
|
|
.FirstOrDefault();
|
|
var details = _unitWork.Find<ShipmentDetail>(x => x.ShipmentHeaderId == shipment.ShipmentHeaderId)
|
|
.ToList();
|
|
if (details.All(x => x.Status == ShipStatusEnum.拣货完成))
|
|
{
|
|
header.FirstStatus = ShipStatusEnum.拣货完成;
|
|
}
|
|
else
|
|
{
|
|
header.FirstStatus = ShipStatusEnum.拣货中;
|
|
}
|
|
header.UpdateTime = DateTime.Now;
|
|
header.UpdateBy = Wtm.LoginUserInfo?.ITCode??"WMS";
|
|
_unitWork.Update(header);
|
|
|
|
var inv = _unitWork.FindSingle<Inventory>(x => x.UniqueCode.Equals(uniqueCode) && x.LocationCode == station);
|
|
if (inv != null)
|
|
{
|
|
//回传MES
|
|
/*
|
|
var qr = _unitWork.FindSingle<MaterialQr>(x => x.UniqueCode.Equals(inv.UniqueCode))?.QRCode;
|
|
|
|
var bizData = new InStore
|
|
{
|
|
INWMS = new INWMS
|
|
{
|
|
INITEMS = new INITEMS
|
|
{
|
|
INITEM = new List<INITEMItem>()
|
|
{
|
|
new INITEMItem()
|
|
{
|
|
ERPSN = qr,
|
|
WMSSN = inv?.UniqueCode,
|
|
QTY = "0",
|
|
TYPE = "2",
|
|
FLAG = "1"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
var str = JsonConvert.SerializeObject(bizData);
|
|
var request = new ServiceReference1.bizOperationV1Request
|
|
{
|
|
fromUnit = "8357S",
|
|
toUnit = "8357TEST",
|
|
fromSys = "WMSTEST",
|
|
toSys = "MES",
|
|
bizOperation = "InStore",
|
|
bizData = str
|
|
};
|
|
var client = new ServiceReference1.portTypeClient();
|
|
var result = client.bizOperationV1Async(request).Result;
|
|
*/
|
|
var result = new bizOperationV1Response();
|
|
result.Status = "Y";
|
|
if (result.Status == "Y")
|
|
{
|
|
// 删除库存,扣账,记录库存交易 todo,根据站台查询是否还有未拣货的物料,如果没有就清空站台占用
|
|
|
|
var invTran = new InventoryTransaction
|
|
{
|
|
BillType = "out",
|
|
ZoneCode = inv.ZoneCode,
|
|
Type = inv.UniqueCode,
|
|
MaterialCode = inv.MaterialCode,
|
|
MaterialName = inv.MaterialName,
|
|
MaterialSpec = inv.MaterialSpec,
|
|
MaterialUnit = inv.MaterialUnit,
|
|
MaterialType = inv.MaterialType,
|
|
Batch = inv.Batch,
|
|
Lot = inv.Lot,
|
|
CompanyCode = inv.CompanyCode,
|
|
LocationCode = inv.LocationCode,
|
|
SupplierCode = inv.SupplierCode,
|
|
BillCode = header.Code,
|
|
BillDetailId = shipment.ID,
|
|
ContainerCode = inv.ContainerCode,
|
|
Qty = inv.Qty,
|
|
CreateTime = DateTime.Now
|
|
};
|
|
_unitWork.Add(invTran);
|
|
_unitWork.Delete(inv);
|
|
|
|
var Sation = _unitWork.Find<Location>(x => x.Code == station).FirstOrDefault();
|
|
if (Sation != null && Sation.Type == "T")
|
|
{
|
|
Sation.Height -= 1;
|
|
if (Sation.Height <= 0)
|
|
{
|
|
Sation.Height = 0;
|
|
Sation.ContainerCode = "";
|
|
}
|
|
_unitWork.Update(Sation);
|
|
}
|
|
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.Type == "T")
|
|
{
|
|
Sation.ContainerCode = "";
|
|
Sation.Height = 0;
|
|
_unitWork.Update(Sation);
|
|
}
|
|
}
|
|
|
|
// Wtm.DoLog("", ActionLogTypesEnum.Normal, "mes", request: JsonConvert.SerializeObject(request), result: "success");
|
|
tran.Commit();
|
|
return JsonMore(null);
|
|
}
|
|
else
|
|
{
|
|
tran.Rollback();
|
|
// Wtm.DoLog("", ActionLogTypesEnum.Normal, "mes", request: JsonConvert.SerializeObject(request), result: "error");
|
|
return JsonMore(null, 500, $"回传MES失败,失败原因{result.Message}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
tran.Rollback();
|
|
return JsonMore(null, 500, $"站台{station}上的{uniqueCode}不存在!");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tran.Rollback();
|
|
return JsonMore(null, 500, $"拣货失败,失败原因{ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <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.FromLocation.Equals(boxCode))){
|
|
return JsonMore(null, 500, $"库内已存在{boxCode}的任务,请勿重复操作!");
|
|
};
|
|
var station = _unitWork.FindSingle<Location>(x => x.Code.Equals(boxCode)
|
|
&& x.Type == LocationTypeEnum.散料库站台);
|
|
if(station == null)
|
|
{
|
|
return JsonMore(null, 500, $"站台{boxCode}不存在,无法回库!");
|
|
}
|
|
if (string.IsNullOrEmpty(station.ContainerCode))
|
|
{
|
|
return JsonMore(null, 500, $"{boxCode}站台没有料箱,无法入库!");
|
|
}
|
|
//判断是否拣货完成
|
|
if (_unitWork.IsExit<Inventory>(x => x.LocationCode.Equals(station.Code)
|
|
&& x.TaskStatus == InventoryTaskStatus.任务中))
|
|
{
|
|
return JsonMore(null, 500, $"站台{boxCode}存在未拣货物料,无法回库!");
|
|
}
|
|
// 判断箱号是否合理
|
|
var box = _unitWork.FindSingle<Location>(x => x.ContainerCode.Equals(station.ContainerCode)
|
|
&& x.Type != LocationTypeEnum.散料库站台);
|
|
if (box != null)
|
|
{
|
|
//if(box.Type != LocationTypeEnum.散料库站台)
|
|
//{
|
|
// return JsonMore(null, 500, $"{boxCode}不在站台,无法入库!");
|
|
//}
|
|
//else
|
|
//{
|
|
// 查找目标库位 回原位
|
|
var toLocation = _unitWork.FindSingle<Location>(x => x.Code.Equals(box.Code));
|
|
|
|
if (toLocation != null)
|
|
{
|
|
// 创建任务
|
|
var task = new TaskHeader
|
|
{
|
|
ZoneCode = ZoneCodeEnum.散料库,
|
|
TaskNo = _unitWork.GetSerialNumber("CIn"),
|
|
TaskType = TaskTypeEnum.散料盒入库,
|
|
ContainerCode = toLocation.Code,
|
|
FromLocation = station.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}不正确!");
|
|
}
|
|
}
|
|
}
|