WMS_API.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Newtonsoft.Json.Linq;
  6. using WCS.Data;
  7. using WCS.Data.Models;
  8. using WCS.Data.Utils;
  9. using static WCS.WMSWorkflow.ApiParam;
  10. namespace WCS.WMSWorkflow
  11. {
  12. /// <summary>
  13. /// 调用WMS接口
  14. /// </summary>
  15. public class WMS_API : IWMS
  16. {
  17. private static readonly object emptyFrameBack_lock = new object();
  18. public GetInTaskReply I_WCS_GetInTask(GetInTaskParam param)
  19. {
  20. GetInTaskReply reply = null;
  21. try
  22. {
  23. DateTime startDateTime = DateTime.Now;
  24. Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetInTask。参数:[{0}]", WebApiHelper.GetJson(param)));
  25. //调用WMS接口
  26. reply = (GetInTaskReply)MethodOutTimeHelper.OutTimeSomeParemReturn(WCS_GetInTask, AppSettingsHelper.AppSettings.MethodOutTimeMilliseconds, param);
  27. //JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetInTask, "", "Post", ja);
  28. //reply = WebApiHelper.ParseFromJson<GetInTaskReply>(jobj.ToString());
  29. if (reply == null)
  30. {
  31. //reply = new GetInTaskReply();
  32. //throw new Exception(string.Format("结束:WCS调用WMS接口函数I_WCS_GetInTask。参数:[{0}]反馈结果:[接口报错或接口超时]", WebApiHelper.GetJson(param)));
  33. //throw new Exception("访问网络超时");
  34. }
  35. else
  36. {
  37. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetInTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  38. }
  39. DateTime endDateTime = DateTime.Now;
  40. if (startDateTime.AddSeconds(30) < endDateTime)
  41. {
  42. 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));
  43. //接口超时30秒以上
  44. LogMessageHelper.RecordLogMessage(message);
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  50. reply.ResMessage = ex.Message;
  51. }
  52. return reply;
  53. }
  54. private object WCS_GetInTask(object obj)
  55. {
  56. GetInTaskReply reply = null;
  57. try
  58. {
  59. var param = obj as GetInTaskParam;
  60. JArray ja = new JArray();
  61. ja.Add(WebApiHelper.GetJson(param));
  62. JObject jobj = WebApiHelper.SendInfoToAPI(AppSettingsHelper.AppSettings.GetInTask, "", "Post", ja);
  63. reply = WebApiHelper.ParseFromJson<GetInTaskReply>(jobj.ToString());
  64. }
  65. catch (Exception ex)
  66. {
  67. LogMessageHelper.RecordLogMessage(ex);
  68. }
  69. return reply;
  70. }
  71. public GetMoveTaskReply I_WCS_GetMoveTask(GetMoveTaskParam param)
  72. {
  73. GetMoveTaskReply reply = null;
  74. try
  75. {
  76. Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetMoveTask。参数:[{0}]", WebApiHelper.GetJson(param)));
  77. JArray ja = new JArray();
  78. ja.Add(WebApiHelper.GetJson(param));
  79. //调用MES接口
  80. JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetMoveTask, "", "Post", ja);
  81. reply = WebApiHelper.ParseFromJson<GetMoveTaskReply>(jobj.ToString());
  82. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetMoveTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  83. }
  84. catch (Exception ex)
  85. {
  86. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  87. }
  88. return reply;
  89. }
  90. public GetOutTaskReply I_WCS_GetOutTask(GetOutTaskParam param)
  91. {
  92. GetOutTaskReply reply = null;
  93. try
  94. {
  95. string msg = string.Format("开始:WCS调用WMS接口函数I_WCS_GetOutTask。参数:{0}", WebApiHelper.GetJson(param));
  96. Log4netHelper.Logger_Info.Info(msg);
  97. //调用WMS接口
  98. reply = (GetOutTaskReply)MethodOutTimeHelper.OutTimeSomeParemReturn(I_WCS_GetOutTask, AppSettingsHelper.AppSettings.MethodOutTimeMilliseconds, param);
  99. //JArray ja = new JArray();
  100. //ja.Add(WebApiHelper.GetJson(param));
  101. ////调用MES接口
  102. //JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetOutTask, "", "Post", ja);
  103. //reply = WebApiHelper.ParseFromJson<GetOutTaskReply>(jobj.ToString());
  104. if (reply == null)
  105. {
  106. reply = new GetOutTaskReply();
  107. //throw new Exception(string.Format("结束:WCS调用WMS接口函数I_WCS_GetOutTask。参数:[{0}]反馈结果:[接口报错或接口超时]", WebApiHelper.GetJson(param)));
  108. throw new Exception("访问网络超时");
  109. }
  110. else
  111. {
  112. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetOutTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  113. }
  114. }
  115. catch (Exception ex)
  116. {
  117. reply.ResMessage = ex.Message;
  118. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  119. }
  120. return reply;
  121. }
  122. private object I_WCS_GetOutTask(object obj)
  123. {
  124. GetOutTaskParam param = null;
  125. GetOutTaskReply reply = null;
  126. try
  127. {
  128. param = obj as GetOutTaskParam;
  129. JArray ja = new JArray();
  130. ja.Add(WebApiHelper.GetJson(param));
  131. JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetOutTask, "", "Post", ja);
  132. reply = WebApiHelper.ParseFromJson<GetOutTaskReply>(jobj.ToString());
  133. }
  134. catch (Exception ex)
  135. {
  136. Log4netHelper.Logger_Error.Error(ex.ToString());
  137. }
  138. return reply;
  139. }
  140. public GetTunnelListReply I_WCS_GetTunnelList(GetTunnelListParam param)
  141. {
  142. GetTunnelListReply reply = null;
  143. try
  144. {
  145. Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetTunnelList。参数:[{0}]", WebApiHelper.GetJson(param)));
  146. JArray ja = new JArray();
  147. ja.Add(WebApiHelper.GetJson(param));
  148. JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetTunnelList, "", "Post", ja);
  149. reply = WebApiHelper.ParseFromJson<GetTunnelListReply>(jobj.ToString());
  150. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetTunnelList。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  151. }
  152. catch (Exception ex)
  153. {
  154. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  155. }
  156. return reply;
  157. }
  158. public GetWareCellReply I_WCS_GetWareCell(GetWareCellParam param)
  159. {
  160. GetWareCellReply reply = null;
  161. try
  162. {
  163. Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetWareCell。参数:[{0}]", WebApiHelper.GetJson(param)));
  164. JArray ja = new JArray();
  165. ja.Add(WebApiHelper.GetJson(param));
  166. JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetWareCell, "", "Post", ja);
  167. reply = WebApiHelper.ParseFromJson<GetWareCellReply>(jobj.ToString());
  168. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWareCell。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  169. }
  170. catch (Exception ex)
  171. {
  172. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  173. }
  174. return reply;
  175. }
  176. public GetMatureContinueModeReply I_WCS_GetMatureContinueMode(GetMatureContinueParam param)
  177. {
  178. GetMatureContinueModeReply reply = null;
  179. string replyTxt = "";
  180. try
  181. {
  182. Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetMatureContinueMode。参数:[{0}]", WebApiHelper.GetJson(param)));
  183. JArray ja = new JArray();
  184. ja.Add(WebApiHelper.GetJson(param));
  185. JObject jobj = WebApiHelper.SendInfoToAPI(AppSettingsHelper.AppSettings.GetMatureContinueMode, "", "Post", ja);
  186. replyTxt = jobj.ToString();
  187. reply = WebApiHelper.ParseFromJson<GetMatureContinueModeReply>(replyTxt);
  188. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetMatureContinueMode。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  189. }
  190. catch (Exception ex)
  191. {
  192. LogMessageHelper.RecordLogMessage(ex);
  193. }
  194. finally
  195. {
  196. reply.ResType = replyTxt.Contains("true") ? true : false;
  197. }
  198. return reply;
  199. }
  200. public GetWeightReply I_WCS_GetWeight(GetWeightParam param)
  201. {
  202. GetWeightReply reply = null;
  203. try
  204. {
  205. Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]", WebApiHelper.GetJson(param)));
  206. //调用WMS接口
  207. reply = (GetWeightReply)MethodOutTimeHelper.OutTimeSomeParemReturn(WCS_GetWeight, AppSettingsHelper.AppSettings.MethodOutTimeMilliseconds, param);
  208. if (reply == null)
  209. {
  210. reply = new GetWeightReply();
  211. throw new Exception(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]反馈结果:[接口报错或接口超时]", WebApiHelper.GetJson(param)));
  212. }
  213. else
  214. {
  215. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  216. }
  217. //JArray ja = new JArray();
  218. //ja.Add(WebApiHelper.GetJson(param));
  219. //JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetWeight, "", "Post", ja);
  220. //reply = WebApiHelper.ParseFromJson<GetWeightReply>(jobj.ToString());
  221. //Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetWeight。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), reply.ResMessage));
  222. }
  223. catch (Exception ex)
  224. {
  225. reply.ResMessage = ex.Message;
  226. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  227. }
  228. return reply;
  229. }
  230. private object WCS_GetWeight(object obj)
  231. {
  232. GetWeightParam param = null;
  233. GetWeightReply reply = null;
  234. try
  235. {
  236. param = obj as GetWeightParam;
  237. JArray ja = new JArray();
  238. ja.Add(WebApiHelper.GetJson(param));
  239. JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetWeight, "", "Post", ja);
  240. reply = WebApiHelper.ParseFromJson<GetWeightReply>(jobj.ToString());
  241. }
  242. catch (Exception ex)
  243. {
  244. Log4netHelper.Logger_Error.Error(ex.ToString());
  245. }
  246. return reply;
  247. }
  248. public GetExcTaskReply I_WCS_PutDevInfo(List<PutDevInfoParam> param)
  249. {
  250. GetExcTaskReply reply = null;
  251. try
  252. {
  253. //Log4netHelper.Logger_Info.InfoFormat(string.Format("开始:WCS调用WMS接口函数I_WCS_PutDevInfo"));
  254. JArray ja = new JArray();
  255. ja.Add(WebApiHelper.GetJson(param));
  256. JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.PutDevInfo, "", "Post", ja);
  257. if (jobj == null) throw new Exception(string.Format("任务进程更新接口返回json解析失败。"));
  258. reply = WebApiHelper.ParseFromJson<GetExcTaskReply>(jobj.ToString());
  259. //Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutDevInfo。反馈结果:[{0}]", reply.ResMessage));
  260. }
  261. catch (Exception ex)
  262. {
  263. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  264. }
  265. return reply;
  266. }
  267. public List<PutTaskStepReply> I_WCS_PutTaskStep(List<WCS_TASK> task)
  268. {
  269. List<PutTaskStepReply> reply = null;
  270. try
  271. {
  272. foreach (var item in task)
  273. {
  274. if (item.TASK_WKSTATUS >= 99)
  275. {
  276. Log4netHelper.Logger_Info.InfoFormat(string.Format("任务[{0}]状态[{1}]开始:WCS调用WMS接口函数I_WCS_PutTaskStep", item.TASK_NO, item.TASK_WKSTATUS));
  277. }
  278. }
  279. //Log4netHelper.Logger_Info.InfoFormat(string.Format("开始:WCS调用WMS接口函数I_WCS_PutTaskStep"));
  280. JArray ja = new JArray();
  281. ja.Add(WebApiHelper.GetJson(task));
  282. //Log4netHelper.Logger_Info.InfoFormat(WebApiHelper.GetJson(task));
  283. JArray jobj = WebApiHelper.SendInfoToWebAPIList(AppSettingsHelper.AppSettings.PutTaskStep, "", "Post", ja);
  284. reply = WebApiHelper.ParseFromJson<List<PutTaskStepReply>>(jobj.ToString());
  285. foreach (var item in reply)
  286. {
  287. var ts = task.FirstOrDefault(v => v.TASK_WMSNO == item.WMSTaskNum);
  288. if (ts != null && ts.TASK_WKSTATUS >= 99)
  289. {
  290. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutTaskStep成功反馈结果:[{0}]", WebApiHelper.GetJson(item)));
  291. }
  292. if (!item.ResType)
  293. {
  294. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutTaskStep失败反馈结果:[{0}]", WebApiHelper.GetJson(item)));
  295. }
  296. }
  297. //Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_PutTaskStep。反馈结果:[{0}]", jobj.ToString()));
  298. }
  299. catch (Exception ex)
  300. {
  301. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  302. }
  303. return reply;
  304. }
  305. public GetExcTaskReply I_WCS_UploadExcTask(UploadExcTaskParam param)
  306. {
  307. GetExcTaskReply reply = null;
  308. try
  309. {
  310. Log4netHelper.Logger_Info.Info(string.Format("开始:WCS调用WMS接口函数I_WCS_GetExcTask。参数:[{0}]", WebApiHelper.GetJson(param)));
  311. JArray ja = new JArray();
  312. ja.Add(WebApiHelper.GetJson(param));
  313. JObject jobj = WebApiHelper.SendInfoToWebAPI(AppSettingsHelper.AppSettings.GetExcTask, "", "Post", ja);
  314. reply = WebApiHelper.ParseFromJson<GetExcTaskReply>(jobj.ToString());
  315. Log4netHelper.Logger_Info.Info(string.Format("结束:WCS调用WMS接口函数I_WCS_GetExcTask。参数:[{0}]反馈结果:[{1}]", WebApiHelper.GetJson(param), WebApiHelper.GetJson(reply)));
  316. }
  317. catch (Exception ex)
  318. {
  319. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  320. }
  321. return reply;
  322. }
  323. }
  324. }