using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityDataSet;
using IntelligentControlForsx.Service.WindturbineControl.Domain;
using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
using Gyee_Control.Svc.Cache;
namespace IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc
{
///
/// 风机控制筛选
///
public class CmdInfoScreenSvc
{
private static CmdInfoScreenSvc screenSvc = new CmdInfoScreenSvc();
private CmdInfoScreenSvc()
{
}
public static CmdInfoScreenSvc GetCmdInfoScreenSvc()
{
return screenSvc;
}
///
/// 允许控制的风机信息集合
///
/// 控制风机信息集合
/// 允许控制风机信息Table
/// 允许控制风机信息Table
/// 允许控制风机信息Table
/// 允许控制风机集合
public IList GetAllowInfo(IList infoList, out DataTable allowTable, out IList forbidenList, out DataTable forbidenTable)
{
#region 状态判断 风机是否允许操作
string stationId = infoList[0].StationId;
IList lockWindturbineId = new List();
for (int i = 0; i < infoList.Count; i++)
{
if (CacheInfo.CacheWindturbineDataDic.ContainsKey(infoList[i].WindturbineId))
{
WindturbinePointData d = CacheInfo.CacheWindturbineDataDic[infoList[i].WindturbineId];
if (d.HungType != HungType.UnLock)
lockWindturbineId.Add(d.WindturbineName);
}
}
IList allowList = new List();
forbidenList = new List();
CmdType type = infoList[0].CmdType;
IList cacheDataList = new List();
for (int i = 0; i < infoList.Count; i++)
{
if (CacheInfo.CacheWindturbineDataDic.ContainsKey(infoList[i].WindturbineId))
cacheDataList.Add(CacheInfo.CacheWindturbineDataDic[infoList[i].WindturbineId]);
}
allowList = infoList;
IList busyList = new List();
switch (type)
{
case CmdType.Start://风机在待机状态下才能进行启动操作
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();
//操作过频繁的风机
busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
//排除状态允许操作,且操作过频繁的风机
forbidenList = infoList.Except(allowList).ToList();
for (int i = 0; i < forbidenList.Count; i++)
{
if (busyList.Contains(forbidenList[i]))
forbidenList[i].ForbidenDescription = "风机操作过于频繁";
else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
forbidenList[i].ForbidenDescription = "风机已被挂牌";
else
forbidenList[i].ForbidenDescription = "风机只有待机状态下才能进行启动操作";
}
break;
case CmdType.Stop://风机在运行状态,启动状态才能进行停机操作
//风机状态为并网,且任务队列中没有的风机编号,为允许操作的风机
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();
//操作过频繁的风机
busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
//排除状态允许操作,且操作过频繁的风机
forbidenList = infoList.Except(allowList).ToList().Union(busyList).ToList();
for (int i = 0; i < forbidenList.Count; i++)
{
if (busyList.Contains(forbidenList[i]))
forbidenList[i].ForbidenDescription = "风机操作过于频繁";
else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
forbidenList[i].ForbidenDescription = "风机已被挂牌";
else
forbidenList[i].ForbidenDescription = "风机只有在运行状态才能进行停机操作";
}
break;
case CmdType.Maintain://风机在待机状态下才可以进行维护
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();
//操作过频繁的风机
busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
//排除状态允许操作,且操作过频繁的风机
forbidenList = infoList.Except(allowList).ToList();
for (int i = 0; i < forbidenList.Count; i++)
{
if (busyList.Contains(forbidenList[i]))
forbidenList[i].ForbidenDescription = "风机操作过于频繁";
else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
forbidenList[i].ForbidenDescription = "风机已被挂牌";
else
forbidenList[i].ForbidenDescription = "风机只有在非运行,非离线状态下才可以进行维护";
}
break;
case CmdType.UnMaintain://风机在维护状态下才可以进行取消维护
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();
//操作过频繁的风机
busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
//排除状态允许操作,且操作过频繁的风机
forbidenList = infoList.Except(allowList).ToList();
for (int i = 0; i < forbidenList.Count; i++)
{
if (busyList.Contains(forbidenList[i]))
forbidenList[i].ForbidenDescription = "风机操作过于频繁";
else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
forbidenList[i].ForbidenDescription = "风机已被挂牌";
else
forbidenList[i].ForbidenDescription = "风机只有在维护状态下才可以进行取消维护";
}
break;
case CmdType.Reset://只有故障状态的的风机才能进行复位,且故障不为12种主要故障
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();
//操作过频繁的风机
busyList = infoList.Where(s => TaskQueueSvc.dicTask.ContainsKey(s.WindturbineId)).ToList();
//排除状态允许操作,且操作过频繁的风机
forbidenList = infoList.Except(allowList).ToList();
for (int i = 0; i < forbidenList.Count; i++)
{
if (busyList.Contains(forbidenList[i]))
forbidenList[i].ForbidenDescription = "风机操作过于频繁";
else if (lockWindturbineId.Contains(forbidenList[i].WindturbineId))
forbidenList[i].ForbidenDescription = "风机已被挂牌";
else
forbidenList[i].ForbidenDescription = "风机只有在故障状态才能进行复位,且故障不为12种主要故障";
}
break;
default: break;
}
allowTable = GetAllowTable(allowList);
forbidenTable = GetForbidenTable(forbidenList);
return allowList;
#endregion
}
public DataTable GetAllowTable(IList infoList)
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("风机名称");
dataTable.Columns.Add("风速");
dataTable.Columns.Add("功率");
dataTable.Columns.Add("状态");
dataTable.Columns.Add("电机转速");
dataTable.Columns.Add("叶轮转速");
dataTable.Columns.Add("桨叶角度1");
dataTable.Columns.Add("桨叶角度2");
dataTable.Columns.Add("桨叶角度3");
for (int i = 0; i < infoList.Count; i++)
{
if (CacheInfo.CacheWindturbineDataDic.ContainsKey(infoList[i].WindturbineId))
{
WindturbinePointData data = CacheInfo.CacheWindturbineDataDic[infoList[i].WindturbineId];
if (data != null)
{
DataRow row = dataTable.NewRow();
row["风机名称"] = data.WindturbineName;
row["风速"] = data.WindSpeed.ToString("f2") + "m/s";
row["功率"] = data.Power.ToString("f2") + "kW";
#region 风机状态
switch (data.Status)
{
case WindturbineStatus.Standby:
row["状态"] = "待机";
break;
case WindturbineStatus.Online:
row["状态"] = "并网";
break;
case WindturbineStatus.Maintain:
row["状态"] = "维护";
break;
case WindturbineStatus.Fault:
row["状态"] = "故障";
break;
case WindturbineStatus.Offline:
row["状态"] = "离线";
break;
case WindturbineStatus.Start:
row["状态"] = "启动";
break;
case WindturbineStatus.OnPower:
row["状态"] = "上电";
break;
case WindturbineStatus.Stop:
row["状态"] = "停机";
break;
}
#endregion
row["电机转速"] = data.AlternatorSpeed.ToString("f2") + "rpm";
row["叶轮转速"] = data.LaminaSpeed.ToString("f2") + "rpm";
row["桨叶角度1"] = data.LaminaAngle1.ToString("f2") + "°";
row["桨叶角度2"] = data.LaminaAngle2.ToString("f2") + "°";
row["桨叶角度3"] = data.LaminaAngle3.ToString("f2") + "°";
dataTable.Rows.Add(row);
}
}
}
return dataTable;
}
public DataTable GetForbidenTable(IList infoList)
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("风机名称");
dataTable.Columns.Add("原因");
for (int i = 0; i < infoList.Count; i++)
{
DataRow row = dataTable.NewRow();
row["风机名称"] = infoList[i].WindturbineId;
row["原因"] = infoList[i].ForbidenDescription;
dataTable.Rows.Add(row);
}
return dataTable;
}
public DataTable GetControlOverTable(IList list, out DataTable unSuccessTable)
{
IList successList = list.Where(s => s.IsSuccessSend == true).ToList();
IList unSuccessList = list.Except(successList).ToList();
DataTable successDataTable = new DataTable();
unSuccessTable = new DataTable();
#region 操作成功数据
successDataTable.Columns.Add("风机名称");
successDataTable.Columns.Add("风速");
successDataTable.Columns.Add("功率");
successDataTable.Columns.Add("状态");
successDataTable.Columns.Add("电机转速");
successDataTable.Columns.Add("叶轮转速");
successDataTable.Columns.Add("桨叶角度1");
successDataTable.Columns.Add("桨叶角度2");
successDataTable.Columns.Add("桨叶角度3");
for (int i = 0; i < successList.Count; i++)
{
WindturbinePointData data = CacheInfo.CacheWindturbineDataList.Where(s => s.WindturbineName == successList[i].WindturbineId)
.FirstOrDefault();
if (data != null)
{
DataRow row = successDataTable.NewRow();
row["风机名称"] = data.WindturbineName;
row["风速"] = data.WindSpeed.ToString("f2") + "m/s";
row["功率"] = data.Power.ToString("f2") + "kW";
row["状态"] = data.Status;
row["发电机转速"] = data.AlternatorSpeed.ToString("f2") + "rpm";
row["叶轮转速"] = data.LaminaSpeed.ToString("f2") + "rpm";
row["桨叶角度1"] = data.LaminaAngle1.ToString("f2") + "°";
row["桨叶角度2"] = data.LaminaAngle2.ToString("f2") + "°";
row["桨叶角度3"] = data.LaminaAngle3.ToString("f2") + "°";
successDataTable.Rows.Add(row);
}
}
#endregion
#region 操作失败数据
unSuccessTable.Columns.Add("风机名称");
unSuccessTable.Columns.Add("风速");
unSuccessTable.Columns.Add("功率");
unSuccessTable.Columns.Add("状态");
unSuccessTable.Columns.Add("电机转速");
unSuccessTable.Columns.Add("叶轮转速");
unSuccessTable.Columns.Add("桨叶角度1");
unSuccessTable.Columns.Add("桨叶角度2");
unSuccessTable.Columns.Add("桨叶角度3");
for (int i = 0; i < unSuccessList.Count; i++)
{
WindturbinePointData data = CacheInfo.CacheWindturbineDataList.Where(s => s.WindturbineName == unSuccessList[i].WindturbineId)
.FirstOrDefault();
if (data != null)
{
DataRow row = unSuccessTable.NewRow();
row["风机名称"] = data.WindturbineName;
row["风速"] = data.WindSpeed.ToString("f2") + "m/s";
row["功率"] = data.Power.ToString("f2") + "kW";
row["状态"] = data.Status;
row["电机转速"] = data.AlternatorSpeed.ToString("f2") + "rpm";
row["叶轮转速"] = data.LaminaSpeed.ToString("f2") + "rpm";
row["桨叶角度1"] = data.LaminaAngle1.ToString("f2") + "°";
row["桨叶角度2"] = data.LaminaAngle2.ToString("f2") + "°";
row["桨叶角度3"] = data.LaminaAngle3.ToString("f2") + "°";
unSuccessTable.Rows.Add(row);
}
}
#endregion
return successDataTable;
}
}
}