using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.Tools;
|
using WIDESEA_Core.EFDbContext;
|
using WIDESEA_Core.Extensions;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_Services.IRepositories;
|
using WIDESEA_Services.Repositories;
|
|
namespace WIDESEA_Services
|
{
|
public class MESAPIInvoke
|
{
|
public static string upperMaterIPAddresss = ConfigUtil.GetConfiguration["upperMaterURL"];
|
public static string lowerMaterIPAddresss = ConfigUtil.GetConfiguration["lowerMaterURL"];
|
public static string BindMaterIPAddresss = ConfigUtil.GetConfiguration["BindMaterURL"];
|
public static string StockChangeIPAddresss = ConfigUtil.GetConfiguration["StockChangeURL"];
|
public static string AgvStatusIPAddresss = ConfigUtil.GetConfiguration["AgvStatusURL"];
|
public static string StockMaterBindsIPAddresss = ConfigUtil.GetConfiguration["StockMaterBindsURL"];
|
public static string NeedStoskIPAddresss = ConfigUtil.GetConfiguration["NeedStoskURL"];
|
public static string StockMaterMoveIPAddresss = ConfigUtil.GetConfiguration["StockMaterMoveURL"];
|
public static string BakingFeedingBindingIPAddresss = ConfigUtil.GetConfiguration["BakingFeedingBindingURL"];
|
public static string PreTaskIPAddresss = ConfigUtil.GetConfiguration["PreTaskURL"];
|
public static string RescheduleIPAddresss = ConfigUtil.GetConfiguration["RescheduleURL"];
|
|
public static void GetInterfaceInfo(string InterfaceName, string TaskID, string DeviceID, int Code, string Message)
|
{
|
VOLContext Context = new VOLContext();
|
IInterfaceInfoRepository InterfaceInfoRepository = new InterfaceInfoRepository(Context);
|
try
|
{
|
var info = InterfaceInfoRepository.FindFirst(f => f.InterfaceName == InterfaceName);
|
info.TaskID = TaskID;
|
info.DeviceID = DeviceID;
|
info.Code = Code;
|
info.Message = Message;
|
info.updatetime = DateTime.Now;
|
InterfaceInfoRepository.Update(info, true);
|
}
|
catch (Exception ex)
|
{
|
|
}
|
}
|
|
/// <summary>
|
/// 设备请求上料
|
/// </summary>
|
/// <param name="Devid"></param>
|
/// <param name="BatchNo"></param>
|
/// <returns></returns>
|
public static MESback EquipFeeding(string Devid, string BatchNo)
|
{
|
try
|
{
|
Task.Delay(10000).Wait();
|
WriteLog.Info("设备请求上料").Write("EquipFeeding接口调用开始,设备编号:" + Devid + "工单号:" + BatchNo + DateTime.Now, "设备请求上料");
|
EquipONorUPrequest req = new EquipONorUPrequest();
|
req.Devid = Devid;
|
req.BatchNo = BatchNo;
|
//JArray ja = new JArray();
|
//ja.Add(WebApiHelper.GetJson(req));
|
//JObject jobj = WebApiHelper.SendInfoToWebAPI(upperMaterIPAddresss, "", "Post", ja);
|
//MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(upperMaterIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
GetInterfaceInfo("EquipFeeding", "", Devid, reply.Code, reply.Message);
|
WriteLog.Info("设备请求上料").Write("EquipFeeding接口调用结束" + jobj + DateTime.Now, "设备请求上料");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("设备请求上料").Write("EquipFeeding接口调用异常:" + ex.Message, "设备请求上料");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 设备请求下料调用MES接口
|
/// </summary>
|
/// <param name="Devid"></param>
|
/// <param name="BatchNo"></param>
|
/// <returns></returns>
|
public static MESback EquipUnloading(string Devid, string BatchNo)
|
{
|
try
|
{
|
WriteLog.Info("设备请求下料").Write("EquipUnloading接口调用开始,设备编号:" + Devid + "工单号:" + BatchNo + DateTime.Now, "设备请求下料");
|
EquipONorUPrequest req = new EquipONorUPrequest();
|
req.Devid = Devid;
|
req.BatchNo = BatchNo;
|
//JArray ja = new JArray();
|
//ja.Add(WebApiHelper.GetJson(req));
|
//JObject jobj = WebApiHelper.SendInfoToWebAPI(lowerMaterIPAddresss, "", "Post", ja);
|
//MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(lowerMaterIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
GetInterfaceInfo("EquipUnloading", "", Devid, reply.Code, reply.Message);
|
WriteLog.Info("设备请求下料").Write("EquipUnloading接口调用结束" + jobj + DateTime.Now, "设备请求下料");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("设备请求下料").Write("EquipUnloading接口调用异常:" + ex.Message, "设备请求下料");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 记录批号与缓存架绑定信息,物料绑定信息
|
/// </summary>
|
/// <param name="DevidGet"></param>
|
/// <param name="DevidPut"></param>
|
/// <param name="MaterialType"></param>
|
/// <param name="BarCode"></param>
|
/// <param name="MaterialStatus"></param>
|
/// <returns></returns>
|
public static MESback BindMaterialDevid(string DevidGet, string DevidPut, string MaterialType, string BarCode, string MaterialStatus)
|
{
|
try
|
{
|
WriteLog.Info("BindMaterialDevid").Write("BindMaterialDevid接口调用开始,DevidGet:" + DevidGet + "DevidPut:" + DevidPut + "MaterialType:" + MaterialType + "BarCode:" + BarCode + "MaterialStatus:" + MaterialStatus + DateTime.Now, "BindMaterialDevid");
|
BindMaterrequest req = new BindMaterrequest();
|
req.DevidGet = DevidGet;
|
req.DevidPut = DevidPut;
|
req.MaterialType = MaterialType;
|
req.BarCode = BarCode;
|
req.MaterialStatus = MaterialStatus;
|
//JArray ja = new JArray();
|
//ja.Add(WebApiHelper.GetJson(req));
|
//JObject jobj = WebApiHelper.SendInfoToWebAPI(BindMaterIPAddresss, "", "Post", ja);
|
//MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(BindMaterIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
WriteLog.Info("BindMaterialDevid").Write("BindMaterialDevid接口调用结束,DevidGet:" + DevidGet + "DevidPut:" + DevidPut + "MaterialType:" + MaterialType + "BarCode:" + BarCode + "MaterialStatus:" + MaterialStatus + DateTime.Now, "BindMaterialDevid");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("BindMaterialDevid").Write("BindMaterialDevid接口调用异常:" + ex.Message, "BindMaterialDevid");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// AGV库存异动登记
|
/// </summary>
|
/// <param name="CallSn"></param>
|
/// <param name="DevidGet"></param>
|
/// <param name="DevidPut"></param>
|
/// <param name="MaterialType"></param>
|
/// <param name="BarCode"></param>
|
/// <param name="MaterialStatus"></param>
|
/// <returns></returns>
|
public static MESback AgvStockChange(string CallSn, string DevidGet, string DevidPut, string MaterialType, string BarCode, string MaterialStatus)
|
{
|
try
|
{
|
WriteLog.Info("AgvStockChange").Write("AgvStockChange接口调用开始", "AgvStockChange");
|
StockChangerequest req = new StockChangerequest();
|
req.CallSn = CallSn;
|
req.DevidGet = DevidGet;
|
req.DevidPut = DevidPut;
|
req.MaterialType = MaterialType;
|
req.BarCode = BarCode;
|
req.MaterialStatus = MaterialStatus;
|
//JArray ja = new JArray();
|
//ja.Add(WebApiHelper.GetJson(req));
|
//JObject jobj = WebApiHelper.SendInfoToWebAPI(StockChangeIPAddresss, "", "Post", ja);
|
//MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(StockChangeIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
WriteLog.Info("AgvStockChange").Write("AgvStockChange接口调用结束", "AgvStockChange");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("AgvStockChange").Write("AgvStockChange接口调用异常:" + ex.Message, "AgvStockChange");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 上传AGV运行状态,调用MES
|
/// </summary>
|
/// <param name="AgvCode"></param>
|
/// <param name="RunningTime"></param>
|
/// <param name="RealtimeSpeed"></param>
|
/// <param name="HandState"></param>
|
/// <param name="AbnormalState"></param>
|
/// <returns></returns>
|
public static MESback UploadAgvStatus(string AgvCode, string RunningTime, string RealtimeSpeed, string HandState, string AbnormalState)
|
{
|
try
|
{
|
WriteLog.Info("UploadAgvStatus").Write("UploadAgvStatus接口调用开始", "UploadAgvStatus");
|
AgvStatusrequest req = new AgvStatusrequest();
|
req.AgvCode = AgvCode;
|
req.RunningTime = RunningTime;
|
req.RealtimeSpeed = RealtimeSpeed;
|
req.HandState = HandState;
|
req.AbnormalState = AbnormalState;
|
JArray ja = new JArray();
|
ja.Add(WebApiHelper.GetJson(req));
|
JObject jobj = WebApiHelper.SendInfoToWebAPI(AgvStatusIPAddresss, "", "Post", ja);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
WriteLog.Info("UploadAgvStatus").Write("UploadAgvStatus接口调用结束" + jobj, "UploadAgvStatus");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("UploadAgvStatus").Write("UploadAgvStatus接口调用异常:" + ex.Message, "UploadAgvStatus");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 入库预定
|
/// </summary>
|
public static MESback PreTask(int InType)
|
{
|
try
|
{
|
WriteLog.Info("入库预定").Write("PreTask接口调用开始,入库地址:" + InType + DateTime.Now, "入库预定");
|
PreStoreClass req = new PreStoreClass();
|
req.InType = InType;
|
//JArray ja = new JArray();
|
//ja.Add(WebApiHelper.GetJson_2(req));hjhjhj
|
//JObject jobj = WebApiHelper.SendInfoToWebAPI(StockMaterBindsIPAddresss, "", "Post", ja);
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(PreTaskIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
WriteLog.Info("入库预定").Write("PreTask接口调用结束,返回结果:" + jobj + DateTime.Now, "入库预定");
|
if (reply.Code > 0) { return null; };
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("入库预定").Write("PreTask接口调用异常:" + ex.Message, "入库预定");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 解绑预定入库任务
|
/// </summary>
|
public static MESback Reschedule(int InType)
|
{
|
try
|
{
|
WriteLog.Info("解绑预定入库任务").Write("Reschedule接口调用开始,入库地址:" + InType + DateTime.Now, "解绑预定入库任务");
|
PreStoreClass req = new PreStoreClass();
|
req.InType = InType;
|
//JArray ja = new JArray();
|
//ja.Add(WebApiHelper.GetJson_2(req));hjhjhj
|
//JObject jobj = WebApiHelper.SendInfoToWebAPI(StockMaterBindsIPAddresss, "", "Post", ja);
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(RescheduleIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
WriteLog.Info("解绑预定入库任务").Write("Reschedule接口调用结束,返回结果:" + jobj + DateTime.Now, "解绑预定入库任务");
|
if (reply.Code > 0) { return null; };
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("解绑预定入库任务").Write("Reschedule接口调用异常:" + ex.Message, "解绑预定入库任务");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 入库物料绑定
|
/// </summary>
|
/// <param name="Devid"></param>
|
/// <param name="MaterialType"></param>
|
/// <param name="BarCode"></param>
|
/// <param name="MaterialStatus"></param>
|
/// <returns></returns>
|
public static MESback InStockMaterBind(string Devid, string MaterialType, string BarCode, string MaterialStatus, int InType)
|
{
|
try
|
{
|
WriteLog.Info("入库物料绑定").Write("InStockMaterBind接口调用开始,当前设备:" + Devid + ",物料类型:" + MaterialType + ",物料条码:" + BarCode + ",物料状态:" + MaterialStatus + DateTime.Now, "入库物料绑定");
|
StockMaterBindsrequest req = new StockMaterBindsrequest();
|
req.Devid = Devid;
|
req.MaterialType = MaterialType;
|
req.BarCode = BarCode;
|
req.MaterialStatus = MaterialStatus;
|
req.InType = InType;
|
//JArray ja = new JArray();
|
//ja.Add(WebApiHelper.GetJson_2(req));hjhjhj
|
//JObject jobj = WebApiHelper.SendInfoToWebAPI(StockMaterBindsIPAddresss, "", "Post", ja);
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(StockMaterBindsIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
GetInterfaceInfo("InStockMaterBind", "", Devid, reply.Code, reply.Message);
|
WriteLog.Info("入库物料绑定").Write("InStockMaterBind接口调用结束,返回结果:" + jobj + DateTime.Now, "入库物料绑定");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("入库物料绑定").Write("InStockMaterBind接口调用异常:" + ex.Message, "入库物料绑定");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 出库要料
|
/// </summary>
|
/// <param name="TaskID"></param>
|
/// <param name="Devid"></param>
|
/// <param name="OutType"></param>
|
/// <param name="MaterialType"></param>
|
/// <returns></returns>
|
public static MESback OutNeedStosk(string TaskID, List<string> Devid, int OutType, string MaterialType, string ProcessName, string DevicelD)
|
{
|
try
|
{
|
NeedStoskrequest req = new NeedStoskrequest();
|
WriteLog.Info("出库要料").Write($"OutNeedStosk接口调用开始,:任务号{TaskID},设备编号" + DevicelD + "出库类型" + OutType + "物料类型" + MaterialType + DateTime.Now, "出库要料");
|
req.Devid = Devid;
|
req.MaterialType = MaterialType;
|
req.OutType = OutType;
|
req.TaskID = TaskID;
|
req.DeviceID = DevicelD;
|
req.ProcessName = ProcessName;
|
string a = JsonConvert.SerializeObject(req);//这个A就是他要的JSON字符串
|
object jobj = HttpHelper.PostByPara(NeedStoskIPAddresss, a);
|
if (jobj == null)
|
{
|
WriteLog.Info("出库要料").Write("OutNeedStosk接口调用异常:返回值为空", "出库要料");
|
return null;
|
}
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
GetInterfaceInfo("OutNeedStosk", TaskID, DevicelD, reply.Code, reply.Message);
|
WriteLog.Info("出库要料").Write("OutNeedStosk接口调用结束," + a + jobj + DateTime.Now, "出库要料");
|
if (reply.Code > 0) { Thread.Sleep(3000); return null; };
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("出库要料").Write("OutNeedStosk接口调用异常:" + ex.Message, "出库要料");
|
return null;
|
//throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 出库物料确认搬走
|
/// </summary>
|
/// <param name="Devid"></param>
|
/// <param name="MaterialType"></param>
|
/// <returns></returns>
|
public static MESback OutStockMaterMove(string Devid, string MaterialType, int OutType, int sum, string taskId = "")
|
{
|
VOLContext Context = new VOLContext();
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
try
|
{
|
WriteLog.Info("出库物料确认搬走").Write(taskId + ":" + "OutStockMaterMove接口调用开始" + "缓存架编号:" + Devid + "\t" + "物料类型:" + MaterialType + "\t" + "出库类型:" + OutType + "\t" + DateTime.Now, "出库物料确认搬走");
|
StockMaterMoverequest req = new StockMaterMoverequest();
|
req.Devid = Devid;
|
req.MaterialType = MaterialType;
|
req.OutType = OutType;
|
if (Devid.Contains("FBT"))
|
{
|
req.sum = sum;
|
}
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(StockMaterMoveIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
GetInterfaceInfo("OutStockMaterMove", "", Devid, reply.Code, reply.Message);
|
WriteLog.Info("出库物料确认搬走").Write("OutStockMaterMove接口调用结束" + a + jobj + DateTime.Now, "出库物料确认搬走");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("出库物料确认搬走").Write("OutStockMaterMove接口调用异常:" + ex.Message, "出库物料确认搬走");
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 烘箱物料绑定
|
/// </summary>
|
/// <param name="Devid"></param>
|
/// <param name="Materials"></param>
|
/// <returns></returns>
|
public static MESback BakingFeedingBinding(string Devid, List<BakingClass> Materials)
|
{
|
try
|
{
|
WriteLog.Info("烘箱物料绑定").Write("BakingFeedingBinding接口调用开始,烘箱编码:" + Devid + "\t" + "条码1:" + Materials[0].BarCode + "\t" + "物料类型1:" + Materials[0].MaterialType + "\t" + "条码2" + Materials[1].BarCode + "\t" + "物料类型2:" + Materials[1].MaterialType + "\t" + DateTime.Now, "烘箱物料绑定");
|
BakingFeedingClass req = new BakingFeedingClass();
|
req.Materials = new List<BakingClass>();
|
|
req.Devid = Devid;
|
for (int i = 0; i < Materials.Count(); i++)
|
{
|
BakingClass bakingClass = new BakingClass();
|
bakingClass.MaterialType = Materials[i].MaterialType;
|
bakingClass.BarCode = Materials[i].BarCode;
|
req.Materials.Add(bakingClass);
|
WriteLog.Info("烘箱物料绑定").Write("BakingFeedingBinding接口调用" + req.Materials[i].BarCode + "\t" + req.Materials[i].MaterialType + "\t" + bakingClass.BarCode + "\t" + bakingClass.MaterialType + DateTime.Now, "烘箱物料绑定");
|
}
|
string a = JsonConvert.SerializeObject(req);
|
object jobj = HttpHelper.PostByPara(BakingFeedingBindingIPAddresss, a);
|
if (jobj == null) { throw new Exception(); }
|
MESback reply = WebApiHelper.ParseFromJson<MESback>(jobj.ToString());
|
GetInterfaceInfo("BakingFeedingBinding", "", Devid, reply.Code, reply.Message);
|
WriteLog.Info("烘箱物料绑定").Write("BakingFeedingBinding接口调用结束" + a + jobj + DateTime.Now, "烘箱物料绑定");
|
return reply;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Info("烘箱物料绑定").Write("BakingFeedingBinding接口调用异常:" + ex.Message, "烘箱物料绑定");
|
throw new Exception(ex.Message);
|
}
|
}
|
|
}
|
}
|