DataCache.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using GDNXFD.Data.Repositories;
  4. using log4net;
  5. namespace GDNXFD.Data
  6. {
  7. public class DataCache
  8. {
  9. private ILog logger = LogManager.GetLogger("AppLog");
  10. #region 单例模式
  11. private DataCache()
  12. {
  13. }
  14. public static DataCache Instance
  15. {
  16. get { return SingletonCreator.instance; }
  17. }
  18. class SingletonCreator
  19. {
  20. internal static readonly DataCache instance = new DataCache();
  21. }
  22. #endregion
  23. #region 所有风机数据
  24. private IList<WindTurbine> windTurbinies;
  25. public IList<WindTurbine> WindTurbinies
  26. {
  27. get
  28. {
  29. if (windTurbinies == null)
  30. {
  31. windTurbinies = WindTurbineRepository.GetWindTurbinies();
  32. logger.Info("加载风机数据,总数:" + windTurbinies.Count);
  33. }
  34. return windTurbinies;
  35. }
  36. }
  37. public void ReloadWindTurbinies()
  38. {
  39. windTurbinies = null;
  40. }
  41. public IList<WindTurbine> GetWindTurbiniesByModelId(string modelId)
  42. {
  43. return WindTurbinies.Where(q => q.ModelId == modelId).ToList();
  44. }
  45. private Dictionary<string, object> dictWindturbine;
  46. public Dictionary<string, object> DictWindturbine
  47. {
  48. get
  49. {
  50. if (dictWindturbine == null)
  51. {
  52. dictWindturbine = new Dictionary<string, object>();
  53. foreach (WindTurbine wps in this.WindTurbinies)
  54. {
  55. if (dictWindturbine.ContainsKey(wps.Name))
  56. continue;
  57. dictWindturbine.Add(wps.Name, wps);
  58. }
  59. }
  60. return dictWindturbine;
  61. }
  62. }
  63. private Dictionary<string, WindTurbine> dictWindturbine2;
  64. public Dictionary<string, WindTurbine> DictWindturbine2
  65. {
  66. get
  67. {
  68. if (dictWindturbine2 == null)
  69. {
  70. dictWindturbine2 = new Dictionary<string, WindTurbine>();
  71. foreach (WindTurbine wps in this.WindTurbinies)
  72. {
  73. if (dictWindturbine2.ContainsKey(wps.Name))
  74. continue;
  75. dictWindturbine2.Add(wps.Id, wps);
  76. }
  77. }
  78. return dictWindturbine2;
  79. }
  80. }
  81. #endregion
  82. #region 风机测点
  83. //包含所有自定义报警规则中出现的测点统一编码,在生成Interpreter时,填充
  84. public IList<string> RelateUniformCodes { get; set; }
  85. private string[] aiCodes;
  86. public string[] AICodes
  87. {
  88. get
  89. {
  90. if (aiCodes == null && RelateUniformCodes != null && RelateUniformCodes.Count > 0)
  91. {
  92. aiCodes = RelateUniformCodes.Where(s => s.StartsWith("AI")).ToArray();
  93. }
  94. return aiCodes;
  95. }
  96. }
  97. private string[] diCodes;
  98. public string[] DICodes
  99. {
  100. get
  101. {
  102. if (diCodes == null && RelateUniformCodes != null && RelateUniformCodes.Count > 0)
  103. {
  104. diCodes = RelateUniformCodes.Where(s => s.StartsWith("DI")).ToArray();
  105. }
  106. return diCodes;
  107. }
  108. }
  109. private IList<WindTurbineTestingPointAI> windTurbineAIPoints;
  110. public IList<WindTurbineTestingPointAI> WindTurbineAIPoints
  111. {
  112. get
  113. {
  114. if (windTurbineAIPoints == null)
  115. {
  116. windTurbineAIPoints = WindTurbineRepository.GetWindTurbineAIPoints(AICodes);
  117. logger.Info("加载风机AI测点,总数:" + windTurbineAIPoints.Count);
  118. //logger.Info("AICodes = " + AICodes);
  119. }
  120. return windTurbineAIPoints;
  121. }
  122. }
  123. private IList<WindTurbineTestingPointDI> windTurbineDIPoints;
  124. public IList<WindTurbineTestingPointDI> WindTurbineDIPoints
  125. {
  126. get
  127. {
  128. if (windTurbineDIPoints == null)
  129. {
  130. windTurbineDIPoints = WindTurbineRepository.GetWindTurbineDIPoints(DICodes);
  131. logger.Info("加载风机DI测点,总数:" + windTurbineDIPoints.Count);
  132. logger.Info("DICodes = " + DICodes);
  133. }
  134. return windTurbineDIPoints;
  135. }
  136. }
  137. private IList<WindTurbineTestingPointAI> windTurbineAlertPoints;
  138. public IList<WindTurbineTestingPointAI> WindTurbineAlertPoints
  139. {
  140. get
  141. {
  142. if (windTurbineAlertPoints == null)
  143. {
  144. windTurbineAlertPoints = WindTurbineRepository.GetWindTurbineAIPoints("FJBJ3");
  145. logger.Info("加载风机报警测点,总数:" + windTurbineAlertPoints.Count);
  146. logger.Info("统一编码 : FJBJ3 ");
  147. }
  148. return windTurbineAlertPoints;
  149. }
  150. }
  151. #endregion
  152. #region 数据字典
  153. private IList<DictItem> dataDict;
  154. public IList<DictItem> DataDict
  155. {
  156. get
  157. {
  158. if (dataDict == null)
  159. {
  160. dataDict = WindPowerStationRepository.GetDataDictionary();
  161. logger.Info("加载数据字典,总数:" + dataDict.Count);
  162. }
  163. return dataDict;
  164. }
  165. }
  166. public void ReloadDataDict()
  167. {
  168. dataDict = null;
  169. }
  170. public IList<DictItem> GetDataDictByCategory(string category)
  171. {
  172. if (DataDict != null)
  173. {
  174. var tmp = DataDict.Where(c => c.Category == category && c.Enabled);
  175. if (tmp != null)
  176. return tmp.OrderBy(c => c.OrderNo).ToList();
  177. }
  178. return null;
  179. }
  180. #endregion
  181. #region 风电场
  182. private IList<WindPowerStation> windPowerStation;
  183. public IList<WindPowerStation> WindPowerStation
  184. {
  185. get
  186. {
  187. if (windPowerStation == null)
  188. {
  189. windPowerStation = WindPowerStationRepository.GetWindPowerStations();
  190. logger.Info("加载风电场,总数:" + windPowerStation.Count);
  191. }
  192. return windPowerStation;
  193. }
  194. }
  195. public void ReloadWindPowerStation()
  196. {
  197. windPowerStation = null;
  198. }
  199. public WindPowerStation GetWindPowerStationByID(string id)
  200. {
  201. return WindPowerStation.Where(c => c.Id == id).FirstOrDefault();
  202. }
  203. private Dictionary<string, object> dictStation;
  204. public Dictionary<string, object> DictStation
  205. {
  206. get
  207. {
  208. if (dictStation == null)
  209. {
  210. dictStation = new Dictionary<string, object>();
  211. foreach(WindPowerStation wps in this.WindPowerStation)
  212. {
  213. if (dictStation.ContainsKey(wps.Name))
  214. continue;
  215. dictStation.Add(wps.Name, wps);
  216. }
  217. }
  218. return dictStation;
  219. }
  220. }
  221. private Dictionary<string, WindPowerStation> dictStation2;
  222. public Dictionary<string, WindPowerStation> DictStation2
  223. {
  224. get
  225. {
  226. if (dictStation2 == null)
  227. {
  228. dictStation2 = new Dictionary<string, WindPowerStation>();
  229. foreach (WindPowerStation wps in this.WindPowerStation)
  230. {
  231. if (dictStation2.ContainsKey(wps.Name))
  232. continue;
  233. dictStation2.Add(wps.Id, wps);
  234. }
  235. }
  236. return dictStation2;
  237. }
  238. }
  239. #endregion
  240. #region 风机类型
  241. private IList<EquipmentModel> equipmentModel;
  242. public IList<EquipmentModel> EquipmentModel
  243. {
  244. get
  245. {
  246. if (equipmentModel == null)
  247. {
  248. equipmentModel = WindTurbineRepository.GetEquipmentModels();
  249. logger.Info("加载设备类型,总数:" + equipmentModel.Count);
  250. }
  251. return equipmentModel;
  252. }
  253. }
  254. public void ReloadEquipmentModels()
  255. {
  256. equipmentModel = null;
  257. }
  258. public EquipmentModel GetEquipmentModelByID(string id)
  259. {
  260. if (equipmentModel != null)
  261. {
  262. return equipmentModel.Where(c => c.Id == id).FirstOrDefault();
  263. }
  264. return null;
  265. }
  266. private Dictionary<string, object> dictModel;
  267. public Dictionary<string, object> DictModel
  268. {
  269. get
  270. {
  271. if (dictModel == null)
  272. {
  273. dictModel = new Dictionary<string, object>();
  274. foreach (EquipmentModel wps in this.EquipmentModel)
  275. {
  276. if (dictModel.ContainsKey(wps.Id))
  277. continue;
  278. dictModel.Add(wps.Id, wps);
  279. }
  280. }
  281. return dictModel;
  282. }
  283. }
  284. #endregion
  285. #region 线路
  286. private IList<Line> lines;
  287. public IList<Line> Lines
  288. {
  289. get
  290. {
  291. if (lines == null)
  292. {
  293. lines = WindPowerStationRepository.GetLines();
  294. logger.Info("加载线路,总数:" + lines.Count);
  295. }
  296. return lines;
  297. }
  298. }
  299. public void ReloadLines()
  300. {
  301. lines = null;
  302. }
  303. public Line GetLinesByID(string id)
  304. {
  305. return Lines.Where(c => c.Id == id).FirstOrDefault();
  306. }
  307. private Dictionary<string, object> dictLine;
  308. public Dictionary<string, object> DictLine
  309. {
  310. get
  311. {
  312. if (dictLine == null)
  313. {
  314. dictLine = new Dictionary<string, object>();
  315. foreach (Line wps in this.Lines)
  316. {
  317. if (dictLine.ContainsKey(wps.Name))
  318. continue;
  319. dictLine.Add(wps.Name, wps);
  320. }
  321. }
  322. return dictLine;
  323. }
  324. }
  325. private Dictionary<string, Line> dictLine2;
  326. public Dictionary<string, Line> DictLine2
  327. {
  328. get
  329. {
  330. if (dictLine2 == null)
  331. {
  332. dictLine2 = new Dictionary<string, Line>();
  333. foreach (Line wps in this.Lines)
  334. {
  335. if (dictLine2.ContainsKey(wps.Name))
  336. continue;
  337. dictLine2.Add(wps.Id, wps);
  338. }
  339. }
  340. return dictLine2;
  341. }
  342. }
  343. #endregion
  344. #region 工程
  345. private IList<Project> projects;
  346. public IList<Project> Projects
  347. {
  348. get
  349. {
  350. if (projects == null)
  351. {
  352. projects = WindPowerStationRepository.GetProjects();
  353. logger.Info("加载工程,总数:" + projects.Count);
  354. }
  355. return projects;
  356. }
  357. }
  358. public void ReloadProjects()
  359. {
  360. projects = null;
  361. }
  362. public Project GetProjectsByID(string id)
  363. {
  364. return Projects.Where(c => c.Id == id).FirstOrDefault();
  365. }
  366. private Dictionary<string, object> dictProject;
  367. public Dictionary<string, object> DictProject
  368. {
  369. get
  370. {
  371. if (dictProject == null)
  372. {
  373. dictProject = new Dictionary<string, object>();
  374. foreach (Project wps in this.Projects)
  375. {
  376. if (dictProject.ContainsKey(wps.Name))
  377. continue;
  378. dictProject.Add(wps.Name, wps);
  379. }
  380. }
  381. return dictProject;
  382. }
  383. }
  384. private Dictionary<string, Project> dictProject2;
  385. public Dictionary<string, Project> DictProject2
  386. {
  387. get
  388. {
  389. if (dictProject2 == null)
  390. {
  391. dictProject2 = new Dictionary<string, Project>();
  392. foreach (Project wps in this.Projects)
  393. {
  394. if (dictProject2.ContainsKey(wps.Name))
  395. continue;
  396. dictProject2.Add(wps.Id, wps);
  397. }
  398. }
  399. return dictProject2;
  400. }
  401. }
  402. #endregion
  403. #region 测点(风电场、线路、工程)
  404. private IList<LevelTypeTestingPoint> ltPoint;
  405. public IList<LevelTypeTestingPoint> LevelTypeTestingPoints
  406. {
  407. get
  408. {
  409. if (ltPoint == null)
  410. {
  411. ltPoint = WindPowerStationRepository.GetLevelTypeTestingPoints();
  412. logger.Info("加载分级测点数据,总数:" + ltPoint.Count);
  413. }
  414. return ltPoint;
  415. }
  416. }
  417. public void ReloadLevelTypeTestingPoints()
  418. {
  419. ltPoint = null;
  420. }
  421. public IList<LevelTypeTestingPoint> GetTestingPointByLevelType(string levelType)
  422. {
  423. return LevelTypeTestingPoints.Where(q => q.LevelType == levelType).ToList();
  424. }
  425. #endregion
  426. #region 电气测点
  427. private IList<ElectricalTestingPointAI> etPointAIs;
  428. public IList<ElectricalTestingPointAI> ElectricalTestingPointAIs
  429. {
  430. get
  431. {
  432. if (etPointAIs == null)
  433. {
  434. etPointAIs = WindPowerStationRepository.GetElectricalTestingPointAIs();
  435. logger.Info("加载电气AI测点数据,总数:" + etPointAIs.Count);
  436. }
  437. return etPointAIs;
  438. }
  439. }
  440. public void ReloadElectricalTestingPointAIs()
  441. {
  442. etPointAIs = null;
  443. }
  444. public IList<ElectricalTestingPointAI> GetElecTestingPointAIByStationId(string stationId)
  445. {
  446. return ElectricalTestingPointAIs.Where(q => q.WindPowerStationId == stationId).ToList();
  447. }
  448. private IList<ElectricalTestingPointDI> etPointDIs;
  449. public IList<ElectricalTestingPointDI> ElectricalTestingPointDIs
  450. {
  451. get
  452. {
  453. if (etPointDIs == null)
  454. {
  455. etPointDIs = WindPowerStationRepository.GetElectricalTestingPointDIs();
  456. logger.Info("加载电气AI测点数据,总数:" + etPointDIs.Count);
  457. }
  458. return etPointDIs;
  459. }
  460. }
  461. public void ReloadElectricalTestingPointDIs()
  462. {
  463. etPointDIs = null;
  464. }
  465. public IList<ElectricalTestingPointDI> GetElecTestingPointDIByStationId(string stationId)
  466. {
  467. return ElectricalTestingPointDIs.Where(q => q.WindPowerStationId == stationId).ToList();
  468. }
  469. #endregion
  470. #region EDOS报警测点(风机报警、风机首出报警,电气报警(来自IFIX))
  471. private IList<WindTurbineTestingPointAI> wtBJPoints;
  472. public IList<WindTurbineTestingPointAI> WtBJPoints
  473. {
  474. get
  475. {
  476. if (wtBJPoints == null)
  477. {
  478. wtBJPoints = WindTurbineRepository.GetWindTurbineAIPointsFJBJ();
  479. logger.Info("加载风机报警测点数据,总数:" + wtBJPoints.Count);
  480. }
  481. return wtBJPoints;
  482. }
  483. }
  484. private Dictionary<string, WindTurbineTestingPointAI> dictWTP;
  485. public Dictionary<string, WindTurbineTestingPointAI> DictWTP
  486. {
  487. get
  488. {
  489. if (dictWTP == null)
  490. {
  491. dictWTP = new Dictionary<string, WindTurbineTestingPointAI>();
  492. foreach (WindTurbineTestingPointAI wps in this.WtBJPoints)
  493. {
  494. string key = CommonMethod.BuildPointId(wps.Id);
  495. if (key != null)
  496. {
  497. if (dictWTP.ContainsKey(key))
  498. continue;
  499. dictWTP.Add(key, wps);
  500. }
  501. }
  502. }
  503. return dictWTP;
  504. }
  505. }
  506. public void ReloadWtBJPoints()
  507. {
  508. wtBJPoints = null;
  509. }
  510. private IList<IFixBJTestingPointDI> ifixBJPoints;
  511. public IList<IFixBJTestingPointDI> IFixBJPoints
  512. {
  513. get
  514. {
  515. if (ifixBJPoints == null)
  516. {
  517. ifixBJPoints = WindPowerStationRepository.GetIFixBJPoints();
  518. logger.Info("加载IFIX报警测点数据,总数:" + ifixBJPoints.Count);
  519. }
  520. return ifixBJPoints;
  521. }
  522. }
  523. private Dictionary<string, IFixBJTestingPointDI> dictFixTP;
  524. public Dictionary<string, IFixBJTestingPointDI> DictFixTP
  525. {
  526. get
  527. {
  528. if (dictFixTP == null)
  529. {
  530. dictFixTP = new Dictionary<string, IFixBJTestingPointDI>();
  531. foreach (IFixBJTestingPointDI wps in this.ifixBJPoints)
  532. {
  533. if (dictFixTP.ContainsKey(wps.PointKey))
  534. continue;
  535. dictFixTP.Add(wps.PointKey, wps);
  536. }
  537. }
  538. return dictFixTP;
  539. }
  540. }
  541. public void ReloadIFixBJPoints()
  542. {
  543. ifixBJPoints = null;
  544. }
  545. private IList<Warning> warning;
  546. public IList<Warning> Warning
  547. {
  548. get
  549. {
  550. if (warning == null)
  551. {
  552. warning = WindPowerStationRepository.GetWarning();
  553. logger.Info("加载风机报警数据,总数:" + warning.Count);
  554. }
  555. return warning;
  556. }
  557. }
  558. public void ReloadWarning()
  559. {
  560. warning = null;
  561. }
  562. private Dictionary<long, Warning> dictWarning;
  563. public Dictionary<long, Warning> DictWarning
  564. {
  565. get
  566. {
  567. if (dictWarning == null)
  568. {
  569. dictWarning = new Dictionary<long, Warning>();
  570. foreach (Warning wps in this.Warning)
  571. {
  572. if (dictWarning.ContainsKey(wps.EDnaValue))
  573. continue;
  574. dictWarning.Add(wps.EDnaValue, wps);
  575. }
  576. }
  577. return dictWarning;
  578. }
  579. }
  580. #endregion
  581. }
  582. }