using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Cache;
using System.Text;
using System.Threading.Tasks;
using EntityDataSet;
using IntelligentControlForsx.Common;
using IntelligentControlForsx.Service.WindturbineControl.Domain;
using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
using WisdomClient;
using WisdomClient.data;
namespace IntelligentControlForsx.Service.CleverRecommend
{
///
/// 启停智能计算
///
public class CalculationSvc
{
#region 构造方法--单例
private CalculationSvc()
{
}
public static CalculationSvc Instance
{
get { return SingletonCreator.instance; }
}
private class SingletonCreator
{
internal static readonly CalculationSvc instance = new CalculationSvc();
}
#endregion
///
/// 推荐控制风机集合 key 风场编号,value为推荐集合
///
public static Dictionary> RecommendDic = new Dictionary>();
///
/// 风机实时状态 key风场编号,value为风机信息集合
///
public static Dictionary> InfoDic = new Dictionary>();
///
/// 风机控制计算方法
///
/// 风场编号
public static void WindturbineCalculation(object stationId)
{
IList infoList = new List();
if (!InfoDic.ContainsKey((string)stationId))
GetWindturbineInfo(stationId);
infoList = InfoDic[(string)stationId];
//风机启动推荐集合 待机状态,60s平均风速大于4.5m/s,非挂牌
IList startList =
infoList.Where(
s => s.Status == WindturbineStatus.Standby && s.WindSpeed.HasValue && s.WindSpeed.Value > 4.5 && s.LimitInvolvement == HungType.UnLock)
.ToList();
//风机停机推荐集合 并网状态,60s平均风速小于4.5m/s,非挂牌
IList stopList = infoList.Where(
s => s.Status == WindturbineStatus.Online && s.WindSpeed.HasValue && s.WindSpeed.Value < 4.5 && s.LimitInvolvement == HungType.UnLock)
.ToList();
//风机复位推荐集合 故障状态,故障情况允许进行复位操作,风机型号不为UP105
IList resetList = infoList.Where(
s => s.Status == WindturbineStatus.Fault && s.LimitInvolvement == HungType.UnLock)
.ToList();
IList recommendList = new List();
DateTime time = DateTime.Now;
for (int i = 0; i < startList.Count; i++)
{
RecommendData rdata = new RecommendData();
rdata.WindturbineId = startList[i].WindturbineId;
rdata.RecommendType = CmdType.Start;
rdata.Status = startList[i].Status;
rdata.RecommendTime = time;
rdata.RecommendReason = "--";
recommendList.Add(rdata);
}
for (int i = 0; i < stopList.Count; i++)
{
RecommendData rdata = new RecommendData();
rdata.WindturbineId = stopList[i].WindturbineId;
rdata.RecommendType = CmdType.Stop;
rdata.Status = stopList[i].Status;
rdata.RecommendTime = time;
rdata.RecommendReason = "--";
recommendList.Add(rdata);
}
for (int i = 0; i < resetList.Count; i++)
{
RecommendData rdata = new RecommendData();
rdata.WindturbineId = resetList[i].WindturbineId;
rdata.RecommendType = CmdType.Reset;
rdata.Status = resetList[i].Status;
rdata.RecommendTime = time;
rdata.RecommendReason = "--";
recommendList.Add(rdata);
}
if (RecommendDic.ContainsKey((string)stationId))
RecommendDic[(string)stationId] = recommendList;
else
RecommendDic.Add((string)stationId, recommendList);
}
///
/// 获取风机当前信息(风速,状态等)
///
///
public static void GetWindturbineInfo(object stationId)
{
if (!InfoDic.ContainsKey((string)stationId))
InitInfoDic((string)stationId);
IList list = InfoDic[(string)stationId];
for (int i = 0; i < list.Count; i++)
{
string[] codeArr = new[]
{
list[i].WindSpeedCode,
list[i].StatusCode,
list[i].LimitInvolvementCode
};
Dictionary resultDic = RestfulClient.findLatestByThingCodes("windturbine", list[i].WindturbineId, codeArr);
if (resultDic.ContainsKey(list[i].WindSpeedCode))
list[i].WindSpeed = resultDic[list[i].WindSpeedCode].doubleValue.HasValue
? resultDic[list[i].WindSpeedCode].doubleValue.Value
: 0.0;
if (resultDic.ContainsKey(list[i].StatusCode))
{
if (resultDic[list[i].StatusCode].doubleValue.HasValue)
list[i].Status =
CommonMethod.GetWindturbineStatus(resultDic[list[i].StatusCode].doubleValue.Value);
}
if (resultDic.ContainsKey(list[i].WindSpeedCode))
{
if (resultDic[list[i].WindSpeedCode].doubleValue.HasValue)
{
list[i].WindSpeed = resultDic[list[i].WindSpeedCode].doubleValue;
}
}
if (resultDic.ContainsKey(list[i].LimitInvolvementCode))
{
if (resultDic[list[i].LimitInvolvementCode].doubleValue.HasValue)
{
list[i].LimitInvolvement = CommonMethod.GetHungLock(resultDic[list[i].LimitInvolvementCode].doubleValue.Value);
}
}
}
}
///
/// 获取风机当前信息统一编码
///
///
public static void InitInfoDic(string stationId)
{
IList list = new List();
using (wisdom_cs_entity ctx = new wisdom_cs_entity())
{
list = ctx.windturbine_uniform_code.Where(s => s.station_id == stationId).ToList();
}
IList infoList = new List();
for (int i = 0; i < list.Count; i++)
{
WInfo w = new WInfo();
w.WindturbineId = list[i].windturbine_id;
w.StatusCode = list[i].status_uniform_code;
w.ModelId = list[i].model_id;
w.LimitInvolvementCode = "XDSL";
if (list[i].model_id.Contains("105"))
w.WindSpeedCode = "AI373";//中期平均风速
else
w.WindSpeedCode = "AI024";//60s平均风速
infoList.Add(w);
}
if (!InfoDic.ContainsKey(stationId))
InfoDic.Add(stationId, infoList);
}
}
}