using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using EntityDataSet; using IntelligentControlForsx.Model; using IntelligentControlForsx.MyControls; using IntelligentControlForsx.Service.HomeFormInfo.Domain; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.Service.HomeFormInfo { public class HomeFormInfoSvc { private static IList leftList; private static IList leftStatList; private static IList centerList; private static IList centerSBQList; private static IList centerQSList; private static IList centerMHSList; private static IList centerXSList; private static IList centerNSSList; private static IList rightList; private static IList rightSBQList; private static IList rightQSList; private static IList rightMHSList; private static IList rightXSList; private static IList rightNSSList; private static IList rightDWKList; private static IList rightPLList; private static IList rightXHList; private HomeFormInfoSvc() { } public static HomeFormInfoSvc Instance { get { return SingletonCreator.instance; } } class SingletonCreator { internal static readonly HomeFormInfoSvc instance = new HomeFormInfoSvc(); } public LeftInfo GetLeftInfo() { LeftInfo info = new LeftInfo(); IList codeList = new List(); codeList.Add(Point.RFDLB);//日发电量 codeList.Add(Point.YFDL);//月发电量 codeList.Add(Point.NFDL);//年发电量 codeList.Add(Point.YFDLB);//月发电量(升压站) codeList.Add(Point.NFDLB);//年发电量(升压站) codeList.Add(Point.SSZGL);//实时总功率 codeList.Add(Point.SSFS);//全省实时风速 if (leftList == null) { leftList = new List(); GetTagNameList(codeList, "station", "0", ref leftList); } //风电-1 Dictionary dic = RestfulClient.findLatestByTagNames(leftList.Select(s => s.PointId).ToArray()); foreach (KeyValuePair kv in dic) { var data = leftList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } for (int i = 0; i < leftList.Count; i++) { switch (leftList[i].UniformCode) { case "RFDLB": info.PowerByDay = leftList[i].Value.ToString("f2"); break; case "YFDLB": info.PowerByMonth = leftList[i].Value.ToString("f2"); break; case "NFDLB": info.PowerByYear = leftList[i].Value.ToString("f2"); break; case "SSFS": info.WindSpeedNow = leftList[i].Value.ToString("f2"); break; case "SSZGL": info.PowerNow = leftList[i].Value.ToString("f2"); break; } } #region 全场风机状态统计 IList statUniformCodeList = new List(); statUniformCodeList.Add("YXTS");//全省运行台数 statUniformCodeList.Add("GZTJ"); //全省故障台数 statUniformCodeList.Add("DJTS"); //全省待机台数 statUniformCodeList.Add("TXZD"); //全省离线台数 statUniformCodeList.Add("TJNUM"); //全省停机台数 statUniformCodeList.Add("WHTJ"); //全省维护台数 if (leftStatList == null) { leftStatList = new List(); GetTagNameList(statUniformCodeList, "station", "-1", ref leftStatList); } Dictionary statDic = RestfulClient.findLatestByTagNames(leftStatList.Select(s => s.PointId).ToArray()); foreach (KeyValuePair kv in statDic) { var data = leftStatList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } for (int i = 0; i < leftStatList.Count; i++) { switch (leftStatList[i].UniformCode) { case "YXTS": info.RunCount = leftStatList[i].Value.ToString(); break; case "GZTJ": info.FaultCount = leftStatList[i].Value.ToString(); break; case "WHTJ": info.MaintainCount = leftStatList[i].Value.ToString(); break; case "TJNUM": info.StopCount = leftStatList[i].Value.ToString(); break; case "TXZD": info.OfflineCount = leftStatList[i].Value.ToString(); break; case "DJTS": info.StandByCount = leftStatList[i].Value.ToString(); break; } } #endregion info.PowerAll = "674.5"; double powerByMounth = Convert.ToDouble(leftList.Where(s => s.UniformCode == Point.YFDLB).FirstOrDefault().Value); double result1 = ((powerByMounth / 67.45) * 100) / 100; info.UseHourByMounth = result1.ToString("f2"); double powerByyear = Convert.ToDouble(leftList.Where(s => s.UniformCode == Point.NFDL).FirstOrDefault().Value); double result2 = ((powerByyear / 67.45) * 100) / 100; info.UseHourByYear = result2.ToString("f2"); info.LinkCount = "382"; return info; } public CenterInfo GetCenterInfo() { CenterInfo info = new CenterInfo(); IList codeList = new List(); codeList.Add(Point.SSFS);//实时风速 codeList.Add(Point.RFDL);//日发电量 codeList.Add(Point.SSZGL);//实时总功率 codeList.Add(Point.YXTS);//运行3 codeList.Add(Point.GZTJ);//故障4 codeList.Add(Point.DJTS);//待机5 codeList.Add(Point.XDTS);//限电6 codeList.Add(Point.WHTJ);//维护7 codeList.Add(Point.LXTS);//离线8 if (centerList == null) { centerList = new List(); GetTagNameList(codeList, "station", "-1", ref centerList); } if (centerMHSList == null) { centerMHSList = new List(); GetTagNameList(codeList, "station", "MHS_FDC", ref centerMHSList); } if (centerNSSList == null) { centerNSSList = new List(); GetTagNameList(codeList, "station", "NSS_FDC", ref centerNSSList); } if (centerSBQList == null) { centerSBQList = new List(); GetTagNameList(codeList, "station", "SBQ_FDC", ref centerSBQList); } if (centerQSList == null) { centerQSList = new List(); GetTagNameList(codeList, "station", "QS_FDC", ref centerQSList); } if (centerXSList == null) { centerXSList = new List(); GetTagNameList(codeList, "station", "XS_FDC", ref centerXSList); } Dictionary dicSBQ = RestfulClient.findLatestByTagNames(centerSBQList.Select(s => s.PointId).ToArray()); Dictionary dicQS = RestfulClient.findLatestByTagNames(centerQSList.Select(s => s.PointId).ToArray()); Dictionary dicMHS = RestfulClient.findLatestByTagNames(centerMHSList.Select(s => s.PointId).ToArray()); Dictionary dicXS = RestfulClient.findLatestByTagNames(centerXSList.Select(s => s.PointId).ToArray()); Dictionary dicNSS = RestfulClient.findLatestByTagNames(centerNSSList.Select(s => s.PointId).ToArray()); foreach (KeyValuePair kv in dicSBQ) { var data = centerSBQList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicQS) { var data = centerQSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicMHS) { var data = centerMHSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicXS) { var data = centerXSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicNSS) { var data = centerNSSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } info.NSS_Speed = GetValueByUniformCode(codeList[0], centerNSSList); info.NSS_PowerByDay = GetValueByUniformCode(codeList[1], centerNSSList); info.NSS_PowerByNow = GetValueByUniformCode(codeList[2], centerNSSList); info.NSS_Status = GetStatusByStation(centerNSSList); info.SBQ_Speed = GetValueByUniformCode(codeList[0], centerSBQList); info.SBQ_PowerByDay = GetValueByUniformCode(codeList[1], centerSBQList); info.SBQ_PowerByNow = GetValueByUniformCode(codeList[2], centerSBQList); info.SBQ_Status = GetStatusByStation(centerSBQList); info.MHS_Speed = GetValueByUniformCode(codeList[0], centerMHSList); info.MHS_PowerByDay = GetValueByUniformCode(codeList[1], centerMHSList); ; info.MHS_PowerByNow = GetValueByUniformCode(codeList[2], centerMHSList); info.MHS_Status = GetStatusByStation(centerMHSList); info.XS_Speed = GetValueByUniformCode(codeList[0], centerNSSList); info.XS_PowerByDay = GetValueByUniformCode(codeList[1], centerXSList); info.XS_PowerByNow = GetValueByUniformCode(codeList[2], centerXSList); info.XS_Status = GetStatusByStation(centerXSList); info.QS_Speed = GetValueByUniformCode(codeList[0], centerNSSList); info.QS_PowerByDay = GetValueByUniformCode(codeList[1], centerQSList); info.QS_PowerByNow = GetValueByUniformCode(codeList[2], centerQSList); info.QS_Status = GetStatusByStation(centerQSList); return info; } public RightInfo GetRightInfo() { RightInfo info = new RightInfo(); IList codeList = new List(); codeList.Add(Point.RFDL); //宣和日发电量 IList xhCodeList = new List(); xhCodeList.Add("RFDLB"); if (rightList == null || rightList.Count == 0) { rightList = new List(); GetTagNameList(codeList, "station", "-1", ref rightList); } if (rightMHSList == null || rightMHSList.Count == 0) { rightMHSList = new List(); GetTagNameList(codeList, "station", "MHS_FDC", ref rightMHSList); } if (rightNSSList == null || rightNSSList.Count == 0) { rightNSSList = new List(); GetTagNameList(codeList, "station", "NSS_FDC", ref rightNSSList); } if (rightSBQList == null || rightSBQList.Count == 0) { rightSBQList = new List(); GetTagNameList(codeList, "station", "SBQ_FDC", ref rightSBQList); } if (rightQSList == null || rightQSList.Count == 0) { rightQSList = new List(); GetTagNameList(codeList, "station", "QS_FDC", ref rightQSList); } if (rightXSList == null || rightXSList.Count == 0) { rightXSList = new List(); GetTagNameList(codeList, "station", "XS_FDC", ref rightXSList); } if (rightDWKList == null || rightDWKList.Count == 0) { rightDWKList = new List(); GetTagNameList(codeList, "station", "DWK_GDC", ref rightDWKList); } if (rightPLList == null || rightPLList.Count == 0) { rightPLList = new List(); GetTagNameList(codeList, "station", "PL_GDC", ref rightPLList); } if (rightXHList == null || rightXHList.Count == 0) { rightXHList = new List(); GetTagNameList(xhCodeList, "station", "XH_GDC", ref rightXHList); } Dictionary dicSBQ = RestfulClient.findLatestByTagNames(rightSBQList.Select(s => s.PointId).ToArray()); Dictionary dicQS = RestfulClient.findLatestByTagNames(rightQSList.Select(s => s.PointId).ToArray()); Dictionary dicMHS = RestfulClient.findLatestByTagNames(rightMHSList.Select(s => s.PointId).ToArray()); Dictionary dicXS = RestfulClient.findLatestByTagNames(rightXSList.Select(s => s.PointId).ToArray()); Dictionary dicNSS = RestfulClient.findLatestByTagNames(rightNSSList.Select(s => s.PointId).ToArray()); Dictionary dicDWK = RestfulClient.findLatestByTagNames(rightDWKList.Select(s => s.PointId).ToArray()); Dictionary dicPL = RestfulClient.findLatestByTagNames(rightPLList.Select(s => s.PointId).ToArray()); Dictionary dicXH = RestfulClient.findLatestByTagNames(rightXHList.Select(s => s.PointId).ToArray()); foreach (KeyValuePair kv in dicSBQ) { var data = rightSBQList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicQS) { var data = rightQSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicMHS) { var data = rightMHSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicXS) { var data = rightXSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicNSS) { var data = rightNSSList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicDWK) { var data = rightDWKList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicPL) { var data = rightPLList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } foreach (KeyValuePair kv in dicXH) { var data = rightXHList.Where(s => s.PointId == kv.Key).FirstOrDefault(); if (data != null) data.Value = Convert.ToDouble(kv.Value.getValue()); } IList list = new List(); Info sbqInfo = new Info() { Station = "石板泉", Power = Convert.ToDouble(GetValueByUniformCode(codeList[0], rightSBQList)) }; Info qsInfo = new Info() { Station = "青山", Power = Convert.ToDouble(GetValueByUniformCode(codeList[0], rightQSList)) }; Info mhsInfo = new Info() { Station = "麻黄山", Power = Convert.ToDouble(GetValueByUniformCode(codeList[0], rightMHSList)) }; Info xsInfo = new Info() { Station = "香山", Power = Convert.ToDouble(GetValueByUniformCode(codeList[0], rightXSList)) }; Info nssInfo = new Info() { Station = "牛首山", Power = Convert.ToDouble(GetValueByUniformCode(codeList[0], rightNSSList)) }; Info dwkInfo = new Info() { Station = "大武口", Power = Convert.ToDouble(GetValueByUniformCode(codeList[0], rightDWKList)) }; Info plInfo = new Info() { Station = "平罗", Power = Convert.ToDouble(GetValueByUniformCode(codeList[0], rightPLList)) }; Info xhInfo = new Info() { Station = "宣和", Power = Convert.ToDouble(GetValueByUniformCode(xhCodeList[0], rightXHList)) }; list.Add(dwkInfo); list.Add(plInfo); list.Add(xhInfo); list.Add(sbqInfo); list.Add(qsInfo); list.Add(mhsInfo); list.Add(xsInfo); list.Add(nssInfo); info.InfoList = list; //安全生产天数 Dictionary aqDic = RestfulClient.findLatestByTagNames(new[] { "JSFW.NX_GD_XXX_XX_XX_XXX_XXX_CI0220" }); if (aqDic.Select(s => s.Value).ToList().Count > 0) info.SafetyDayCount = aqDic.Select(s => s.Value).ToList()[0].getValue(); else info.SafetyDayCount = "NAN"; DateTime FirstTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); DateTime startDateTime = DateTime.Now.AddHours(-12); long startTimeStamp = (long)(startDateTime - FirstTime).TotalMilliseconds; long endTimeStamp = (long)(DateTime.Now - FirstTime).TotalMilliseconds; List speedList = RestfulClient.findHistorySnapByThingCodes("station", "-1", "SSFS", startTimeStamp, endTimeStamp, 3600); List powerList = RestfulClient.findHistorySnapByThingCodes("station", "0", Point.SSZGL, startTimeStamp, endTimeStamp, 3600); if (speedList != null && powerList != null && speedList.Count == powerList.Count) { info.DateTimeArray = new DateTime[powerList.Count]; info.PowerArray = new double[powerList.Count]; info.SpeedArray = new double[powerList.Count]; for (int i = 0; i < powerList.Count; i++) { info.DateTimeArray[i] = ConvertStringToDateTime(speedList[i].ts.ToString()); info.PowerArray[i] = Convert.ToDouble(powerList[i].getValue()); info.SpeedArray[i] = Convert.ToDouble(speedList[i].getValue()); } } return info; } //限电5》运行1》待机0》维护4》故障2》离线3 private Status GetStatusByStation(IList list) { var xdData = list.Where(s => s.UniformCode == Point.XDTS).FirstOrDefault(); int xdCount = Convert.ToInt32(xdData.Value); var yxData = list.Where(s => s.UniformCode == Point.YXTS).FirstOrDefault(); int yxCount = Convert.ToInt32(yxData.Value); var djData = list.Where(s => s.UniformCode == Point.DJTS).FirstOrDefault(); int djCount = Convert.ToInt32(djData.Value); var whData = list.Where(s => s.UniformCode == Point.WHTJ).FirstOrDefault(); int whCount = Convert.ToInt32(whData.Value); var gzData = list.Where(s => s.UniformCode == Point.GZTJ).FirstOrDefault(); int gzCount = Convert.ToInt32(gzData.Value); var lxData = list.Where(s => s.UniformCode == Point.LXTS).FirstOrDefault(); int lxCount = Convert.ToInt32(lxData.Value); if (xdCount > 0) return Status.Limit; else if (yxCount > 0) return Status.Run; else if (djCount > 0) return Status.StandBy; else if (whCount > 0) return Status.Maintain; else if (gzCount > 0) return Status.Falut; else if (lxCount > 0) return Status.Offline; else return Status.StandBy; } private string GetValueByUniformCode(string uniformCode, IList list) { var data = list.Where(s => s.UniformCode == uniformCode).FirstOrDefault(); if (data != null) return data.Value.ToString("f2"); else return ""; } private DateTime ConvertStringToDateTime(string timeStamp) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp.Substring(0,timeStamp.Length-3)+ "0000000"); TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow); } public void GetTagNameList(IList codeList, string type, string thingId, ref IList tagNameList) { using (wisdom_cs_entity entity = new wisdom_cs_entity()) { if (type == "station") { IList pointList = entity.windpowerstationtestingpoint.Where( s => s.WINDPOWERSTATIONID == thingId && codeList.Contains(s.UNIFORMCODE)).ToList(); for (int i = 0; i < pointList.Count; i++) { PointMapModel model = new PointMapModel(); model.ThingType = 0; model.DataType = 0; model.ThingId = thingId; model.PointName = pointList[i].NAME; model.PointId = pointList[i].CODE; model.UniformCode = pointList[i].UNIFORMCODE; tagNameList.Add(model); } } } } } }