| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 | 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{    /// <summary>    /// 调用WMS接口    /// </summary>    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<GetInTaskReply>(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<GetInTaskReply>(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<GetMoveTaskReply>(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<GetOutTaskReply>(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<GetOutTaskReply>(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<GetTunnelListReply>(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<GetWareCellReply>(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<GetWeightReply>(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<GetWeightReply>(jobj.ToString());            }            catch (Exception ex)            {                Log4netHelper.Logger_Error.Error(ex.ToString());            }            return reply;        }        public GetExcTaskReply I_WCS_PutDevInfo(List<PutDevInfoParam> 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<GetExcTaskReply>(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<PutTaskStepReply> I_WCS_PutTaskStep(List<WCS_TASK> task)        {            List<PutTaskStepReply> 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<List<PutTaskStepReply>>(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<GetExcTaskReply>(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;        }    }}
 |