颐和api

HangfireService.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System.Net.Http;
  2. using System.Threading.Tasks;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Logging;
  5. using Pivotal.Discovery.Client;
  6. using System.Collections.Generic;
  7. using System.Linq.Expressions;
  8. using System;
  9. using MadRunFabric.Common;
  10. namespace Api.SignToken
  11. {
  12. public class HangfireService : IHangfireService
  13. {
  14. DiscoveryHttpClientHandler _handler;
  15. ILogger<HangfireService> _logger;
  16. /// <summary>
  17. /// URL
  18. /// </summary>
  19. private const string URL = "http://hangfireapi/api/";
  20. public HangfireService(IDiscoveryClient client, ILoggerFactory logFactory)
  21. {
  22. _handler = new DiscoveryHttpClientHandler(client, logFactory.CreateLogger<DiscoveryHttpClientHandler>());
  23. _logger = logFactory.CreateLogger<HangfireService>();
  24. }
  25. private HttpClient GetClient()
  26. {
  27. var client = new HttpClient(_handler, false);
  28. return client;
  29. }
  30. /// <summary>
  31. /// 保养计划
  32. /// </summary>
  33. /// <param name="proname"></param>
  34. /// <param name="sysname"></param>
  35. /// <param name="equipname"></param>
  36. /// <param name="id"></param>
  37. /// <param name="expirytime"></param>
  38. /// <param name="advancelong"></param>
  39. /// <param name="content"></param>
  40. /// <param name="maintype"></param>
  41. /// <param name="plancycle"></param>
  42. /// <param name="plandate"></param>
  43. /// <param name="planhour"></param>
  44. /// <returns></returns>
  45. public async Task<string> AddWoMaintainBase(string proname, string sysname, string equipname, string id,
  46. string expirytime, int advancelong, string content,string maintype,
  47. int plancycle, int plandate, int planhour)
  48. {
  49. var client = GetClient();
  50. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  51. {
  52. {"proname", proname},
  53. {"sysname", sysname},
  54. {"equipname", equipname},
  55. {"id", id},
  56. {"expirytime",expirytime },
  57. {"advancelong",advancelong.ToString() },
  58. {"content",content },
  59. {"maintype",maintype},
  60. {"plancycle", plancycle.ToString()},
  61. {"plandate", plandate.ToString()},
  62. {"planhour", planhour.ToString()}
  63. });
  64. var response = await client.PostAsync(URL + "equipment/addwomaintainbase", postContent);
  65. _logger.LogInformation("创建保养计划定时任务成功");
  66. return await response.Content.ReadAsStringAsync();
  67. }
  68. /// <summary>
  69. /// 保养计划
  70. /// </summary>
  71. public async Task<string> AddWoMaintainBase(string id, int plancycle, int planinterval, int plantimes)
  72. {
  73. _logger.LogError("HangfireService/AddWoMaintainBase start");
  74. var client = GetClient();
  75. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  76. {
  77. {"id", id},
  78. {"plancycle", plancycle.ToString()},
  79. {"planinterval", planinterval.ToString()},
  80. {"plantimes", plantimes.ToString()}
  81. });
  82. var response = await client.PostAsync(URL + "equipment/addwomaintainbase", postContent);
  83. _logger.LogInformation("创建保养计划定时任务成功");
  84. return await response.Content.ReadAsStringAsync();
  85. }
  86. /// <summary>
  87. /// 添加 设备运维计划定时任务
  88. /// </summary>
  89. /// <param name="projectid">项目id</param>
  90. /// <param name="sysnameid">系统</param>
  91. /// <param name="equipmentid">设备</param>
  92. /// <param name="id">计划id</param>
  93. /// <param name="plancycle"></param>
  94. /// <param name="plandate"></param>
  95. /// <param name="planhour"></param>
  96. /// <returns></returns>
  97. public async Task<string> AddWoEquipmentRunning(string projectid, string sysnameid, string equipmentid, string id,
  98. string expirytime,int advancelong, int plancycle, int plandate, int planhour)
  99. {
  100. var client = GetClient();
  101. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  102. {
  103. {"projectid", projectid},
  104. {"sysnameid", sysnameid},
  105. {"equipmentid", equipmentid},
  106. {"id", id},
  107. {"expirytime",expirytime },
  108. {"advancelong",advancelong.ToString() },
  109. {"plancycle", plancycle.ToString()},
  110. {"plandate", plandate.ToString()},
  111. {"planhour", planhour.ToString()}
  112. });
  113. var response = await client.PostAsync(URL + "equipment/addwoequipmentrunning", postContent);
  114. _logger.LogInformation("创建设备运维计划定时任务成功");
  115. return await response.Content.ReadAsStringAsync();
  116. }
  117. public async Task<string> AddWoEquipmentRunning(string id, int plancycle, int planinterval, int plantimes)
  118. {
  119. _logger.LogError("HangfireService/AddWoEquipmentRunning start");
  120. var client = GetClient();
  121. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  122. {
  123. {"id", id},
  124. {"plancycle", plancycle.ToString()},
  125. {"planinterval", planinterval.ToString()},
  126. {"plantimes", plantimes.ToString()}
  127. });
  128. var response = await client.PostAsync(URL + "equipment/addwoequipmentrunning", postContent);
  129. _logger.LogInformation("创建设备运维计划定时任务成功");
  130. return await response.Content.ReadAsStringAsync();
  131. }
  132. /// <summary>
  133. /// 保持超时工单定时任务
  134. /// </summary>
  135. /// <param name="woid"></param>
  136. /// <param name="wotype"></param>
  137. /// <param name="id"></param>
  138. /// <returns></returns>
  139. public async Task<string> SaveTimeOutRunning(string id, int wotype, int plancycle, int planinterval)
  140. {
  141. var client = GetClient();
  142. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  143. {
  144. {"id", id},
  145. {"wotype", wotype.ToString()},
  146. {"plancycle", plancycle.ToString()},
  147. {"planinterval", planinterval.ToString()},
  148. });
  149. var response = await client.PostAsync(URL + "equipment/savetimeout", postContent);
  150. _logger.LogInformation("创建超时工单定时任务成功");
  151. return await response.Content.ReadAsStringAsync();
  152. }
  153. /// <summary>
  154. /// 根据id删除定时任务
  155. /// </summary>
  156. /// <param name="id"></param>
  157. /// <returns></returns>
  158. public async Task<string> RemovePlan(string id)
  159. {
  160. var client = GetClient();
  161. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  162. {
  163. {"id", id}
  164. });
  165. var response = await client.PostAsync(URL + "equipment/remove", postContent);
  166. _logger.LogInformation("删除定时任务成功");
  167. return await response.Content.ReadAsStringAsync();
  168. }
  169. public string GetInfo()
  170. {
  171. var client = GetClient();
  172. var result = client.GetStringAsync(URL + "info").Result;
  173. _logger.LogInformation("返回的权限信息为: {0}", result);
  174. return result;
  175. }
  176. #region 配送物品计划
  177. /// <summary>
  178. /// 添加配送计划 - 来源 DistriWorkOrderPlanController
  179. /// </summary>
  180. /// <param name="id"></param>
  181. /// <param name="plancycle"></param>
  182. /// <param name="planinterval"></param>
  183. /// <param name="plantimes"></param>
  184. /// <returns></returns>
  185. public async Task<string> AddDistriWorkOrderPlan(string id, int plancycle, int planinterval, int plantimes, string extensiontime)
  186. {
  187. _logger.LogError("HangfireService/AddWoEquipmentRunning start ");
  188. var client = GetClient();
  189. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  190. {
  191. {"id", id},
  192. {"plancycle", plancycle.ToString()},
  193. {"planinterval", planinterval.ToString()},
  194. {"plantimes", plantimes.ToString()},
  195. {"extensiontime", extensiontime}
  196. });
  197. //访问接口 HangfireDistributionPlanController
  198. var response = await client.PostAsync(URL + "hangfiredistributionplan/adddistributionplan", postContent);
  199. _logger.LogInformation("创建配送物品计划定时任务成功");
  200. return await response.Content.ReadAsStringAsync();
  201. }
  202. /// <summary>
  203. /// 删除配送计划 - 定时任务 - 来源 DistriWorkOrderPlanController
  204. /// </summary>
  205. /// <param name="id"></param>
  206. /// <returns></returns>
  207. public async Task<string> RemoveDistriWorkOrderPlan(string id)
  208. {
  209. var client = GetClient();
  210. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  211. {
  212. {"id", id}
  213. });
  214. //访问接口 HangfireDistributionPlanController
  215. var response = await client.PostAsync(URL + "hangfiredistributionplan/remove", postContent);
  216. _logger.LogInformation("删除定时任务成功");
  217. return await response.Content.ReadAsStringAsync();
  218. }
  219. /// <summary>
  220. /// 自动定时计划 - 自动分配
  221. /// </summary>
  222. /// <param name="id"></param>
  223. /// <param name="wotype"></param>
  224. /// <param name="plancycle"></param>
  225. /// <param name="planinterval"></param>
  226. /// <returns></returns>
  227. public async Task<string> SaveAutoAssign(string id, int wotype, int plancycle, int planinterval)
  228. {
  229. var client = GetClient();
  230. HttpContent postContent = new FormUrlEncodedContent(new Dictionary<string, string>()
  231. {
  232. {"id", id},
  233. {"wotype", wotype.ToString()},
  234. {"plancycle", plancycle.ToString()},
  235. {"planinterval", planinterval.ToString()},
  236. });
  237. var response = await client.PostAsync(URL + "hangfiredistributionplan/saveautoassign", postContent);
  238. _logger.LogInformation("创建自动定时(自动分配)任务成功");
  239. return await response.Content.ReadAsStringAsync();
  240. }
  241. #endregion
  242. }
  243. }