using HH.WCS.Emerson.device;
|
|
using HH.WCS.Emerson.process;
|
using HH.WCS.Emerson.util;
|
using HH.WCS.Emerson.wms;
|
using Newtonsoft.Json;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading;
|
using static HH.WCS.Emerson.api.ApiModel;
|
using static HH.WCS.Emerson.api.OtherModel;
|
|
namespace HH.WCS.Emerson.api
|
{
|
/// <summary>
|
/// api接口辅助类
|
/// </summary>
|
public class ApiHelper
|
{
|
static ApiHelper()
|
{
|
|
}
|
|
internal static void AddTask(AddTaskModel model)
|
{
|
if (!WCSHelper.CheckExist(model.No))
|
{
|
if (LocationHelper.CheckExist(model.From) && LocationHelper.CheckExist(model.To))
|
{
|
WCSHelper.CreateTask(model.No, model.From, model.To, "搬运", 99, "");
|
}
|
|
}
|
}
|
|
internal static SimpleResult Putaway_Order_In(Putaway_Order_In model)
|
{
|
var result = new SimpleResult();
|
//创建入库单主子表
|
var po = WMSHelper.GetPutawayOrder(model.Data.arrival_no);
|
if (po == null)
|
{
|
po = new PutawayOrder { S_NO = model.Data.arrival_no, S_BS_TYPE = model.Data.op_type };
|
po.Details = new List<PutawayDetail>();
|
if (model.Data.items.Count > 0)
|
{
|
model.Data.items.ForEach(a =>
|
{
|
po.Details.Add(new PutawayDetail
|
{
|
S_PUTAWAY_NO = model.Data.arrival_no,
|
N_ROW_NO = po.Details.Count + 1,
|
S_ITEM_CODE = a.item_code,
|
F_QTY = a.qty,
|
S_BATCH_NO = a.batch_no,
|
});
|
});
|
WMSHelper.CreatePutawayOrder(po);
|
}
|
|
}
|
return result;
|
}
|
|
internal static SimpleResult PalletSorting(PalletSorting model)
|
{
|
var result = new SimpleResult();
|
//校验入库单数量,不可以超,成功后插入托盘物料表,更新入库单累计数量
|
//也可以直接lua查询入库单数量,做校验
|
var info = WMSHelper.GetPutawayOrderDetail(model.arrival_no, model.item_code);
|
if (info != null)
|
{
|
if (info.F_QTY - info.F_ACC_B_QTY >= model.qty)
|
{
|
// 插入到托盘明细表
|
var cntr = ContainerHelper.GetCntr(model.cntr_code, true);
|
if (cntr != null)
|
{
|
ContainerHelper.BindCntrItem(cntr, model.item_code, info.S_BATCH_NO, model.qty, model.arrival_no);
|
//更新入库单累计绑定数量
|
info.F_ACC_B_QTY += model.qty;
|
WMSHelper.UpdatePutawayOrderDetailQty(info);
|
}
|
else
|
{
|
result.resultCode = 2;
|
result.resultMsg = "获取托盘信息失败";
|
}
|
|
|
}
|
else
|
{
|
result.resultCode = 1;
|
result.resultMsg = "累计码盘数量超出入库单数量";
|
}
|
}
|
else
|
{
|
result.resultCode = 3;
|
result.resultMsg = $"未找到入库单{model.arrival_no}";
|
}
|
|
return result;
|
}
|
|
internal static SimpleResult OutboundOrder(OutboundOrder model)
|
{
|
var result = new SimpleResult();
|
//创建发货单,人工点确认后生成分拣单,没有缺货的自动更新为失败,有货的更新为执行中
|
//创建入库单主子表
|
var po = WMSHelper.GetShippingOrder(model.Data.out_no);
|
if (po == null)
|
{
|
po = new ShippingOrder { S_NO = model.Data.out_no, S_BS_TYPE = model.Data.op_type };
|
po.Details = new List<ShippingDetail>();
|
if (model.Data.items.Count > 0)
|
{
|
model.Data.items.ForEach(a =>
|
{
|
po.Details.Add(new ShippingDetail
|
{
|
S_SHIPPING_NO = model.Data.out_no,
|
N_ROW_NO = po.Details.Count + 1,
|
S_ITEM_CODE = a.item_code,
|
F_QTY = a.qty,
|
S_BATCH_NO = a.batch_no,
|
});
|
});
|
WMSHelper.CreateShippingOrder(po);
|
}
|
|
}
|
return result;
|
}
|
|
#region 废弃老流程
|
//internal static Result createtask(CreateTask model)
|
//{
|
// Result result = new Result { resultCode = 0, resultMsg = "创建成功" };
|
// var db = new SqlHelper<object>().GetInstance();
|
// string start = model.startBit;
|
// string end = model.endBit;
|
// string Type = "";
|
// string cntrcode = "";
|
// int startlayer = 1;
|
|
// int endlayer = 1;
|
// // string startarea = "";
|
// //string endarea = "";
|
// //1创建取托盘任务
|
// if (model.TaskType == "1")
|
// {
|
// if (LocControl(start))
|
// {
|
// string startZone = "HJQ";
|
// //找空托盘
|
// var cntr = ContainerHelper.GetItemCntrRel(model.ItemCode).ToList();
|
// if (cntr.Count > 0)
|
// {
|
// string[] cntrcodes = cntr.Select(a => a.S_CNTR_CODE).ToArray();
|
// // 根据托盘找货位
|
// var trayInfo = db.Queryable<LocCntrRel>().Where(a => cntrcodes.Contains(a.S_CNTR_CODE)).ToList();
|
// if (trayInfo.Count() > 0)
|
// {
|
// //判断起点是否是指定库区的货位
|
// foreach (var item in trayInfo)
|
// {
|
// var locations = db.Queryable<Location>().Where(a => a.S_CODE == item.S_LOC_CODE && a.S_AREA_CODE == startZone).First();
|
// if (locations != null)
|
// {
|
// start = locations.S_CODE;
|
// cntrcode = item.S_CNTR_CODE;
|
// break;
|
// }
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "根据托盘编码未找到所属货位编码";
|
// return result;
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "找不到空托盘";
|
// return result;
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "外侧货位有托盘";
|
// return result;
|
// }
|
// }
|
// // 2创建取物料任务
|
// else if (model.TaskType == "2")
|
// {
|
// if (LocControl(start))
|
// {
|
// string startZone = "AGVZYQ";
|
|
// //根据物料编码找托盘
|
// var cntr = ContainerHelper.GetItemCntrRel(model.ItemCode).FirstOrDefault();
|
// if (cntr != null)
|
// {
|
// //根据托盘找货位
|
// var trayInfo = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE == cntr.S_CNTR_CODE).ToList();
|
// if (trayInfo.Count() > 0)
|
// {
|
// //判断起点是否是指定库区的货位
|
// foreach (var item in trayInfo)
|
// {
|
// var locations = db.Queryable<Location>().Where(a => a.S_CODE == item.S_LOC_CODE && a.S_AREA_CODE == startZone).First();
|
// if (locations != null)
|
// {
|
// start = locations.S_CODE;
|
// cntrcode = cntr.S_CNTR_CODE;
|
// //startlayer = locations.N_CURRENT_NUM == 1 ? 1 : 2;
|
// // startlayer = locations.N_LAYER;
|
// break;
|
// }
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "根据物料托盘编码未找到所属货位编码";
|
// return result;
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "根据物料编码未找到所属容器号";
|
// return result;
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "外侧货位有托盘,不允许生成任务";
|
// return result;
|
// }
|
|
// }
|
// //3满拖入库
|
// else if (model.TaskType == "3")
|
// {
|
|
// string endlloc = "JBW_01_01";
|
|
|
// var locations = LocationHelper.GetLocList(endlloc).FirstOrDefault();
|
// if (locations.S_LOCK_STATE != "无")
|
// {
|
// if (locations.N_CURRENT_NUM > 0)
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = $"货位{endlloc}已有托盘,不允许生成任务";
|
// return result;
|
// }
|
// else
|
// {
|
// end = endlloc;
|
// }
|
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = $"货位{endlloc}已有任务正在执行中,不允许生成任务";
|
// return result;
|
// }
|
// //var locations = LocationHelper.GetLocListAny(startZone).OrderBy(a => a.N_ROW).ToList();
|
// //var suo = locations.Find(a => a.S_LOCK_STATE != "无");
|
// //if (suo != null)
|
// //{
|
// // var endloc = FindEndcolByLocList(locations, model.ItemCode);
|
// // if (endloc != null)
|
// // {
|
// // end = endloc.S_CODE;
|
// // }
|
// //}
|
// //else
|
// //{
|
// // result.resultCode = -1;
|
// // result.resultMsg = $"库区{suo.S_AREA_CODE}已有任务正在执行中,不允许生成任务";
|
// // return result;
|
// //}
|
|
|
|
// }
|
// //4分拣出
|
// else if (model.TaskType == "4")
|
// {
|
// string startZone = "HJQ";
|
|
// //根据物料编码找托盘
|
// var cntr = ContainerHelper.GetItemCntrRel(model.ItemCode).FirstOrDefault();
|
// if (cntr != null)
|
// {
|
// //根据托盘找货位
|
// var trayInfo = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE == cntr.S_CNTR_CODE).ToList();
|
// if (trayInfo.Count() > 0)
|
// {
|
// //判断起点是否是指定库区的货位
|
// foreach (var item in trayInfo)
|
// {
|
// var locations = db.Queryable<Location>().Where(a => a.S_CODE == item.S_LOC_CODE && a.S_AREA_CODE == startZone).First();
|
// if (locations != null)
|
// {
|
// start = locations.S_CODE;
|
// cntrcode = cntr.S_CNTR_CODE;
|
// break;
|
// }
|
// }
|
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "根据物料托盘编码未找到所属货位编码";
|
// return result;
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = "根据物料编码未找到所属容器号";
|
// return result;
|
// }
|
// }
|
// else
|
// {
|
// result.resultCode = -1;
|
// result.resultMsg = $"任务类型有误,{model.TaskType}任务类型不是规定任务类型";
|
// return result;
|
// }
|
// if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end))
|
// {
|
// //创建wcs任务
|
// var wcsTask = new WCSTask
|
// {
|
// S_CODE = WCSHelper.GenerateTaskNo(),
|
// S_TYPE = Type,
|
// S_START_LOC = start,
|
// S_END_LOC = end,
|
// N_CNTR_COUNT = 1,
|
// N_SCHEDULE_TYPE = 1,
|
// S_CNTR_CODE = cntrcode,
|
// N_START_LAYER = startlayer,
|
// N_END_LAYER = endlayer
|
|
// };
|
// LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
|
// if (WCSHelper.CreateTask(wcsTask))
|
// {
|
// LocationHelper.LockLoc(start, 2);
|
// LocationHelper.LockLoc(end, 1);
|
// LogHelper.Info("创建任务成功");
|
// }
|
// }
|
|
// return result;
|
//}
|
#endregion
|
|
private static object lockObj = new object();
|
/// <summary>
|
/// 创建任务
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static Result createtask(CreateTask model)
|
{
|
Result result = new Result { resultCode = 0, resultMsg = "创建成功" };
|
if (model == null)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "入参为空";
|
return result;
|
}
|
var db = new SqlHelper<object>().GetInstance();
|
string start = model.startBit;
|
Location endloc = new Location();
|
Location startloc = new Location();
|
string Type = "";
|
string cntrcode = "";
|
int startlayer = 1;
|
string endZone = "";
|
lock (lockObj)
|
{
|
try
|
{
|
int endlayer = 1;
|
// 1 创建入库任务
|
if (model.TaskType == "1")
|
{
|
Type = "入库";
|
endZone = "HJQ";
|
}
|
// 2 创建出库任务
|
else if (model.TaskType == "2")
|
{
|
Type = "码盘出库";
|
endZone = "CKFJQ";
|
|
}
|
// 1 创建入库任务
|
else if (model.TaskType == "3")
|
{
|
Type = "码盘入库";
|
endZone = "HJQ";
|
}
|
else
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"任务类型有误,{model.TaskType}任务类型不是规定任务类型";
|
LogHelper.Info($"creattask:任务类型有误,{model.TaskType}任务类型不是规定任务类型");
|
return result;
|
}
|
//根据托盘编码找托盘货位表
|
// var LocCntr = ContainerHelper.GetLocCntrByCntr(model.CntrCode);
|
//获取起点信息
|
startloc = LocationHelper.GetLoc(model.startBit);
|
if (startloc != null)
|
{
|
if (startloc.N_LOCK_STATE != 0)
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"起点:{model.startBit}货位状态{startloc.N_LOCK_STATE},无法下发任务";
|
LogHelper.Info($"creattask:起点:{model.startBit}货位状态{startloc.N_LOCK_STATE},无法下发任务");
|
return result;
|
}
|
//创建托盘货位绑定关系
|
if (model.TaskType == "1")
|
{
|
if (!ContainerHelper.CreateCntrLoc(model.startBit, model.CntrCode))
|
{
|
// result.resultCode = -1;
|
// result.resultMsg = $"添加货位{model.startBit}与托盘{model.CntrCode}绑定关系失败";
|
LogHelper.Info($"creattask:添加货位{model.startBit}与托盘{model.CntrCode}绑定关系失败");
|
// return result;
|
}
|
}
|
|
cntrcode = model.CntrCode;
|
start = startloc.S_CODE;
|
//出库正常算货位, 入库根据托盘算货位
|
if (model.TaskType == "2")
|
{
|
if (string.IsNullOrEmpty(model.endBit))
|
{
|
var endlocations = LocationHelper.GetLocListAny(endZone).OrderBy(a => a.N_ROW).ToList();
|
endloc = FindEndcolByLocList(endlocations);
|
}
|
else
|
{
|
endloc = LocationHelper.GetLoc(model.endBit);
|
}
|
|
if (endloc == null && endloc.N_LOCK_STATE == 0 && endloc.N_CURRENT_NUM == 0)
|
{
|
LogHelper.Info($"终点货位:{model.endBit}不可用");
|
}
|
}
|
else
|
{
|
//根据托盘找货位
|
var endlocation = LocationHelper.GetLoc(model.CntrCode);
|
if (endlocation.N_LOCK_STATE != 0 && endlocation.N_CURRENT_NUM == 0)
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"终点:{endlocation.S_CODE},货位状态{endlocation.N_LOCK_STATE},货位数量:{endlocation.N_CURRENT_NUM}无法下发任务";
|
LogHelper.Info($"creattask:终点:{endlocation.S_CODE},货位状态{endlocation.N_LOCK_STATE},货位数量:{endlocation.N_CURRENT_NUM}无法下发任务");
|
return result;
|
}
|
else
|
{
|
endloc = endlocation;
|
}
|
}
|
|
|
}
|
else
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"根据起点:{model.startBit}未找到货位信息";
|
LogHelper.Info($"creattask:根据起点:{model.startBit}未找到货位信息");
|
return result;
|
}
|
|
if (!string.IsNullOrEmpty(start) && endloc != null)
|
{
|
//创建wcs任务
|
var wcsTask = new WCSTask
|
{
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = Type,
|
S_START_LOC = start,
|
S_END_LOC = endloc.S_CODE,
|
N_CNTR_COUNT = 1,
|
S_CNTR_CODE = cntrcode,
|
N_SCHEDULE_TYPE = 1,
|
S_END_WH = endloc.S_WH_CODE,
|
S_START_WH = startloc.S_WH_CODE,
|
N_START_LAYER = startlayer,
|
N_END_LAYER = endlayer,
|
S_START_AREA = startloc.S_AREA_CODE,
|
S_END_AREA = endloc.S_AREA_CODE,
|
|
};
|
LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
|
|
//LocationHelper.LockLoc(start, 2);
|
LocationHelper.LockLoc(endloc.S_CODE, 1);
|
LogHelper.Info("创建任务成功");
|
}
|
}
|
|
return result;
|
}
|
catch (Exception ex)
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"{ex.ToString()}";
|
return result;
|
|
}
|
}
|
|
|
}
|
|
/// <summary>
|
/// 呼叫空托
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static Result Callfixture(CreateTask model)
|
{
|
Result result = new Result { resultCode = 0, resultMsg = "创建成功" };
|
if (model == null)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "入参为空";
|
return result;
|
}
|
//var task = WCSHelper.GetTaskbyType("呼叫空托");
|
//if (task.Count >= 2)
|
//{
|
// result.resultCode = -1;
|
// result.resultMsg = "呼叫空托任务已存在两条,请等待当前任务完成再呼叫空托";
|
// return result;
|
//}
|
var db = new SqlHelper<object>().GetInstance();
|
|
string endZone = "RKQ";
|
string cntrcode = model.CntrCode;
|
//创建取托盘任务
|
|
Location startloc = new Location();
|
Location endloc = new Location();
|
//艾默生托盘编码和货位编码一样
|
try
|
{
|
startloc = LocationHelper.GetLoc(cntrcode);
|
endloc = LocationHelper.GetLocListAny(endZone).Find(a => a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM == 0);
|
|
|
if (startloc != null)
|
{
|
string endcode = "";
|
string endwh = "";
|
int endlayer = 0;
|
string endarea = "";
|
//创建wcs任务
|
if (endloc != null)
|
{
|
endcode = endloc.S_CODE;
|
endwh = endloc.S_WH_CODE;
|
endlayer = endloc.N_LAYER;
|
endarea = endloc.S_AREA_CODE;
|
}
|
|
var wcsTask = new WCSTask
|
{
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = "呼叫空托",
|
S_START_LOC = startloc.S_CODE,
|
N_CNTR_COUNT = 1,
|
S_CNTR_CODE = cntrcode,
|
N_SCHEDULE_TYPE = 1,
|
S_START_WH = startloc.S_WH_CODE,
|
N_START_LAYER = startloc.N_LAYER,
|
S_START_AREA = startloc.S_AREA_CODE,
|
S_END_LOC = endcode,
|
S_END_WH = endwh,
|
N_END_LAYER = endlayer,
|
S_END_AREA = endarea,
|
|
};
|
LogHelper.Info("呼叫空托任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
LocationHelper.LockLoc(startloc.S_CODE, 2);
|
if (endloc != null)
|
{
|
LocationHelper.LockLoc(endloc.S_CODE, 1);
|
}
|
|
LogHelper.Info("创建呼叫空托任务成功");
|
}
|
}
|
else
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"根据起点托盘{model.CntrCode}找不到货位,请检查货位表";
|
return result;
|
}
|
|
|
|
|
|
return result;
|
}
|
catch (Exception ex)
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"error: {ex}";
|
LogHelper.Info($"Callfixture error:{ex}");
|
return result;
|
}
|
|
}
|
|
/// <summary>
|
/// 呼叫空托
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static Result CreatePeerTask(CreateTask model)
|
{
|
Result result = new Result { resultCode = 0, resultMsg = "创建成功" };
|
if (model == null)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "入参为空";
|
return result;
|
}
|
|
var db = new SqlHelper<object>().GetInstance();
|
|
string cntrcode = "";
|
//创建取托盘任务
|
|
Location startloc = new Location();
|
Location endloc = new Location();
|
//找空托盘
|
|
|
startloc = LocationHelper.GetLoc(model.startBit);
|
endloc = LocationHelper.GetLoc(model.startBit);
|
|
|
if (startloc != null && endloc != null)
|
{
|
//创建wcs任务
|
var wcsTask = new WCSTask
|
{
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = "室外搬运",
|
S_START_LOC = startloc.S_CODE,
|
S_END_LOC = endloc.S_CODE,
|
N_CNTR_COUNT = 1,
|
S_CNTR_CODE = cntrcode,
|
N_SCHEDULE_TYPE = 1,
|
S_END_WH = endloc.S_WH_CODE,
|
S_START_WH = startloc.S_WH_CODE,
|
N_START_LAYER = startloc.N_LAYER,
|
N_END_LAYER = endloc.N_LAYER,
|
S_START_AREA = startloc.S_AREA_CODE,
|
S_END_AREA = endloc.S_AREA_CODE,
|
|
};
|
LogHelper.Info("室外搬运任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
LocationHelper.LockLoc(startloc.S_CODE, 2);
|
LocationHelper.LockLoc(endloc.S_CODE, 1);
|
LogHelper.Info("创建室外搬运任务成功");
|
}
|
}
|
else
|
{
|
result.resultCode = -1;
|
result.resultMsg = $"根据起点货位{model.startBit},或者终点货位;{model.endBit}找不到可用货位,请检查货位表";
|
return result;
|
}
|
|
|
|
|
|
return result;
|
}
|
|
|
internal static void transport()
|
{
|
string endZone = "HJQ";
|
string loc = "JBW_01_01";
|
|
try
|
{
|
var startlocation = LocationHelper.GetLocListbyloc(loc).FirstOrDefault();
|
if (startlocation == null)
|
{
|
LogHelper.Info($"transport:==>根据货位{loc}未找到货位信息");
|
return;
|
}
|
if (startlocation.S_LOCK_STATE != "无" && startlocation.N_CURRENT_NUM > 0)
|
{
|
var endlocations = LocationHelper.GetLocListAny(endZone).OrderBy(a => a.N_ROW).ToList();
|
|
var suo = endlocations.Find(a => a.S_LOCK_STATE != "无");
|
if (suo != null)
|
{
|
//获取容器物料编码
|
var cntr = LocationHelper.GetLocCntr(loc).First();
|
if (cntr != null)
|
{
|
var iteminfo = ContainerHelper.GetCntrItemRel(cntr.S_CNTR_CODE).First();
|
if (iteminfo != null)
|
{
|
//根据终点库区货位和物料计算货位
|
var endloc = FindEndcolByLocList(endlocations);
|
if (endloc != null)
|
{
|
//创建wcs任务
|
var wcsTask = new WCSTask
|
{
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = "入库转运",
|
S_START_LOC = loc,
|
S_END_LOC = endloc.S_CODE,
|
N_CNTR_COUNT = 1,
|
N_SCHEDULE_TYPE = 1,
|
S_CNTR_CODE = cntr.S_CNTR_CODE,
|
N_START_LAYER = startlocation.N_LAYER,
|
N_END_LAYER = endloc.N_LAYER
|
|
};
|
LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
LocationHelper.LockLoc(loc, 2);
|
LocationHelper.LockLoc(endloc.S_CODE, 1);
|
LogHelper.Info("创建任务成功");
|
}
|
}
|
}
|
else
|
{
|
LogHelper.Info($"transport:==>根据托盘{cntr}获取物料信息失败,请检查托盘物料表");
|
}
|
}
|
else
|
{
|
LogHelper.Info($"transport:==>根据货位{loc}获取托盘失败,请检查货位托盘表");
|
}
|
|
}
|
else
|
{
|
LogHelper.Info($"transport:==>库区{suo.S_AREA_CODE}已有任务正在执行中,不允许生成任务");
|
}
|
|
|
}
|
}
|
catch (Exception ex)
|
{
|
|
LogHelper.Info($"transport:==>Error==> {ex}");
|
}
|
|
|
}
|
|
/// <summary>
|
/// 判断同列外侧排是否存在托盘
|
/// </summary>
|
/// <param name="startloc"></param>
|
/// <returns></returns>
|
internal static bool LocControl(string startloc)
|
{
|
var db = new SqlHelper<object>().GetInstance();
|
var trayInfo = db.Queryable<Location>().Where(a => a.S_CODE == startloc).First();
|
if (trayInfo != null)
|
{
|
//判断
|
var rightloc = db.Queryable<Location>().Where(a => a.S_AREA_CODE == trayInfo.S_AREA_CODE && a.N_COL == trayInfo.N_COL && a.N_ROW == trayInfo.N_ROW + 1).First();
|
if (rightloc != null)
|
{
|
if (rightloc.N_CURRENT_NUM > 0)
|
{
|
return false;
|
}
|
}
|
}
|
return true;
|
}
|
/// <summary>
|
/// 绑定托盘物料
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
///
|
internal static Result bindCntr(BindCntr model)
|
{
|
Result result = new Result { resultCode = 0, resultMsg = "绑定成功" };
|
try
|
{
|
|
var traylist = ContainerHelper.GenerateCntrNo();
|
|
if (ContainerHelper.CreateCntrItem(model.LocCode, traylist, model.ItemCode))
|
{
|
return result;
|
}
|
else
|
{
|
result.resultCode = -1;
|
result.resultMsg = "绑定失败";
|
return result;
|
}
|
|
|
}
|
catch (Exception ex)
|
{
|
result.resultCode = -1;
|
result.resultMsg = ex.ToString();
|
return result;
|
}
|
|
|
}
|
|
/// <summary>
|
/// 解绑托盘
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static Result untieCntr(UntieCntr model)
|
{
|
Result result = new Result { resultCode = 0, resultMsg = "创建成功" };
|
// var result = new SimpleResultModel { success = false, errCode = -1 };
|
string msg = ""; int n = 0;
|
var db = new SqlHelper<object>().GetInstance();
|
|
|
string cntrCode = model.CntrCode;
|
string locCode = model.LocCode;
|
var trayInfo = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == locCode).First();
|
if (trayInfo != null)
|
{
|
cntrCode = trayInfo.S_CNTR_CODE;
|
//locCode = trayInfo.S_LOC_CODE.Trim();
|
|
db.Deleteable<LocCntrRel>(a => a.S_CNTR_CODE == cntrCode).ExecuteCommand();
|
db.Deleteable<CntrItemDetail>(a => a.S_CNTR_CODE == cntrCode).ExecuteCommand();
|
msg = msg + $"{n++}:当前托盘号:{model.CntrCode},解绑成功!";
|
}
|
else msg = msg + $"{n++}:当前托盘号:{model.CntrCode},不存在对应货位!";
|
if (!string.IsNullOrEmpty(locCode))
|
{
|
var locNum = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == locCode).ToList();
|
int num = 0;
|
var locInfo = db.Queryable<Location>().Where(a => a.S_CODE == locCode).First();
|
|
if (locInfo != null)
|
{
|
locInfo.N_CURRENT_NUM = GetLocTrayNum(locNum, num);
|
LogHelper.Info("UnbindingTrayCode Dispose:更新当前货位当前数量!" + $"货位编码:{locCode},数量:{locInfo.N_CURRENT_NUM}", "ThirdSystemLog");
|
db.Updateable(locInfo).UpdateColumns(a => new { a.N_CURRENT_NUM }).ExecuteCommand();
|
// var locaHaveTray = db.Queryable<Location>().Where(a => a.N_ROW == locInfo.N_ROW && a.N_CURRENT_NUM > 0).ToList();
|
//if (locaHaveTray.Count == 0) TaskHelper.YiKuUnLockRow(db, locInfo.N_ROW.Trim(), locInfo.S_AREA_CODE.Trim(), true, false, true);
|
//else TaskController.Monitor.YiKuUnLockRow(db, locInfo.N_ROW.Trim(), locInfo.S_AREA_CODE.Trim(), false);
|
}
|
}
|
|
|
result.resultMsg = msg;
|
LogHelper.Info("UnbindingTrayCode Dispose:" + result.resultMsg, "ThirdSystemLog");
|
return result;
|
|
}
|
|
/// <summary>
|
/// 找终点空货位
|
/// </summary>
|
/// <param name="locations"></param>
|
/// <returns></returns>
|
internal static Location FindEndcolByLocList(List<Location> locations)
|
{
|
try
|
{
|
var db = new SqlHelper<object>().GetInstance();
|
Location end = null;
|
//根据终点货位找空闲货位
|
var rows = locations.Select(a => a.N_COL).Distinct().ToList();
|
for (int i = 0; i < rows.Count; i++)
|
{
|
var rowList = locations.Where(r => r.N_COL == rows[i]).ToList();
|
if (rowList.Count(a => a.N_CURRENT_NUM == 0) > 0)
|
{
|
Location other = null;
|
|
//先找满位,然后后面一层要么是空,要么不存在
|
other = rowList.OrderByDescending(a => a.N_LAYER).Where(a => a.N_CURRENT_NUM == 0).FirstOrDefault();
|
//if (full == null)
|
//{
|
// //没有满位,那就找最小的空位
|
// other = rowList.OrderBy(a => a.N_LAYER).FirstOrDefault();
|
//}
|
//else
|
//{
|
// other = rowList.OrderBy(a => a.N_LAYER).Where(a => a.N_LAYER > full.N_LAYER).FirstOrDefault();
|
//}
|
//if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "禁用"))
|
//{
|
// //禁用了选择后面一个货位
|
// other = db.Queryable<Location>().OrderBy(a => a.N_LAYER).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "禁用") && a.S_AREA_CODE == other.S_AREA_CODE && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
|
|
// //LogHelper.Info($"禁用选择后一个货位{result}", "成品");
|
//}
|
if (other != null)
|
{
|
end = other;
|
break;
|
|
}
|
|
}
|
}
|
return end;
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
|
}
|
|
/// <summary>
|
/// 找起点满货位
|
/// </summary>
|
/// <param name="locations"></param>
|
/// <returns></returns>
|
internal static Location FindStartcolByLoclist(List<Location> locations)
|
{
|
try
|
{
|
Location start = null;
|
var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList();
|
for (int i = 0; i < rowsStart.Count; i++)
|
{
|
var rowList = locations.Where(r => r.N_ROW == rowsStart[i]).ToList().OrderByDescending(a => a.N_COL);
|
//当前排没有锁并且有满货位
|
if (rowList.Count(a => a.S_LOCK_STATE.Trim() != "无") == 0 && rowList.Count(a => a.N_CURRENT_NUM == 1) > 0)
|
{
|
Location other = null;
|
|
//找到最大的满位,如果有就直接出
|
var full = rowList.OrderByDescending(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 1).FirstOrDefault();
|
if (full != null)
|
{
|
other = full;
|
}
|
|
if (other != null)
|
{
|
|
|
start = other;
|
break;
|
|
|
}
|
}
|
}
|
return start;
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
|
}
|
|
private static int GetLocTrayNum(List<LocCntrRel> locNum, int num)
|
{
|
int trayNum = locNum.Count();
|
switch (trayNum)
|
{
|
case 0:
|
num = 0;
|
break;
|
case 1:
|
num = 1;
|
break;
|
case 2:
|
num = 1;
|
break;
|
case 3:
|
num = 2;
|
break;
|
case 4:
|
num = 2;
|
break;
|
}
|
|
return num;
|
}
|
internal static SimpleResult ShippingOrderExecute(ShippingOrderCheck model)
|
{
|
var result = new SimpleResult();
|
//检查库存,更新发货单,生成分拣单,自动合并波次
|
//这个后台做比较麻烦,mobox3库存在内存中,任务完成的时候无法增加,还是用c#直接管内存,计算比较方便
|
WMSHelper.CreateSortingOrder(model.out_nos.Split(',').ToList());
|
return result;
|
}
|
|
/// <summary>
|
/// 后面要把方法放到wmsHelper中
|
/// </summary>
|
/// <param name="models"></param>
|
/// <returns></returns>
|
internal static SimpleResult SortingResultCheck(List<SortingResultCheck> models)
|
{
|
//生成分拣结果,更新分拣明细状态
|
var result = new SimpleResult();
|
WMSHelper.SortingConfrim(models);
|
return result;
|
}
|
|
|
|
/// <summary>
|
/// 后面要把方法放到wmsHelper中
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult Instock(InstockInfo model)
|
{
|
var result = new SimpleResult();
|
//pda入库,目前人工放货在巷道口,扫托盘,后台只能计算当前巷道的终点,单深位立库
|
//1,判断托盘信息,一种是码盘后的,默认enable是N,另一种是分拣回的
|
var cntr = ContainerHelper.GetCntr(model.cntr);
|
if (cntr != null)
|
{
|
var sortingInfo = WMSHelper.GetSortingDetailByCntr(model.cntr);
|
if (cntr.C_ENABLE == "Y" && sortingInfo != null && sortingInfo.Count > 0)
|
{
|
result.resultCode = 2;
|
result.resultMsg = $"托盘{model.cntr}未分拣完成";
|
}
|
}
|
else
|
{
|
result.resultCode = 1;
|
result.resultMsg = $"托盘{model.cntr}不存在";
|
}
|
if (result.resultCode == 0)
|
{
|
//获取接驳位所在的巷道, 查找功能区,入库接驳位找逻辑库区(每个巷道一个逻辑库区)
|
var fa = LocationHelper.GetFunctionAreaByCode(model.start, 2, 10);
|
if (fa != null)
|
{
|
//创建入库作业,简单判断一下是否有可入货位,如果不判断,人工货放上去一直不能入,也不知道原因
|
var end = LocationHelper.GetZoneLoc(fa.S_MASTER_CODE);
|
if (end != null)
|
{
|
//判断托盘是否已经生成任务,如果没有则生成
|
var wmsTask = WMSHelper.GetWmsTaskByCntr(model.cntr);
|
if (wmsTask != null)
|
{
|
result.resultCode = 3;
|
result.resultMsg = $"起点{model.start} 托盘{model.cntr}已经创建任务,请勿重复申请";
|
}
|
else
|
{
|
wmsTask = new WMSTask
|
{
|
S_CNTR_CODE = model.cntr,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = model.start,
|
S_END_LOC = end.S_LOC_CODE,
|
N_TYPE = 1,
|
S_TYPE = WMSTask.GetTypeStr(1),
|
S_OP_DEF_CODE = "",
|
S_OP_DEF_NAME = "pda入立库"
|
};
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
LocationHelper.LockLoc(end.S_LOC_CODE, 1);
|
result.resultMsg = $"创建作业成功,作业号{wmsTask.S_CODE}";
|
}
|
}
|
|
}
|
else
|
{
|
result.resultCode = 3;
|
result.resultMsg = $"起点{model.start}对应的逻辑库区{fa.S_MASTER_CODE}没有可用货位,请更换巷道";
|
}
|
}
|
else
|
{
|
result.resultCode = 3;
|
result.resultMsg = $"起点{model.start}没有对应的逻辑库区,请在逻辑库区设置功能区-入库接驳位";
|
}
|
}
|
return result;
|
}
|
|
internal static SimpleResult SortingOrderExecute(SortingOrderCheck model)
|
{
|
var result = new SimpleResult();
|
//分拣单配货执行
|
WMSHelper.CreateSortingOrderDetail(model.s_no);
|
return result;
|
}
|
|
|
internal static SimpleResult CheckSortingWholeCntr(CheckSortingWholeCntr model)
|
{
|
var result = new SimpleResult();
|
if (WMSHelper.CheckSortingWholeCntr(model.cntr, model.autoSort == 1))
|
{
|
result.resultCode = 1;
|
result.resultMsg = "整托分拣";
|
}
|
return result;
|
}
|
internal static CodeInfo GetCodeInfo(string code, string org)
|
{
|
//return new CodeInfo { Fitemid_XK=code, FSourceNo="123456"};
|
CodeInfo result = null;
|
try
|
{
|
var db = new SqlHelper<object>().GetInstance(Settings.SqlServer1);
|
var nameP = new SugarParameter("@FBarCode", code);
|
var orgP = new SugarParameter("@Forg", org);
|
//var ageP = new SugarParameter("@age", null, true);//设置为output
|
//var dt = db.Ado.UseStoredProcedure().GetDataTable("sp_school", nameP, ageP);//返回dt
|
result = db.Ado.UseStoredProcedure().SqlQuery<CodeInfo>("WMS_FBarCode", nameP, orgP).First();//返回List
|
Console.WriteLine($"读存储过程成功,result={result}");
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine(ex.Message);
|
}
|
return result;
|
}
|
|
internal static SimpleResult PalletSorting1(PalletSorting1 model)
|
{
|
var result = new SimpleResult();
|
//校验入库单数量,不可以超,成功后插入托盘物料表,更新入库单累计数量
|
//也可以直接lua查询入库单数量,做校验
|
//先用bar_code读存储过程获取信息
|
var codeInfo = GetCodeInfo(model.bar_code, model.org);
|
var info = WMSHelper.GetPutawayOrderDetail(model.bar_code);
|
if (info != null)
|
{
|
if (info.F_QTY - info.F_ACC_B_QTY >= model.qty)
|
{
|
// 插入到托盘明细表
|
|
var cntr = ContainerHelper.GetCntr(model.cntr_code, true);
|
if (cntr != null)
|
{
|
ContainerHelper.BindCntrItem(cntr, model.bar_code, info.S_BATCH_NO, model.qty, info.S_BATCH_NO);
|
//更新入库单累计绑定数量
|
info.F_ACC_B_QTY += model.qty;
|
WMSHelper.UpdatePutawayOrderDetailQty(info);
|
}
|
else
|
{
|
result.resultCode = 2;
|
result.resultMsg = "获取托盘信息失败";
|
}
|
|
|
}
|
else
|
{
|
result.resultCode = 1;
|
result.resultMsg = "累计码盘数量超出入库单数量";
|
}
|
}
|
else
|
{
|
result.resultCode = 3;
|
result.resultMsg = $"未获取到该物料{model.bar_code}的入库单明细信息";
|
}
|
|
return result;
|
}
|
|
|
public class AddTaskModel
|
{
|
public string From { get; set; }
|
public string To { get; set; }
|
public string No { get; set; }
|
}
|
public class TN_LocationModel
|
{
|
public string TN_Location { get; set; }
|
}
|
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; }
|
}
|
}
|
}
|