WindturbinePointDataSvc.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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.ChildForms;
  8. using IntelligentControlForsx.Service.WindturbineControl.Domain;
  9. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  10. using Gyee_Control.Svc.Cache;
  11. using WisdomClient;
  12. using WisdomClient.data;
  13. namespace IntelligentControlForsx.Service.WindturbineControl.FormInfoSvc
  14. {
  15. public class WindturbinePointDataSvc
  16. {
  17. private static WindturbinePointDataSvc dataSvc = new WindturbinePointDataSvc();
  18. private WindturbinePointDataSvc()
  19. {
  20. }
  21. public static WindturbinePointDataSvc GetWindturbinePointDataSvc()
  22. {
  23. return dataSvc;
  24. }
  25. /// <summary>
  26. /// 根据风场编号查询风机实时数据
  27. /// </summary>
  28. /// <param name="stationId"></param>
  29. /// <returns></returns>
  30. public IList<WindturbinePointData> GetWindturbinePointDataListByStationId(string stationId)
  31. {
  32. return new List<WindturbinePointData>();
  33. }
  34. /// <summary>
  35. /// 根据风机编号查询风机实时数据
  36. /// </summary>
  37. /// <param name="windtrubineIdList"></param>
  38. /// <returns></returns>
  39. public IList<WindturbinePointData> GetWindturbinePointDataListByWindturbineIds(IList<string> windtrubineIdList)
  40. {
  41. return new List<WindturbinePointData>();
  42. }
  43. public static void UpdatePointData(object stationCode)
  44. {
  45. IList<windturbine_uniform_code> list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList();
  46. if (list.Count <= 0)
  47. {
  48. CacheInfo.StationChange((string)stationCode);
  49. list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList();
  50. }
  51. if (list.Count > 0)
  52. {
  53. IList<WindturbinePointData> dataList = new List<WindturbinePointData>();
  54. for (int i = 0; i < list.Count; i++)
  55. {
  56. string[] uniformCodeArr = new string[]
  57. {
  58. list[i].wind_speed_uniform_code,
  59. list[i].power_uniform_code,
  60. list[i].status_uniform_code,
  61. list[i].alternator_speed_uniform_code,
  62. list[i].lamina_speed_uniform_code,
  63. list[i].lamina_angle1_uniform_code,
  64. list[i].lamina_angle2_uniform_code,
  65. list[i].lamina_angle3_uniform_code,
  66. list[i].wind_angle_uniform_code,
  67. list[i].yaw_position_uniform_code
  68. };
  69. WindturbinePointData newData = new WindturbinePointData();
  70. Dictionary<string, TsData> dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].windturbine_id, uniformCodeArr);
  71. if (dic != null)
  72. {
  73. foreach (KeyValuePair<string, TsData> kv in dic)
  74. {
  75. if (kv.Key == list[i].wind_speed_uniform_code)
  76. newData.WindSpeed = Convert.ToDouble(kv.Value.getValue());
  77. if (kv.Key == list[i].power_uniform_code)
  78. newData.Power = Convert.ToDouble(kv.Value.getValue());
  79. if (kv.Key == list[i].alternator_speed_uniform_code)
  80. newData.AlternatorSpeed = Convert.ToDouble(kv.Value.getValue());
  81. if (kv.Key == list[i].lamina_speed_uniform_code)
  82. newData.LaminaSpeed = Convert.ToDouble(kv.Value.getValue());
  83. if (kv.Key == list[i].lamina_angle1_uniform_code)
  84. newData.LaminaAngle1 = Convert.ToDouble(kv.Value.getValue());
  85. if (kv.Key == list[i].lamina_angle2_uniform_code)
  86. newData.LaminaAngle2 = Convert.ToDouble(kv.Value.getValue());
  87. if (kv.Key == list[i].lamina_angle3_uniform_code)
  88. newData.LaminaAngle3 = Convert.ToDouble(kv.Value.getValue());
  89. if (kv.Key == list[i].wind_angle_uniform_code)
  90. newData.WindAngle = Convert.ToDouble(kv.Value.getValue());
  91. if (kv.Key == list[i].yaw_position_uniform_code)
  92. newData.YawPosition = Convert.ToDouble(kv.Value.getValue());
  93. //风机状态判定 五种状态 运行1》待机0》维护4》故障2》离线3
  94. if (kv.Key == list[i].status_uniform_code)
  95. {
  96. int statusValue = Convert.ToInt32(kv.Value.getValue());
  97. switch (statusValue)
  98. {
  99. case 0:
  100. newData.Status = WindturbineStatus.Stop;
  101. break;
  102. case 1:
  103. newData.Status = WindturbineStatus.OnPower;
  104. break;
  105. case 2:
  106. newData.Status = WindturbineStatus.Standby;
  107. break;
  108. case 3:
  109. newData.Status = WindturbineStatus.Start;
  110. break;
  111. case 4:
  112. newData.Status = WindturbineStatus.Online;
  113. break;
  114. case 5:
  115. newData.Status = WindturbineStatus.Fault;
  116. break;
  117. case 6:
  118. newData.Status = WindturbineStatus.Maintain;
  119. break;
  120. case 7:
  121. newData.Status = WindturbineStatus.Offline;
  122. break;
  123. }
  124. }
  125. }
  126. }
  127. //newData.Status = WindturbineStatus.BuildPower;//测试使用
  128. newData.StationId = list[i].station_id;
  129. newData.WindturbineName = list[i].windturbine_id;
  130. newData.ProjectId = list[i].project_id;
  131. windturbine_uniform_code entity =
  132. list.Where(s => s.windturbine_id == newData.WindturbineName).FirstOrDefault();
  133. if (entity != null)
  134. newData.ModelId = entity.model_id;
  135. dataList.Add(newData);
  136. }
  137. string[] isCheckArr =
  138. CacheInfo.CacheWindturbineDataList.Where(s => s.IsCheck).Select(s => s.WindturbineName).ToArray();
  139. for (int i = 0; i < isCheckArr.Length; i++)
  140. {
  141. var data = dataList.Where(s => s.WindturbineName == isCheckArr[i]).FirstOrDefault();
  142. if (data != null)
  143. data.IsCheck = true;
  144. }
  145. var selectWindturbine =
  146. CacheInfo.CacheWindturbineDataList.Where(s => s.IsSelect == true).FirstOrDefault();
  147. if (selectWindturbine != null)
  148. {
  149. var data =
  150. dataList.Where(s => s.WindturbineName == selectWindturbine.WindturbineName).FirstOrDefault();
  151. if (data != null)
  152. data.IsSelect = true;
  153. }
  154. CacheInfo.CacheWindturbineDataList = dataList;
  155. ControlForm.isUpdateOverData = true;
  156. }
  157. }
  158. public static void UpdatePointDataByStationAndProject(object stationAndProject)
  159. {
  160. IList<string> parameterList = (IList<string>)stationAndProject;
  161. IList<windturbine_uniform_code> list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == parameterList[0] && s.project_id == parameterList[1]).ToList();
  162. if (list.Count <= 0)
  163. {
  164. CacheInfo.StationChange((string)parameterList[0]);
  165. list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == parameterList[0] && s.project_id == parameterList[1]).ToList();
  166. }
  167. if (list.Count > 0)
  168. {
  169. IList<WindturbinePointData> dataList = new List<WindturbinePointData>();
  170. for (int i = 0; i < list.Count; i++)
  171. {
  172. string[] uniformCodeArr = new string[]
  173. {
  174. list[i].wind_speed_uniform_code,
  175. list[i].power_uniform_code,
  176. list[i].status_uniform_code,
  177. list[i].hung_uniform_code,
  178. list[i].alternator_speed_uniform_code,
  179. list[i].lamina_speed_uniform_code,
  180. list[i].lamina_angle1_uniform_code,
  181. list[i].lamina_angle2_uniform_code,
  182. list[i].lamina_angle3_uniform_code,
  183. list[i].wind_angle_uniform_code,
  184. list[i].yaw_position_uniform_code
  185. };
  186. WindturbinePointData newData = new WindturbinePointData();
  187. Dictionary<string, TsData> dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].windturbine_id, uniformCodeArr);
  188. if (dic != null)
  189. {
  190. foreach (KeyValuePair<string, TsData> kv in dic)
  191. {
  192. if (kv.Key == list[i].wind_speed_uniform_code)
  193. newData.WindSpeed = Convert.ToDouble(kv.Value.getValue());
  194. if (kv.Key == list[i].power_uniform_code)
  195. newData.Power = Convert.ToDouble(kv.Value.getValue());
  196. if (kv.Key == list[i].alternator_speed_uniform_code)
  197. newData.AlternatorSpeed = Convert.ToDouble(kv.Value.getValue());
  198. if (kv.Key == list[i].lamina_speed_uniform_code)
  199. newData.LaminaSpeed = Convert.ToDouble(kv.Value.getValue());
  200. if (kv.Key == list[i].lamina_angle1_uniform_code)
  201. newData.LaminaAngle1 = Convert.ToDouble(kv.Value.getValue());
  202. if (kv.Key == list[i].lamina_angle2_uniform_code)
  203. newData.LaminaAngle2 = Convert.ToDouble(kv.Value.getValue());
  204. if (kv.Key == list[i].lamina_angle3_uniform_code)
  205. newData.LaminaAngle3 = Convert.ToDouble(kv.Value.getValue());
  206. if (kv.Key == list[i].wind_angle_uniform_code)
  207. newData.WindAngle = Convert.ToDouble(kv.Value.getValue());
  208. if (kv.Key == list[i].yaw_position_uniform_code)
  209. newData.YawPosition = Convert.ToDouble(kv.Value.getValue());
  210. //风机状态判定
  211. if (kv.Key == list[i].status_uniform_code)
  212. {
  213. int statusValue = Convert.ToInt32(kv.Value.getValue());
  214. switch (statusValue)
  215. {
  216. case 0:
  217. newData.Status = WindturbineStatus.Stop;
  218. break;
  219. case 1:
  220. newData.Status = WindturbineStatus.OnPower;
  221. break;
  222. case 2:
  223. newData.Status = WindturbineStatus.Standby;
  224. break;
  225. case 3:
  226. newData.Status = WindturbineStatus.Start;
  227. break;
  228. case 4:
  229. newData.Status = WindturbineStatus.Online;
  230. break;
  231. case 5:
  232. newData.Status = WindturbineStatus.Fault;
  233. break;
  234. case 6:
  235. newData.Status = WindturbineStatus.Maintain;
  236. break;
  237. case 7:
  238. newData.Status = WindturbineStatus.Offline;
  239. break;
  240. }
  241. }
  242. //风机挂牌判断
  243. if (kv.Key == list[i].hung_uniform_code)
  244. {
  245. int hungValue = Convert.ToInt32(kv.Value.getValue());
  246. newData.HungType = (HungType)hungValue;
  247. }
  248. }
  249. }
  250. newData.StationId = list[i].station_id;
  251. newData.WindturbineName = list[i].windturbine_id;
  252. newData.ProjectId = list[i].project_id;
  253. newData.ModelId = list[i].model_id;
  254. dataList.Add(newData);
  255. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(newData.WindturbineName))
  256. {
  257. WindturbinePointData data = CacheInfo.CacheWindturbineDataDic[newData.WindturbineName];
  258. data.WindSpeed = newData.WindSpeed;
  259. data.Power = newData.Power;
  260. data.Status = newData.Status;
  261. data.HungType = newData.HungType;
  262. data.AlternatorSpeed = newData.AlternatorSpeed;
  263. data.LimitSpeed = newData.LimitSpeed;
  264. data.LaminaSpeed = newData.LaminaSpeed;
  265. data.LaminaAngle1 = newData.LaminaAngle1;
  266. data.LaminaAngle2 = newData.LaminaAngle2;
  267. data.LaminaAngle3 = newData.LaminaAngle3;
  268. data.WindAngle = newData.WindAngle;
  269. data.YawPosition = newData.YawPosition;
  270. }
  271. else
  272. {
  273. CacheInfo.CacheWindturbineDataDic.Add(newData.WindturbineName, newData);
  274. }
  275. }
  276. }
  277. }
  278. public static void UpdatePointData_Test(object stationCode)
  279. {
  280. while (true)
  281. {
  282. IList<windturbine_uniform_code> list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList();
  283. if (list.Count <= 0)
  284. {
  285. CacheInfo.StationChange((string)stationCode);
  286. list = CacheInfo.CacheUniformCodeList.Where(s => s.station_id == (string)stationCode).ToList();
  287. }
  288. if (list.Count > 0)
  289. {
  290. IList<WindturbinePointData> dataList = new List<WindturbinePointData>();
  291. for (int i = 0; i < list.Count; i++)
  292. {
  293. string[] uniformCodeArr = new string[]
  294. {
  295. list[i].wind_speed_uniform_code,
  296. list[i].power_uniform_code,
  297. list[i].status_uniform_code,
  298. list[i].alternator_speed_uniform_code,
  299. list[i].lamina_speed_uniform_code,
  300. list[i].lamina_angle1_uniform_code,
  301. list[i].lamina_angle2_uniform_code,
  302. list[i].lamina_angle3_uniform_code,
  303. list[i].wind_angle_uniform_code,
  304. list[i].yaw_position_uniform_code
  305. };
  306. WindturbinePointData newData = new WindturbinePointData();
  307. Dictionary<string, TsData> dic = RestfulClient.findLatestByThingCodes("windturbine", list[i].windturbine_id, uniformCodeArr);
  308. if (dic != null)
  309. {
  310. foreach (KeyValuePair<string, TsData> kv in dic)
  311. {
  312. if (kv.Key == list[i].wind_speed_uniform_code)
  313. newData.WindSpeed = Convert.ToDouble(kv.Value.getValue());
  314. if (kv.Key == list[i].power_uniform_code)
  315. newData.Power = Convert.ToDouble(kv.Value.getValue());
  316. if (kv.Key == list[i].alternator_speed_uniform_code)
  317. newData.AlternatorSpeed = Convert.ToDouble(kv.Value.getValue());
  318. if (kv.Key == list[i].lamina_speed_uniform_code)
  319. newData.LaminaSpeed = Convert.ToDouble(kv.Value.getValue());
  320. if (kv.Key == list[i].lamina_angle1_uniform_code)
  321. newData.LaminaAngle1 = Convert.ToDouble(kv.Value.getValue());
  322. if (kv.Key == list[i].lamina_angle2_uniform_code)
  323. newData.LaminaAngle2 = Convert.ToDouble(kv.Value.getValue());
  324. if (kv.Key == list[i].lamina_angle3_uniform_code)
  325. newData.LaminaAngle3 = Convert.ToDouble(kv.Value.getValue());
  326. if (kv.Key == list[i].wind_angle_uniform_code)
  327. newData.WindAngle = Convert.ToDouble(kv.Value.getValue());
  328. if (kv.Key == list[i].yaw_position_uniform_code)
  329. newData.YawPosition = Convert.ToDouble(kv.Value.getValue());
  330. //风机状态判定 五种状态 运行1》待机0》维护4》故障2》离线3
  331. if (kv.Key == list[i].status_uniform_code)
  332. {
  333. int statusValue = Convert.ToInt32(kv.Value.getValue());
  334. switch (statusValue)
  335. {
  336. case 0:
  337. newData.Status = WindturbineStatus.Stop;
  338. break;
  339. case 1:
  340. newData.Status = WindturbineStatus.OnPower;
  341. break;
  342. case 2:
  343. newData.Status = WindturbineStatus.Standby;
  344. break;
  345. case 3:
  346. newData.Status = WindturbineStatus.Start;
  347. break;
  348. case 4:
  349. newData.Status = WindturbineStatus.Online;
  350. break;
  351. case 5:
  352. newData.Status = WindturbineStatus.Fault;
  353. break;
  354. case 6:
  355. newData.Status = WindturbineStatus.Maintain;
  356. break;
  357. case 7:
  358. newData.Status = WindturbineStatus.Offline;
  359. break;
  360. }
  361. }
  362. }
  363. }
  364. //newData.Status = WindturbineStatus.BuildPower;//测试使用
  365. newData.StationId = list[i].station_id;
  366. newData.WindturbineName = list[i].windturbine_id;
  367. dataList.Add(newData);
  368. }
  369. string[] isCheckArr =
  370. CacheInfo.CacheWindturbineDataList.Where(s => s.IsCheck).Select(s => s.WindturbineName).ToArray();
  371. for (int i = 0; i < isCheckArr.Length; i++)
  372. {
  373. var data = dataList.Where(s => s.WindturbineName == isCheckArr[i]).FirstOrDefault();
  374. if (data != null)
  375. data.IsCheck = true;
  376. }
  377. var selectWindturbine =
  378. CacheInfo.CacheWindturbineDataList.Where(s => s.IsSelect == true).FirstOrDefault();
  379. if (selectWindturbine != null)
  380. {
  381. var data =
  382. dataList.Where(s => s.WindturbineName == selectWindturbine.WindturbineName).FirstOrDefault();
  383. if (data != null)
  384. data.IsSelect = true;
  385. }
  386. CacheInfo.CacheWindturbineDataList = dataList;
  387. }
  388. }
  389. }
  390. }
  391. }