using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using WCS.Data;
using WCS.Data.Models;
using WCS.Data.Utils;
using static WCS.WMSWorkflow.ApiParam;
namespace WCS.WMSWorkflow
{
///
/// 调用WMS接口
///
public class WMS_API : IWMS
{
private static readonly object emptyFrameBack_lock = new object();
public GetInTaskReply I_WCS_GetInTask(GetInTaskParam param)
{
GetInTaskReply reply = null;
try
{
DateTime startDateTime = DateTime.Now;
Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetInTask。参数:[{0}]", WebApiHelper.GetJson(param)));
//调用WMS接口
reply = (GetInTaskReply)MethodOutTimeHelper.OutTimeSomeParemReturn(WCS_GetInTask, AppSettingsHelper.AppSettings.MethodOutTimeMilliseconds, param);
//JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetInTask, "", "Post", ja);
//reply = WebApiHelper.ParseFromJson(jobj.ToString());
if (reply == null)
{
//reply = new GetInTaskReply();
//throw new Exception(string.Format("结束:WCS调用WMS接口函数I_WCS_GetInTask。参数:[{0}]反馈结果:[接口报错或接口超时]", WebApiHelper.GetJson(param)));
//throw new Exception("访问网络超时");
}
else
{
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetInTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
}
DateTime endDateTime = DateTime.Now;
if (startDateTime.AddSeconds(30) < endDateTime)
{
string message = string.Format("WCS调用WMS接口函数I_WCS_GetInTask超过30秒,调用开始时间:[{0}]调用结束时间[{1}]参数[{2}]", startDateTime.ToString("yyyy-MM-dd HH:mm:ss"), endDateTime.ToString("yyyy-MM-dd HH:mm:ss"), WebApiHelper.GetJson(param));
//接口超时30秒以上
LogMessageHelper.RecordLogMessage(message);
}
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
reply.ResMessage = ex.Message;
}
return reply;
}
private object WCS_GetInTask(object obj)
{
GetInTaskReply reply = null;
try
{
var param = obj as GetInTaskParam;
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
JObject jobj = WebApiHelper.SendInfoToAPI(AppSettingsHelper.AppSettings.GetInTask, "", "Post", ja);
reply = WebApiHelper.ParseFromJson(jobj.ToString());
}
catch (Exception ex)
{
LogMessageHelper.RecordLogMessage(ex);
}
return reply;
}
public GetMoveTaskReply I_WCS_GetMoveTask(GetMoveTaskParam param)
{
GetMoveTaskReply reply = null;
try
{
Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetMoveTask。参数:[{0}]", WebApiHelper.GetJson(param)));
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
//调用MES接口
JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetMoveTask, "", "Post", ja);
reply = WebApiHelper.ParseFromJson(jobj.ToString());
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetMoveTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
public GetOutTaskReply I_WCS_GetOutTask(GetOutTaskParam param)
{
GetOutTaskReply reply = null;
try
{
string msg = string.Format("开始:WCS调用WMS接口函数I_WCS_GetOutTask。参数:{0}", WebApiHelper.GetJson(param));
Log4netHelper.Logger_Info.Info(msg);
//调用WMS接口
reply = (GetOutTaskReply)MethodOutTimeHelper.OutTimeSomeParemReturn(I_WCS_GetOutTask, AppSettingsHelper.AppSettings.MethodOutTimeMilliseconds, param);
//JArray ja = new JArray();
//ja.Add(WebApiHelper.GetJson(param));
////调用MES接口
//JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetOutTask, "", "Post", ja);
//reply = WebApiHelper.ParseFromJson(jobj.ToString());
if (reply == null)
{
reply = new GetOutTaskReply();
//throw new Exception(string.Format("结束:WCS调用WMS接口函数I_WCS_GetOutTask。参数:[{0}]反馈结果:[接口报错或接口超时]", WebApiHelper.GetJson(param)));
throw new Exception("访问网络超时");
}
else
{
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetOutTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
}
}
catch (Exception ex)
{
reply.ResMessage = ex.Message;
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
private object I_WCS_GetOutTask(object obj)
{
GetOutTaskParam param = null;
GetOutTaskReply reply = null;
try
{
param = obj as GetOutTaskParam;
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetOutTask, "", "Post", ja);
reply = WebApiHelper.ParseFromJson(jobj.ToString());
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.Error(ex.ToString());
}
return reply;
}
public GetTunnelListReply I_WCS_GetTunnelList(GetTunnelListParam param)
{
GetTunnelListReply reply = null;
try
{
Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetTunnelList。参数:[{0}]", WebApiHelper.GetJson(param)));
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetTunnelList, "", "Post", ja);
reply = WebApiHelper.ParseFromJson(jobj.ToString());
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetTunnelList。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
public GetWareCellReply I_WCS_GetWareCell(GetWareCellParam param)
{
GetWareCellReply reply = null;
try
{
Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetWareCell。参数:[{0}]", WebApiHelper.GetJson(param)));
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetWareCell, "", "Post", ja);
reply = WebApiHelper.ParseFromJson(jobj.ToString());
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWareCell。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
public GetWeightReply I_WCS_GetWeight(GetWeightParam param)
{
GetWeightReply reply = null;
try
{
Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]", WebApiHelper.GetJson(param)));
//调用WMS接口
reply = (GetWeightReply)MethodOutTimeHelper.OutTimeSomeParemReturn(WCS_GetWeight, AppSettingsHelper.AppSettings.MethodOutTimeMilliseconds, param);
if (reply == null)
{
reply = new GetWeightReply();
throw new Exception(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]反馈结果:[接口报错或接口超时]", WebApiHelper.GetJson(param)));
}
else
{
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
}
//JArray ja = new JArray();
//ja.Add(WebApiHelper.GetJson(param));
//JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetWeight, "", "Post", ja);
//reply = WebApiHelper.ParseFromJson(jobj.ToString());
//Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), reply.ResMessage));
}
catch (Exception ex)
{
reply.ResMessage = ex.Message;
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
private object WCS_GetWeight(object obj)
{
GetWeightParam param = null;
GetWeightReply reply = null;
try
{
param = obj as GetWeightParam;
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetWeight, "", "Post", ja);
reply = WebApiHelper.ParseFromJson(jobj.ToString());
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.Error(ex.ToString());
}
return reply;
}
public GetExcTaskReply I_WCS_PutDevInfo(List param)
{
GetExcTaskReply reply = null;
try
{
//Log4netHelper.Logger_Info.InfoFormat(string.Format("开始:WCS调用WMS接口函数I_WCS_PutDevInfo"));
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.PutDevInfo, "", "Post", ja);
if (jobj == null) throw new Exception(string.Format("任务进程更新接口返回json解析失败。"));
reply = WebApiHelper.ParseFromJson(jobj.ToString());
//Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutDevInfo。反馈结果:[{0}]", reply.ResMessage));
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
public List I_WCS_PutTaskStep(List task)
{
List reply = null;
try
{
foreach (var item in task)
{
if (item.TASK_WKSTATUS >= 99)
{
Log4netHelper.Logger_Info.InfoFormat(string.Format("任务[{0}]状态[{1}]开始:WCS调用WMS接口函数I_WCS_PutTaskStep", item.TASK_NO, item.TASK_WKSTATUS));
}
}
//Log4netHelper.Logger_Info.InfoFormat(string.Format("开始:WCS调用WMS接口函数I_WCS_PutTaskStep"));
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(task));
//Log4netHelper.Logger_Info.InfoFormat(WebApiHelper.GetJson(task));
JArray jobj = WebApiHelper.SendInfoToWebAPIList(AppSettingsHelper.AppSettings.PutTaskStep, "", "Post", ja);
reply = WebApiHelper.ParseFromJson>(jobj.ToString());
foreach (var item in reply)
{
var ts = task.FirstOrDefault(v => v.TASK_WMSNO == item.WMSTaskNum);
if (ts != null && ts.TASK_WKSTATUS >= 99)
{
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutTaskStep成功反馈结果:[{0}]", WebApiHelper.GetJson(item)));
}
if (!item.ResType)
{
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutTaskStep失败反馈结果:[{0}]", WebApiHelper.GetJson(item)));
}
}
//Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutTaskStep。反馈结果:[{0}]", jobj.ToString()));
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
public GetExcTaskReply I_WCS_UploadExcTask(UploadExcTaskParam param)
{
GetExcTaskReply reply = null;
try
{
Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetExcTask。参数:[{0}]", WebApiHelper.GetJson(param)));
JArray ja = new JArray();
ja.Add(WebApiHelper.GetJson(param));
JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetExcTask, "", "Post", ja);
reply = WebApiHelper.ParseFromJson(jobj.ToString());
Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetExcTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
}
catch (Exception ex)
{
Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
}
return reply;
}
}
}