using Newtonsoft.Json;
using System;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Common;
using WIDESEA_Core.ManageUser;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.DomainModels.Mes;
namespace WIDESEA_WMS
{
public partial class ToMesServer
{
///
/// 手动移库
///
///
///
public WebResponseContent AddToFloat3(MesRequestTemp requestTemp)
{
WebResponseContent content = new WebResponseContent();
try
{
//var route = freeDB.Select().Where(t => t.stationCode == requestTemp.from_address && t.route_end == requestTemp.to_address).ToOne();
var station1 = freeDB.Select().Where(t => t.stationCode == requestTemp.from_address).First();
var station2 = freeDB.Select().Where(t => t.stationCode == requestTemp.to_address).First();
if (station1 == null || station2 == null)
{
throw new Exception($"路径{requestTemp.from_address}到{requestTemp.to_address},不存在!");
}
if (station1.location_state != LocationStateEnum.Stroge.ToString())
throw new Exception($"起点{requestTemp.from_address}未找到物料!");
if (station2.location_state != LocationStateEnum.Empty.ToString())
throw new Exception($"终点{requestTemp.to_address}不是空货位!");
if (string.IsNullOrEmpty(station1.stationType))
throw new Exception($"起点{requestTemp.from_address}未绑定物料类型!");
if (station1.stationType != station2.stationType)
throw new Exception($"起点与终点绑定物料类型不一致!");
var haveInTask = freeDB.Select()
.Where(t => t.agv_fromaddress == requestTemp.from_address
|| t.agv_fromaddress == requestTemp.to_address
|| t.agv_toaddress == requestTemp.from_address
|| t.agv_toaddress == requestTemp.to_address
).Any();
if (!haveInTask)
{
station2.quantity = station1.quantity;
station2.bindSN = station1.bindSN;
station2.location_state = LocationStateEnum.Stroge.ToString();
station2.tray_status = station1.tray_status;
freeDB.Update(station2);
station1.quantity = 0;
station1.bindSN = string.Empty;
station1.location_state = LocationStateEnum.Empty.ToString();
station1.tray_status = string.Empty;
freeDB.Update(station1);
}
else
{
throw new Exception("起始或目的地址,已存在任务!");
}
content.OK();
WriteDBLog.Success($"手动移库", new { 数据 = requestTemp }, "WMS", UserContext.Current.UserName + UserContext.Current.UserTrueName);
}
catch (Exception ex)
{
WriteDBLog.Error($"手动移库", new { 数据 = requestTemp, 异常信息 = ex.Message }, "WMS", UserContext.Current.UserName + UserContext.Current.UserTrueName);
content.Error(ex.Message);
}
return content;
}
}
}