ShardingClient.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using RestSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Linq;
  6. using System.Text;
  7. using WisdomClient.data;
  8. namespace WisdomClient
  9. {
  10. public class ShardingClient
  11. {
  12. private static string serverUrl;
  13. public static string ServerUrl
  14. {
  15. get
  16. {
  17. if (string.IsNullOrWhiteSpace(serverUrl))
  18. serverUrl = ConfigurationManager.AppSettings["ShardingServerUrl"];
  19. return serverUrl;
  20. }
  21. set { serverUrl = value; }
  22. }
  23. public static AlarmPage pageQueryAlarmHistory(
  24. int pageNum,
  25. int pageSize,
  26. String stId,
  27. string wtId,
  28. string category1,
  29. string category2,
  30. string rank,
  31. string modelId,
  32. int? isOpened,
  33. string keyWord,
  34. DateTime startTime,
  35. DateTime endTime)
  36. {
  37. try
  38. {
  39. var client = new RestClient(ServerUrl);
  40. var request = new RestRequest("history/page", Method.GET);
  41. request.AddParameter("pagenum", pageNum);
  42. request.AddParameter("pagesize", pageSize);
  43. if (String.IsNullOrWhiteSpace(stId) == false)
  44. request.AddParameter("stationid", stId);
  45. if (String.IsNullOrWhiteSpace(wtId) == false)
  46. request.AddParameter("windturbineid", wtId);
  47. if (String.IsNullOrWhiteSpace(category1) == false)
  48. request.AddParameter("category1", category1);
  49. if (String.IsNullOrWhiteSpace(category2) == false)
  50. request.AddParameter("category2", category2);
  51. if (String.IsNullOrWhiteSpace(rank) == false)
  52. request.AddParameter("rank", rank);
  53. if (String.IsNullOrWhiteSpace(modelId) == false)
  54. request.AddParameter("modelid", modelId);
  55. if (String.IsNullOrWhiteSpace(keyWord) == false)
  56. request.AddParameter("keyword", keyWord);
  57. request.AddParameter("starttime", startTime.ToString("yyyy-MM-dd HH:mm:ss"));
  58. request.AddParameter("endtime", endTime.ToString("yyyy-MM-dd HH:mm:ss"));
  59. IRestResponse<PageObject> response = client.Execute<PageObject>(request);
  60. var obj = response.Data;
  61. if (obj != null)
  62. {
  63. AlarmPage result = new AlarmPage();
  64. result.current = obj.current;
  65. result.pages = obj.pages;
  66. result.searchCount = obj.searchCount;
  67. result.size = obj.size;
  68. result.total = obj.total;
  69. result.records = new List<AlarmInfo>();
  70. if (obj.records != null && obj.records.Count > 0)
  71. {
  72. foreach (IDictionary<string, object> item in obj.records)
  73. {
  74. AlarmInfo info = new AlarmInfo();
  75. info.id = Convert.ToInt64(item["id"]);
  76. info.alertTime = Convert.ToDateTime(item["alertTime"]);
  77. info.messageType = Convert.ToInt32(item["messageType"]);
  78. info.snapId = Convert.ToInt64(item["snapId"]);
  79. if (item.ContainsKey("stationId"))
  80. info.stationId = Convert.ToString(item["stationId"]);
  81. if (item.ContainsKey("projectId"))
  82. info.projectId = Convert.ToString(item["projectId"]);
  83. if (item.ContainsKey("lineId"))
  84. info.lineId = Convert.ToString(item["lineId"]);
  85. if (item.ContainsKey("windturbineId"))
  86. info.windturbineId = Convert.ToString(item["windturbineId"]);
  87. if (item.ContainsKey("alertValue"))
  88. info.alertValue = Convert.ToInt32(item["alertValue"]);
  89. if (item.ContainsKey("category1"))
  90. info.category1 = Convert.ToString(item["category1"]);
  91. if (item.ContainsKey("category2"))
  92. info.category2 = Convert.ToString(item["category2"]);
  93. if (item.ContainsKey("rank"))
  94. info.rank = Convert.ToString(item["rank"]);
  95. if (item.ContainsKey("stationName"))
  96. info.stationName = Convert.ToString(item["stationName"]);
  97. if (item.ContainsKey("windturbineName"))
  98. info.windturbineName = Convert.ToString(item["windturbineName"]);
  99. if (item.ContainsKey("alertText"))
  100. info.alertText = Convert.ToString(item["alertText"]);
  101. if (item.ContainsKey("modelId"))
  102. info.modelId = Convert.ToString(item["modelId"]);
  103. result.records.Add(info);
  104. //"id":597063729539973100,
  105. //"alertTime":"2019-07-06 13:58:06",
  106. //"messageType":1,
  107. //"snapId":597063729539973100,
  108. //"stationId":"MHS_FDC",
  109. //"projectId":"MHS02_GC",
  110. //"lineId":"MHS04_XL",
  111. //"windturbineId":"MG01_39",
  112. //"alertValue":1846,
  113. //"category1":"windturbine",
  114. //"category2":"bj",
  115. //"rank":"3",
  116. //"stationName":"麻黄山风电场",
  117. //"windturbineName":"麻黄山39号风机",
  118. //"alertText":"变桨轴箱3心跳",
  119. //"modelId":"UP105_2000_S"
  120. }
  121. }
  122. return result;
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. Console.Out.WriteLine(ex.Message);
  128. }
  129. return null;// response.Data;
  130. }
  131. }
  132. }