using HH.WCS.JiaTong.device;
|
using HH.WCS.JiaTong.dispatch;
|
using HH.WCS.JiaTong.LISTA.models;
|
using HH.WCS.JiaTong.process;
|
using HH.WCS.JiaTong.util;
|
using HH.WCS.JiaTong.wms;
|
using Newtonsoft.Json;
|
using NLog.Fluent;
|
using S7.Net;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection.Emit;
|
using System.Runtime.CompilerServices;
|
using System.ServiceModel;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Web.UI.WebControls;
|
using static HH.WCS.JiaTong.api.ApiModel;
|
using static HH.WCS.JiaTong.api.OtherModel;
|
using static HH.WCS.JiaTong.LISTA.process.HttpModel;
|
using static HH.WCS.JiaTong.util.Settings;
|
|
namespace HH.WCS.JiaTong.api
|
{
|
/// <summary>
|
/// api接口辅助类
|
/// </summary>
|
public class ApiHelper
|
{
|
static ApiHelper()
|
{
|
|
}
|
|
|
#region 佳通合肥大车间接口业务
|
|
|
public static object _lockCreateTask = new object();
|
|
|
|
|
|
|
|
|
public static object _Point = new object();
|
/// <summary>
|
/// 点对点接口
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static Result Point(PointModel model)
|
{
|
Result result = new Result() { code = "200", msg = "入平库任务下发成功" };
|
string Source = "Mes";
|
|
if (model == null)
|
{
|
result.code = "1";
|
result.msg = "参数为null";
|
AddErrorInfo("参数为空", result.msg, Source);
|
return result;
|
}
|
//1.出平库,2入平库,3平库空工装呼叫,4平库余料回库,5粉料空托返回。
|
var db = new SqlHelper<object>().GetInstance();
|
string type = "";
|
Location startloc = null;
|
Location endloc = null;
|
switch (model.Status)
|
{
|
case "1":
|
type = "出平库";
|
break;
|
case "2":
|
type = "入平库";
|
break;
|
case "3":
|
type = "平库空工装呼叫";
|
break;
|
case "4":
|
type = "平库余料回库";
|
break;
|
case "5":
|
type = "粉料空托返回";
|
break;
|
}
|
if (string.IsNullOrEmpty(type))
|
{
|
result.code = "1";
|
result.msg = $"任务类型{model.Status},不在规定范围";
|
AddErrorInfo("任务类型错误", result.msg, Source);
|
return result;
|
}
|
|
try
|
{
|
lock (_Point)
|
{
|
startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.InitialLocation).First();
|
if (startloc == null)
|
{
|
result.code = "1";
|
result.msg = $"根据起点{model.InitialLocation},找不到对应货位,请检查货位表";
|
AddErrorInfo("货位查找失败", result.msg, Source);
|
return result;
|
}
|
else
|
{
|
//判断起点是否绑定其他托盘
|
var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).OrderBy(a => a.T_CREATE).FirstOrDefault();
|
if (CntrRel != null)
|
{
|
if (CntrRel.S_CNTR_CODE != model.Rfid)
|
{
|
result.code = "1";
|
result.msg = $"根据起点:{model.InitialLocation}获取托盘:{CntrRel.S_CNTR_CODE}与下发托盘:{model.Rfid}不一致,请检查托盘码是否正确";
|
AddErrorInfo("托盘码校检失败", result.msg, Source);
|
return result;
|
}
|
}
|
else
|
{
|
LocationHelper.BindingLoc(startloc.S_CODE, new List<string> { model.Rfid });
|
}
|
}
|
endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.TargetLocation).First();
|
if (endloc == null)
|
{
|
result.code = "1";
|
result.msg = $"根据终点{model.TargetLocation},找不到对应货位,请检查货位表";
|
AddErrorInfo("货位查找失败", result.msg, Source);
|
return result;
|
}
|
|
|
#region 创建任务
|
if (endloc != null && startloc != null)
|
{
|
if (startloc.N_LOCK_STATE != 0)
|
{
|
result.code = "1";
|
result.msg = $"创建任务失败,起点:{startloc.S_CODE}有锁";
|
AddErrorInfo("货位有锁", result.msg, Source);
|
return result;
|
}
|
//创建wcs任务
|
var wcsTask = new WCSTask
|
{
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = type,
|
S_EQ_NO = model.TaskNumber,
|
S_START_LOC = startloc.S_CODE,
|
S_END_LOC = endloc.S_CODE,
|
S_START_WH = startloc.S_WH_CODE,
|
S_START_AREA = startloc.S_AREA_CODE,
|
S_END_WH = endloc.S_WH_CODE,
|
S_END_AREA = endloc.S_AREA_CODE,
|
N_CNTR_COUNT = 1,
|
N_SCHEDULE_TYPE = 1,
|
S_CNTR_CODE = model.Rfid,
|
N_START_LAYER = 1,
|
N_END_LAYER = 1,
|
N_PRIORITY = 1,
|
Z_TYPE = 5
|
};
|
LogHelper.Info("创建点对点任务:" + JsonConvert.SerializeObject(wcsTask));
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
if (type == "平库余料回库")
|
{ //创建任务成功 更新余料信息
|
var CntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
|
if (CntrItem != null)
|
{
|
CntrItem.F_WEIGHT = model.Weight.ToString();
|
CntrItem.S_BS_TYPE = "余料";
|
//CntrItem.F_QTY = float.Parse(model.qty);
|
//CntrItem.S_ITEM_STATE = model..QualityStatus;
|
|
db.Updateable(CntrItem).UpdateColumns(a => new { a.F_WEIGHT, a.S_BS_TYPE }).ExecuteCommand();
|
}
|
}
|
|
LocationHelper.LockLoc(startloc.S_CODE, 2);
|
LocationHelper.LockLoc(endloc.S_CODE, 1);
|
LogHelper.Info("创建任务成功");
|
}
|
else
|
{
|
result.code = "1";
|
result.msg = $"任务创建失败";
|
AddErrorInfo("任务创建失败", result.msg, Source);
|
return result;
|
}
|
}
|
else
|
{
|
result.code = "1";
|
result.msg = "创建任务失败,未找到对应的取货点或卸货点";
|
return result;
|
}
|
#endregion
|
|
}
|
|
return result;
|
}
|
catch (Exception ex)
|
{
|
result.code = "1";
|
result.msg = ex.ToString();
|
LogHelper.Error("Putin Error:" + ex.ToString(), ex);
|
return result;
|
}
|
}
|
|
|
/// <summary>
|
/// 货位信息上传
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static Result UploadLoc(List<LocList> model)
|
{
|
|
Result result = new Result() { code = "200", msg = "货位信息上传成功" };
|
String Source = "MES";
|
RequestList<UploadLoc> result1 = new RequestList<UploadLoc>();
|
List<UploadLoc> listuploadloc = new List<UploadLoc>();
|
var db = new SqlHelper<object>().GetInstance();
|
foreach (var item in model)
|
{
|
var loc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == item.Location).First();
|
if (loc != null)
|
{
|
UploadLoc upload = new UploadLoc();
|
//获取时间戳
|
var time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
|
result1.RequestId = "杭叉AGV" + time;
|
result1.UseToken = "iFQ5fExGrLYLXliHYWzs";
|
upload.LocationNum = loc.S_CODE;
|
upload.Type = loc.S_TYPE;
|
upload.LockState =loc.S_LOCK_STATE;
|
upload.WorkCenter = loc.S_AREA_CODE;
|
upload.Warehouse = loc.S_AREA_CODE;
|
listuploadloc.Add(upload);
|
}
|
else
|
{
|
result.code = "1";
|
result.msg = $"货位上传失败,根据货位编码{item.Location}未找到对应的货位信息";
|
AddErrorInfo("查找货位失败", result.msg, Source);
|
return result;
|
}
|
}
|
result1.data = listuploadloc;
|
HttpHelper httpHelper = new HttpHelper();
|
// Result result = new Result();
|
string date = JsonConvert.SerializeObject(result1);
|
var url = Settings.tableUrls.Find(a => a.id == 3);
|
if (url != null)
|
{
|
LogHelper.Info($"货位上报上报:地址:{url},内容:{date}");
|
var r = httpHelper.MesWebPost(url.url, date);
|
result = JsonConvert.DeserializeObject<Result>(r);
|
if (result.code == "200")
|
{
|
LogHelper.Info($"物料到位回报成功");
|
}
|
else
|
{
|
LogHelper.Info($"物料到位回报失败=>msg:{result.msg}");
|
result.code = "1";
|
result.msg = result.msg;
|
}
|
ApiHelper.AddInfo("Mes", "Mes点对点任务下发", JsonConvert.SerializeObject(date), JsonConvert.SerializeObject(result), "Post", url.url);
|
|
}
|
else
|
{
|
LogHelper.Info($"物料到位回报失败=>回报地址没有配置");
|
result.code = "1";
|
result.msg = $"物料到位回报失败=>回报地址没有配置";
|
AddErrorInfo("地址错误", result.msg, Source);
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 设备状态上报
|
/// </summary>
|
/// <returns></returns>
|
internal static DeviceInfoModel Device()
|
{
|
var db = new SqlHelper<HangChaAGV>().GetInstance();
|
DeviceInfoModel device = new DeviceInfoModel();
|
|
// List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//叠盘机报错信息
|
// List<AgvInfos> agvInfos = new List<AgvInfos>();//agv报错信息
|
|
//获取内存中叠盘机的报错信息
|
//foreach (var dpjInfo in DeviceProcess.DpjInfoDirectory)
|
//{
|
// deviceInfos.Add(new DeviceInfos() { Device = dpjInfo.Value.DeviceName, DeviceInfo = dpjInfo.Value.ErrorInfo });
|
//}
|
// device.DeviceInfos = deviceInfos;
|
//获取车辆报警信息
|
var agvDeviceInfo = db.Queryable<HangChaAGV>().ToList();
|
if (agvDeviceInfo.Count > 0)
|
{
|
device.AgvQty = agvDeviceInfo.Count;
|
device.AgvErrorQty = agvDeviceInfo.FindAll(a => a.agvErrCode != "0" || int.Parse(a.errCode2) > 1 || int.Parse(a.faildCode) > 1).Count;
|
device.AgvChargeQty = agvDeviceInfo.FindAll(a => a.errCode2 == "1").Count;
|
device.AgvRunQty = agvDeviceInfo.FindAll(a => a.agvErrCode == "0" && a.errCode2 == "0" && a.faildCode == "1").Count;
|
//foreach (var agv in agvDeviceInfo)
|
//{
|
// string agvErrorInfo = GetAgvAlarmSendCodeTwo(agv.agvNo, agv.agvErrCode, agv.errCode2, agv.faildCode);
|
// deviceInfos.Add(new DeviceInfos() { AgvNo = agv.agvNo, AgvInfo = agvErrorInfo });
|
//}
|
}
|
// device.DeviceInfos = deviceInfos;
|
|
return device;
|
}
|
|
/// <summary>
|
/// agv小车故障码处理
|
/// </summary>
|
///<param name="agvNo">车号</param>
|
/// <param name="errCode1">错误码1</param>
|
/// <param name="errCode2">错误码2</param>
|
/// <param name="faildCode">错误码3</param>
|
/// <returns></returns>
|
private static string GetAgvAlarmSendCodeTwo(string agvNo, string errCode1, string errCode2, string faildCode)
|
{
|
string result = "";
|
//将报警信息整合
|
string binSW1 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(25, '0');
|
string binSW2 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(20, '0');
|
string binFc = Convert.ToString(int.Parse(errCode1), 2).PadLeft(16, '0');
|
var arr1 = binSW1.ToArray();
|
var arr2 = binSW2.ToArray();
|
var arr3 = binFc.ToArray();
|
|
var AgvError = Settings.agvError.Where(a => a.agvNo.Contains(agvNo)).FirstOrDefault();
|
if (AgvError != null)
|
{
|
for (int i = 0; i <= arr1.Length; i++)
|
{
|
if (arr1[i] == '1')
|
{
|
var ErrorInfo = AgvError.AgvErrorCode1.Find(a => a.ErrorCode == i);
|
if (ErrorInfo != null)
|
{
|
result = result + "," + $"{ErrorInfo.ErrorInfo}";
|
}
|
|
}
|
}
|
for (int i = 0; i <= arr2.Length; i++)
|
{
|
if (arr1[i] == '1')
|
{
|
var ErrorInfo = AgvError.AgvErrorCode2.Find(a => a.ErrorCode == i);
|
if (ErrorInfo != null)
|
{
|
result = result + "," + $"{ErrorInfo.ErrorInfo}";
|
}
|
|
}
|
}
|
for (int i = 0; i <= arr3.Length; i++)
|
{
|
if (arr1[i] == '1')
|
{
|
var ErrorInfo = AgvError.AgvFaildCode.Find(a => a.ErrorCode == i);
|
if (ErrorInfo != null)
|
{
|
result = result + "," + $"{ErrorInfo.ErrorInfo}";
|
}
|
|
}
|
}
|
}
|
else
|
{
|
|
}
|
return result;
|
}
|
#endregion
|
|
#region 合肥佳通业务方法
|
|
|
/// <summary>
|
/// 托盘入库算法
|
/// </summary>
|
/// <param name="itemcode"></param>
|
/// <param name="areacode"></param>
|
/// <returns></returns>
|
internal static Location StorageCompute(string itemcode, string areacode)
|
{
|
//Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).First();
|
var db = new SqlHelper<object>().GetInstance();
|
Location result = null;
|
// 867C567A-183C-413B-9891-15D8F6DE1620
|
|
// var aaa = db.Deleteable<Location>(a => a.S_ID == "867C567A-183C-413B-9891-15D8F6DE1620").ExecuteCommand();
|
// var aaa = db.Deleteable<Location>(a => a.S_ID.Trim() == "867C567A-183C-413B-9891-15D8F6DE1620").ExecuteCommand();
|
|
//LogHelper.Info($"方法:StorageCompute");
|
var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE == areacode && a.N_LOCK_STATE == 0).ToList();
|
// LogHelper.Info($"创建空托回库任务,终点货位集合:根据库区编码:{areacode}" + list.Count);
|
//list.RemoveAll(a => string.IsNullOrEmpty(a.S_CODE.Trim()) || a.S_CODE == null || string.IsNullOrWhiteSpace(a.S_CODE.Trim()));
|
// list = list.FindAll(a => a.N_ROW > 0 && a.N_COL > 0);
|
//LogHelper.Info("创建空托回库任务,终点货位集合过滤:" + list.Count);
|
|
if (list.Count > 0)
|
{
|
result = FindEndcolByLocList(list);
|
}
|
|
return result;
|
}
|
|
|
/// <summary>
|
/// 根据物料计算托盘出库
|
/// </summary>
|
/// <param name="areacode"></param>
|
/// <param name="itemcode"></param>
|
/// <param name="level">物料等级</param>
|
/// <param name="powderType">机型</param>
|
/// <returns></returns>
|
internal static Location
|
airlift(string areacode, string itemcode, string level, string powderType)
|
{
|
var db = new SqlHelper<object>().GetInstance();
|
Location result = null;
|
//根据物料编码获取货位信息
|
#region 废弃
|
//if (string.IsNullOrEmpty(itemcode))
|
//{
|
// //获取库区所有有托盘的货位
|
// var loclist = LocationHelper.GetLocListAny(areacode).FindAll(a => a.N_CURRENT_NUM == 1);
|
// //LogHelper.Info($"获取库区{areacode}数量为1的货位{JsonConvert.SerializeObject(loclist)}");
|
// //根据货位获取托盘
|
// var loccntrlist = LocationHelper.GetLocListByLoc(loclist.Select(a => a.S_CODE).ToList());
|
// List<Location> locs = new List<Location>();
|
// // LogHelper.Info($"获取库区{areacode}数量为1的托盘{JsonConvert.SerializeObject(loccntrlist)}");
|
// //排除所有有物料的托盘
|
// foreach (var item in loccntrlist)
|
// {
|
// var list = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == item.S_CNTR_CODE).First();
|
// if (list == null)
|
// {
|
// LogHelper.Info($"获取库区{areacode}的空托{JsonConvert.SerializeObject(item.S_CNTR_CODE)}");
|
// var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == item.S_CNTR_CODE).First();
|
// var loc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == item.S_LOC_CODE).First();
|
// locs.Add(loc);
|
// }
|
// }
|
// LogHelper.Info($"获取库区{areacode}的空托货位{JsonConvert.SerializeObject(locs)},计算出库货位");
|
|
// if (locs.Count > 0)
|
// {
|
// result = FindStartcolByLoclist(loclist);
|
// }
|
// else
|
// {
|
// LogHelper.Info($"airlift==> 根据库区编码:{areacode},找不到空托");
|
// }
|
|
//}
|
//else
|
//{
|
// var cntrlist = ContainerHelper.GetItemCntrRel(itemcode).FindAll(a => a.LEV == level);
|
// var loccntrlist = LocationHelper.GetLocListBycntrs(cntrlist.Select(a => a.S_CNTR_CODE).ToList());
|
// var loclist = LocationHelper.GetLocListByloc(loccntrlist.Select(a => a.S_LOC_CODE).ToList(), areacode);
|
// if (loclist.Count() > 0)
|
// {
|
// //判断所处库区的货位是否是可出排
|
// // loclist = loclist.FindAll(a => a.S_AREA_CODE == areacode);
|
// result = FindStartcolByLoclist(loclist);
|
// }
|
// else
|
// {
|
// LogHelper.Info($"airlift==> 根据库区编码:{areacode},物料编码:{itemcode}找不到对应出库货位");
|
// }
|
//}
|
|
#endregion
|
var loc = LocationHelper.GetLocByItemCode(areacode, itemcode, level, powderType);
|
LogHelper.Info($"airlift=>根据库区编码:{areacode},物料编码:{itemcode},机型{powderType},物料等级计算出有托盘货位{JsonConvert.SerializeObject(loc)}");
|
// result = FindStartcolByLoclist(loc);
|
if (loc.Count > 0)
|
{
|
result = loc.OrderByDescending(a => a.N_COL).First();
|
}
|
|
LogHelper.Info($"airlift=>可用货位为:{JsonConvert.SerializeObject(result)}");
|
return result;
|
}
|
|
/// <summary>
|
/// 找空排
|
/// </summary>
|
/// <param name="areacode"></param>
|
/// <returns></returns>
|
internal static Location emptyRow(string areacode)
|
{
|
Location result = null;
|
var db = new SqlHelper<object>().GetInstance();
|
|
LogHelper.Info($"根据库区编码:{areacode},查找空排货位");
|
//查找所有数量是空的排;
|
//简化查询只查每一排第一列
|
var list = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == areacode).OrderBy(a => a.N_COL).Take(1).PartitionBy(a => a.N_ROW).ToList().Where(a => a.N_CURRENT_NUM == 0).FirstOrDefault();
|
if (list != null)
|
{
|
result = list;
|
}
|
return result;
|
}
|
|
|
|
//internal static bool CreateCntrLoc(taskData taskData)
|
//{
|
// if ( taskData == null)
|
// {
|
// LogHelper.Info($"CreateCntrIteminfo==> 立库任务下发参数有空,创建物料托盘绑定关系失败");
|
// return false;
|
// }
|
// else
|
// {
|
// LocationHelper.BindingLoc(taskData.pickStation,new List<string>() { taskData.rfid });
|
|
// }
|
|
//}
|
private static object _lockLocation = new object();
|
/// <summary>
|
/// 根据托盘编码,机台编码,工装类型计算机台线边区域
|
/// </summary>
|
/// <param name="cntrcode">托盘编码</param>
|
/// <param name="jtcode">机台编码</param>
|
/// <param name="cntrType">托盘类型</param>
|
/// <returns></returns>
|
internal static Location Computeloc(string cntrcode, string jtcode, string cntrType)
|
{
|
Location End = null;
|
var db = new SqlHelper<object>().GetInstance();
|
|
|
// var location = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).First();
|
|
lock (_lockLocation)
|
{
|
if (string.IsNullOrEmpty(cntrType))
|
{
|
End = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无").First();
|
}
|
else
|
{
|
End = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无").First();
|
}
|
|
if (End == null)
|
{
|
LogHelper.Info($"Computeloc==》根据机台分组:{jtcode},工装类型:{cntrType} 未找到空货位数据,请检查货位表");
|
}
|
|
}
|
return End;
|
}
|
|
/// <summary>
|
/// 合肥佳通添加报错信息表数据
|
/// </summary>
|
/// <param name="errorInfo">错误</param>
|
/// <param name="taskno">任务号</param>
|
/// <param name="areacode">库区编码</param>
|
/// <param name="remake">错误信息</param>
|
/// <returns></returns>
|
public static bool AddErrorInfo(string errorInfo, string remake, string areacode = "", string taskno = "")
|
{
|
bool result = false;
|
var db = new SqlHelper<object>().GetInstance();
|
try
|
{
|
var error = new ErrorInfo
|
{
|
ERRORMESSAGE = errorInfo,
|
TASKNO = taskno,
|
AREACODE = areacode,
|
REMAKE = remake,
|
};
|
if (result = db.Insertable<ErrorInfo>(error).ExecuteCommand() > 0)
|
{
|
|
}
|
//else
|
//{
|
// //添加失败重新添加
|
// AddErrorInfo(errorInfo, remake, areacode, taskno);
|
//}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"AddErrorInfo Error:{ex.Message}");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 合肥佳通接口调用信息
|
/// </summary>
|
/// <param name="source">系统来源</param>
|
/// <param name="name">接口名称</param>
|
/// <param name="type">请求地址类型</param>
|
/// <param name="body">请求参数</param>
|
/// <param name="url">请求地址</param>
|
/// <param name="err">错误信息</param>
|
/// <returns></returns>
|
public static bool AddInfo(string source, string name, string body, string err, string type, string url)
|
{
|
bool result = false;
|
var db = new SqlHelper<object>().GetInstance();
|
try
|
{
|
var error = new GT_Interface_Exc
|
{
|
S_SOURCE = source,
|
S_NAME = name,
|
S_TYPE = type,
|
S_URL = url,
|
S_BODY = body,
|
S_ERR = err
|
};
|
if (result = db.Insertable<GT_Interface_Exc>(error).ExecuteCommand() > 0)
|
{
|
|
}
|
//else
|
//{
|
// //添加失败重新添加
|
// AddErrorInfo(errorInfo, remake, areacode, taskno);
|
//}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"AddInfo Error:{ex.Message}");
|
}
|
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_ROW).Distinct().ToList();
|
for (int i = 0; i < rows.Count; i++)
|
{
|
|
var rowList = locations.Where(r => r.N_ROW == rows[i]).ToList();
|
// LogHelper.Info($"当前排:{rows[i]},获得货位{JsonConvert.SerializeObject(rowList)}");
|
if (rowList.Count(a => a.N_CURRENT_NUM == 0) > 0)
|
{
|
Location other = null;
|
//当前排没有锁并且有空位置
|
|
// other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").FirstOrDefault();
|
other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 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)
|
{
|
if (other.S_CODE != null && !string.IsNullOrEmpty(other.S_CODE))
|
{
|
end = other;
|
break;
|
}
|
}
|
}
|
}
|
return end;
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
|
}
|
|
/// <summary>
|
/// 找终点空货位计算排锁
|
/// </summary>
|
/// <param name="locations"></param>
|
/// <returns></returns>
|
internal static Location FindEndcolByLocListLock(List<Location> locations)
|
{
|
try
|
{
|
var db = new SqlHelper<object>().GetInstance();
|
Location end = null;
|
//根据终点货位找空闲货位
|
var rows = locations.Select(a => a.N_ROW).Distinct().ToList();
|
for (int i = 0; i < rows.Count; i++)
|
{
|
var rowList = locations.Where(r => r.N_ROW == rows[i]).ToList();
|
if (rowList.Count(a => a.S_LOCK_STATE != "无") == 0 && rowList.Count(a => a.N_CURRENT_NUM == 0) > 0)
|
{
|
Location other = null;
|
//当前排没有锁并且有空位置
|
//先找满位,然后后面一位要么是空,要么不存在
|
var full = rowList.OrderByDescending(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 1).FirstOrDefault();
|
if (full == null)
|
{
|
//没有满位,那就找最小的空位
|
other = rowList.OrderBy(a => a.N_COL).FirstOrDefault();
|
}
|
else
|
{
|
other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_COL > full.N_COL).FirstOrDefault();
|
}
|
|
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;
|
}
|
|
}
|
|
|
#endregion
|
|
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;
|
}
|
|
|
static object AGVDeviceReceiveLock = new object();
|
|
/// <summary>
|
/// AGV状态处理
|
/// </summary>
|
/// <param name="forkliftNo"></param>
|
/// <param name="battery"></param>
|
/// <param name="agvCurrTaskInfo"></param>
|
/// <param name="errCode"></param>
|
/// <param name="errCode2"></param>
|
/// <param name="faildCode"></param>
|
internal static void AGVDeviceReceiveSet(string forkliftNo, string battery, string errCode, string errCode2, string faildCode)
|
{
|
lock (AGVDeviceReceiveLock)
|
{
|
var db = new SqlHelper<HangChaAGV>().GetInstance();
|
var agvDeviceInfo = db.Queryable<HangChaAGV>().Where(a => a.agvNo.Trim() == forkliftNo).First();
|
if (agvDeviceInfo == null)
|
{
|
var agvInfo = new HangChaAGV()
|
{
|
agvNo = forkliftNo,
|
agvBattery = battery,
|
// agvCurrTaskInfo = agvCurrTaskInfo,
|
agvErrCode = errCode,
|
errCode2 = errCode2,
|
faildCode = faildCode
|
};
|
db.Insertable(agvInfo).ExecuteCommand();
|
}
|
else
|
{
|
//判断中间表信息有无变化,无变化不更新中间表
|
if (agvDeviceInfo.agvErrCode == errCode && agvDeviceInfo.errCode2 == errCode2 && agvDeviceInfo.faildCode == faildCode)
|
{
|
return;
|
}
|
agvDeviceInfo.agvBattery = battery;
|
// agvDeviceInfo.agvCurrTaskInfo = agvCurrTaskInfo;
|
agvDeviceInfo.agvErrCode = errCode;
|
agvDeviceInfo.errCode2 = errCode2;
|
agvDeviceInfo.faildCode = faildCode;
|
// agvDeviceInfo.ext1 = "0";
|
//agvDeviceInfo.agvRunStatus = agvDeviceInfo.agvRunStatus?.Trim() == "1" ? "1" : "";
|
//if (int.Parse(agvDeviceInfo.agvBattery) >= 1000)
|
// agvDeviceInfo.agvRunStatus = "";
|
db.Updateable(agvDeviceInfo).UpdateColumns(a => new
|
{ a.agvBattery, a.agvCurrTaskInfo, a.agvErrCode, a.errCode2, a.faildCode, a.agvRunStatus }).ExecuteCommand();
|
}
|
}
|
}
|
|
#region 数据模型
|
|
#endregion
|
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; }
|
}
|
}
|
}
|