123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- 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<PointMapModel> leftList;
- private static IList<PointMapModel> leftStatList;
- private static IList<PointMapModel> centerList;
- private static IList<PointMapModel> centerSBQList;
- private static IList<PointMapModel> centerQSList;
- private static IList<PointMapModel> centerMHSList;
- private static IList<PointMapModel> centerXSList;
- private static IList<PointMapModel> centerNSSList;
- private static IList<PointMapModel> rightList;
- private static IList<PointMapModel> rightSBQList;
- private static IList<PointMapModel> rightQSList;
- private static IList<PointMapModel> rightMHSList;
- private static IList<PointMapModel> rightXSList;
- private static IList<PointMapModel> rightNSSList;
- private static IList<PointMapModel> rightDWKList;
- private static IList<PointMapModel> rightPLList;
- private static IList<PointMapModel> 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<string> codeList = new List<string>();
- 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<PointMapModel>();
- GetTagNameList(codeList, "station", "0", ref leftList);
- }
- //风电-1
- Dictionary<string, TsData> dic = RestfulClient.findLatestByTagNames(leftList.Select(s => s.PointId).ToArray());
- foreach (KeyValuePair<string, TsData> 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<string> statUniformCodeList = new List<string>();
- statUniformCodeList.Add("YXTS");//全省运行台数
- statUniformCodeList.Add("GZTJ"); //全省故障台数
- statUniformCodeList.Add("DJTS"); //全省待机台数
- statUniformCodeList.Add("TXZD"); //全省离线台数
- statUniformCodeList.Add("TJNUM"); //全省停机台数
- statUniformCodeList.Add("WHTJ"); //全省维护台数
- if (leftStatList == null)
- {
- leftStatList = new List<PointMapModel>();
- GetTagNameList(statUniformCodeList, "station", "-1", ref leftStatList);
- }
- Dictionary<string, TsData> statDic = RestfulClient.findLatestByTagNames(leftStatList.Select(s => s.PointId).ToArray());
- foreach (KeyValuePair<string, TsData> 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<string> codeList = new List<string>();
- 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<PointMapModel>();
- GetTagNameList(codeList, "station", "-1", ref centerList);
- }
- if (centerMHSList == null)
- {
- centerMHSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "MHS_FDC", ref centerMHSList);
- }
- if (centerNSSList == null)
- {
- centerNSSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "NSS_FDC", ref centerNSSList);
- }
- if (centerSBQList == null)
- {
- centerSBQList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "SBQ_FDC", ref centerSBQList);
- }
- if (centerQSList == null)
- {
- centerQSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "QS_FDC", ref centerQSList);
- }
- if (centerXSList == null)
- {
- centerXSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "XS_FDC", ref centerXSList);
- }
- Dictionary<string, TsData> dicSBQ = RestfulClient.findLatestByTagNames(centerSBQList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicQS = RestfulClient.findLatestByTagNames(centerQSList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicMHS = RestfulClient.findLatestByTagNames(centerMHSList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicXS = RestfulClient.findLatestByTagNames(centerXSList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicNSS = RestfulClient.findLatestByTagNames(centerNSSList.Select(s => s.PointId).ToArray());
- foreach (KeyValuePair<string, TsData> 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<string, TsData> 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<string, TsData> 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<string, TsData> 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<string, TsData> 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<string> codeList = new List<string>();
- codeList.Add(Point.RFDL);
- //宣和日发电量
- IList<string> xhCodeList = new List<string>();
- xhCodeList.Add("RFDLB");
- if (rightList == null || rightList.Count == 0)
- {
- rightList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "-1", ref rightList);
- }
- if (rightMHSList == null || rightMHSList.Count == 0)
- {
- rightMHSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "MHS_FDC", ref rightMHSList);
- }
- if (rightNSSList == null || rightNSSList.Count == 0)
- {
- rightNSSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "NSS_FDC", ref rightNSSList);
- }
- if (rightSBQList == null || rightSBQList.Count == 0)
- {
- rightSBQList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "SBQ_FDC", ref rightSBQList);
- }
- if (rightQSList == null || rightQSList.Count == 0)
- {
- rightQSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "QS_FDC", ref rightQSList);
- }
- if (rightXSList == null || rightXSList.Count == 0)
- {
- rightXSList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "XS_FDC", ref rightXSList);
- }
- if (rightDWKList == null || rightDWKList.Count == 0)
- {
- rightDWKList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "DWK_GDC", ref rightDWKList);
- }
- if (rightPLList == null || rightPLList.Count == 0)
- {
- rightPLList = new List<PointMapModel>();
- GetTagNameList(codeList, "station", "PL_GDC", ref rightPLList);
- }
- if (rightXHList == null || rightXHList.Count == 0)
- {
- rightXHList = new List<PointMapModel>();
-
- GetTagNameList(xhCodeList, "station", "XH_GDC", ref rightXHList);
- }
- Dictionary<string, TsData> dicSBQ = RestfulClient.findLatestByTagNames(rightSBQList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicQS = RestfulClient.findLatestByTagNames(rightQSList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicMHS = RestfulClient.findLatestByTagNames(rightMHSList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicXS = RestfulClient.findLatestByTagNames(rightXSList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicNSS = RestfulClient.findLatestByTagNames(rightNSSList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicDWK = RestfulClient.findLatestByTagNames(rightDWKList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicPL = RestfulClient.findLatestByTagNames(rightPLList.Select(s => s.PointId).ToArray());
- Dictionary<string, TsData> dicXH = RestfulClient.findLatestByTagNames(rightXHList.Select(s => s.PointId).ToArray());
- foreach (KeyValuePair<string, TsData> 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<string, TsData> 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<string, TsData> 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<string, TsData> 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<string, TsData> 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<string, TsData> 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<string, TsData> 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<string, TsData> kv in dicXH)
- {
- var data = rightXHList.Where(s => s.PointId == kv.Key).FirstOrDefault();
- if (data != null)
- data.Value = Convert.ToDouble(kv.Value.getValue());
- }
- IList<Info> list = new List<Info>();
- 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<string, TsData> 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<TsData> speedList = RestfulClient.findHistorySnapByThingCodes("station", "-1", "SSFS", startTimeStamp, endTimeStamp, 3600);
- List<TsData> 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<PointMapModel> 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<PointMapModel> 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<string> codeList, string type, string thingId, ref IList<PointMapModel> tagNameList)
- {
- using (wisdom_cs_entity entity = new wisdom_cs_entity())
- {
- if (type == "station")
- {
- IList<windpowerstationtestingpoint> 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);
- }
- }
- }
- }
- }
- }
|