123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- 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<string, WindturbineStatus> windturbineStatusDictionary;
- public Dictionary<string, WindturbineStatus> WindturbineStatusDictionary
- {
- get
- {
- return windturbineStatusDictionary;
- }
- }
- #endregion
- #region 构造方法
- public StationStatus(string stationId)
- {
- this.stationId = stationId;
- windturbineStatusDictionary = CreateWindturbineStatusDictionary(stationId);
- }
- private Dictionary<string, WindturbineStatus> CreateWindturbineStatusDictionary(string stId)
- {
- Dictionary<string, WindturbineStatus> result = new Dictionary<string, WindturbineStatus>();
- 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<String, TsData> attributes = new Dictionary<string, TsData>();
- /// <summary>
- /// 以索引的方式访问场站属性状态,注意用统一编码做索引
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- 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<string, TsData> 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
- }
- }
|