123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- 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<WindTurbine> GetWindTurbinies()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindTurbine.ToList();
- }
- }
- public static IList<WindTurbine> GetWindTurbinies(string stationId)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindTurbine.Where(q=>q.WindPowerStationId == stationId).ToList();
- }
- }
- public static IList<WindTurbine> GetFDCWindTurbinies()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindTurbine.Where(q=>q.WindPowerStationId.EndsWith("FDC")).ToList();
- }
- }
- public static IList<EquipmentModel> GetEquipmentModels()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.EquipmentModel.ToList();
- }
- }
- #region 取风机测点
- public static IList<WindTurbineTestingPointAI> 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<WindTurbineTestingPointDI> 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<WindTurbineTestingPointAI> GetWindTurbineAIPoints(string uniformCode)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindTurbineTestingPointAI
- .Where(q => q.UniformCode == uniformCode)
- .ToList();
- }
- }
-
- /// <summary>
- /// 获取风机报警及首出报警的点
- /// </summary>
- /// <returns></returns>
- public static IList<WindTurbineTestingPointAI> 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<TestingPointAI> GetTestPointAIsByModelId(string modelId)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.TestingPointAI.Where(a => a.ModelId == modelId).ToList();
- }
- }
- public static IList<TestingPointDI> GetTestPointDIsByModelId(string modelId)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.TestingPointDI.Where(a => a.ModelId == modelId).ToList();
- }
- }
- public static IList<TestingPointAI> GetTestPointAIsByModels(IList<string> 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<TestingPointDI> GetTestPointDIsByModels(IList<string> 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
- }
- }
|