CacheService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using IntelligentControlForsx.ChildForms;
  8. using IntelligentControlForsx.Template;
  9. using EntityDataSet;
  10. using IntelligentControlForsx.Model;
  11. using System.Collections;
  12. using WisdomClient.data;
  13. using log4net;
  14. namespace IntelligentControlForsx.Service
  15. {
  16. public class CacheService
  17. {
  18. private ILog logger = LogManager.GetLogger("AppInfoLog");
  19. #region 构造方法--单例
  20. private CacheService()
  21. {
  22. }
  23. public static CacheService Instance
  24. {
  25. get { return SingletonCreator.instance; }
  26. }
  27. class SingletonCreator
  28. {
  29. internal static readonly CacheService instance = new CacheService();
  30. }
  31. #endregion
  32. #region 场站数据
  33. private IList<windpowerstation> stationList;
  34. public IList<windpowerstation> StationList
  35. {
  36. get
  37. {
  38. if (stationList == null)
  39. stationList = LoadStationList();
  40. return stationList;
  41. }
  42. }
  43. private IList<windpowerstation> LoadStationList()
  44. {
  45. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  46. {
  47. return ctx.windpowerstation.ToList();
  48. }
  49. }
  50. public IList<windpowerstation> GetFDCList()
  51. {
  52. return StationList.Where(q => q.ID.EndsWith("_FDC")).OrderByDescending(q => q.ID).ToList();
  53. }
  54. private Dictionary<string, StationStatus> stationStatusDictionary;
  55. public Dictionary<string, StationStatus> StationStatusDictionary
  56. {
  57. get
  58. {
  59. if (stationStatusDictionary == null)
  60. stationStatusDictionary = LoadStationStatusDictionary();
  61. return stationStatusDictionary;
  62. }
  63. }
  64. private Dictionary<string, StationStatus> LoadStationStatusDictionary()
  65. {
  66. Dictionary<string, StationStatus> result = new Dictionary<string, StationStatus>();
  67. try
  68. {
  69. var stationList = GetFDCList();
  70. foreach (var station in stationList)
  71. {
  72. StationStatus ss = new StationStatus(station.ID);
  73. if (result.ContainsKey(ss.StationId) == false)
  74. {
  75. result.Add(ss.StationId, ss);
  76. }
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. logger.Error(ex);
  82. }
  83. return result;
  84. }
  85. public string getStationName(string stationId)
  86. {
  87. return StationList.Where(q => q.ID == stationId).FirstOrDefault().NAME;
  88. }
  89. public windpowerstation getStationInfo(string stationId)
  90. {
  91. return StationList.Where(q => q.ID == stationId).FirstOrDefault();
  92. }
  93. #endregion
  94. #region 风机数据
  95. private IList<windturbine> windturbineList;
  96. public IList<windturbine> WindturbineList
  97. {
  98. get
  99. {
  100. if (windturbineList == null)
  101. windturbineList = LoadWindturbineList();
  102. return windturbineList;
  103. }
  104. }
  105. private IList<windturbine> LoadWindturbineList()
  106. {
  107. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  108. {
  109. return ctx.windturbine.Where(q => q.WINDPOWERSTATIONID.EndsWith("FDC")).ToList();
  110. }
  111. }
  112. public IList<windturbine> GetWindturbineListByStationId(string stationId)
  113. {
  114. return WindturbineList.Where(q => q.WINDPOWERSTATIONID == stationId).OrderBy(q => q.LINEID).ToList();
  115. }
  116. #endregion
  117. #region 设备矩阵
  118. private string[] matrixStationPoints = new string[]
  119. {
  120. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  121. "TJTS8",
  122. "SDTS8",
  123. "DJTS8",
  124. "QDTS8",
  125. "BWTS8",
  126. "GZTS8",
  127. "WHTS8",
  128. "LXTS8",
  129. "RFDL",
  130. "YFDL",
  131. "NFDL",
  132. "ZFDL",
  133. "SSFS",
  134. "SSZGL"
  135. };
  136. private string[] matrixWindturbinePoints = new string[]
  137. {
  138. "AI022", //10秒平均风速
  139. "AI130", //功率
  140. //"AI010", //风向角度
  141. "FJZT8", //风机状态
  142. "XDSL" //限电受累(挂牌)
  143. };
  144. private Dictionary<string, PointMapModel> matrixPointMap;
  145. public Dictionary<string, PointMapModel> MatrixPointMap
  146. {
  147. get
  148. {
  149. if (matrixPointMap == null)
  150. LoadMatrixPointMap();
  151. return matrixPointMap;
  152. }
  153. }
  154. private void LoadMatrixPointMap()
  155. {
  156. if (matrixPointMap == null)
  157. matrixPointMap = new Dictionary<string, PointMapModel>();
  158. var lst1 = PointService.GetTestingPoints(PointType.Station, matrixStationPoints);
  159. if (lst1 != null && lst1.Count > 0)
  160. {
  161. foreach (var obj in lst1)
  162. {
  163. if (!matrixPointMap.ContainsKey(obj.PointId))
  164. {
  165. matrixPointMap.Add(obj.PointId, obj);
  166. }
  167. }
  168. }
  169. var lst2 = PointService.GetTestingPoints(PointType.Windturbine, matrixWindturbinePoints);
  170. if (lst2 != null && lst2.Count > 0)
  171. {
  172. foreach (var obj in lst2)
  173. {
  174. if (!matrixPointMap.ContainsKey(obj.PointId))
  175. {
  176. matrixPointMap.Add(obj.PointId, obj);
  177. }
  178. }
  179. }
  180. }
  181. #endregion
  182. #region 设备矩阵---启停推荐
  183. private string[] matrixPowerPoints = new string[]
  184. {
  185. "YGSDZ", //AGC有功设定值
  186. "SSZGL", //实时总功率
  187. "ZLLGL", //理论功率
  188. "FCFGCDQ0001", //15分钟预测功率
  189. "FCFGCDQ0002", //30分钟预测功率
  190. "FCFGCDQ0004", //60分钟预测功率
  191. "FCFGCDQ0016" //4小时预测功率
  192. };
  193. private Dictionary<string, PointMapModel> matrixPopupPointMap;
  194. public Dictionary<string, PointMapModel> MatrixPopupPointMap
  195. {
  196. get
  197. {
  198. if (matrixPopupPointMap == null)
  199. LoadMatrixPopupPointMap();
  200. return matrixPopupPointMap;
  201. }
  202. }
  203. private void LoadMatrixPopupPointMap()
  204. {
  205. if (matrixPopupPointMap == null)
  206. matrixPopupPointMap = new Dictionary<string, PointMapModel>();
  207. var lst1 = PointService.GetTestingPoints(PointType.Station, matrixPowerPoints);
  208. if (lst1 != null && lst1.Count > 0)
  209. {
  210. foreach (var obj in lst1)
  211. {
  212. if (!matrixPopupPointMap.ContainsKey(obj.PointId))
  213. {
  214. matrixPopupPointMap.Add(obj.PointId, obj);
  215. }
  216. }
  217. }
  218. }
  219. //场站功率曲线历史数据缓存
  220. private Dictionary<String, Model.PowerCurveModel> dictPowerCurveModel;
  221. public Dictionary<string, PowerCurveModel> DictPowerCurveModel
  222. {
  223. get
  224. {
  225. if (dictPowerCurveModel == null)
  226. {
  227. dictPowerCurveModel = createPowerCurveModelDictionary();
  228. }
  229. return dictPowerCurveModel;
  230. }
  231. set
  232. {
  233. dictPowerCurveModel = value;
  234. }
  235. }
  236. private Dictionary<string, PowerCurveModel> createPowerCurveModelDictionary()
  237. {
  238. var result = new Dictionary<string, PowerCurveModel>();
  239. var lstFDCStation = GetFDCList();
  240. foreach (var st in lstFDCStation)
  241. {
  242. PowerCurveModel pcm = new PowerCurveModel();
  243. pcm.StationId = st.ID;
  244. pcm.LastUpdateTime = DateTime.Today.AddDays(-1);
  245. pcm.FactPowerData = new List<TsData>();
  246. pcm.PredictPowerData = new List<TsData>();
  247. pcm.TheoryPowerData = new List<TsData>();
  248. pcm.AgcPowerData = new List<TsData>();
  249. pcm.WindSpeedData = new List<TsData>();
  250. pcm.CDQPredictPowerData = new TsData[16];
  251. pcm.FactPowerPoint = PointService.GetStationTestingPointByUniformCode(st.ID, "SSZGL");
  252. pcm.TheoryPowerPoint = PointService.GetStationTestingPointByUniformCode(st.ID, "ZLLGL");
  253. pcm.AgcPowerPoint = PointService.GetStationTestingPointByUniformCode(st.ID, "YGSDZ");
  254. pcm.PredictPowerPoint = PointService.GetStationTestingPointByUniformCode(st.ID, "FCFGCDQ0001");
  255. result.Add(pcm.StationId, pcm);
  256. }
  257. return result;
  258. }
  259. private string[] matrixCDQPredictPoints = new string[]
  260. {
  261. "FCFGCDQ0001",
  262. "FCFGCDQ0002",
  263. "FCFGCDQ0003",
  264. "FCFGCDQ0004",
  265. "FCFGCDQ0005",
  266. "FCFGCDQ0006",
  267. "FCFGCDQ0007",
  268. "FCFGCDQ0008",
  269. "FCFGCDQ0009",
  270. "FCFGCDQ0010",
  271. "FCFGCDQ0011",
  272. "FCFGCDQ0012",
  273. "FCFGCDQ0013",
  274. "FCFGCDQ0014",
  275. "FCFGCDQ0015",
  276. "FCFGCDQ0016"
  277. };
  278. private Dictionary<string, PointMapModel> matrixCDQPredictPointMap;
  279. public Dictionary<string, PointMapModel> MatrixCDQPredictPointMap
  280. {
  281. get
  282. {
  283. if (matrixCDQPredictPointMap == null)
  284. LoadatrixCDQPredictPointMap();
  285. return matrixCDQPredictPointMap;
  286. }
  287. }
  288. private void LoadatrixCDQPredictPointMap()
  289. {
  290. if (matrixCDQPredictPointMap == null)
  291. matrixCDQPredictPointMap = new Dictionary<string, PointMapModel>();
  292. var lst1 = PointService.GetTestingPoints(PointType.Station, matrixCDQPredictPoints);
  293. if (lst1 != null && lst1.Count > 0)
  294. {
  295. foreach (var obj in lst1)
  296. {
  297. if (!matrixCDQPredictPointMap.ContainsKey(obj.PointId))
  298. {
  299. matrixCDQPredictPointMap.Add(obj.PointId, obj);
  300. }
  301. }
  302. }
  303. }
  304. #endregion
  305. #region 总貌图
  306. #endregion
  307. }
  308. }