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 GetWindPowerStations() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindPowerStation.ToList(); } } public static IList GetDataDictionary() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.DataDictionary.ToList(); } } public static IList GetWarningLevels() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WarningLevel.ToList(); } } public static IList GetLines() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.Line.ToList(); } } public static IList GetProjects() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.Project.ToList(); } } #endregion #region 测点数据 public static IList GetStationTestingPointsByUniformCode(string uniformcode) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindPowerStationTestingPoint.Where(a => a.UniformCode == uniformcode && a.StationId.EndsWith("_FDC")).ToList(); } } public static IList 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 GetLevelTypeTestingPoints() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.LevelTypeTestingPoint.ToList(); } } public static IList GetElectricalTestingPointAIs() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.ElectricalTestingPointAI.ToList(); } } public static IList GetElectricalTestingPointDIs() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.ElectricalTestingPointDI.ToList(); } } public static IList GetElecTestPointAIsByStationId(string stationId) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.ElectricalTestingPointAI.Where(a => a.WindPowerStationId == stationId).ToList(); } } public static IList GetElecTestPointAIsByStations(IList 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 GetElecTestPointDIsByStationId(string stationId) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.ElectricalTestingPointDI.Where(a => a.WindPowerStationId == stationId).ToList(); } } public static IList GetElecTestPointDIsByStations(IList 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 GetIFixBJPoints() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.IFixBJTestingPointDI.Where(q=>q.Enabled == true).ToList(); } } public static IList GetWarning() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.Warning.ToList(); } } public static IList GetModelPowerDetails() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.ModelPowerDetails.ToList(); } } #endregion public static IList GetMaintainPlans() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { try { return ctx.MaintainPlan.ToList(); } catch (Exception ex) { var a = ex; return null; } } } } }