using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Security; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Controls; using EntityDataSet; using IntelligentControlForsx.ChildForms; using IntelligentControlForsx.Model; using IntelligentControlForsx.Service.ParameterFormInfo.Domain; using log4net.Util; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.Service.ParameterFormInfo { public class ParameterFormInfoSvc { private ParameterFormInfoSvc() { BuilDicUnifromCodeList(); } public static ParameterFormInfoSvc Instance { get { return SingletonCreator.instance; } } class SingletonCreator { internal static readonly ParameterFormInfoSvc instance = new ParameterFormInfoSvc(); } private static Dictionary> dicGridPointData = new Dictionary>();//key1--风场编号 private static Dictionary> dicTopPointData = new Dictionary>(); //key1--风场编号 private static Dictionary> dicUniformCodeListByWindturbineId = new Dictionary>();//key1--风机编号,key2为统一编码 private static Dictionary> dicUniformCodeListByStation = new Dictionary>();//key1--风场编号,key2为统一编码 private static string stationNameNow = ""; /// /// 获取实时数据 /// /// public void RefreshDataList(object stationName) { IList topPointList = new List(); IList gridPointList = GetDicByStationName((string)stationName, out topPointList); //gridPointList 长度超过1000条则进行分段查询 Dictionary resultGridDic = RestfulClient.findLatestByTagNames(gridPointList.Select(s => s.PointId).ToArray()); Console.WriteLine("================================================================================================================================"); foreach (KeyValuePair kv in resultGridDic) { PointMapModel data = gridPointList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) { data.Value = Convert.ToDouble(kv.Value.getValue()); Console.WriteLine(kv.Key + "---" + kv.Value.getValue()); } } Console.WriteLine("================================================================================================================================"); dicGridPointData.Remove((string)stationName); dicGridPointData.Add((string)stationName, gridPointList); Dictionary resultTopDic = RestfulClient.findLatestByTagNames(topPointList.Select(s => s.PointId).ToArray()); foreach (KeyValuePair kv in resultTopDic) { PointMapModel data = topPointList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } dicTopPointData.Remove((string)stationName); dicTopPointData.Add((string)stationName, topPointList); } private IList GetDicByStationName(string stationName, out IList topPointList) { if (dicGridPointData == null) { dicGridPointData = new Dictionary>(); } if (dicTopPointData == null) { dicTopPointData = new Dictionary>(); } IList gridPointList = null; topPointList = null; if (dicGridPointData.ContainsKey(stationName)) { gridPointList = dicGridPointData[stationName]; } if (dicTopPointData.ContainsKey(stationName)) { topPointList = dicTopPointData[stationName]; } if (gridPointList == null || gridPointList.Count <= 0) { gridPointList = GetGridPoint(stationName); dicGridPointData.Add(stationName, gridPointList); } if (topPointList == null || topPointList.Count <= 0) { topPointList = GetTopPoint(stationName); // dicTopPointData.Add(stationName, topPointList); } return gridPointList; } /// /// 根据风场编号获取风机测点,字典key为风机编号,value为每台风机测点集合 /// /// /// private IList GetGridPoint(string stationName) { List list = new List(); DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); long tt = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == stationName).ToList(); for (int i = 0; i < windturbineList.Count; i++) { Dictionary uniformCodeDic = dicUniformCodeListByWindturbineId[windturbineList[i].ID]; string windturbineId = windturbineList[i].ID; IList pointList = ctx.view_tspoint.Where(s => uniformCodeDic.Keys.Contains(s.uniform_code) && s.thing_id == windturbineId).ToList(); //IList pointList = ctx.view_tspoint.Where(s => s.thing_id == "XG01_01").ToList(); for (int j = 0; j < pointList.Count; j++) { PointMapModel data = new PointMapModel(); data.ThingId = pointList[j].thing_id; data.PointId = pointList[j].id; data.PointName = uniformCodeDic[pointList[j].uniform_code]; list.Add(data); } } } long ee = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 long re = ee - tt; Console.WriteLine("========================================时间差为:"+re); return list; } /// /// 根据风场获取风场主要参数测点 /// /// /// private IList GetTopPoint(string stationName) { return new List(); } /// /// 根据风场获取DataTable /// /// /// public DataTable GetDataTable(string stationName) { IList list = GetInfoData(stationName).OrderBy(s=>Convert.ToInt32(Regex.Replace(s.WindturbineId,"[a-zA-Z]","").Replace("_",""))).ToList(); DataTable resultTable = GetDataTableHeaders(); for (int i = 0; i < list.Count; i++) { #region 生成GridView信息 DataRow row = resultTable.NewRow(); row["风机名称"] = list[i].WindturbineId; row["冷却风温度"] = list[i].ColdWindTemperature.ToString("f2"); row["有功功率"] = list[i].Power.ToString("f2"); row["液压油温度"] = list[i].OilTemperature.ToString("f2"); row["U1绕组温度"] = list[i].U1CirclingTemperature.ToString("f2"); row["U2绕组温度"] = list[i].U2CirclingTemperature.ToString("f2"); row["V1绕组温度"] = list[i].V1CirclingTemperature.ToString("f2"); row["V2绕组温度"] = list[i].V2CirclingTemperature.ToString("f2"); row["W1绕组温度"] = list[i].W1CirclingTemperature.ToString("f2"); row["W2绕组温度"] = list[i].W2CirclingTemperature.ToString("f2"); row["轴承A温度"] = list[i].AxisATemperature.ToString("f2"); row["轴承B温度"] = list[i].AxisBTemperature.ToString("f2"); row["齿轮箱温度"] = list[i].GearBoxTemperature.ToString("f2"); row["齿轮箱轴1温度"] = list[i].GearAxis1Temperature.ToString("f2"); row["齿轮箱轴2温度"] = list[i].GearAxis2Temperature.ToString("f2"); row["机舱温度"] = list[i].RoomTemperature.ToString("f2"); row["环境温度"] = list[i].RoundTemperature.ToString("f2"); resultTable.Rows.Add(row); #endregion } return resultTable; } public DataTable GetDataTableHeaders() { DataTable dataTable = new DataTable(); dataTable.Columns.Add("风机名称"); dataTable.Columns.Add("冷却风温度"); dataTable.Columns.Add("有功功率"); dataTable.Columns.Add("液压油温度"); dataTable.Columns.Add("U1绕组温度"); dataTable.Columns.Add("U2绕组温度"); dataTable.Columns.Add("V1绕组温度"); dataTable.Columns.Add("V2绕组温度"); dataTable.Columns.Add("W1绕组温度"); dataTable.Columns.Add("W2绕组温度"); dataTable.Columns.Add("轴承A温度"); dataTable.Columns.Add("轴承B温度"); dataTable.Columns.Add("齿轮箱温度"); dataTable.Columns.Add("齿轮箱轴1温度"); dataTable.Columns.Add("齿轮箱轴2温度"); dataTable.Columns.Add("机舱温度"); dataTable.Columns.Add("环境温度"); return dataTable; } /// /// 根据风场获取gridview实体信息 /// /// /// public IList GetInfoData(string stationName) { IList dataList = new List(); // RefreshDataList(stationName);//刷新数据 if (dicGridPointData.ContainsKey(stationName)) { IList stationAllList = dicGridPointData[stationName]; IList windturbineIdList = stationAllList.Select(s => s.ThingId).Distinct().ToList(); for (int i = 0; i < windturbineIdList.Count(); i++) { //根据风机编号获取测点值 IList pointValueList = stationAllList.Where(s => s.ThingId == windturbineIdList[i]).ToList(); GridViewData data = new GridViewData(); data.WindturbineId = windturbineIdList[i]; PointMapModel coldWindTemperatureData = pointValueList.Where(s => s.PointName == "冷却风温度").FirstOrDefault(); data.ColdWindTemperature = coldWindTemperatureData != null ? coldWindTemperatureData.Value : 0.0; PointMapModel powerData = pointValueList.Where(s => s.PointName == "有功功率").FirstOrDefault(); data.Power = powerData != null ? powerData.Value : 0.0; PointMapModel OilTemperature = pointValueList.Where(s => s.PointName == "液压油温度").FirstOrDefault(); data.OilTemperature = OilTemperature != null ? OilTemperature.Value : 0.0; PointMapModel U1CirclingTemperature = pointValueList.Where(s => s.PointName == "U1绕组温度").FirstOrDefault(); data.U1CirclingTemperature = U1CirclingTemperature != null ? U1CirclingTemperature.Value : 0.0; PointMapModel U2CirclingTemperature = pointValueList.Where(s => s.PointName == "U2绕组温度").FirstOrDefault(); data.U2CirclingTemperature = U2CirclingTemperature != null ? U2CirclingTemperature.Value : 0.0; PointMapModel V1CirclingTemperature = pointValueList.Where(s => s.PointName == "V1绕组温度").FirstOrDefault(); data.V1CirclingTemperature = V1CirclingTemperature != null ? V1CirclingTemperature.Value : 0.0; PointMapModel V2CirclingTemperature = pointValueList.Where(s => s.PointName == "V2绕组温度").FirstOrDefault(); data.V2CirclingTemperature = V2CirclingTemperature != null ? V2CirclingTemperature.Value : 0.0; PointMapModel W1CirclingTemperature = pointValueList.Where(s => s.PointName == "W1绕组温度").FirstOrDefault(); data.W1CirclingTemperature = W1CirclingTemperature != null ? W1CirclingTemperature.Value : 0.0; PointMapModel W2CirclingTemperature = pointValueList.Where(s => s.PointName == "W2绕组温度").FirstOrDefault(); data.W2CirclingTemperature = W2CirclingTemperature != null ? W2CirclingTemperature.Value : 0.0; PointMapModel poweAxisATemperaturerData = pointValueList.Where(s => s.PointName == "轴承A温度").FirstOrDefault(); data.AxisATemperature = poweAxisATemperaturerData != null ? poweAxisATemperaturerData.Value : 0.0; PointMapModel AxisBTemperature = pointValueList.Where(s => s.PointName == "轴承B温度").FirstOrDefault(); data.AxisBTemperature = AxisBTemperature != null ? AxisBTemperature.Value : 0.0; PointMapModel GearBoxTemperature = pointValueList.Where(s => s.PointName == "齿轮箱温度").FirstOrDefault(); data.GearBoxTemperature = GearBoxTemperature != null ? GearBoxTemperature.Value : 0.0; PointMapModel GearAxis1Temperature = pointValueList.Where(s => s.PointName == "齿轮箱轴1温度").FirstOrDefault(); data.GearAxis1Temperature = GearAxis1Temperature != null ? GearAxis1Temperature.Value : 0.0; PointMapModel GearAxis2Temperature = pointValueList.Where(s => s.PointName == "齿轮箱轴2温度").FirstOrDefault(); data.GearAxis2Temperature = GearAxis2Temperature != null ? GearAxis2Temperature.Value : 0.0; PointMapModel RoomTemperature = pointValueList.Where(s => s.PointName == "机舱温度").FirstOrDefault(); data.RoomTemperature = RoomTemperature != null ? RoomTemperature.Value : 0.0; PointMapModel RoundTemperature = pointValueList.Where(s => s.PointName == "环境温度").FirstOrDefault(); data.RoundTemperature = RoundTemperature != null ? RoundTemperature.Value : 0.0; dataList.Add(data); } } return dataList; } /// /// 获取各个风机对应的统一编码及其含义 /// public void BuilDicUnifromCodeList() { #region 香山 string[] XS_UP105 = { "XG01_01", "XG01_02", "XG01_03", "XG01_04", "XG01_05", "XG01_06", "XG01_07", "XG01_08", "XG01_09", "XG01_10", "XG01_11", "XG01_12", "XG01_13", "XG01_14", "XG01_15", "XG01_16", "XG01_17", "XG01_18", "XG01_19", "XG01_20", "XG01_21", "XG01_22", "XG01_23", "XG01_24", "XG01_25" }; string[] XS_UP97 = { "XG01_26", "XG01_27", "XG01_28", "XG01_29", "XG01_30", "XG01_31", "XG01_32", "XG01_33", "XG01_34", "XG01_35", "XG01_36", "XG01_37", "XG01_38", "XG01_39", "XG01_40", "XG01_41", "XG01_42", "XG01_43", "XG01_44", "XG01_45", "XG01_46", "XG01_47", "XG01_48", "XG01_49", "XG01_50", "XG01_51", "XG01_52", "XG01_53", "XG01_54", "XG01_55", "XG01_56", "XG01_57", "XG01_58", }; Dictionary XS_UP105_UniformCode = new Dictionary();//UP105机型统一编码映射 Dictionary XS_UP97_UniformCode = new Dictionary();//UP97机型统一编码映射 Dictionary XS_Station_UniformCode = new Dictionary();//香山风场相关指标统一 编码映射 XS_UP97_UniformCode.Add("AI054", "冷却风温度"); XS_UP97_UniformCode.Add("AI130", "有功功率"); XS_UP97_UniformCode.Add("AI021", "液压油温度"); XS_UP97_UniformCode.Add("AI045", "U1绕组温度"); XS_UP97_UniformCode.Add("AI046", "U2绕组温度"); XS_UP97_UniformCode.Add("AI047", "V1绕组温度"); XS_UP97_UniformCode.Add("AI048", "V2绕组温度"); XS_UP97_UniformCode.Add("AI049", "W1绕组温度"); XS_UP97_UniformCode.Add("AI050", "W2绕组温度"); XS_UP97_UniformCode.Add("AI052", "轴承A温度"); XS_UP97_UniformCode.Add("AI053", "轴承B温度"); XS_UP97_UniformCode.Add("AI072", "齿轮箱温度"); XS_UP97_UniformCode.Add("AI038", "齿轮箱轴1温度"); XS_UP97_UniformCode.Add("AI039", "齿轮箱轴2温度"); XS_UP97_UniformCode.Add("AI057", "机舱温度"); XS_UP97_UniformCode.Add("AI056", "环境温度"); XS_UP105_UniformCode.Add("AI042", "冷却风温度"); XS_UP105_UniformCode.Add("AI130B", "有功功率"); XS_UP105_UniformCode.Add("AI041", "液压油温度"); XS_UP105_UniformCode.Add("AI045", "U1绕组温度"); XS_UP105_UniformCode.Add("AI046", "U2绕组温度"); XS_UP105_UniformCode.Add("AI047", "V1绕组温度"); XS_UP105_UniformCode.Add("AI048", "V2绕组温度"); XS_UP105_UniformCode.Add("AI049", "W1绕组温度"); XS_UP105_UniformCode.Add("AI050", "W2绕组温度"); XS_UP105_UniformCode.Add("AI052", "轴承A温度"); XS_UP105_UniformCode.Add("AI053", "轴承B温度"); XS_UP105_UniformCode.Add("AI038", "齿轮箱温度"); XS_UP105_UniformCode.Add("AI291", "齿轮箱轴1温度"); XS_UP105_UniformCode.Add("AI292", "齿轮箱轴2温度"); XS_UP105_UniformCode.Add("AI070", "机舱温度"); XS_UP105_UniformCode.Add("AI057", "环境温度"); #endregion #region 石板泉 string[] SBQ_UP105 = { "SG01_67", "SG01_68", "SG01_69", "SG01_70", "SG01_71", "SG01_72", "SG01_73", "SG01_74", "SG01_75", "SG01_76", "SG01_77", "SG01_78", "SG01_79", "SG01_80", "SG01_81", "SG01_82", "SG01_83", "SG01_84", "SG01_85", "SG01_86", "SG01_87", "SG01_88", "SG01_89", "SG01_90", "SG01_91", "SG01_100", "SG01_101", "SG01_102", "SG01_103", "SG01_104", "SG01_105", "SG01_106", "SG01_107", "SG01_108", "SG01_109", "SG01_110", "SG01_111", "SG01_112", "SG01_113", "SG01_114", "SG01_115", "SG01_116", "SG01_92", "SG01_93", "SG01_94", "SG01_95", "SG01_96", "SG01_97", "SG01_98", "SG01_99" }; string[] SBQ_UP82 = { "SG01_01", "SG01_02", "SG01_03", "SG01_04", "SG01_05", "SG01_06", "SG01_07", "SG01_08", "SG01_09", "SG01_10", "SG01_11", "SG01_12", "SG01_13", "SG01_14", "SG01_15", "SG01_16", "SG01_17", "SG01_18", "SG01_19", "SG01_20", "SG01_21", "SG01_22", "SG01_23", "SG01_24", "SG01_25", "SG01_26", "SG01_27", "SG01_28", "SG01_29", "SG01_30", "SG01_31", "SG01_32", "SG01_33" }; string[] SBQ_UP97 = { "SG01_34", "SG01_35", "SG01_36", "SG01_37", "SG01_38", "SG01_39", "SG01_40", "SG01_41", "SG01_42", "SG01_43", "SG01_44", "SG01_45", "SG01_46", "SG01_47", "SG01_48", "SG01_49", "SG01_50", "SG01_51", "SG01_52", "SG01_53", "SG01_54", "SG01_55", "SG01_56", "SG01_57", "SG01_58", "SG01_59", "SG01_60", "SG01_61", "SG01_62", "SG01_63", "SG01_64", "SG01_65", "SG01_66" }; Dictionary SBQ_UP105_UniformCode = new Dictionary();//UP105机型统一编码映射 Dictionary SBQ_UP82_UniformCode = new Dictionary();//UP82机型统一编码映射 Dictionary SBQ_UP97_UniformCode = new Dictionary();//UP97机型统一编码映射 SBQ_UP105_UniformCode.Add("AI042", "冷却风温度"); SBQ_UP105_UniformCode.Add("AI130", "有功功率"); SBQ_UP105_UniformCode.Add("AI041", "液压油温度"); SBQ_UP105_UniformCode.Add("AI045", "U1绕组温度"); SBQ_UP105_UniformCode.Add("AI046", "U2绕组温度"); SBQ_UP105_UniformCode.Add("AI047", "V1绕组温度"); SBQ_UP105_UniformCode.Add("AI048", "V2绕组温度"); SBQ_UP105_UniformCode.Add("AI049", "W1绕组温度"); SBQ_UP105_UniformCode.Add("AI050", "W2绕组温度"); SBQ_UP105_UniformCode.Add("AI052", "轴承A温度"); SBQ_UP105_UniformCode.Add("AI053", "轴承B温度"); SBQ_UP105_UniformCode.Add("AI071", "齿轮箱温度"); SBQ_UP105_UniformCode.Add("AI038", "齿轮箱轴1温度"); SBQ_UP105_UniformCode.Add("AI039", "齿轮箱轴2温度"); SBQ_UP105_UniformCode.Add("AI070", "机舱温度"); SBQ_UP105_UniformCode.Add("AI056", "环境温度"); SBQ_UP82_UniformCode.Add("AI054", "冷却风温度"); SBQ_UP82_UniformCode.Add("AI130", "有功功率"); SBQ_UP82_UniformCode.Add("AI020", "液压油温度"); SBQ_UP82_UniformCode.Add("AI045", "U1绕组温度"); SBQ_UP82_UniformCode.Add("AI046", "U2绕组温度"); SBQ_UP82_UniformCode.Add("AI047", "V1绕组温度"); SBQ_UP82_UniformCode.Add("AI048", "V2绕组温度"); SBQ_UP82_UniformCode.Add("AI049", "W1绕组温度"); SBQ_UP82_UniformCode.Add("AI050", "W2绕组温度"); SBQ_UP82_UniformCode.Add("AI052", "轴承A温度"); SBQ_UP82_UniformCode.Add("AI053", "轴承B温度"); SBQ_UP82_UniformCode.Add("AI041", "齿轮箱温度"); SBQ_UP82_UniformCode.Add("AI038", "齿轮箱轴1温度"); SBQ_UP82_UniformCode.Add("AI039", "齿轮箱轴2温度"); SBQ_UP82_UniformCode.Add("AI057", "机舱温度"); SBQ_UP82_UniformCode.Add("AI056", "环境温度"); SBQ_UP97_UniformCode.Add("AI054", "冷却风温度"); SBQ_UP97_UniformCode.Add("AI130", "有功功率"); SBQ_UP97_UniformCode.Add("AI020", "液压油温度"); SBQ_UP97_UniformCode.Add("AI045", "U1绕组温度"); SBQ_UP97_UniformCode.Add("AI046", "U2绕组温度"); SBQ_UP97_UniformCode.Add("AI047", "V1绕组温度"); SBQ_UP97_UniformCode.Add("AI048", "V2绕组温度"); SBQ_UP97_UniformCode.Add("AI049", "W1绕组温度"); SBQ_UP97_UniformCode.Add("AI050", "W2绕组温度"); SBQ_UP97_UniformCode.Add("AI052", "轴承A温度"); SBQ_UP97_UniformCode.Add("AI053", "轴承B温度"); SBQ_UP97_UniformCode.Add("AI041", "齿轮箱温度"); SBQ_UP97_UniformCode.Add("AI038", "齿轮箱轴1温度"); SBQ_UP97_UniformCode.Add("AI039", "齿轮箱轴2温度"); SBQ_UP97_UniformCode.Add("AI057", "机舱温度"); SBQ_UP97_UniformCode.Add("AI056", "环境温度"); #endregion using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList list = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID.Contains("_FDC")).ToList(); for (int i = 0; i < list.Count; i++) { //香山 if (list[i].WINDPOWERSTATIONID == "XS_FDC") { if (XS_UP105.Contains(list[i].ID)) { dicUniformCodeListByWindturbineId.Add(list[i].ID, XS_UP105_UniformCode); } else { dicUniformCodeListByWindturbineId.Add(list[i].ID, XS_UP97_UniformCode); } } //石板泉 if (list[i].WINDPOWERSTATIONID == "SBQ_FDC") { if (SBQ_UP105.Contains(list[i].ID)) { dicUniformCodeListByWindturbineId.Add(list[i].ID, SBQ_UP105_UniformCode); } else if (SBQ_UP97.Contains(list[i].ID)) { dicUniformCodeListByWindturbineId.Add(list[i].ID, SBQ_UP97_UniformCode); } else { dicUniformCodeListByWindturbineId.Add(list[i].ID, SBQ_UP82_UniformCode); } } //青山 if (list[i].WINDPOWERSTATIONID == "QS_FDC") { } //牛首山 if (list[i].WINDPOWERSTATIONID == "NSS_FDC") { } //麻黄山 if (list[i].WINDPOWERSTATIONID == "MHS_FDC") { } } } } } }