ZmWindturbineInfoSvc.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using EntityDataSet;
  7. using IntelligentControlForsx.Service.WindturbineControl.Domain;
  8. using IntelligentControlForsx.Service.ZM.Domain;
  9. using WisdomClient;
  10. using WisdomClient.data;
  11. namespace IntelligentControlForsx.Service.ZM
  12. {
  13. public class ZmWindturbineInfoSvc
  14. {
  15. #region 单例方法
  16. private ZmWindturbineInfoSvc()
  17. {
  18. }
  19. class SingletonCreator
  20. {
  21. internal static readonly ZmWindturbineInfoSvc instance = new ZmWindturbineInfoSvc();
  22. }
  23. public static ZmWindturbineInfoSvc Instance
  24. {
  25. get { return SingletonCreator.instance; }
  26. }
  27. #endregion
  28. public static IList<ZmWindturbineInfo> infoList = new List<ZmWindturbineInfo>();
  29. public static void GetInfo(string stationId, string projectId)
  30. {
  31. IList<ZmWindturbineInfo> list = new List<ZmWindturbineInfo>();
  32. list = infoList.Where(s => s.StationId == stationId && s.ProjectId == projectId).ToList();
  33. if (list.Count == 0)
  34. {
  35. if (stationId == "QS_FDC")
  36. {
  37. list = GetStationProjectItemsInfo(stationId, projectId);// 青山
  38. }
  39. else
  40. {
  41. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  42. {
  43. IList<windturbine> windturbineList =
  44. ctx.windturbine.Where(s => s.PROJECTID == projectId && s.WINDPOWERSTATIONID == stationId)
  45. .ToList();
  46. IList<windturbine_uniform_code> uniformCodeList =
  47. ctx.windturbine_uniform_code.Where(s => s.project_id == projectId && s.station_id == stationId)
  48. .ToList();
  49. for (int i = 0; i < windturbineList.Count; i++)
  50. {
  51. ZmWindturbineInfo info = new ZmWindturbineInfo();
  52. info.WindturbineId = windturbineList[i].ID;
  53. info.StationId = windturbineList[i].WINDPOWERSTATIONID;
  54. info.ProjectId = windturbineList[i].PROJECTID;
  55. windturbine_uniform_code uniformCodeData =
  56. uniformCodeList.Where(s => s.windturbine_id == windturbineList[i].ID).FirstOrDefault();
  57. if (uniformCodeData != null)
  58. {
  59. info.PowerUniformCode = uniformCodeData.power_uniform_code;
  60. info.WindSpeedUniformCode = uniformCodeData.wind_speed_uniform_code;
  61. info.StatusUniformCode = uniformCodeData.status_uniform_code;
  62. }
  63. var data =
  64. infoList.Where(
  65. s =>
  66. s.ProjectId == projectId && s.WindturbineId == windturbineList[i].ID &&
  67. s.StationId == windturbineList[i].WINDPOWERSTATIONID).FirstOrDefault();
  68. if (data == null)
  69. {
  70. list.Add(info);
  71. infoList.Add(info);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. for (int i = 0; i < list.Count; i++)
  78. {
  79. string[] uniformCodeArr = new string[]
  80. {
  81. list[i].PowerUniformCode ,
  82. list[i].WindSpeedUniformCode,
  83. list[i].StatusUniformCode
  84. };
  85. Dictionary<string, TsData> dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].WindturbineId, uniformCodeArr);
  86. if (dic != null)
  87. {
  88. foreach (KeyValuePair<string, TsData> kv in dic)
  89. {
  90. #region 风机状态
  91. if (kv.Key == list[i].StatusUniformCode)
  92. {
  93. int statusValue = Convert.ToInt32(kv.Value.getValue());
  94. switch (statusValue)
  95. {
  96. case 0:
  97. list[i].Status = WindturbineStatus.Stop;
  98. break;
  99. case 1:
  100. list[i].Status = WindturbineStatus.OnPower;
  101. break;
  102. case 2:
  103. list[i].Status = WindturbineStatus.Standby;
  104. break;
  105. case 3:
  106. list[i].Status = WindturbineStatus.Start;
  107. break;
  108. case 4:
  109. list[i].Status = WindturbineStatus.Online;
  110. break;
  111. case 5:
  112. list[i].Status = WindturbineStatus.Fault;
  113. break;
  114. case 6:
  115. list[i].Status = WindturbineStatus.Maintain;
  116. break;
  117. case 7:
  118. list[i].Status = WindturbineStatus.Offline;
  119. break;
  120. }
  121. }
  122. #endregion
  123. if (kv.Key == list[i].PowerUniformCode)
  124. list[i].Power = Convert.ToDouble(kv.Value.getValue());
  125. if (kv.Key == list[i].WindSpeedUniformCode)
  126. list[i].WindSpeed = Convert.ToDouble(kv.Value.getValue());
  127. }
  128. }
  129. }
  130. }
  131. // FOR 青山
  132. public static IList<ZmWindturbineInfo> GetStationProjectItemsInfo(string stationId, string projectId)
  133. {
  134. IList<ZmWindturbineInfo> list= new List<ZmWindturbineInfo>();
  135. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  136. {
  137. IList<windturbine> windturbineList =
  138. ctx.windturbine.Where(s => s.PROJECTID == projectId && s.WINDPOWERSTATIONID == stationId)
  139. .ToList();
  140. for (int i = 0; i < windturbineList.Count; i++)
  141. {
  142. ZmWindturbineInfo info = new ZmWindturbineInfo();
  143. info.WindturbineId = windturbineList[i].ID;
  144. info.StationId = windturbineList[i].WINDPOWERSTATIONID;
  145. info.ProjectId = windturbineList[i].PROJECTID;
  146. info.StatusUniformCode = "FJZT8";
  147. info.WindSpeedUniformCode = "AI022";
  148. info.PowerUniformCode = "AI130";
  149. infoList.Add(info);
  150. list.Add(info);
  151. }
  152. }
  153. return list;
  154. }
  155. }
  156. }