123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GDNXFD.Data.Repositories
- {
- public class WindPowerStationRepository
- {
- #region 基础数据
- public static IList<WindPowerStation> GetWindPowerStations()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindPowerStation.ToList();
- }
- }
- public static IList<DictItem> GetDataDictionary()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.DataDictionary.ToList();
- }
- }
- public static IList<WarningLevel> GetWarningLevels()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WarningLevel.ToList();
- }
- }
- public static IList<Line> GetLines()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.Line.ToList();
- }
- }
- public static IList<Project> GetProjects()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.Project.ToList();
- }
- }
- #endregion
- #region 测点数据
- public static IList<WindPowerStationTestingPoint> GetStationTestingPointsByUniformCode(string uniformcode)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindPowerStationTestingPoint.Where(a => a.UniformCode == uniformcode && a.StationId.EndsWith("_FDC")).ToList();
- }
- }
- public static IList<WindPowerStationTestingPoint> GetStationTestingPoints(string[] uniformcodes)
- {
- if (uniformcodes == null)
- return null;
- if (uniformcodes.Length == 1)
- return GetStationTestingPointsByUniformCode(uniformcodes[0]);
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindPowerStationTestingPoint.Where(a => uniformcodes.Contains(a.UniformCode) && a.StationId.EndsWith("_FDC")).ToList();
- }
- }
- public static IList<LevelTypeTestingPoint> GetLevelTypeTestingPoints()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.LevelTypeTestingPoint.ToList();
- }
- }
- public static IList<ElectricalTestingPointAI> GetElectricalTestingPointAIs()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointAI.ToList();
- }
- }
- public static IList<ElectricalTestingPointDI> GetElectricalTestingPointDIs()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointDI.ToList();
- }
- }
- public static IList<ElectricalTestingPointAI> GetElecTestPointAIsByStationId(string stationId)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointAI.Where(a => a.WindPowerStationId == stationId).ToList();
- }
- }
- public static IList<ElectricalTestingPointAI> GetElecTestPointAIsByStations(IList<string> lstStations)
- {
- if (lstStations == null)
- return null;
- if (lstStations.Count == 1)
- return GetElecTestPointAIsByStationId(lstStations[0]);
- string sqltemplate = @"
- select t2.* from
- (
- select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.*
- from electricaltestingpointai t
- where t.windpowerstationid in ({0})
- ) t2
- where t2.num = {1}
- ";
- StringBuilder sbStations = new StringBuilder();
- foreach (string m in lstStations)
- {
- sbStations.Append("'");
- sbStations.Append(m.Trim());
- sbStations.Append("',");
- }
- string strStations = sbStations.ToString();
- strStations = strStations.TrimEnd(',');
- string sql = string.Format(sqltemplate, strStations, lstStations.Count);
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointAI.SqlQuery(sql, new object[] { }).ToList();
- }
- }
- public static IList<ElectricalTestingPointDI> GetElecTestPointDIsByStationId(string stationId)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointDI.Where(a => a.WindPowerStationId == stationId).ToList();
- }
- }
- public static IList<ElectricalTestingPointDI> GetElecTestPointDIsByStations(IList<string> lstStations)
- {
- if (lstStations == null)
- return null;
- if (lstStations.Count == 1)
- return GetElecTestPointDIsByStationId(lstStations[0]);
- string sqltemplate = @"
- select t2.* from
- (
- select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.*
- from electricaltestingpointdi t
- where t.windpowerstationid in ({0})
- ) t2
- where t2.num = {1}
- ";
- StringBuilder sbStations = new StringBuilder();
- foreach (string m in lstStations)
- {
- sbStations.Append("'");
- sbStations.Append(m.Trim());
- sbStations.Append("',");
- }
- string strStations = sbStations.ToString();
- strStations = strStations.TrimEnd(',');
- string sql = string.Format(sqltemplate, strStations, lstStations.Count);
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointDI.SqlQuery(sql, new object[] { }).ToList();
- }
- }
- public static string GetWindPowerStationPointId(string wId, string uCode)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindPowerStationTestingPoint
- .Where(q => q.StationId == wId && q.UniformCode == uCode)
- .Select(q => q.Id)
- .FirstOrDefault();
- }
- }
- public static string[] GetWindPowerStationPointFJZT(string wId)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- string[] codes = new string[] { "YXTS","TXZD", "DJTS", "WHTJ", "GZTJ", "XDTS" };
- return ctx.WindPowerStationTestingPoint
- .Where(q => q.StationId == wId && codes.Contains(q.UniformCode))
- .OrderBy(q=>q.Id)
- .Select(q => q.Id)
- .ToArray();
- }
- }
- public static string GetElectricalAIPointId(string wId, string uCode)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointAI
- .Where(q => q.WindPowerStationId == wId && q.UniformCode == uCode)
- .Select(q => q.Id)
- .FirstOrDefault();
- }
- }
- public static string GetElectricalDIPointId(string wId, string uCode)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ElectricalTestingPointDI
- .Where(q => q.WindPowerStationId == wId && q.UniformCode == uCode)
- .Select(q => q.Id)
- .FirstOrDefault();
- }
- }
- public static IList<IFixBJTestingPointDI> GetIFixBJPoints()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.IFixBJTestingPointDI.Where(q=>q.Enabled == true).ToList();
- }
- }
- public static IList<Warning> GetWarning()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.Warning.ToList();
- }
- }
- public static IList<ModelPowerDetails> GetModelPowerDetails()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.ModelPowerDetails.ToList();
- }
- }
- #endregion
- public static IList<MaintainPlan> GetMaintainPlans()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- try
- {
- return ctx.MaintainPlan.ToList();
- }
- catch (Exception ex)
- {
- var a = ex;
- return null;
- }
- }
- }
- }
- }
|