using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using EntityDataSet; using IntelligentControlForsx.ChildForms; using IntelligentControlForsx.Service.WindturbineControl.Domain; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; using Gyee_Control.Svc.Cache; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.Service.WindturbineControl.FormInfoSvc { public class WindturbinePointDataSvc { private static WindturbinePointDataSvc dataSvc = new WindturbinePointDataSvc(); private WindturbinePointDataSvc() { } public static WindturbinePointDataSvc GetWindturbinePointDataSvc() { return dataSvc; } /// /// 根据风场编号查询风机实时数据 /// /// /// public IList GetWindturbinePointDataListByStationId(string stationId) { return new List(); } /// /// 根据风机编号查询风机实时数据 /// /// /// public IList GetWindturbinePointDataListByWindturbineIds(IList windtrubineIdList) { return new List(); } public static void UpdatePointData(object stationCode) { IList list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList(); if (list.Count <= 0) { CacheInfo.StationChange((string)stationCode); list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList(); } if (list.Count > 0) { IList dataList = new List(); for (int i = 0; i < list.Count; i++) { string[] uniformCodeArr = new string[] { list[i].wind_speed_uniform_code, list[i].power_uniform_code, list[i].status_uniform_code, list[i].alternator_speed_uniform_code, list[i].lamina_speed_uniform_code, list[i].lamina_angle1_uniform_code, list[i].lamina_angle2_uniform_code, list[i].lamina_angle3_uniform_code, list[i].wind_angle_uniform_code, list[i].yaw_position_uniform_code }; WindturbinePointData newData = new WindturbinePointData(); Dictionary dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].windturbine_id, uniformCodeArr); if (dic != null) { foreach (KeyValuePair kv in dic) { if (kv.Key == list[i].wind_speed_uniform_code) newData.WindSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].power_uniform_code) newData.Power = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].alternator_speed_uniform_code) newData.AlternatorSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_speed_uniform_code) newData.LaminaSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle1_uniform_code) newData.LaminaAngle1 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle2_uniform_code) newData.LaminaAngle2 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle3_uniform_code) newData.LaminaAngle3 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].wind_angle_uniform_code) newData.WindAngle = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].yaw_position_uniform_code) newData.YawPosition = Convert.ToDouble(kv.Value.getValue()); //风机状态判定 五种状态 运行1》待机0》维护4》故障2》离线3 if (kv.Key == list[i].status_uniform_code) { int statusValue = Convert.ToInt32(kv.Value.getValue()); switch (statusValue) { case 0: newData.Status = WindturbineStatus.Stop; break; case 1: newData.Status = WindturbineStatus.OnPower; break; case 2: newData.Status = WindturbineStatus.Standby; break; case 3: newData.Status = WindturbineStatus.Start; break; case 4: newData.Status = WindturbineStatus.Online; break; case 5: newData.Status = WindturbineStatus.Fault; break; case 6: newData.Status = WindturbineStatus.Maintain; break; case 7: newData.Status = WindturbineStatus.Offline; break; } } } } //newData.Status = WindturbineStatus.BuildPower;//测试使用 newData.StationId = list[i].station_id; newData.WindturbineName = list[i].windturbine_id; newData.ProjectId = list[i].project_id; windturbine_uniform_code entity = list.Where(s => s.windturbine_id == newData.WindturbineName).FirstOrDefault(); if (entity != null) newData.ModelId = entity.model_id; dataList.Add(newData); } string[] isCheckArr = CacheInfo.CacheWindturbineDataList.Where(s => s.IsCheck).Select(s => s.WindturbineName).ToArray(); for (int i = 0; i < isCheckArr.Length; i++) { var data = dataList.Where(s => s.WindturbineName == isCheckArr[i]).FirstOrDefault(); if (data != null) data.IsCheck = true; } var selectWindturbine = CacheInfo.CacheWindturbineDataList.Where(s => s.IsSelect == true).FirstOrDefault(); if (selectWindturbine != null) { var data = dataList.Where(s => s.WindturbineName == selectWindturbine.WindturbineName).FirstOrDefault(); if (data != null) data.IsSelect = true; } CacheInfo.CacheWindturbineDataList = dataList; ControlForm.isUpdateOverData = true; } } public static void UpdatePointDataByStationAndProject(object stationAndProject) { IList parameterList = (IList)stationAndProject; IList list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == parameterList[0] && s.project_id == parameterList[1]).ToList(); if (list.Count <= 0) { CacheInfo.StationChange((string)parameterList[0]); list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == parameterList[0] && s.project_id == parameterList[1]).ToList(); } if (list.Count > 0) { IList dataList = new List(); for (int i = 0; i < list.Count; i++) { string[] uniformCodeArr = new string[] { list[i].wind_speed_uniform_code, list[i].power_uniform_code, list[i].status_uniform_code, list[i].hung_uniform_code, list[i].alternator_speed_uniform_code, list[i].lamina_speed_uniform_code, list[i].lamina_angle1_uniform_code, list[i].lamina_angle2_uniform_code, list[i].lamina_angle3_uniform_code, list[i].wind_angle_uniform_code, list[i].yaw_position_uniform_code }; WindturbinePointData newData = new WindturbinePointData(); Dictionary dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].windturbine_id, uniformCodeArr); if (dic != null) { foreach (KeyValuePair kv in dic) { if (kv.Key == list[i].wind_speed_uniform_code) newData.WindSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].power_uniform_code) newData.Power = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].alternator_speed_uniform_code) newData.AlternatorSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_speed_uniform_code) newData.LaminaSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle1_uniform_code) newData.LaminaAngle1 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle2_uniform_code) newData.LaminaAngle2 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle3_uniform_code) newData.LaminaAngle3 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].wind_angle_uniform_code) newData.WindAngle = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].yaw_position_uniform_code) newData.YawPosition = Convert.ToDouble(kv.Value.getValue()); //风机状态判定 if (kv.Key == list[i].status_uniform_code) { int statusValue = Convert.ToInt32(kv.Value.getValue()); switch (statusValue) { case 0: newData.Status = WindturbineStatus.Stop; break; case 1: newData.Status = WindturbineStatus.OnPower; break; case 2: newData.Status = WindturbineStatus.Standby; break; case 3: newData.Status = WindturbineStatus.Start; break; case 4: newData.Status = WindturbineStatus.Online; break; case 5: newData.Status = WindturbineStatus.Fault; break; case 6: newData.Status = WindturbineStatus.Maintain; break; case 7: newData.Status = WindturbineStatus.Offline; break; } } //风机挂牌判断 if (kv.Key == list[i].hung_uniform_code) { int hungValue = Convert.ToInt32(kv.Value.getValue()); newData.HungType = (HungType)hungValue; } } } newData.StationId = list[i].station_id; newData.WindturbineName = list[i].windturbine_id; newData.ProjectId = list[i].project_id; newData.ModelId = list[i].model_id; dataList.Add(newData); if (CacheInfo.CacheWindturbineDataDic.ContainsKey(newData.WindturbineName)) { WindturbinePointData data = CacheInfo.CacheWindturbineDataDic[newData.WindturbineName]; data.WindSpeed = newData.WindSpeed; data.Power = newData.Power; data.Status = newData.Status; data.HungType = newData.HungType; data.AlternatorSpeed = newData.AlternatorSpeed; data.LimitSpeed = newData.LimitSpeed; data.LaminaSpeed = newData.LaminaSpeed; data.LaminaAngle1 = newData.LaminaAngle1; data.LaminaAngle2 = newData.LaminaAngle2; data.LaminaAngle3 = newData.LaminaAngle3; data.WindAngle = newData.WindAngle; data.YawPosition = newData.YawPosition; } else { CacheInfo.CacheWindturbineDataDic.Add(newData.WindturbineName, newData); } } } } public static void UpdatePointData_Test(object stationCode) { while (true) { IList list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList(); if (list.Count <= 0) { CacheInfo.StationChange((string)stationCode); list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList(); } if (list.Count > 0) { IList dataList = new List(); for (int i = 0; i < list.Count; i++) { string[] uniformCodeArr = new string[] { list[i].wind_speed_uniform_code, list[i].power_uniform_code, list[i].status_uniform_code, list[i].alternator_speed_uniform_code, list[i].lamina_speed_uniform_code, list[i].lamina_angle1_uniform_code, list[i].lamina_angle2_uniform_code, list[i].lamina_angle3_uniform_code, list[i].wind_angle_uniform_code, list[i].yaw_position_uniform_code }; WindturbinePointData newData = new WindturbinePointData(); Dictionary dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].windturbine_id, uniformCodeArr); if (dic != null) { foreach (KeyValuePair kv in dic) { if (kv.Key == list[i].wind_speed_uniform_code) newData.WindSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].power_uniform_code) newData.Power = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].alternator_speed_uniform_code) newData.AlternatorSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_speed_uniform_code) newData.LaminaSpeed = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle1_uniform_code) newData.LaminaAngle1 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle2_uniform_code) newData.LaminaAngle2 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].lamina_angle3_uniform_code) newData.LaminaAngle3 = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].wind_angle_uniform_code) newData.WindAngle = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].yaw_position_uniform_code) newData.YawPosition = Convert.ToDouble(kv.Value.getValue()); //风机状态判定 五种状态 运行1》待机0》维护4》故障2》离线3 if (kv.Key == list[i].status_uniform_code) { int statusValue = Convert.ToInt32(kv.Value.getValue()); switch (statusValue) { case 0: newData.Status = WindturbineStatus.Stop; break; case 1: newData.Status = WindturbineStatus.OnPower; break; case 2: newData.Status = WindturbineStatus.Standby; break; case 3: newData.Status = WindturbineStatus.Start; break; case 4: newData.Status = WindturbineStatus.Online; break; case 5: newData.Status = WindturbineStatus.Fault; break; case 6: newData.Status = WindturbineStatus.Maintain; break; case 7: newData.Status = WindturbineStatus.Offline; break; } } } } //newData.Status = WindturbineStatus.BuildPower;//测试使用 newData.StationId = list[i].station_id; newData.WindturbineName = list[i].windturbine_id; dataList.Add(newData); } string[] isCheckArr = CacheInfo.CacheWindturbineDataList.Where(s => s.IsCheck).Select(s => s.WindturbineName).ToArray(); for (int i = 0; i < isCheckArr.Length; i++) { var data = dataList.Where(s => s.WindturbineName == isCheckArr[i]).FirstOrDefault(); if (data != null) data.IsCheck = true; } var selectWindturbine = CacheInfo.CacheWindturbineDataList.Where(s => s.IsSelect == true).FirstOrDefault(); if (selectWindturbine != null) { var data = dataList.Where(s => s.WindturbineName == selectWindturbine.WindturbineName).FirstOrDefault(); if (data != null) data.IsSelect = true; } CacheInfo.CacheWindturbineDataList = dataList; } } } } }