using IntelligentControlForsx.Common; using IntelligentControlForsx.Service; using log4net; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.Model { public class StationStatus { private ILog logger = LogManager.GetLogger("AppInfoLog"); #region 基本属性定义 private string stationId; public string StationId { get { return stationId; } } private DateTime lastUpdateTime; public DateTime LastUpdateTime { get { return lastUpdateTime; } } private Dictionary windturbineStatusDictionary; public Dictionary WindturbineStatusDictionary { get { return windturbineStatusDictionary; } } #endregion #region 构造方法 public StationStatus(string stationId) { this.stationId = stationId; windturbineStatusDictionary = CreateWindturbineStatusDictionary(stationId); } private Dictionary CreateWindturbineStatusDictionary(string stId) { Dictionary result = new Dictionary(); try { var wtList = CacheService.Instance.GetWindturbineListByStationId(stId); foreach(var wt in wtList) { var wtId = CommonMethod.GetShortWindturbineId(wt.ID); WindturbineStatus ws = new WindturbineStatus(wtId); if (result.ContainsKey(ws.WindturbineId) == false) { result.Add(ws.WindturbineId, ws); } } }catch (Exception ex) { logger.Error(ex); } return result; } #endregion #region 属性缓存定义 private Dictionary attributes = new Dictionary(); /// /// 以索引的方式访问场站属性状态,注意用统一编码做索引 /// /// /// public TsData this[string key] { get { return attributes[key]; } set { if (attributes.ContainsKey(key)) { attributes[key] = value; } else { attributes.Add(key, value); } } } #endregion #region 重写比较方法 public override bool Equals(object obj) { StationStatus ws = obj as StationStatus; if (ws != null && ws.StationId == this.StationId) return true; return false; } public override int GetHashCode() { return base.GetHashCode(); } #endregion #region 更新场站状态 #endregion #region 更新风机状态 public void RefreshBasicWindturbineStatus() { string[] deviceArray = MatrixFormService.GetDeviceIdArrayByStationId(stationId); if (deviceArray == null || deviceArray.Length < 1) return; var dict = CacheService.Instance.MatrixPointMap; if (dict == null) return; var pmms = dict.Values.Where(q => q.ThingType == PointType.Windturbine && deviceArray.Contains(q.ThingId)).ToArray(); var points = pmms.Select(q => q.PointId).ToArray(); Dictionary dictResult = RestfulClient.findLatestByTagNames(points); foreach (var tmp in dictResult) { for (int i = 0; i < points.Length; i++) { string wtId = pmms[i].ThingId; WindturbineStatus ws = windturbineStatusDictionary[wtId]; if (ws == null) continue; ws[pmms[i].UniformCode] = dictResult[points[i]]; double value = dictResult[points[i]].doubleValue.Value; pmms[i].Value = value; } } } #endregion } }