using RestSharp; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using WisdomClient.data; namespace WisdomClient { public class ShardingClient { private static string serverUrl; public static string ServerUrl { get { if (string.IsNullOrWhiteSpace(serverUrl)) serverUrl = ConfigurationManager.AppSettings["ShardingServerUrl"]; return serverUrl; } set { serverUrl = value; } } public static AlarmPage pageQueryAlarmHistory( int pageNum, int pageSize, String stId, string wtId, string category1, string category2, string rank, string modelId, int? isOpened, string keyWord, DateTime startTime, DateTime endTime) { try { var client = new RestClient(ServerUrl); var request = new RestRequest("history/page", Method.GET); request.AddParameter("pagenum", pageNum); request.AddParameter("pagesize", pageSize); if (String.IsNullOrWhiteSpace(stId) == false) request.AddParameter("stationid", stId); if (String.IsNullOrWhiteSpace(wtId) == false) request.AddParameter("windturbineid", wtId); if (String.IsNullOrWhiteSpace(category1) == false) request.AddParameter("category1", category1); if (String.IsNullOrWhiteSpace(category2) == false) request.AddParameter("category2", category2); if (String.IsNullOrWhiteSpace(rank) == false) request.AddParameter("rank", rank); if (String.IsNullOrWhiteSpace(modelId) == false) request.AddParameter("modelid", modelId); if (String.IsNullOrWhiteSpace(keyWord) == false) request.AddParameter("keyword", keyWord); request.AddParameter("starttime", startTime.ToString("yyyy-MM-dd HH:mm:ss")); request.AddParameter("endtime", endTime.ToString("yyyy-MM-dd HH:mm:ss")); IRestResponse response = client.Execute(request); var obj = response.Data; if (obj != null) { AlarmPage result = new AlarmPage(); result.current = obj.current; result.pages = obj.pages; result.searchCount = obj.searchCount; result.size = obj.size; result.total = obj.total; result.records = new List(); if (obj.records != null && obj.records.Count > 0) { foreach (IDictionary item in obj.records) { AlarmInfo info = new AlarmInfo(); info.id = Convert.ToInt64(item["id"]); info.alertTime = Convert.ToDateTime(item["alertTime"]); info.messageType = Convert.ToInt32(item["messageType"]); info.snapId = Convert.ToInt64(item["snapId"]); if (item.ContainsKey("stationId")) info.stationId = Convert.ToString(item["stationId"]); if (item.ContainsKey("projectId")) info.projectId = Convert.ToString(item["projectId"]); if (item.ContainsKey("lineId")) info.lineId = Convert.ToString(item["lineId"]); if (item.ContainsKey("windturbineId")) info.windturbineId = Convert.ToString(item["windturbineId"]); if (item.ContainsKey("alertValue")) info.alertValue = Convert.ToInt32(item["alertValue"]); if (item.ContainsKey("category1")) info.category1 = Convert.ToString(item["category1"]); if (item.ContainsKey("category2")) info.category2 = Convert.ToString(item["category2"]); if (item.ContainsKey("rank")) info.rank = Convert.ToString(item["rank"]); if (item.ContainsKey("stationName")) info.stationName = Convert.ToString(item["stationName"]); if (item.ContainsKey("windturbineName")) info.windturbineName = Convert.ToString(item["windturbineName"]); if (item.ContainsKey("alertText")) info.alertText = Convert.ToString(item["alertText"]); if (item.ContainsKey("modelId")) info.modelId = Convert.ToString(item["modelId"]); result.records.Add(info); //"id":597063729539973100, //"alertTime":"2019-07-06 13:58:06", //"messageType":1, //"snapId":597063729539973100, //"stationId":"MHS_FDC", //"projectId":"MHS02_GC", //"lineId":"MHS04_XL", //"windturbineId":"MG01_39", //"alertValue":1846, //"category1":"windturbine", //"category2":"bj", //"rank":"3", //"stationName":"麻黄山风电场", //"windturbineName":"麻黄山39号风机", //"alertText":"变桨轴箱3心跳", //"modelId":"UP105_2000_S" } } return result; } } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } return null;// response.Data; } } }