using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GDNXFD.Data.Repositories { public class WindTurbineRepository { public static IList GetWindTurbinies() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbine.ToList(); } } public static IList GetWindTurbinies(string stationId) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbine.Where(q=>q.WindPowerStationId == stationId).ToList(); } } public static IList GetFDCWindTurbinies() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbine.Where(q=>q.WindPowerStationId.EndsWith("FDC")).ToList(); } } public static IList GetEquipmentModels() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.EquipmentModel.ToList(); } } #region 取风机测点 public static IList GetWindTurbineAIPoints(string[] filters) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbineTestingPointAI .Where(q => filters.Contains(q.UniformCode)) //.Select(q => q.Id) .ToList(); } } public static IList GetWindTurbineDIPoints(string[] filters) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbineTestingPointDI .Where(q => filters.Contains(q.UniformCode)) //.Select(q => q.Id) .ToList(); } } public static IList GetWindTurbineAIPoints(string uniformCode) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbineTestingPointAI .Where(q => q.UniformCode == uniformCode) .ToList(); } } /// /// 获取风机报警及首出报警的点 /// /// public static IList GetWindTurbineAIPointsFJBJ() { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbineTestingPointAI //.Where(q => q.UniformCode == "FJBJ" || q.UniformCode == "FJBJ2") .Where(q=>q.UniformCode=="FJBJ2") //只报首出报警 .ToList(); } } public static string GetWindTurbineAIPointId(string wId, string uCode) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbineTestingPointAI .Where(q => q.WindturbineId == wId && q.UniformCode == uCode) .Select(q => q.Id) .FirstOrDefault(); } } public static string[] GetWindTurbineAIPointId(string[] wIds, string uCode) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbineTestingPointAI .Where(q => wIds.Contains(q.WindturbineId) && q.UniformCode == uCode) .Select(q => q.Id).ToArray(); } } public static string GetWindTurbineDIPointId(string wId, string uCode) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.WindTurbineTestingPointDI .Where(q => q.WindturbineId == wId && q.UniformCode == uCode) .Select(q => q.Id) .FirstOrDefault(); } } #endregion #region 取设备类型测点 public static IList GetTestPointAIsByModelId(string modelId) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.TestingPointAI.Where(a => a.ModelId == modelId).ToList(); } } public static IList GetTestPointDIsByModelId(string modelId) { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.TestingPointDI.Where(a => a.ModelId == modelId).ToList(); } } public static IList GetTestPointAIsByModels(IList lstModels) { if (lstModels == null) return null; if (lstModels.Count == 1) return GetTestPointAIsByModelId(lstModels[0]); string sqltemplate = @" select t2.* from ( select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.* from testingpointai t where t.modelid in ({0}) ) t2 where t2.num = {1} "; StringBuilder sbModels = new StringBuilder(); foreach (string m in lstModels) { sbModels.Append("'"); sbModels.Append(m.Trim()); sbModels.Append("',"); } string strModels = sbModels.ToString(); strModels = strModels.TrimEnd(','); string sql = string.Format(sqltemplate, strModels, lstModels.Count); using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.TestingPointAI.SqlQuery(sql, new object[] { }).ToList(); } } public static IList GetTestPointDIsByModels(IList lstModels) { if (lstModels == null) return null; if (lstModels.Count == 1) return GetTestPointDIsByModelId(lstModels[0]); string sqltemplate = @" select t2.* from ( select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.* from testingpointdi t where t.modelid in ({0}) ) t2 where t2.num = {1} "; StringBuilder sbModels = new StringBuilder(); foreach (string m in lstModels) { sbModels.Append("'"); sbModels.Append(m.Trim()); sbModels.Append("',"); } string strModels = sbModels.ToString(); strModels = strModels.TrimEnd(','); string sql = string.Format(sqltemplate, strModels, lstModels.Count); using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { return ctx.TestingPointDI.SqlQuery(sql, new object[] { }).ToList(); } } #endregion #region 其他 #endregion } }