SKTrumpRestFullService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using MaxCommunication.DataBase.Document;
  2. using PmsSecondaryPackaging.Interface.Model.Carrier;
  3. using PmsSecondaryPackaging.Interface.Model.TaskBook;
  4. using ProjectManagementSystem.Common.WebApi;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Web;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Pms.DataLibrary.Models;
  13. using ProjectManagementSystem.NHibernateDBHelper;
  14. namespace Pms.WebHandle
  15. {
  16. [ServiceContract(Name = "TCLTrumpRestFullService")]
  17. public interface ISKTrumpRestFullService
  18. {
  19. /// <summary>
  20. /// 获取所有的站点
  21. /// </summary>
  22. /// <returns></returns>
  23. [OperationContract]
  24. [WebGet(UriTemplate = "?OrderID={OrderID}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Json)]
  25. string GetOrder(string OrderID);
  26. [OperationContract]//对应接口编号001
  27. [WebInvoke(Method = "POST", UriTemplate = "TaskDownload", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
  28. SKClentOrderResponse TaskDownload(SKClentOrder orderRequest);
  29. [OperationContract]//对应接口编号001
  30. [WebInvoke(Method = "POST", UriTemplate = "TaskCancel", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
  31. ClentOrderCancelResponse TaskCancel(ClentOrderCancel wmsorderRequest);
  32. [OperationContract]//对应接口编号001
  33. [WebInvoke(Method = "POST", UriTemplate = "TaskRedirection", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
  34. ClentOrderRedirectionResponse TaskRedirection(ClentOrderRedirection wmsorderRequest);
  35. /// <summary>
  36. /// 获取站点信息
  37. /// </summary>
  38. /// <returns></returns>
  39. [OperationContract]
  40. [WebInvoke(Method = "PUT", UriTemplate = "?CancelOrderID={OrderID}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Json)]
  41. string CancelOrder(string OrderID);
  42. /// <summary>
  43. /// 释放小车,用于在完成工作后释放指定的小车。当找到小车时,会返回小车等信息
  44. /// </summary>
  45. /// <returns>失败编码 0 成功</returns>
  46. [OperationContract]
  47. [WebGet(UriTemplate = "ReleaseAGV/{agvID}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
  48. string ReleaseAGV(string agvID);
  49. }
  50. public class SKTrumpRestFullService : ISKTrumpRestFullService
  51. {
  52. public SKClentOrderResponse TaskDownload(SKClentOrder orderRequest)
  53. {
  54. SKClentOrderResponse tCLClentOrderResponse = new SKClentOrderResponse();
  55. try
  56. {
  57. if (orderRequest != null)
  58. {
  59. //
  60. int.TryParse(orderRequest.agvid, out int tempAgvId);
  61. using (var session = MiddleDBModelHelper.Session)
  62. {
  63. var result = session.QueryOver<Order>().Where(p => p.Material == orderRequest.taskid).List();
  64. if (result.Count > 0)
  65. {
  66. tCLClentOrderResponse.code = string.Format("已存在任务号:{0} 的任务!", orderRequest.taskid);
  67. TextDocument.WriteFile(@"PMS/Log", "OrderRequest", tCLClentOrderResponse.code);
  68. return tCLClentOrderResponse;
  69. }
  70. Order tempOrder = new Order(DateTime.Now.ToString("yyyyMMddhhmmssffff") + "_" + orderRequest.taskid, (OrderType)0, orderRequest.source, "", orderRequest.target, -1, tempAgvId, orderRequest.taskid);
  71. tempOrder.CallTime = DateTime.Now;
  72. tempOrder.FinishTime = DateTime.MaxValue;
  73. tempOrder.Suspend = false;
  74. session.Save(tempOrder);
  75. session.Flush();
  76. tCLClentOrderResponse.code = "0";
  77. tCLClentOrderResponse.taskid = orderRequest.taskid;
  78. TextDocument.WriteFile(@"PMS/Log", "OrderRequest", string.Format("添加任务成功,taskid:{0},source:{1},target:{2},tasktype:{3},agvid:{4}!", orderRequest.taskid, orderRequest.source, orderRequest.target, 0, orderRequest.agvid));
  79. }
  80. //TaskAddInfoModel taskAddInfoModel = new TaskAddInfoModel();
  81. //taskAddInfoModel.TaskID = orderRequest.taskid; //System.DateTime.Now.ToString("MMddhhmmssffff")
  82. //taskAddInfoModel.TemplateName ="StandardTemplate1"; //orderRequest.tasktype
  83. ////taskAddInfoModel.AgvType = "1";
  84. ////int.TryParse(orderRequest.agvid, out int tempAgvId);
  85. //taskAddInfoModel.AgvId = tempAgvId;
  86. //Dictionary<string, string> dictionary = new Dictionary<string, string>();
  87. //dictionary.Add("M_R1", orderRequest.source);
  88. //dictionary.Add("M1", orderRequest.source);
  89. //dictionary.Add("M_R2", orderRequest.source);//两台车
  90. // //dictionary.Add("M2", curOrder.DownPos);
  91. //dictionary.Add("ME_R1", orderRequest.target);
  92. //taskAddInfoModel.ParametersDic = dictionary;
  93. ////taskAddInfoModel.ParentTaskId = TaskID;
  94. //PmsSecondaryPackaging.Interface.Service.InterfaceService interfaceService = new PmsSecondaryPackaging.Interface.Service.InterfaceService();
  95. //if (interfaceService.GetCarrier(orderRequest.agvid,out CarrierInfoModel carrierInfoModel,out string message))
  96. //{
  97. // //PmsApi.Get(EPmsApi.GetCarrier, new { },null,out carrier)
  98. // if (!carrierInfoModel.Online)
  99. // {
  100. // //Pms.DataLibrary.Carrier.CarrierTask
  101. // }
  102. // else if(carrierInfoModel.AlarmList.Any(p=>p.alarmId!=0))
  103. // {
  104. // }
  105. //}
  106. //else
  107. //{
  108. // //未找到小车
  109. //}
  110. //if (!interfaceService.TaskAdd(taskAddInfoModel, out string Message))
  111. //{
  112. // TextDocument.WriteFile(@"PMS/Log", "添加任务", Message);
  113. //}
  114. //else
  115. //{
  116. // //curOrder.OrderState = (int)OrderState.None;
  117. // //session.Update(curOrder);
  118. // TextDocument.WriteFile(@"PMS/Log", "添加任务", "任务添加成功!");
  119. //}
  120. //TextDocument.WriteFile(@"PMS/Log","OrderRequest", string.Format("收到请求时间:{0},请求内容",DateTime.Now,JsonHelper.ConvertToJson(typeof(SKClentOrder),orderRequest)));
  121. }
  122. else
  123. {
  124. TextDocument.WriteFile(@"PMS/Log","OrderRequest", "请求数据为空");
  125. tCLClentOrderResponse.code = "请求数据为空";
  126. }
  127. }
  128. catch(Exception ex)
  129. {
  130. TextDocument.WriteFile(@"PMS/Log","OrderRequest", "处理请求数据异常:"+ex.ToString());
  131. tCLClentOrderResponse.code = "处理请求数据异常";
  132. }
  133. return tCLClentOrderResponse;
  134. }
  135. public ClentOrderCancelResponse TaskCancel(ClentOrderCancel orderRequest)
  136. {
  137. ClentOrderCancelResponse tCLClentOrderResponse = new ClentOrderCancelResponse();
  138. try
  139. {
  140. if (orderRequest != null)
  141. {
  142. using (var session = MiddleDBModelHelper.Session)
  143. {
  144. var result = session.QueryOver<Order>().Where(p => p.Material == orderRequest.taskid).List();
  145. if(result.Count<0)
  146. {
  147. tCLClentOrderResponse.code = "0";
  148. return tCLClentOrderResponse;
  149. }
  150. Order tempOrder = result.First();
  151. PmsSecondaryPackaging.Interface.Service.InterfaceService interfaceService = new PmsSecondaryPackaging.Interface.Service.InterfaceService();
  152. if(interfaceService.TaskCancel(new TaskCancelInfoModel(tempOrder.OrderID, false), out string message))
  153. {
  154. tCLClentOrderResponse.code = "0";
  155. return tCLClentOrderResponse;
  156. }
  157. else
  158. {
  159. tCLClentOrderResponse.code = message;
  160. return tCLClentOrderResponse;
  161. }
  162. }
  163. }
  164. else
  165. {
  166. TextDocument.WriteFile(@"PMS/Log","WMSOrderRequest", "请求数据为空");
  167. tCLClentOrderResponse.code = "请求数据为空";
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. TextDocument.WriteFile(@"PMS/Log","WMSOrderRequest", "处理请求数据异常:" + ex.ToString());
  173. tCLClentOrderResponse.code = "处理请求数据异常";
  174. }
  175. return tCLClentOrderResponse;
  176. }
  177. public ClentOrderRedirectionResponse TaskRedirection(ClentOrderRedirection wmsorderRequest)
  178. {
  179. ClentOrderRedirectionResponse tCLClentOrderResponse = new ClentOrderRedirectionResponse();
  180. try
  181. {
  182. if (wmsorderRequest != null)
  183. {
  184. }
  185. else
  186. {
  187. TextDocument.WriteFile(@"PMS/Log", "WMSOrderRequest", "请求数据为空");
  188. tCLClentOrderResponse.code = "请求数据为空";
  189. }
  190. }
  191. catch (Exception ex)
  192. {
  193. TextDocument.WriteFile(@"PMS/Log", "WMSOrderRequest", "处理请求数据异常:" + ex.ToString());
  194. tCLClentOrderResponse.code = "处理请求数据异常";
  195. }
  196. return tCLClentOrderResponse;
  197. }
  198. string[] RESULTS = { "OK", "RUN", "NG", "NEW" };
  199. public string CancelOrder(string OrderID)
  200. {
  201. string result = RESULTS[2];
  202. return result;
  203. }
  204. public string GetOrder(string OrderID)
  205. {
  206. string result = RESULTS[3];
  207. return result;
  208. }
  209. public string ReleaseAGV(string agvID)
  210. {
  211. string result = RESULTS[2];
  212. return result;
  213. }
  214. }
  215. }