StatInfoSvc.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 WisdomClient;
  8. using WisdomClient.data;
  9. namespace IntelligentControlForsx.Service.Control.FormInfo
  10. {
  11. public class StatInfoSvc
  12. {
  13. private StatInfoSvc()
  14. {
  15. }
  16. public static StatInfoSvc Instance
  17. {
  18. get { return SingletonCreator.instance; }
  19. }
  20. class SingletonCreator
  21. {
  22. internal static readonly StatInfoSvc instance = new StatInfoSvc();
  23. }
  24. IList<string> uniformCodeList = new List<string>()
  25. {
  26. "SFDL",//总发电量
  27. "NFDL",//年发电量
  28. "YFDLB",//月发电量
  29. "RFDLB",//日发电量
  30. "SSZGL",//实时总功率
  31. "SSFS",//实时风速
  32. "BWTS8",//并网数量
  33. "DJTS8",//待机数量
  34. "GZTS8",//故障数量
  35. "WHTS8",//维护数量
  36. "QDTS8",//启动台数
  37. "LXTS8",//离线数量
  38. "SDTS8",//上电台数
  39. "TJTS8"//停机数量
  40. };
  41. /// <summary>
  42. /// 根据场站编号查询相关统计信息
  43. /// </summary>
  44. /// <param name="station">场站编码,0为全场,-1为风电,-2为光伏</param>
  45. /// <returns></returns>
  46. public StatInfo GetStatInfoByStation(string station)
  47. {
  48. StatInfo info = new StatInfo();
  49. try
  50. {
  51. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  52. {
  53. IList<view_tspoint> list = ctx.view_tspoint.Where(s => uniformCodeList.Contains(s.uniform_code) && s.thing_id == station).ToList();
  54. Dictionary<string, TsData> resultGridDic = RestfulClient.findLatestByTagNames(list.Select(s => s.id).ToArray());
  55. foreach (var tsData in resultGridDic)
  56. {
  57. view_tspoint data = list.Where(s => s.id == tsData.Key).FirstOrDefault();
  58. if (data != null)
  59. {
  60. switch (data.uniform_code)
  61. {
  62. case "SFDL":
  63. info.PowerAll = Double.Parse(tsData.Value.getValue());
  64. break;
  65. case "NFDL":
  66. info.PowerByYear = Double.Parse(tsData.Value.getValue());
  67. break;
  68. case "YFDLB":
  69. info.PowerByMonth = Double.Parse(tsData.Value.getValue());
  70. break;
  71. case "RFDLB":
  72. info.PowerByDay = Double.Parse(tsData.Value.getValue());
  73. break;
  74. case "SSZGL":
  75. info.Power = Double.Parse(tsData.Value.getValue());
  76. break;
  77. case "SSFS":
  78. info.Speed = Double.Parse(tsData.Value.getValue());
  79. break;
  80. case "BWTS8":
  81. info.OnlineCount = Convert.ToInt32(tsData.Value.getValue());
  82. break;
  83. case "DJTS8":
  84. info.StandByCount = Convert.ToInt32(tsData.Value.getValue());
  85. break;
  86. case "GZTS8":
  87. info.FaultCount = Convert.ToInt32(tsData.Value.getValue());
  88. break;
  89. case "WHTS8":
  90. info.MaintainCount = Convert.ToInt32(tsData.Value.getValue());
  91. break;
  92. case "LXTS8":
  93. info.OfflineCount = Convert.ToInt32(tsData.Value.getValue());
  94. break;
  95. case "TJTS8":
  96. info.StopCount = Convert.ToInt32(tsData.Value.getValue());
  97. break;
  98. case "SDTS8":
  99. info.OnPowerCount = Convert.ToInt32(tsData.Value.getValue());
  100. break;
  101. case "QDTS8":
  102. info.StartCount = Convert.ToInt32(tsData.Value.getValue());
  103. break;
  104. default: break;
  105. }
  106. }
  107. }
  108. IList<windturbine> windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == station).ToList();
  109. windpowerstation stationData = ctx.windpowerstation.Where(s => s.ID == station).FirstOrDefault();
  110. info.StationId = station;
  111. if (stationData != null)
  112. info.StationName = stationData.NAME;
  113. info.LinkCount = windturbineList.Count;
  114. return info;
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. throw ex;
  120. }
  121. }
  122. public StatInfo GeStatInfo()
  123. {
  124. StatInfo info = new StatInfo();
  125. IList<string> allStationUniformCodeList = new List<string>();
  126. allStationUniformCodeList.Add("SFDL");//总发电量
  127. allStationUniformCodeList.Add("NFDLB");//年发电量
  128. allStationUniformCodeList.Add("YFDLB");//月发电量
  129. allStationUniformCodeList.Add("RFDLB");//日发电量
  130. allStationUniformCodeList.Add("SSZGL");//全省运行台数
  131. allStationUniformCodeList.Add("YXTS");//全省运行台数
  132. allStationUniformCodeList.Add("YXTS");//全省运行台数
  133. allStationUniformCodeList.Add("GZTJ"); //全省故障台数
  134. allStationUniformCodeList.Add("DJTS"); //全省待机台数
  135. allStationUniformCodeList.Add("TXZD"); //全省离线台数
  136. allStationUniformCodeList.Add("TJNUM"); //全省停机台数
  137. allStationUniformCodeList.Add("WHTJ"); //全省维护台数
  138. allStationUniformCodeList.Add("SSFS"); //风速
  139. try
  140. {
  141. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  142. {
  143. IList<view_tspoint> list = ctx.view_tspoint.Where(s => allStationUniformCodeList.Contains(s.uniform_code) && s.thing_id == "-1" && s.thing_type == "station").ToList();
  144. Dictionary<string, TsData> resultGridDic = RestfulClient.findLatestByTagNames(list.Select(s => s.id).ToArray());
  145. foreach (var tsData in resultGridDic)
  146. {
  147. view_tspoint data = list.Where(s => s.id == tsData.Key).FirstOrDefault();
  148. if (data != null)
  149. {
  150. switch (data.uniform_code)
  151. {
  152. case "SFDL":
  153. info.PowerAll = Double.Parse(tsData.Value.getValue());
  154. break;
  155. case "NFDLB":
  156. info.PowerByYear = Double.Parse(tsData.Value.getValue());
  157. break;
  158. case "YFDLB":
  159. info.PowerByMonth = Double.Parse(tsData.Value.getValue());
  160. break;
  161. case "RFDLB":
  162. info.PowerByDay = Double.Parse(tsData.Value.getValue());
  163. break;
  164. case "SSZGL":
  165. info.Power = Double.Parse(tsData.Value.getValue());
  166. break;
  167. case "SSFS":
  168. info.Speed = Double.Parse(tsData.Value.getValue());
  169. break;
  170. case "YXTS":
  171. info.OnlineCount = Convert.ToInt32(tsData.Value.getValue());
  172. break;
  173. case "DJTS":
  174. info.StandByCount = Convert.ToInt32(tsData.Value.getValue());
  175. break;
  176. case "GZTJ":
  177. info.FaultCount = Convert.ToInt32(tsData.Value.getValue());
  178. break;
  179. case "WHTJ":
  180. info.MaintainCount = Convert.ToInt32(tsData.Value.getValue());
  181. break;
  182. case "TXZD":
  183. info.OfflineCount = Convert.ToInt32(tsData.Value.getValue());
  184. break;
  185. case "TJNUM":
  186. info.StopCount = Convert.ToInt32(tsData.Value.getValue());
  187. break;
  188. default: break;
  189. }
  190. }
  191. }
  192. /* IList<windturbine> windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == station).ToList();
  193. windpowerstation stationData = ctx.windpowerstation.Where(s => s.ID == station).FirstOrDefault();
  194. info.StationId = "";
  195. if (stationData != null)
  196. info.StationName = stationData.NAME;
  197. info.LinkCount = windturbineList.Count;*/
  198. info.StartCount = 0;
  199. info.OnPowerCount = 0;
  200. return info;
  201. }
  202. }
  203. catch (Exception ex)
  204. {
  205. throw ex;
  206. }
  207. }
  208. }
  209. }