WindTurbineRepository.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace GDNXFD.Data.Repositories
  7. {
  8. public class WindTurbineRepository
  9. {
  10. public static IList<WindTurbine> GetWindTurbinies()
  11. {
  12. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  13. {
  14. return ctx.WindTurbine.ToList();
  15. }
  16. }
  17. public static IList<WindTurbine> GetWindTurbinies(string stationId)
  18. {
  19. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  20. {
  21. return ctx.WindTurbine.Where(q=>q.WindPowerStationId == stationId).ToList();
  22. }
  23. }
  24. public static IList<WindTurbine> GetFDCWindTurbinies()
  25. {
  26. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  27. {
  28. return ctx.WindTurbine.Where(q=>q.WindPowerStationId.EndsWith("FDC")).ToList();
  29. }
  30. }
  31. public static IList<EquipmentModel> GetEquipmentModels()
  32. {
  33. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  34. {
  35. return ctx.EquipmentModel.ToList();
  36. }
  37. }
  38. #region 取风机测点
  39. public static IList<WindTurbineTestingPointAI> GetWindTurbineAIPoints(string[] filters)
  40. {
  41. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  42. {
  43. return ctx.WindTurbineTestingPointAI
  44. .Where(q => filters.Contains(q.UniformCode))
  45. //.Select(q => q.Id)
  46. .ToList();
  47. }
  48. }
  49. public static IList<WindTurbineTestingPointDI> GetWindTurbineDIPoints(string[] filters)
  50. {
  51. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  52. {
  53. return ctx.WindTurbineTestingPointDI
  54. .Where(q => filters.Contains(q.UniformCode))
  55. //.Select(q => q.Id)
  56. .ToList();
  57. }
  58. }
  59. public static IList<WindTurbineTestingPointAI> GetWindTurbineAIPoints(string uniformCode)
  60. {
  61. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  62. {
  63. return ctx.WindTurbineTestingPointAI
  64. .Where(q => q.UniformCode == uniformCode)
  65. .ToList();
  66. }
  67. }
  68. /// <summary>
  69. /// 获取风机报警及首出报警的点
  70. /// </summary>
  71. /// <returns></returns>
  72. public static IList<WindTurbineTestingPointAI> GetWindTurbineAIPointsFJBJ()
  73. {
  74. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  75. {
  76. return ctx.WindTurbineTestingPointAI
  77. //.Where(q => q.UniformCode == "FJBJ" || q.UniformCode == "FJBJ2")
  78. .Where(q=>q.UniformCode=="FJBJ2") //只报首出报警
  79. .ToList();
  80. }
  81. }
  82. public static string GetWindTurbineAIPointId(string wId, string uCode)
  83. {
  84. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  85. {
  86. return ctx.WindTurbineTestingPointAI
  87. .Where(q => q.WindturbineId == wId && q.UniformCode == uCode)
  88. .Select(q => q.Id)
  89. .FirstOrDefault();
  90. }
  91. }
  92. public static string[] GetWindTurbineAIPointId(string[] wIds, string uCode)
  93. {
  94. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  95. {
  96. return ctx.WindTurbineTestingPointAI
  97. .Where(q => wIds.Contains(q.WindturbineId) && q.UniformCode == uCode)
  98. .Select(q => q.Id).ToArray();
  99. }
  100. }
  101. public static string GetWindTurbineDIPointId(string wId, string uCode)
  102. {
  103. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  104. {
  105. return ctx.WindTurbineTestingPointDI
  106. .Where(q => q.WindturbineId == wId && q.UniformCode == uCode)
  107. .Select(q => q.Id)
  108. .FirstOrDefault();
  109. }
  110. }
  111. #endregion
  112. #region 取设备类型测点
  113. public static IList<TestingPointAI> GetTestPointAIsByModelId(string modelId)
  114. {
  115. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  116. {
  117. return ctx.TestingPointAI.Where(a => a.ModelId == modelId).ToList();
  118. }
  119. }
  120. public static IList<TestingPointDI> GetTestPointDIsByModelId(string modelId)
  121. {
  122. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  123. {
  124. return ctx.TestingPointDI.Where(a => a.ModelId == modelId).ToList();
  125. }
  126. }
  127. public static IList<TestingPointAI> GetTestPointAIsByModels(IList<string> lstModels)
  128. {
  129. if (lstModels == null)
  130. return null;
  131. if (lstModels.Count == 1)
  132. return GetTestPointAIsByModelId(lstModels[0]);
  133. string sqltemplate = @"
  134. select t2.* from
  135. (
  136. select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.*
  137. from testingpointai t
  138. where t.modelid in ({0})
  139. ) t2
  140. where t2.num = {1}
  141. ";
  142. StringBuilder sbModels = new StringBuilder();
  143. foreach (string m in lstModels)
  144. {
  145. sbModels.Append("'");
  146. sbModels.Append(m.Trim());
  147. sbModels.Append("',");
  148. }
  149. string strModels = sbModels.ToString();
  150. strModels = strModels.TrimEnd(',');
  151. string sql = string.Format(sqltemplate, strModels, lstModels.Count);
  152. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  153. {
  154. return ctx.TestingPointAI.SqlQuery(sql, new object[] { }).ToList();
  155. }
  156. }
  157. public static IList<TestingPointDI> GetTestPointDIsByModels(IList<string> lstModels)
  158. {
  159. if (lstModels == null)
  160. return null;
  161. if (lstModels.Count == 1)
  162. return GetTestPointDIsByModelId(lstModels[0]);
  163. string sqltemplate = @"
  164. select t2.* from
  165. (
  166. select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.*
  167. from testingpointdi t
  168. where t.modelid in ({0})
  169. ) t2
  170. where t2.num = {1}
  171. ";
  172. StringBuilder sbModels = new StringBuilder();
  173. foreach (string m in lstModels)
  174. {
  175. sbModels.Append("'");
  176. sbModels.Append(m.Trim());
  177. sbModels.Append("',");
  178. }
  179. string strModels = sbModels.ToString();
  180. strModels = strModels.TrimEnd(',');
  181. string sql = string.Format(sqltemplate, strModels, lstModels.Count);
  182. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  183. {
  184. return ctx.TestingPointDI.SqlQuery(sql, new object[] { }).ToList();
  185. }
  186. }
  187. #endregion
  188. #region 其他
  189. #endregion
  190. }
  191. }