AlarmProvider.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. using ivf_tl_Entity.Entity.Alarm;
  2. using ivf_tl_Entity.Entity.Result;
  3. using ivf_tl_Entity.Enums;
  4. using ivf_tl_Entity.Response;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Markup;
  12. using System.Xml.Linq;
  13. namespace ivf_tl_Service.HttpProvider
  14. {
  15. public class AlarmProvider
  16. {
  17. LogService LogService { get; set; }
  18. HttpServiceCall httpServiceCall1 { get; set; }
  19. public AlarmProvider(HttpServiceCall _httpServiceCall, LogService _logService)
  20. {
  21. httpServiceCall1 = _httpServiceCall;
  22. LogService = _logService;
  23. }
  24. private void ExLog(Exception ex, string name)
  25. {
  26. LogService.ExceptionLog(ex, $"AlarmProvider.{name}", LogEnum.RunException);
  27. }
  28. private void ErrorLog(string message, LogEnum logType)
  29. {
  30. LogService.TLLog($"AlarmProvider.{message}", logType);
  31. }
  32. /// <summary>
  33. /// 查询所有报警联系人及配置信息
  34. /// </summary>
  35. /// <returns></returns>
  36. public List<AlarmUserEntity> GetAlarmPersonnelListApi()
  37. {
  38. string funcName = "GetAlarmPersonnelListApi";
  39. try
  40. {
  41. string url = "/api/tl/control/alarmSetting/getAlarmPersonnellist";
  42. string resultString = httpServiceCall1.callWebService(url);
  43. if (string.IsNullOrEmpty(resultString)) return new List<AlarmUserEntity>();
  44. ResultEntity<List<AlarmUserEntity>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmUserEntity>>>(resultString);
  45. if (!rs.success)
  46. {
  47. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  48. return new List<AlarmUserEntity>();
  49. }
  50. if (rs.data != null && rs.data.Any()) return rs.data;
  51. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  52. return new List<AlarmUserEntity>();
  53. }
  54. catch (Exception ex)
  55. {
  56. ExLog(ex, funcName);
  57. return new List<AlarmUserEntity>();
  58. }
  59. }
  60. /// <summary>
  61. /// 查询所有报警类型及其报警编码信息
  62. /// </summary>
  63. /// <returns></returns>
  64. public List<AlarmTypeEntity> GetTypeAndTemplateListApi()
  65. {
  66. string funcName = "GetTypeAndTemplateListApi";
  67. try
  68. {
  69. string url = "/api/tl/control/alarmSetting/getTypeAndTemplateList";
  70. string resultString = httpServiceCall1.callWebService(url);
  71. if (string.IsNullOrEmpty(resultString)) return new List<AlarmTypeEntity>();
  72. ResultEntity<List<AlarmTypeEntity>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmTypeEntity>>>(resultString);
  73. if (!rs.success)
  74. {
  75. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  76. return new List<AlarmTypeEntity>();
  77. }
  78. if (rs.data != null && rs.data.Any()) return rs.data;
  79. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  80. return new List<AlarmTypeEntity>();
  81. }
  82. catch (Exception ex)
  83. {
  84. ExLog(ex, funcName);
  85. return new List<AlarmTypeEntity>();
  86. }
  87. }
  88. /// <summary>
  89. /// 修改报警配置信息
  90. /// </summary>
  91. /// <returns></returns>
  92. public string UpdateAlarmDetailApi(long id, long smsTemplateId, long callTemplateId, int intervalTime, int state)
  93. {
  94. string funcName = "UpdateAlarmDetailApi";
  95. try
  96. {
  97. string url = "/api/tl/control/alarmSetting/updatePersonnelPermission";
  98. string body = JsonConvert.SerializeObject(new { id, smsTemplateId, callTemplateId, intervalTime, state });
  99. string resultString = httpServiceCall1.callWebService(url, body);
  100. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  101. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  102. if (!rs.success)
  103. {
  104. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  105. return rs.message;
  106. }
  107. return null;
  108. }
  109. catch (Exception ex)
  110. {
  111. ExLog(ex, funcName);
  112. return ex.Message;
  113. }
  114. }
  115. /// <summary>
  116. /// 添加的报警配置信息
  117. /// </summary>
  118. /// <returns></returns>
  119. public string AddAlarmDetailApi(AlarmDetailEntity alarmDetail)
  120. {
  121. string funcName = "AddAlarmDetailApi";
  122. try
  123. {
  124. string url = "/api/tl/control/alarmSetting/insertPersonnelPermission";
  125. string body = JsonConvert.SerializeObject(new
  126. {
  127. alarmPersonnelId = alarmDetail.userId,
  128. smsTemplateId = alarmDetail.smsTemplateId,
  129. callTemplateId = alarmDetail.callTemplateId,
  130. intervalTime = alarmDetail.intervalTime,
  131. alarmTypeId = alarmDetail.alarmTypeId,
  132. });
  133. string resultString = httpServiceCall1.callWebService(url, body);
  134. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  135. var rs = JsonConvert.DeserializeObject<ResultEntity<string>>(resultString);
  136. if (!rs.success)
  137. {
  138. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  139. return rs.message;
  140. }
  141. if (string.IsNullOrEmpty(rs.data))
  142. {
  143. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  144. return $"服务器返回id为空";
  145. }
  146. if (long.TryParse(rs.data, out long newId))
  147. {
  148. alarmDetail.perId = newId;
  149. }
  150. else
  151. {
  152. ErrorLog($"{funcName}接口返回成功,但是没有返回正确Id {resultString}", LogEnum.RunError);
  153. }
  154. return null;
  155. }
  156. catch (Exception ex)
  157. {
  158. ExLog(ex, funcName);
  159. return ex.Message;
  160. }
  161. }
  162. /// <summary>
  163. /// 添加报警联系人信息
  164. /// </summary>
  165. /// <returns></returns>
  166. public string AddAlarmUserApi(string name, string phone, int sms, int tel)
  167. {
  168. string funcName = "AddAlarmUserApi";
  169. try
  170. {
  171. string url = "/api/tl/control/alarmSetting/addAlarmPersonnel";
  172. string body = JsonConvert.SerializeObject(new { name, phone, sms, tel });
  173. string resultString = httpServiceCall1.callWebService(url, body);
  174. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  175. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  176. if (!rs.success)
  177. {
  178. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  179. return rs.message;
  180. }
  181. return null;
  182. }
  183. catch (Exception ex)
  184. {
  185. ExLog(ex, funcName);
  186. return ex.Message;
  187. }
  188. }
  189. /// <summary>
  190. /// 修改报警联系人信息
  191. /// </summary>
  192. /// <returns></returns>
  193. public string UpdateAlarmUserApi(long id, string name, string phone, int sms, int tel)
  194. {
  195. string funcName = "UpdateAlarmUserApi";
  196. try
  197. {
  198. string url = "/api/tl/control/alarmSetting/updateAlarmPersonnel";
  199. string body = JsonConvert.SerializeObject(new { id, name, phone, sms, tel });
  200. string resultString = httpServiceCall1.callWebService(url, body);
  201. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  202. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  203. if (!rs.success)
  204. {
  205. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  206. return rs.message;
  207. }
  208. return null;
  209. }
  210. catch (Exception ex)
  211. {
  212. ExLog(ex, funcName);
  213. return ex.Message;
  214. }
  215. }
  216. /// <summary>
  217. /// 通过id删除报警联系人
  218. /// </summary>
  219. /// <returns></returns>
  220. public string DeleteAlarmUserApi(long id)
  221. {
  222. string funcName = "DeleteAlarmUserApi";
  223. try
  224. {
  225. string url = "/api/tl/control/alarmSetting/deleteAlarmPersonnel";
  226. Dictionary<string, string> body = new Dictionary<string, string> { { "id", id.ToString() } };
  227. string resultString = httpServiceCall1.callWebService(url, body);
  228. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  229. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  230. if (!rs.success)
  231. {
  232. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  233. return rs.message;
  234. }
  235. return null;
  236. }
  237. catch (Exception ex)
  238. {
  239. ExLog(ex, funcName);
  240. return ex.Message;
  241. }
  242. }
  243. /// <summary>
  244. /// 报警数据接口 带条件查询系统异常
  245. /// </summary>
  246. /// <returns></returns>
  247. public AlarmHistoryResult SearchAlarmHistoryApi(SearchAlarmResponse searchAlarm)
  248. {
  249. string funcName = "SearchAlarmHistoryApi";
  250. try
  251. {
  252. string url = "/api/tl/control/alarm/getAlarm";
  253. string body = JsonConvert.SerializeObject(searchAlarm, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
  254. string resultString = httpServiceCall1.callWebService(url, body);
  255. if (string.IsNullOrEmpty(resultString)) return new AlarmHistoryResult() { IsSuccess = false };
  256. var rs = JsonConvert.DeserializeObject<ResultEntity<AlarmHistoryResult>>(resultString);
  257. if (!rs.success)
  258. {
  259. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  260. return new AlarmHistoryResult() { IsSuccess = false };
  261. }
  262. if (rs.data != null) return rs.data;
  263. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  264. return new AlarmHistoryResult();
  265. }
  266. catch (Exception ex)
  267. {
  268. ExLog(ex, funcName);
  269. return new AlarmHistoryResult() { IsSuccess = false };
  270. }
  271. }
  272. /// <summary>
  273. /// 报警数据接口 带条件查询系统异常数量
  274. /// </summary>
  275. /// <returns></returns>
  276. public AlarmHistoryNumResult SearchAlarmHistoryNumApi(SearchAlarmResponse searchAlarm)
  277. {
  278. string funcName = "SearchAlarmHistoryNumApi";
  279. try
  280. {
  281. string url = "/api/tl/control/alarm/getAlarmNum";
  282. string body = JsonConvert.SerializeObject(searchAlarm, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
  283. string resultString = httpServiceCall1.callWebService(url, body);
  284. if (string.IsNullOrEmpty(resultString)) return new AlarmHistoryNumResult();
  285. var rs = JsonConvert.DeserializeObject<ResultEntity<AlarmHistoryNumResult>>(resultString);
  286. if (!rs.success)
  287. {
  288. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  289. return new AlarmHistoryNumResult();
  290. }
  291. if (rs.data != null) return rs.data;
  292. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  293. return new AlarmHistoryNumResult();
  294. }
  295. catch (Exception ex)
  296. {
  297. ExLog(ex, funcName);
  298. return new AlarmHistoryNumResult();
  299. }
  300. }
  301. public string SetAlarmNotifyApi(long id, int notify)
  302. {
  303. string funcName = "SetAlarmNotifyApi";
  304. try
  305. {
  306. string url = "/api/tl/control/alarm/muteAlarm";
  307. string body = JsonConvert.SerializeObject(new { id, notify });
  308. string resultString = httpServiceCall1.callWebService(url, body);
  309. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  310. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  311. if (!rs.success)
  312. {
  313. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  314. return rs.message;
  315. }
  316. return null;
  317. }
  318. catch (Exception ex)
  319. {
  320. ExLog(ex, funcName);
  321. return ex.Message;
  322. }
  323. }
  324. public List<AlarmTypeEntity> GetTypeAndTemplateListNewApi()
  325. {
  326. string funcName = "GetTypeAndTemplateListNewApi";
  327. try
  328. {
  329. string url = "api/tl/control/alarmSettingNew/getTypeAndTemplateList";
  330. string resultString = httpServiceCall1.callWebService(url);
  331. if (string.IsNullOrEmpty(resultString)) return new List<AlarmTypeEntity>();
  332. ResultEntity<List<AlarmTypeEntity>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmTypeEntity>>>(resultString);
  333. if (!rs.success)
  334. {
  335. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  336. return new List<AlarmTypeEntity>();
  337. }
  338. if (rs.data != null && rs.data.Any()) return rs.data;
  339. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  340. return new List<AlarmTypeEntity>();
  341. }
  342. catch (Exception ex)
  343. {
  344. ExLog(ex, funcName);
  345. return new List<AlarmTypeEntity>();
  346. }
  347. }
  348. public List<AlarmPersonne> GetAlarmPersonnelListNewApi()
  349. {
  350. string funcName = "GetAlarmPersonnelListNewApi";
  351. try
  352. {
  353. string url = "/api/tl/control/alarmSettingNew/getAlarmPersonnelList";
  354. string resultString = httpServiceCall1.callWebService(url);
  355. if (string.IsNullOrEmpty(resultString)) return new List<AlarmPersonne>();
  356. ResultEntity<List<AlarmPersonne>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmPersonne>>>(resultString);
  357. if (!rs.success)
  358. {
  359. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  360. return new List<AlarmPersonne>();
  361. }
  362. if (rs.data != null && rs.data.Any()) return rs.data;
  363. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  364. return new List<AlarmPersonne>();
  365. }
  366. catch (Exception ex)
  367. {
  368. ExLog(ex, funcName);
  369. return new List<AlarmPersonne>();
  370. }
  371. }
  372. public string UpdateAlarmTypeApi(AlarmTypeEntity alarmTypeEntity, int intervalTime, int alarmLevel)
  373. {
  374. //return "失败测试";
  375. string funcName = "UpdateAlarmTypeApi";
  376. try
  377. {
  378. string url = "/api/tl/control/alarmSettingNew/UpdateAlarmType";
  379. string body = JsonConvert.SerializeObject(new
  380. {
  381. alarmLevel = alarmLevel,
  382. alarmTitle = alarmTypeEntity.alarmTitle,
  383. id = alarmTypeEntity.id,
  384. intervalTime = intervalTime,
  385. mute = alarmTypeEntity.mute,
  386. });
  387. string resultString = httpServiceCall1.callWebService(url, body);
  388. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  389. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  390. if (!rs.success)
  391. {
  392. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  393. return rs.message;
  394. }
  395. return null;
  396. }
  397. catch (Exception ex)
  398. {
  399. ExLog(ex, funcName);
  400. return ex.Message;
  401. }
  402. }
  403. public string DeleteAlarmPersonneApi(long id)
  404. {
  405. string funcName = "DeleteAlarmPersonneApi";
  406. try
  407. {
  408. string url = "/api/tl/control/alarmSettingNew/deleteAlarmPersonnel";
  409. Dictionary<string, string> body = new Dictionary<string, string> { { "id", id.ToString() } };
  410. string resultString = httpServiceCall1.callWebService(url, body);
  411. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  412. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  413. if (!rs.success)
  414. {
  415. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  416. return rs.message;
  417. }
  418. return null;
  419. }
  420. catch (Exception ex)
  421. {
  422. ExLog(ex, funcName);
  423. return ex.Message;
  424. }
  425. }
  426. public string AddAlarmPersonnelApi(AlarmPersonne alarmPersonne)
  427. {
  428. string funcName = "AddAlarmPersonnelApi";
  429. try
  430. {
  431. string url = "/api/tl/control/alarmSettingNew/addAlarmPersonnel";
  432. string body = JsonConvert.SerializeObject(new { name = alarmPersonne.name, phone = alarmPersonne.phone });
  433. string resultString = httpServiceCall1.callWebService(url, body);
  434. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  435. var rs = JsonConvert.DeserializeObject<ResultEntity<object>>(resultString);
  436. if (!rs.success)
  437. {
  438. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  439. return rs.message;
  440. }
  441. return null;
  442. if (rs.data == null)
  443. {
  444. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  445. return $"服务器返回id为空";
  446. }
  447. if (long.TryParse(rs.data.ToString(), out long newId))
  448. {
  449. alarmPersonne.id = newId;
  450. }
  451. else
  452. {
  453. ErrorLog($"{funcName}接口返回成功,但是没有返回正确Id {resultString}", LogEnum.RunError);
  454. }
  455. return null;
  456. }
  457. catch (Exception ex)
  458. {
  459. ExLog(ex, funcName);
  460. return ex.Message;
  461. }
  462. }
  463. public string UpdateAlarmPersonneApi(AlarmPersonne alarmPersonne)
  464. {
  465. string funcName = "UpdateAlarmPersonneApi";
  466. try
  467. {
  468. string url = "/api/tl/control/alarmSettingNew/updateAlarmPersonnel";
  469. string body = JsonConvert.SerializeObject(new
  470. {
  471. id = alarmPersonne.id,
  472. name = alarmPersonne.name,
  473. phone = alarmPersonne.phone
  474. });
  475. string resultString = httpServiceCall1.callWebService(url, body);
  476. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  477. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  478. if (!rs.success)
  479. {
  480. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  481. return rs.message;
  482. }
  483. return null;
  484. }
  485. catch (Exception ex)
  486. {
  487. ExLog(ex, funcName);
  488. return ex.Message;
  489. }
  490. }
  491. public string SetAlarmPersonnelLevelApi(Dictionary<long, int> keyValuePairs)
  492. {
  493. string funcName = "SetAlarmPersonnelLevelApi";
  494. try
  495. {
  496. string url = "/api/tl/control/alarmSettingNew/configAlarmPersonnelLevel";
  497. var resultArray = keyValuePairs.Select(kvp => new { id = kvp.Key, level = kvp.Value });
  498. string body = JsonConvert.SerializeObject(resultArray);
  499. string resultString = httpServiceCall1.callWebService(url, body);
  500. if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
  501. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  502. if (!rs.success)
  503. {
  504. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  505. return rs.message;
  506. }
  507. return null;
  508. }
  509. catch (Exception ex)
  510. {
  511. ExLog(ex, funcName);
  512. return ex.Message;
  513. }
  514. }
  515. }
  516. }