CmdInfoScreenSvc.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using EntityDataSet;
  9. using IntelligentControlForsx.Service.WindturbineControl.Domain;
  10. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  11. using Gyee_Control.Svc.Cache;
  12. namespace IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc
  13. {
  14. /// <summary>
  15. /// 风机控制筛选
  16. /// </summary>
  17. public class CmdInfoScreenSvc
  18. {
  19. private static CmdInfoScreenSvc screenSvc = new CmdInfoScreenSvc();
  20. private CmdInfoScreenSvc()
  21. {
  22. }
  23. public static CmdInfoScreenSvc GetCmdInfoScreenSvc()
  24. {
  25. return screenSvc;
  26. }
  27. /// <summary>
  28. /// 允许控制的风机信息集合
  29. /// </summary>
  30. /// <param name="infoList">控制风机信息集合</param>
  31. /// <param name="allowTable">允许控制风机信息Table</param>
  32. /// <param name="forbidenList">允许控制风机信息Table</param>
  33. /// <param name="forbidenTable">允许控制风机信息Table</param>
  34. /// <returns>允许控制风机集合</returns>
  35. public IList<WindturbineCmdInfo> GetAllowInfo(IList<WindturbineCmdInfo> infoList, out DataTable allowTable, out IList<WindturbineCmdInfo> forbidenList, out DataTable forbidenTable)
  36. {
  37. #region 状态判断 风机是否允许操作
  38. string stationId = infoList[0].StationId;
  39. IList<string> lockWindturbineId = new List<string>();
  40. for (int i = 0; i < infoList.Count; i++)
  41. {
  42. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(infoList[i].WindturbineId))
  43. {
  44. WindturbinePointData d = CacheInfo.CacheWindturbineDataDic[infoList[i].WindturbineId];
  45. if (d.HungType != HungType.UnLock)
  46. lockWindturbineId.Add(d.WindturbineName);
  47. }
  48. }
  49. IList<WindturbineCmdInfo> allowList = new List<WindturbineCmdInfo>();
  50. forbidenList = new List<WindturbineCmdInfo>();
  51. CmdType type = infoList[0].CmdType;
  52. IList<WindturbinePointData> cacheDataList = new List<WindturbinePointData>();
  53. for (int i = 0; i < infoList.Count; i++)
  54. {
  55. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(infoList[i].WindturbineId))
  56. cacheDataList.Add(CacheInfo.CacheWindturbineDataDic[infoList[i].WindturbineId]);
  57. }
  58. allowList = infoList;
  59. IList<WindturbineCmdInfo> busyList = new List<WindturbineCmdInfo>();
  60. switch (type)
  61. {
  62. case CmdType.Start://风机在待机状态下才能进行启动操作
  63. allowList = infoList.Where(s => cacheDataList.Where(r => r.Status == WindturbineStatus.Standby).ToList().Select(t => t.WindturbineName).Contains(s.WindturbineId)).ToList().Where(k => !TaskQueueSvc.dicTask.ContainsKey(k.WindturbineId)).ToList().Where(m => !lockWindturbineId.Contains(m.WindturbineId)).ToList();
  64. //操作过频繁的风机
  65. busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
  66. //排除状态允许操作,且操作过频繁的风机
  67. forbidenList = infoList.Except(allowList).ToList();
  68. for (int i = 0; i < forbidenList.Count; i++)
  69. {
  70. if (busyList.Contains(forbidenList[i]))
  71. forbidenList[i].ForbidenDescription = "风机操作过于频繁";
  72. else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
  73. forbidenList[i].ForbidenDescription = "风机已被挂牌";
  74. else
  75. forbidenList[i].ForbidenDescription = "风机只有待机状态下才能进行启动操作";
  76. }
  77. break;
  78. case CmdType.Stop://风机在运行状态,启动状态才能进行停机操作
  79. //风机状态为并网,且任务队列中没有的风机编号,为允许操作的风机
  80. allowList = infoList.Where(s => cacheDataList.Where(r => r.Status == WindturbineStatus.Online || r.Status == WindturbineStatus.Start).ToList().Select(t => t.WindturbineName).Contains(s.WindturbineId)).ToList().Where(k => !TaskQueueSvc.dicTask.ContainsKey(k.WindturbineId)).ToList().Where(m => !lockWindturbineId.Contains(m.WindturbineId)).ToList();
  81. //操作过频繁的风机
  82. busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
  83. //排除状态允许操作,且操作过频繁的风机
  84. forbidenList = infoList.Except(allowList).ToList().Union(busyList).ToList();
  85. for (int i = 0; i < forbidenList.Count; i++)
  86. {
  87. if (busyList.Contains(forbidenList[i]))
  88. forbidenList[i].ForbidenDescription = "风机操作过于频繁";
  89. else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
  90. forbidenList[i].ForbidenDescription = "风机已被挂牌";
  91. else
  92. forbidenList[i].ForbidenDescription = "风机只有在运行状态才能进行停机操作";
  93. }
  94. break;
  95. case CmdType.Maintain://风机在待机状态下才可以进行维护
  96. allowList = infoList.Where(s => cacheDataList.Where(r => r.Status == WindturbineStatus.Standby).ToList().Select(t => t.WindturbineName).Contains(s.WindturbineId)).ToList().Where(k => !TaskQueueSvc.dicTask.ContainsKey(k.WindturbineId)).ToList().Where(m => !lockWindturbineId.Contains(m.WindturbineId)).ToList();
  97. //操作过频繁的风机
  98. busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
  99. //排除状态允许操作,且操作过频繁的风机
  100. forbidenList = infoList.Except(allowList).ToList();
  101. for (int i = 0; i < forbidenList.Count; i++)
  102. {
  103. if (busyList.Contains(forbidenList[i]))
  104. forbidenList[i].ForbidenDescription = "风机操作过于频繁";
  105. else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
  106. forbidenList[i].ForbidenDescription = "风机已被挂牌";
  107. else
  108. forbidenList[i].ForbidenDescription = "风机只有在非运行,非离线状态下才可以进行维护";
  109. }
  110. break;
  111. case CmdType.UnMaintain://风机在维护状态下才可以进行取消维护
  112. allowList = infoList.Where(s => cacheDataList.Where(r => r.Status == WindturbineStatus.Maintain).ToList().Select(t => t.WindturbineName).Contains(s.WindturbineId)).ToList().Where(k => !TaskQueueSvc.dicTask.ContainsKey(k.WindturbineId)).ToList().Where(m => !lockWindturbineId.Contains(m.WindturbineId)).ToList();
  113. //操作过频繁的风机
  114. busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
  115. //排除状态允许操作,且操作过频繁的风机
  116. forbidenList = infoList.Except(allowList).ToList();
  117. for (int i = 0; i < forbidenList.Count; i++)
  118. {
  119. if (busyList.Contains(forbidenList[i]))
  120. forbidenList[i].ForbidenDescription = "风机操作过于频繁";
  121. else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
  122. forbidenList[i].ForbidenDescription = "风机已被挂牌";
  123. else
  124. forbidenList[i].ForbidenDescription = "风机只有在维护状态下才可以进行取消维护";
  125. }
  126. break;
  127. case CmdType.Reset://只有故障状态的的风机才能进行复位,且故障不为12种主要故障
  128. allowList = infoList.Where(s => cacheDataList.Where(r => r.Status == WindturbineStatus.Fault).ToList().Select(t => t.WindturbineName).Contains(s.WindturbineId)).ToList().Where(k => !TaskQueueSvc.dicTask.ContainsKey(k.WindturbineId)).ToList().Where(m => !lockWindturbineId.Contains(m.WindturbineId)).ToList();
  129. //操作过频繁的风机
  130. busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
  131. //排除状态允许操作,且操作过频繁的风机
  132. forbidenList = infoList.Except(allowList).ToList();
  133. for (int i = 0; i < forbidenList.Count; i++)
  134. {
  135. if (busyList.Contains(forbidenList[i]))
  136. forbidenList[i].ForbidenDescription = "风机操作过于频繁";
  137. else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
  138. forbidenList[i].ForbidenDescription = "风机已被挂牌";
  139. else
  140. forbidenList[i].ForbidenDescription = "风机只有在故障状态才能进行复位,且故障不为12种主要故障";
  141. }
  142. break;
  143. default: break;
  144. }
  145. allowTable = GetAllowTable(allowList);
  146. forbidenTable = GetForbidenTable(forbidenList);
  147. return allowList;
  148. #endregion
  149. }
  150. public DataTable GetAllowTable(IList<WindturbineCmdInfo> infoList)
  151. {
  152. DataTable dataTable = new DataTable();
  153. dataTable.Columns.Add("风机名称");
  154. dataTable.Columns.Add("风速");
  155. dataTable.Columns.Add("功率");
  156. dataTable.Columns.Add("状态");
  157. dataTable.Columns.Add("电机转速");
  158. dataTable.Columns.Add("叶轮转速");
  159. dataTable.Columns.Add("桨叶角度1");
  160. dataTable.Columns.Add("桨叶角度2");
  161. dataTable.Columns.Add("桨叶角度3");
  162. for (int i = 0; i < infoList.Count; i++)
  163. {
  164. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(infoList[i].WindturbineId))
  165. {
  166. WindturbinePointData data = CacheInfo.CacheWindturbineDataDic[infoList[i].WindturbineId];
  167. if (data != null)
  168. {
  169. DataRow row = dataTable.NewRow();
  170. row["风机名称"] = data.WindturbineName;
  171. row["风速"] = data.WindSpeed.ToString("f2") + "m/s";
  172. row["功率"] = data.Power.ToString("f2") + "kW";
  173. #region 风机状态
  174. switch (data.Status)
  175. {
  176. case WindturbineStatus.Standby:
  177. row["状态"] = "待机";
  178. break;
  179. case WindturbineStatus.Online:
  180. row["状态"] = "并网";
  181. break;
  182. case WindturbineStatus.Maintain:
  183. row["状态"] = "维护";
  184. break;
  185. case WindturbineStatus.Fault:
  186. row["状态"] = "故障";
  187. break;
  188. case WindturbineStatus.Offline:
  189. row["状态"] = "离线";
  190. break;
  191. case WindturbineStatus.Start:
  192. row["状态"] = "启动";
  193. break;
  194. case WindturbineStatus.OnPower:
  195. row["状态"] = "上电";
  196. break;
  197. case WindturbineStatus.Stop:
  198. row["状态"] = "停机";
  199. break;
  200. }
  201. #endregion
  202. row["电机转速"] = data.AlternatorSpeed.ToString("f2") + "rpm";
  203. row["叶轮转速"] = data.LaminaSpeed.ToString("f2") + "rpm";
  204. row["桨叶角度1"] = data.LaminaAngle1.ToString("f2") + "°";
  205. row["桨叶角度2"] = data.LaminaAngle2.ToString("f2") + "°";
  206. row["桨叶角度3"] = data.LaminaAngle3.ToString("f2") + "°";
  207. dataTable.Rows.Add(row);
  208. }
  209. }
  210. }
  211. return dataTable;
  212. }
  213. public DataTable GetForbidenTable(IList<WindturbineCmdInfo> infoList)
  214. {
  215. DataTable dataTable = new DataTable();
  216. dataTable.Columns.Add("风机名称");
  217. dataTable.Columns.Add("原因");
  218. for (int i = 0; i < infoList.Count; i++)
  219. {
  220. DataRow row = dataTable.NewRow();
  221. row["风机名称"] = infoList[i].WindturbineId;
  222. row["原因"] = infoList[i].ForbidenDescription;
  223. dataTable.Rows.Add(row);
  224. }
  225. return dataTable;
  226. }
  227. public DataTable GetControlOverTable(IList<WindturbineCmdInfo> list, out DataTable unSuccessTable)
  228. {
  229. IList<WindturbineCmdInfo> successList = list.Where(s => s.IsSuccessSend == true).ToList();
  230. IList<WindturbineCmdInfo> unSuccessList = list.Except(successList).ToList();
  231. DataTable successDataTable = new DataTable();
  232. unSuccessTable = new DataTable();
  233. #region 操作成功数据
  234. successDataTable.Columns.Add("风机名称");
  235. successDataTable.Columns.Add("风速");
  236. successDataTable.Columns.Add("功率");
  237. successDataTable.Columns.Add("状态");
  238. successDataTable.Columns.Add("电机转速");
  239. successDataTable.Columns.Add("叶轮转速");
  240. successDataTable.Columns.Add("桨叶角度1");
  241. successDataTable.Columns.Add("桨叶角度2");
  242. successDataTable.Columns.Add("桨叶角度3");
  243. for (int i = 0; i < successList.Count; i++)
  244. {
  245. WindturbinePointData data = CacheInfo.CacheWindturbineDataList.Where(s => s.WindturbineName == successList[i].WindturbineId)
  246. .FirstOrDefault();
  247. if (data != null)
  248. {
  249. DataRow row = successDataTable.NewRow();
  250. row["风机名称"] = data.WindturbineName;
  251. row["风速"] = data.WindSpeed.ToString("f2") + "m/s";
  252. row["功率"] = data.Power.ToString("f2") + "kW";
  253. row["状态"] = data.Status;
  254. row["发电机转速"] = data.AlternatorSpeed.ToString("f2") + "rpm";
  255. row["叶轮转速"] = data.LaminaSpeed.ToString("f2") + "rpm";
  256. row["桨叶角度1"] = data.LaminaAngle1.ToString("f2") + "°";
  257. row["桨叶角度2"] = data.LaminaAngle2.ToString("f2") + "°";
  258. row["桨叶角度3"] = data.LaminaAngle3.ToString("f2") + "°";
  259. successDataTable.Rows.Add(row);
  260. }
  261. }
  262. #endregion
  263. #region 操作失败数据
  264. unSuccessTable.Columns.Add("风机名称");
  265. unSuccessTable.Columns.Add("风速");
  266. unSuccessTable.Columns.Add("功率");
  267. unSuccessTable.Columns.Add("状态");
  268. unSuccessTable.Columns.Add("电机转速");
  269. unSuccessTable.Columns.Add("叶轮转速");
  270. unSuccessTable.Columns.Add("桨叶角度1");
  271. unSuccessTable.Columns.Add("桨叶角度2");
  272. unSuccessTable.Columns.Add("桨叶角度3");
  273. for (int i = 0; i < unSuccessList.Count; i++)
  274. {
  275. WindturbinePointData data = CacheInfo.CacheWindturbineDataList.Where(s => s.WindturbineName == unSuccessList[i].WindturbineId)
  276. .FirstOrDefault();
  277. if (data != null)
  278. {
  279. DataRow row = unSuccessTable.NewRow();
  280. row["风机名称"] = data.WindturbineName;
  281. row["风速"] = data.WindSpeed.ToString("f2") + "m/s";
  282. row["功率"] = data.Power.ToString("f2") + "kW";
  283. row["状态"] = data.Status;
  284. row["电机转速"] = data.AlternatorSpeed.ToString("f2") + "rpm";
  285. row["叶轮转速"] = data.LaminaSpeed.ToString("f2") + "rpm";
  286. row["桨叶角度1"] = data.LaminaAngle1.ToString("f2") + "°";
  287. row["桨叶角度2"] = data.LaminaAngle2.ToString("f2") + "°";
  288. row["桨叶角度3"] = data.LaminaAngle3.ToString("f2") + "°";
  289. unSuccessTable.Rows.Add(row);
  290. }
  291. }
  292. #endregion
  293. return successDataTable;
  294. }
  295. }
  296. }