using HH.WCS.Mobox3.YNJT_BZP.core;
|
using HH.WCS.Mobox3.YNJT_BZP.device;
|
using HH.WCS.Mobox3.YNJT_BZP.models;
|
using HH.WCS.Mobox3.YNJT_BZP.process;
|
using HH.WCS.Mobox3.YNJT_BZP.util;
|
using HH.WCS.Mobox3.YNJT_BZP.wms;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using NLog.Fluent;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using System.Linq;
|
using System.Reflection;
|
using System.Threading;
|
using System.Web.UI;
|
using static HH.WCS.Mobox3.YNJT_BZP.api.ApiModel;
|
using static HH.WCS.Mobox3.YNJT_BZP.api.OtherModel;
|
using static HH.WCS.Mobox3.YNJT_BZP.api.WmsController;
|
|
namespace HH.WCS.Mobox3.YNJT_BZP.api {
|
/// <summary>
|
/// api接口辅助类
|
/// </summary>
|
public class ApiHelper {
|
static ApiHelper() {
|
|
}
|
|
/// <summary>
|
/// 1.创建入库任务
|
/// </summary>
|
public static ReturnResult createInOrder(CreateInOrderModel model)
|
{
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
if (model.taskType == "机台半制品入库" || model.taskType == "成型机余料回库")
|
{
|
var itemInfos = model.itemInfo;
|
if (itemInfos == null || itemInfos.Count == 0)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "物料信息不能为空";
|
return result;
|
}
|
else
|
{
|
foreach (var item in itemInfos)
|
{
|
// 将MES的物料状态转化成WMS可识别的物料状态
|
if (item.jdge == "" || item.jdge == null)
|
{
|
item.jdge = "OK";
|
}
|
else if(item.jdge != "OK")
|
{
|
item.jdge = "HOLD";
|
}
|
|
// 计算生效时间、失效时间
|
var overage = WMSHelper.getOverage(item.bc_entried);
|
if (overage != null)
|
{
|
DateTime txndate = DateTime.Parse(item.txndate);
|
DateTime minTime = txndate.AddHours(overage.MINHOUR);
|
DateTime maxTime = txndate.AddDays(overage.OVERAGE);
|
item.effective_time = minTime.ToString("yyyy-MM-dd HH:mm:ss");
|
item.expiration_time = maxTime.ToString("yyyy-MM-dd HH:mm:ss");
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = $"未查询到物料存放时间配置信息,条形码:{item.bc_entried}";
|
return result;
|
}
|
}
|
}
|
}
|
|
var container = ContainerHelper.GetCntr(model.trayCode);
|
if (container != null)
|
{
|
// 胎圈容器入库需检测母拖是否存在
|
if (container.N_TYPE == 6)
|
{
|
if (!WMSHelper.CheckBaseTrayNum())
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = $"库内母拖不足,请尽快补充";
|
return result;
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = $"系统未查询到容器:{model.trayCode},请先在系统进行配置";
|
return result;
|
}
|
|
Location startLoc = LocationHelper.GetLoc(model.startLoc);
|
Location middleLoc = null;
|
if (Settings.getAgvWaitLoc().Count > 0)
|
{
|
middleLoc = LocationHelper.GetLoc(Settings.getAgvWaitLoc()[0]);
|
}
|
Location endLoc = new Location() { S_CODE = "虚拟货位", S_AREA_CODE = "虚拟库区" };
|
|
if (startLoc != null)
|
{
|
if (startLoc.N_LOCK_STATE != 0)
|
{
|
var wcsTask = WCSHelper.GetTaskByStartAndEnd(startLoc.S_CODE);
|
if (wcsTask != null)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "开始货位已存在任务,请勿重复下发任务";
|
return result;
|
}
|
}
|
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = model.trayCode,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = model.taskType,
|
S_OP_DEF_CODE = model.taskNo,
|
S_OP_DEF_NAME = "半制品/余料/空托下发入库任务",
|
N_PRIORITY = model.priority,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = wmsTask.S_CNTR_CODE,
|
S_TYPE = wmsTask.S_TYPE + "-1",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = middleLoc.S_CODE,
|
S_END_AREA = middleLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "AGV",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
|
// 记录入库的物料信息
|
ItemHelper.addCntrItem(model.trayCode, model.itemInfo);
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "开始货位不存在,请检查开始货位编码是否正确";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 2.空托出库
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static ReturnResult emptyTrayOutOrder(EmptyTrayOutOrderModel model)
|
{
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
EmptyTrayBuffer buffer = new EmptyTrayBuffer()
|
{
|
TASK_NO = model.taskNo,
|
TRAY_TYPE = model.trayType,
|
END_LOC = model.endLoc,
|
PRIORITY = model.priority,
|
};
|
WMSHelper.addEmptyTrayBuffer(buffer);
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 3.创建出库任务
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static ReturnResult createOutOrder(CreateOutOrderModel model)
|
{
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
Location endLoc = LocationHelper.GetLoc(model.endLoc);
|
if (endLoc.N_CURRENT_NUM == 0)
|
{
|
int taskNum = 0;
|
for (int i = 0; i < endLoc.N_CAPACITY; i++)
|
{
|
Location startLoc = WMSHelper.GetoutStockStartLoc(model.itemCode);
|
Location middleLoc = null;
|
string descCntrCode = "";
|
string cntrCode = "";
|
if (startLoc != null)
|
{
|
// 查询接驳位
|
var locCodes = Settings.getAgvJBLocList(startLoc.N_ROADWAY, 2);
|
if (locCodes.Count > 0)
|
{
|
middleLoc = LocationHelper.GetLoc(locCodes[0]);
|
}
|
|
// 查询货位容器编码 、目标容器编码
|
var locCntrRels = LocationHelper.GetLocCntrRel(startLoc.S_CODE);
|
if (locCntrRels.Count > 0)
|
{
|
foreach (var item in locCntrRels)
|
{
|
var cntrItemRels = ContainerHelper.GetCntrItemRel(item.S_CNTR_CODE);
|
if (cntrItemRels.Count > 0)
|
{
|
descCntrCode = cntrItemRels[0].S_CNTR_CODE;
|
}
|
cntrCode = cntrCode + "," + item.S_CNTR_CODE;
|
}
|
cntrCode = cntrCode.Substring(1, cntrCode.Length - 1);
|
}
|
}
|
else
|
{
|
LogHelper.Info($"库内没有物料:{model.itemCode}", "WMS");
|
break;
|
}
|
|
|
if (endLoc != null)
|
{
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = descCntrCode,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "成型机叫料出库任务",
|
S_OP_DEF_CODE = model.taskNo,
|
S_OP_DEF_NAME = "成型机叫料出库任务",
|
N_PRIORITY = model.priority,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段出库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = cntrCode,
|
S_TYPE = wmsTask.S_TYPE + "-1",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = middleLoc.S_CODE,
|
S_END_AREA = middleLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
taskNum++;
|
}
|
}
|
}
|
}
|
|
if (taskNum < endLoc.N_CAPACITY)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = $"库内物料不足,已生成出库任务数:{taskNum}";
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "终点货位当前容量不为0,无法叫料";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 4.创建人工入库任务
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static ReturnResult manualStorage(CreateInOrderModel model)
|
{
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
if(model.itemInfo != null && model.itemInfo.Count > 0)
|
{
|
foreach (var item in model.itemInfo)
|
{
|
// 将MES的物料状态转化成WMS可识别的物料状态
|
if (item.jdge == "" || item.jdge == null)
|
{
|
item.jdge = "OK";
|
}
|
else if (item.jdge != "OK")
|
{
|
item.jdge = "HOLD";
|
}
|
|
var overage = WMSHelper.getOverage(item.bc_entried);
|
if (overage != null && overage.OVERAGE != 0)
|
{
|
DateTime txndate = DateTime.Parse(item.txndate);
|
DateTime minTime = txndate.AddHours(overage.MINHOUR);
|
DateTime maxTime = txndate.AddDays(overage.OVERAGE);
|
item.effective_time = minTime.ToString("yyyy-MM-dd HH:mm:ss");
|
item.expiration_time = maxTime.ToString("yyyy-MM-dd HH:mm:ss");
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = $"未查询到物料存放时间配置信息,条形码:{item.bc_entried}";
|
return result;
|
}
|
}
|
}
|
|
var container = ContainerHelper.GetCntr(model.trayCode);
|
if (container != null)
|
{
|
Location startLoc = LocationHelper.GetLoc(model.startLoc);
|
Location endLoc = WMSHelper.GetInstockEndLoc(container.N_TYPE, model.startLoc, 2);
|
|
if (endLoc != null)
|
{
|
string cntrCode = model.trayCode;
|
var locCntrRels = LocationHelper.GetLocCntr(model.startLoc);
|
if (locCntrRels.Count > 0)
|
{
|
cntrCode = cntrCode + "," + locCntrRels[0].S_CNTR_CODE;
|
}
|
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = model.trayCode,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "人工入库任务",
|
S_OP_DEF_CODE = model.taskNo,
|
S_OP_DEF_NAME = "人工入库任务",
|
N_PRIORITY = model.priority,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = cntrCode,
|
S_TYPE = wmsTask.S_TYPE + "-1",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
|
// 记录入库的物料信息
|
ItemHelper.addCntrItem(model.trayCode, model.itemInfo);
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "没有空余的货位";
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 5.创建人工出库任务
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static ReturnResult manualDelivery(CreateOutOrderModel model)
|
{
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
Location startLoc = WMSHelper.GetoutStockStartLoc(model.itemCode,model.trayCode , model.endLoc);
|
Location endLoc = LocationHelper.GetLoc(model.endLoc);
|
|
if (startLoc != null)
|
{
|
string descCntrCode = "";
|
string cntrCode = "";
|
var locCntrRels = LocationHelper.GetLocCntrRel(startLoc.S_CODE);
|
if (locCntrRels.Count > 0)
|
{
|
foreach (var item in locCntrRels)
|
{
|
var cntrItemRels = ContainerHelper.GetCntrItemRel(item.S_CNTR_CODE);
|
if (cntrItemRels.Count > 0)
|
{
|
descCntrCode = cntrItemRels[0].S_CNTR_CODE;
|
}
|
cntrCode = cntrCode + ","+ item.S_CNTR_CODE;
|
}
|
cntrCode = cntrCode.Substring(1, cntrCode.Length-1);
|
}
|
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = descCntrCode,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "人工出库任务",
|
S_OP_DEF_CODE = model.taskNo,
|
S_OP_DEF_NAME = "人工出库任务",
|
N_PRIORITY = model.priority,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = cntrCode,
|
S_TYPE = wmsTask.S_TYPE + "-1",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WMS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "库内没有满足条件的物料";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 6.母拖入库任务
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="taskNo"></param>
|
/// <returns></returns>
|
public static ReturnResult baseTrayInStock(string loc, string taskNo )
|
{
|
LogHelper.Info("【母拖入库任务】开始下发母拖入库任务", "WMS");
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
Location startLoc = LocationHelper.GetLoc(loc);
|
Location endLoc = WMSHelper.GetInstockEndLoc(0, loc, 2);
|
|
if (endLoc != null && startLoc != null)
|
{
|
string trayCode = null;
|
var locCntrRels = LocationHelper.GetLocCntrRel(loc);
|
if (locCntrRels.Count > 0)
|
{
|
var container = ContainerHelper.GetCntr(locCntrRels[0].S_CNTR_CODE);
|
if (container.N_TYPE == 0)
|
{
|
trayCode = container.S_CODE;
|
}
|
}
|
else
|
{
|
trayCode = ContainerHelper.GenerateCntrNo();
|
ContainerHelper.AddCntr(trayCode, 0);
|
}
|
|
if (trayCode != null)
|
{
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = trayCode,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "母拖入库任务",
|
S_OP_DEF_CODE = taskNo,
|
S_OP_DEF_NAME = "母拖入库任务",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = wmsTask.S_CNTR_CODE,
|
S_TYPE = wmsTask.S_TYPE + "-1",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
}
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "没有空余的货位";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 6.1.母拖入库任务
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="wmsTaskNo"></param>
|
/// <returns></returns>
|
public static ReturnResult autoBaseTrayInStock(string loc, string wmsTaskNo)
|
{
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
var cst = WCSHelper.GetTaskByStart(loc);
|
if (cst == null)
|
{
|
Location startLoc = LocationHelper.GetLoc(loc);
|
Location endLoc = null;
|
var baseTrayBufferLoc = Settings.baseTrayBufferLocList.Where(a => a.bufferOutLoc == loc).FirstOrDefault();
|
if (baseTrayBufferLoc != null)
|
{
|
endLoc = LocationHelper.GetLoc(baseTrayBufferLoc.bufferInLoc);
|
}
|
if (endLoc == null || endLoc.N_CURRENT_NUM > 0)
|
{
|
endLoc = WMSHelper.GetInstockEndLoc(0, loc, 2);
|
}
|
|
if (endLoc != null && startLoc != null)
|
{
|
string trayCode = null;
|
var locCntrRels = LocationHelper.GetLocCntrRel(loc);
|
if (locCntrRels.Count > 0)
|
{
|
var container = ContainerHelper.GetCntr(locCntrRels[0].S_CNTR_CODE);
|
if (container.N_TYPE == 0)
|
{
|
trayCode = container.S_CODE;
|
}
|
}
|
else
|
{
|
trayCode = ContainerHelper.GenerateCntrNo();
|
ContainerHelper.AddCntr(trayCode, 0);
|
}
|
|
if (trayCode != null)
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_CODE = wmsTaskNo,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = trayCode,
|
S_TYPE = "母拖入库任务",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "没有空余的货位";
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 7.母拖出库任务
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="taskNo"></param>
|
/// <returns></returns>
|
public static ReturnResult baseTrayOutStock(string loc ,string taskNo ,int exclude = 1)
|
{
|
LogHelper.Info("【母拖出库任务】开始下发母拖出库任务", "WMS");
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
Location startLoc = WMSHelper.GetEmptyTrayStartLoc(0, exclude);
|
Location endLoc = LocationHelper.GetLoc(loc);
|
var agvJBLoc = Settings.getAgvJBLoc(loc);
|
|
if (startLoc != null)
|
{
|
string trayCode = null;
|
var locCntrRels = LocationHelper.GetLocCntr(startLoc.S_CODE);
|
if (locCntrRels.Count == 1)
|
{
|
trayCode = locCntrRels[0].S_CNTR_CODE;
|
}
|
if (trayCode != null)
|
{
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = trayCode,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "母拖出库任务",
|
S_OP_DEF_CODE = taskNo,
|
S_OP_DEF_NAME = "母拖出库任务",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = wmsTask.S_CNTR_CODE,
|
S_TYPE = wmsTask.S_TYPE + "-1",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
}
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "没有空余的母拖";
|
LogHelper.Info("【母拖出库任务】库内没有空余的母拖", "WMS");
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 7.1.母拖出库任务(AGV)
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="wmsTaskNo"></param>
|
/// <returns></returns>
|
public static ReturnResult autoBaseTrayOutStock(string loc, string wmsTaskNo)
|
{
|
ReturnResult result = new ReturnResult();
|
try
|
{
|
var cst = WCSHelper.GetTaskByEnd(loc);
|
if (cst == null)
|
{
|
Location startLoc = WMSHelper.GetEmptyTrayStartLoc(0, 0);
|
Location endLoc = LocationHelper.GetLoc(loc);
|
|
if (startLoc != null)
|
{
|
string trayCode = null;
|
var locCntrRels = LocationHelper.GetLocCntr(startLoc.S_CODE);
|
if (locCntrRels.Count == 1)
|
{
|
trayCode = locCntrRels[0].S_CNTR_CODE;
|
}
|
|
if (trayCode != null)
|
{
|
// 创建入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_CODE = wmsTaskNo,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = trayCode,
|
S_TYPE = "母拖出库任务",
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
}
|
}
|
}
|
else
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "没有空余的母拖";
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = 1;
|
result.ResultMsg = "WMS内部错误,请联系开发人员排查";
|
LogHelper.Info($"WMS内部错误,错误原因:{ex.Message}", "WMS");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 任务状态回报
|
/// 任务状态 1:开始/执行中;完成;3:准备取货;4:取货完成;5:准备卸货;6:卸货完成;7:异常取消;8:强制完成
|
/// 1.根据任务状态回报更新货位状态、任务状态
|
/// 2.更新任务中间表状态
|
/// 4.更新出库任务中间表状态
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static ReturnResult taskStatusFeedback(TaskStatusFeedbackModel model)
|
{
|
ReturnResult responseResult = new ReturnResult();
|
WCSTask cst = WCSHelper.GetTask(model.taskNo);
|
if (cst != null)
|
{
|
bool isExist = WCSHelper.CheckActionRecordExist(cst.S_CODE, model.status);
|
if (!isExist)
|
{
|
WMSTask mst = WMSHelper.GetWmsTask(cst.S_OP_CODE);
|
if (mst != null)
|
{
|
switch (model.status)
|
{
|
case 1:
|
WCSHelper.Begin(cst);
|
break;
|
case 2:
|
WCSHelper.End(cst);
|
break;
|
case 3:
|
WCSHelper.UpdateStatus(cst, "准备取货");
|
break;
|
case 4:
|
WCSHelper.UpdateStatus(cst, "取货完成");
|
TaskProcess.OperateStatus(cst, 4);
|
break;
|
case 5:
|
WCSHelper.UpdateStatus(cst, "准备卸货");
|
break;
|
case 6:
|
WCSHelper.UpdateStatus(cst, "卸货完成");
|
TaskProcess.OperateStatus(cst, 6);
|
break;
|
case 7:
|
WCSHelper.Cancel(cst);
|
WCSHelper.UpdateStatus(cst, "取消");
|
TaskProcess.OperateStatus(cst, 7);
|
break;
|
case 8:
|
WCSHelper.UpdateStatus(cst, "强制完成");
|
WCSHelper.End(cst);
|
break;
|
}
|
// 添加WCS动作记录
|
WCSHelper.AddActionRecord(model.taskNo, model.status, model.deviceNo, model.loc);
|
|
if (model.status == 2 || model.status == 8)
|
{
|
if (mst != null)
|
{
|
if(mst.N_B_STATE != 2)
|
{
|
// 创建下个任务
|
if (cst.S_TYPE.Contains("出库") && !cst.S_TYPE.Contains("母拖") && !cst.S_TYPE.Contains("人工"))
|
{
|
WCSCore.createLastTask(cst.S_END_LOC, mst, 2);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
return responseResult;
|
}
|
|
/// <summary>
|
/// 货位状态反馈
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static bool locStateFeedBack(LocStateFeedBackModel model)
|
{
|
bool result = false;
|
var task = WCSHelper.GetTask(model.req_no);
|
if (task != null)
|
{
|
TaskAction taskAction = null;
|
if (model.type == "1")
|
{
|
taskAction = WCSHelper.getActionRecord(task.S_CODE, 1101);
|
}
|
if (model.type == "2")
|
{
|
taskAction = WCSHelper.getActionRecord(task.S_CODE, 1103);
|
}
|
if (taskAction != null)
|
{
|
taskAction.N_S_STATUS = 1;
|
result = WCSHelper.updateActionRecord(taskAction);
|
}
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 读码反馈
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static ReturnResult readCodeFeedback(ReadCodeFeedbackModel model)
|
{
|
ReturnResult responseResult = new ReturnResult();
|
var locCntrRels = LocationHelper.GetLocCntr(model.locCode);
|
if (locCntrRels.Count > 0)
|
{
|
foreach (var locCntr in locCntrRels)
|
{
|
var container = ContainerHelper.GetCntr(locCntr.S_CNTR_CODE);
|
if (container != null && container.N_TYPE != 0)
|
{
|
var mst = WMSHelper.GetWmsTaskByCntr(locCntr.S_CNTR_CODE);
|
if (mst != null)
|
{
|
int actType = 1;
|
if (locCntr.S_CNTR_CODE == model.trayCode)
|
{
|
if (mst.S_END_LOC == "虚拟货位")
|
{
|
// 获取入库终点
|
var endLoc = WMSHelper.GetInstockEndLoc(container.N_TYPE, model.locCode, 1);
|
if (endLoc != null)
|
{
|
mst.S_END_LOC = endLoc.S_CODE;
|
mst.S_END_AREA = endLoc.S_AREA_CODE;
|
}
|
else
|
{
|
LogHelper.Info("【WCS读码反馈】,没有获取到终点货位,可能立库没有空余货位", "WMS");
|
responseResult.ResultCode = 1;
|
responseResult.ResultMsg = "没有获取到终点货位,可能立库没有空余货位";
|
return responseResult;
|
}
|
}
|
}
|
else
|
{
|
LogHelper.Info($"【WCS读码反馈】,托盘码匹配失败,反馈托盘码:{model.trayCode} ,货位{model.locCode}托盘码:{locCntr.S_CNTR_CODE}", "WMS");
|
// 获取入库终点
|
var endLoc = WMSHelper.getErrorBufferAreaLoc();
|
if (endLoc != null)
|
{
|
actType = 2;
|
LocationHelper.UnLockLoc(mst.S_END_LOC);
|
mst.S_END_LOC = endLoc.S_CODE;
|
mst.S_END_AREA = endLoc.S_AREA_CODE;
|
}
|
else
|
{
|
LogHelper.Info("【WCS读码反馈】,没有获取到缓存货位", "WMS");
|
responseResult.ResultCode = 1;
|
responseResult.ResultMsg = "没有获取到缓存货位";
|
return responseResult;
|
}
|
}
|
|
// 创建下个任务
|
if (mst.S_END_LOC != "虚拟货位")
|
{
|
WMSHelper.UpdateTaskEnd(mst);
|
WCSCore.createLastTask(model.locCode, mst, actType);
|
}
|
}
|
else
|
{
|
LogHelper.Info($"【WCS读码反馈】,容器:{model.trayCode}没有查询到执行中任务", "WMS");
|
}
|
}
|
}
|
}
|
return responseResult;
|
}
|
|
/// <summary>
|
/// 同步物料信息
|
/// </summary>
|
/// <param name="matls"></param>
|
/// <returns></returns>
|
public static ReturnResult synMatlInformation(List<MatlInformation> matls)
|
{
|
ReturnResult responseResult = new ReturnResult();
|
List<ItemBarcodeInfo> itemBarcodeInfos = new List<ItemBarcodeInfo>();
|
CultureInfo enGB = new CultureInfo("en-GB");
|
foreach (MatlInformation matl in matls)
|
{
|
ItemBarcodeInfo itemBarcodeInfo = new ItemBarcodeInfo()
|
{
|
S_ITEM = matl.item,
|
S_BC_ENTRIED = matl.bc_entried,
|
S_MCN = matl.mcn,
|
S_OPR = matl.opr,
|
TXNDATE = DateTime.Parse(matl.txndate, enGB) ,
|
S_SHIFT = matl.shift,
|
N_QTY = matl.qty,
|
N_STOCK = matl.stock,
|
S_LOKASI = matl.lokasi,
|
S_SARANA = matl.sarana,
|
BOM1 = matl.bom1,
|
BOM2 = matl.bom2,
|
BOM3 = matl.bom3,
|
S_FOVRAGE = matl.fovrage,
|
S_JDGE = matl.jdge,
|
LAST_MODIFY_TIME = matl.last_modify_time
|
};
|
itemBarcodeInfos.Add(itemBarcodeInfo);
|
}
|
|
var bo = WMSHelper.batchAddItemBarcodeInfo(itemBarcodeInfos);
|
if (!bo)
|
{
|
responseResult.ResultCode = 1;
|
responseResult.ResultMsg = "同步物料条码信息失败";
|
}
|
return responseResult;
|
}
|
|
/// <summary>
|
/// 同步物料状态信息
|
/// </summary>
|
/// <param name="updateMatlStatuses"></param>
|
/// <returns></returns>
|
public static ReturnResult synUpdateMatlStatus(List<UpdateMatlStatus> updateMatlStatuses)
|
{
|
ReturnResult responseResult = new ReturnResult();
|
var bo = WMSHelper.batchUpdateItemStatus(updateMatlStatuses);
|
if (!bo)
|
{
|
responseResult.ResultCode = 1;
|
responseResult.ResultMsg = "同步物料状态信息失败";
|
}
|
return responseResult;
|
}
|
|
/// <summary>
|
/// 同步更新物料存放时间配置信息
|
/// </summary>
|
/// <param name="overages"></param>
|
/// <returns></returns>
|
public static ReturnResult synUpdateMatlTimeConfig(List<MatlOverage> overages)
|
{
|
ReturnResult responseResult = new ReturnResult();
|
if (overages != null && overages.Count > 0)
|
{
|
List<Overage> overageList = new List<Overage>();
|
foreach (var item in overages)
|
{
|
Overage overage = new Overage
|
{
|
MCNGRP = item.mcngrp,
|
ITEMPATT = item.itempatt,
|
OVERAGE = item.overage,
|
MINHOUR = float.Parse(item.minhour.ToString()),
|
FLAG_STS = item.flag_sts,
|
RECID = item.recid,
|
};
|
overageList.Add(overage);
|
}
|
var bo = WMSHelper.batchUpdateMatlTimeConfig(overageList);
|
if (!bo)
|
{
|
responseResult.ResultCode = 1;
|
responseResult.ResultMsg = "同步物料状态信息失败";
|
}
|
}
|
return responseResult;
|
}
|
|
/// <summary>
|
/// 记录数据同步时间
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public static ReturnResult recordDataSynTime(RecordDataSynTimeModel model)
|
{
|
ReturnResult responseResult = new ReturnResult();
|
SynDataTimeRecord record = new SynDataTimeRecord()
|
{
|
S_SYN_TIME = model.sysTime,
|
N_SYN_NUM = model.synNum,
|
RECORD_TABLE = model.recordTable
|
};
|
var bo = WMSHelper.addSynDataTimeReord(record);
|
if (!bo)
|
{
|
responseResult.ResultCode = 1;
|
responseResult.ResultMsg = "记录数据同步时间失败";
|
}
|
return responseResult;
|
}
|
|
|
/// <summary>
|
/// 查询上一次的数据同步时间
|
/// </summary>
|
/// <param name="recordTable"></param>
|
/// <returns></returns>
|
public static ReturnResult findLastDataSynTime(string recordTable)
|
{
|
ReturnResult responseResult = new ReturnResult();
|
var synDataTime = WMSHelper.getLastDataSynTime(recordTable);
|
if (synDataTime != null)
|
{
|
Dictionary<string, string> map = new Dictionary<string, string>();
|
map.Add("S_SYN_TIME", synDataTime.S_SYN_TIME);
|
map.Add("RECORD_TABLE", synDataTime.RECORD_TABLE);
|
responseResult.data = map;
|
}
|
return responseResult;
|
}
|
|
/// <summary>
|
/// 查询班次
|
/// </summary>
|
/// <param name="time"></param>
|
/// <returns></returns>
|
public static string getShift(TimeSpan time)
|
{
|
TimeSpan shiftI_Start = new TimeSpan(07, 00, 0); // 07:00:00
|
TimeSpan shiftI_End = new TimeSpan(14, 59, 59); // 14:59:59
|
|
TimeSpan shiftII_Start = new TimeSpan(15, 00, 0); // 15:00:00
|
TimeSpan shiftII_End = new TimeSpan(22, 59, 59); // 22:59:59
|
|
TimeSpan shiftIII_Start = new TimeSpan(23, 00, 0); // 23:00:00
|
TimeSpan shiftIII_End = new TimeSpan(06, 59, 59); // 06:59:59
|
|
// 判断是否在 Shift III(跨天需特殊处理)
|
bool isShiftIII = time >= shiftIII_Start || time <= shiftIII_End;
|
|
// 返回结果
|
if (time >= shiftI_Start && time <= shiftI_End)
|
return "I";
|
else if (time >= shiftII_Start && time <= shiftII_End)
|
return "II";
|
else if (isShiftIII)
|
return "III";
|
else
|
return "No shift"; // 理论上不会触发
|
}
|
|
/// <summary>
|
/// 任务状态反馈模型
|
/// </summary>
|
public class TaskStatusFeedbackModel
|
{
|
public string taskNo { get; set; } // 任务号
|
public string subTaskNo { get; set; } // 子任务号
|
public int status { get; set; } // 任务状态 1:开始/执行中;2:完成;3:准备取货;4:取货完成;5:准备卸货;6:卸货完成;7:异常取消;8:强制完成
|
public string deviceNo { get; set; } // 设备号
|
public string errCode { get; set; } // 异常代码 0.无异常 1.设备故障码、2.rfid校验失败、3.取货无货、4.放货有货
|
public string loc { get; set; } // 当前货位
|
}
|
|
/// <summary>
|
/// 读码反馈模型
|
/// </summary>
|
public class ReadCodeFeedbackModel
|
{
|
public string trayCode { get; set; } // 容器号
|
public string locCode { get; set; } // 当前货位
|
}
|
public class BaseTrayOutInStockModel
|
{
|
public string locCode { get; set; } // 货位编码
|
public string taskNo { get; set; } // 任务号
|
public string taskType { get; set; } // 任务类型 1.入库 2.出库
|
}
|
|
public class CreateOutOrderModel
|
{
|
public string taskNo { get; set; } // 任务号
|
public string trayCode { get; set; } // 任务号
|
public string itemCode { get; set; } // 物料编码
|
public string endLoc { get; set; } // 终点货位
|
public int priority { get; set; } = 0; // 优先级 默认0
|
}
|
|
public class EmptyTrayOutOrderModel
|
{
|
public string taskNo { get; set; } // 任务号
|
public int trayType { get; set; } // 托盘类型
|
public string endLoc { get; set; } // 终点货位
|
public int priority { get; set; } = 0; // 优先级 默认0
|
}
|
|
public class CreateInOrderModel
|
{
|
public string taskNo { get; set; } // 任务号
|
public string startLoc { get; set; } // 起点货位
|
public string taskType { get; set; } // 任务类型 入库回库类型,1:机台半制品入库,2:成型机余料回库,3:成型机空托回库
|
public string trayCode { get; set; } // 托盘号
|
public int priority { get; set; } = 0;// 优先级 默认传0
|
public List<GTItemInfo> itemInfo { get; set; }
|
}
|
|
public class GTItemInfo
|
{
|
public string item { get; set; } // 物品代码
|
public string bc_entried { get; set; } // 条形码编号
|
public string mcn { get; set; } // 机器代码编号
|
public string opr { get; set; } // 操作员
|
public string txndate { get; set; } // 生产时间
|
public string shift { get; set; } // 工作班次
|
public int qty { get; set; } // 产品数量
|
public string sarana { get; set; } // 产品材料的托盘/盒/推车/货车ID
|
public string fovrage { get; set; } // 是否过期的状态 Y=过期,N=未过期
|
public string jdge { get; set; } // 质量状态 OK=产品合格,NG=产品不合格,HLM=产品待定
|
public string effective_time { get; set; } // 生效时间 (yyyy-MM-dd HH:mm:ss)
|
public string expiration_time { get; set; } // 失效时间 (yyyy-MM-dd HH:mm:ss)
|
}
|
|
|
|
public class CodeInfo {
|
/// <summary>
|
/// 生产订单内码
|
/// </summary>
|
public string FInterID { get; set; }
|
/// <summary>
|
/// 生产订单编号
|
/// </summary>
|
public string FSourceNo { get; set; }
|
/// <summary>
|
/// 批号
|
/// </summary>
|
public string FGMPBatchNo { get; set; }
|
public string FState { get; set; }
|
/// <summary>
|
/// 物料编码(内码就是编码)
|
/// </summary>
|
public string Fitemid_XK { get; set; }
|
/// <summary>
|
/// 分录id
|
/// </summary>
|
public string Fentryid { get; set; }
|
}
|
public class NoteInfo : CodeInfo {
|
public string WmsBillNo { get; set; }
|
}
|
}
|
}
|