WindPowerStationRepository.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 WindPowerStationRepository
  9. {
  10. #region 基础数据
  11. public static IList<WindPowerStation> GetWindPowerStations()
  12. {
  13. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  14. {
  15. return ctx.WindPowerStation.ToList();
  16. }
  17. }
  18. public static IList<DictItem> GetDataDictionary()
  19. {
  20. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  21. {
  22. return ctx.DataDictionary.ToList();
  23. }
  24. }
  25. public static IList<WarningLevel> GetWarningLevels()
  26. {
  27. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  28. {
  29. return ctx.WarningLevel.ToList();
  30. }
  31. }
  32. public static IList<Line> GetLines()
  33. {
  34. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  35. {
  36. return ctx.Line.ToList();
  37. }
  38. }
  39. public static IList<Project> GetProjects()
  40. {
  41. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  42. {
  43. return ctx.Project.ToList();
  44. }
  45. }
  46. #endregion
  47. #region 测点数据
  48. public static IList<WindPowerStationTestingPoint> GetStationTestingPointsByUniformCode(string uniformcode)
  49. {
  50. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  51. {
  52. return ctx.WindPowerStationTestingPoint.Where(a => a.UniformCode == uniformcode && a.StationId.EndsWith("_FDC")).ToList();
  53. }
  54. }
  55. public static IList<WindPowerStationTestingPoint> GetStationTestingPoints(string[] uniformcodes)
  56. {
  57. if (uniformcodes == null)
  58. return null;
  59. if (uniformcodes.Length == 1)
  60. return GetStationTestingPointsByUniformCode(uniformcodes[0]);
  61. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  62. {
  63. return ctx.WindPowerStationTestingPoint.Where(a => uniformcodes.Contains(a.UniformCode) && a.StationId.EndsWith("_FDC")).ToList();
  64. }
  65. }
  66. public static IList<LevelTypeTestingPoint> GetLevelTypeTestingPoints()
  67. {
  68. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  69. {
  70. return ctx.LevelTypeTestingPoint.ToList();
  71. }
  72. }
  73. public static IList<ElectricalTestingPointAI> GetElectricalTestingPointAIs()
  74. {
  75. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  76. {
  77. return ctx.ElectricalTestingPointAI.ToList();
  78. }
  79. }
  80. public static IList<ElectricalTestingPointDI> GetElectricalTestingPointDIs()
  81. {
  82. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  83. {
  84. return ctx.ElectricalTestingPointDI.ToList();
  85. }
  86. }
  87. public static IList<ElectricalTestingPointAI> GetElecTestPointAIsByStationId(string stationId)
  88. {
  89. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  90. {
  91. return ctx.ElectricalTestingPointAI.Where(a => a.WindPowerStationId == stationId).ToList();
  92. }
  93. }
  94. public static IList<ElectricalTestingPointAI> GetElecTestPointAIsByStations(IList<string> lstStations)
  95. {
  96. if (lstStations == null)
  97. return null;
  98. if (lstStations.Count == 1)
  99. return GetElecTestPointAIsByStationId(lstStations[0]);
  100. string sqltemplate = @"
  101. select t2.* from
  102. (
  103. select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.*
  104. from electricaltestingpointai t
  105. where t.windpowerstationid in ({0})
  106. ) t2
  107. where t2.num = {1}
  108. ";
  109. StringBuilder sbStations = new StringBuilder();
  110. foreach (string m in lstStations)
  111. {
  112. sbStations.Append("'");
  113. sbStations.Append(m.Trim());
  114. sbStations.Append("',");
  115. }
  116. string strStations = sbStations.ToString();
  117. strStations = strStations.TrimEnd(',');
  118. string sql = string.Format(sqltemplate, strStations, lstStations.Count);
  119. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  120. {
  121. return ctx.ElectricalTestingPointAI.SqlQuery(sql, new object[] { }).ToList();
  122. }
  123. }
  124. public static IList<ElectricalTestingPointDI> GetElecTestPointDIsByStationId(string stationId)
  125. {
  126. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  127. {
  128. return ctx.ElectricalTestingPointDI.Where(a => a.WindPowerStationId == stationId).ToList();
  129. }
  130. }
  131. public static IList<ElectricalTestingPointDI> GetElecTestPointDIsByStations(IList<string> lstStations)
  132. {
  133. if (lstStations == null)
  134. return null;
  135. if (lstStations.Count == 1)
  136. return GetElecTestPointDIsByStationId(lstStations[0]);
  137. string sqltemplate = @"
  138. select t2.* from
  139. (
  140. select ROW_NUMBER() over(PARTITION by uniformcode order by uniformcode desc) as num, t.*
  141. from electricaltestingpointdi t
  142. where t.windpowerstationid in ({0})
  143. ) t2
  144. where t2.num = {1}
  145. ";
  146. StringBuilder sbStations = new StringBuilder();
  147. foreach (string m in lstStations)
  148. {
  149. sbStations.Append("'");
  150. sbStations.Append(m.Trim());
  151. sbStations.Append("',");
  152. }
  153. string strStations = sbStations.ToString();
  154. strStations = strStations.TrimEnd(',');
  155. string sql = string.Format(sqltemplate, strStations, lstStations.Count);
  156. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  157. {
  158. return ctx.ElectricalTestingPointDI.SqlQuery(sql, new object[] { }).ToList();
  159. }
  160. }
  161. public static string GetWindPowerStationPointId(string wId, string uCode)
  162. {
  163. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  164. {
  165. return ctx.WindPowerStationTestingPoint
  166. .Where(q => q.StationId == wId && q.UniformCode == uCode)
  167. .Select(q => q.Id)
  168. .FirstOrDefault();
  169. }
  170. }
  171. public static string[] GetWindPowerStationPointFJZT(string wId)
  172. {
  173. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  174. {
  175. string[] codes = new string[] { "YXTS","TXZD", "DJTS", "WHTJ", "GZTJ", "XDTS" };
  176. return ctx.WindPowerStationTestingPoint
  177. .Where(q => q.StationId == wId && codes.Contains(q.UniformCode))
  178. .OrderBy(q=>q.Id)
  179. .Select(q => q.Id)
  180. .ToArray();
  181. }
  182. }
  183. public static string GetElectricalAIPointId(string wId, string uCode)
  184. {
  185. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  186. {
  187. return ctx.ElectricalTestingPointAI
  188. .Where(q => q.WindPowerStationId == wId && q.UniformCode == uCode)
  189. .Select(q => q.Id)
  190. .FirstOrDefault();
  191. }
  192. }
  193. public static string GetElectricalDIPointId(string wId, string uCode)
  194. {
  195. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  196. {
  197. return ctx.ElectricalTestingPointDI
  198. .Where(q => q.WindPowerStationId == wId && q.UniformCode == uCode)
  199. .Select(q => q.Id)
  200. .FirstOrDefault();
  201. }
  202. }
  203. public static IList<IFixBJTestingPointDI> GetIFixBJPoints()
  204. {
  205. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  206. {
  207. return ctx.IFixBJTestingPointDI.Where(q=>q.Enabled == true).ToList();
  208. }
  209. }
  210. public static IList<Warning> GetWarning()
  211. {
  212. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  213. {
  214. return ctx.Warning.ToList();
  215. }
  216. }
  217. public static IList<ModelPowerDetails> GetModelPowerDetails()
  218. {
  219. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  220. {
  221. return ctx.ModelPowerDetails.ToList();
  222. }
  223. }
  224. #endregion
  225. public static IList<MaintainPlan> GetMaintainPlans()
  226. {
  227. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  228. {
  229. try
  230. {
  231. return ctx.MaintainPlan.ToList();
  232. }
  233. catch (Exception ex)
  234. {
  235. var a = ex;
  236. return null;
  237. }
  238. }
  239. }
  240. }
  241. }