using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using EntityDataSet; using IntelligentControlForsx.Service.WindturbineControl.Domain; using IntelligentControlForsx.Service.ZM.Domain; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.Service.ZM { public class ZmWindturbineInfoSvc { #region 单例方法 private ZmWindturbineInfoSvc() { } class SingletonCreator { internal static readonly ZmWindturbineInfoSvc instance = new ZmWindturbineInfoSvc(); } public static ZmWindturbineInfoSvc Instance { get { return SingletonCreator.instance; } } #endregion public static IList infoList = new List(); public static void GetInfo(string stationId, string projectId) { IList list = new List(); list = infoList.Where(s => s.StationId == stationId && s.ProjectId == projectId).ToList(); if (list.Count == 0) { if (stationId == "QS_FDC") { list = GetStationProjectItemsInfo(stationId, projectId);// 青山 } else { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList windturbineList = ctx.windturbine.Where(s => s.PROJECTID == projectId && s.WINDPOWERSTATIONID == stationId) .ToList(); IList uniformCodeList = ctx.windturbine_uniform_code.Where(s => s.project_id == projectId && s.station_id == stationId) .ToList(); for (int i = 0; i < windturbineList.Count; i++) { ZmWindturbineInfo info = new ZmWindturbineInfo(); info.WindturbineId = windturbineList[i].ID; info.StationId = windturbineList[i].WINDPOWERSTATIONID; info.ProjectId = windturbineList[i].PROJECTID; windturbine_uniform_code uniformCodeData = uniformCodeList.Where(s => s.windturbine_id == windturbineList[i].ID).FirstOrDefault(); if (uniformCodeData != null) { info.PowerUniformCode = uniformCodeData.power_uniform_code; info.WindSpeedUniformCode = uniformCodeData.wind_speed_uniform_code; info.StatusUniformCode = uniformCodeData.status_uniform_code; } var data = infoList.Where( s => s.ProjectId == projectId && s.WindturbineId == windturbineList[i].ID && s.StationId == windturbineList[i].WINDPOWERSTATIONID).FirstOrDefault(); if (data == null) { list.Add(info); infoList.Add(info); } } } } } for (int i = 0; i < list.Count; i++) { string[] uniformCodeArr = new string[] { list[i].PowerUniformCode , list[i].WindSpeedUniformCode, list[i].StatusUniformCode }; Dictionary dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].WindturbineId, uniformCodeArr); if (dic != null) { foreach (KeyValuePair kv in dic) { #region 风机状态 if (kv.Key == list[i].StatusUniformCode) { int statusValue = Convert.ToInt32(kv.Value.getValue()); switch (statusValue) { case 0: list[i].Status = WindturbineStatus.Stop; break; case 1: list[i].Status = WindturbineStatus.OnPower; break; case 2: list[i].Status = WindturbineStatus.Standby; break; case 3: list[i].Status = WindturbineStatus.Start; break; case 4: list[i].Status = WindturbineStatus.Online; break; case 5: list[i].Status = WindturbineStatus.Fault; break; case 6: list[i].Status = WindturbineStatus.Maintain; break; case 7: list[i].Status = WindturbineStatus.Offline; break; } } #endregion if (kv.Key == list[i].PowerUniformCode) list[i].Power = Convert.ToDouble(kv.Value.getValue()); if (kv.Key == list[i].WindSpeedUniformCode) list[i].WindSpeed = Convert.ToDouble(kv.Value.getValue()); } } } } // FOR 青山 public static IList GetStationProjectItemsInfo(string stationId, string projectId) { IList list= new List(); using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList windturbineList = ctx.windturbine.Where(s => s.PROJECTID == projectId && s.WINDPOWERSTATIONID == stationId) .ToList(); for (int i = 0; i < windturbineList.Count; i++) { ZmWindturbineInfo info = new ZmWindturbineInfo(); info.WindturbineId = windturbineList[i].ID; info.StationId = windturbineList[i].WINDPOWERSTATIONID; info.ProjectId = windturbineList[i].PROJECTID; info.StatusUniformCode = "FJZT8"; info.WindSpeedUniformCode = "AI022"; info.PowerUniformCode = "AI130"; infoList.Add(info); list.Add(info); } } return list; } } }