NozzleService.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using EasyTemplate.Tool.Entity.App;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection.PortableExecutable;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using EasyTemplate.Tool.Entity.App;
  10. using EasyTemplate.Tool;
  11. using EasyTemplate.Tool.Entity;
  12. namespace EasyTemplate.Service
  13. {
  14. public class NozzleService
  15. {
  16. private readonly SqlSugarRepository<TEngine> _engine;
  17. private readonly SqlSugarRepository<TBoard> _board;
  18. private readonly SqlSugarRepository<TNozzle> _nozzle;
  19. public NozzleService(SqlSugarRepository<TEngine> engine, SqlSugarRepository<TBoard> board, SqlSugarRepository<TNozzle> nozzle)
  20. {
  21. _engine = engine;
  22. _board = board;
  23. _nozzle = nozzle;
  24. }
  25. // Engine操作
  26. public async Task<List<TEngine>> GetEnginesAsync()
  27. {
  28. return await _engine.AsQueryable().ToListAsync();
  29. }
  30. public async Task<TEngine> GetEngineByIdAsync(int id)
  31. {
  32. return await _engine.AsQueryable()
  33. .Where(m => m.EngineId == id)
  34. .FirstAsync();
  35. }
  36. public async Task<bool> CreateEngineAsync(TEngine engine)
  37. {
  38. return await _engine.InsertAsync(engine);
  39. }
  40. public async Task<bool> UpdateEngineAsync(TEngine engine)
  41. {
  42. return await _engine.UpdateAsync(engine) == true;
  43. }
  44. public async Task<bool> DeleteEngineAsync(int id)
  45. {
  46. return await _engine.DeleteByIdAsync(id) == true;
  47. }
  48. // Board操作
  49. public async Task<List<TBoard>> GetBoardsAsync()
  50. {
  51. return await _board.AsQueryable().OrderBy(b => b.EngineId).ToListAsync();
  52. }
  53. public async Task<List<TBoard>> GetboardsByEngineAsync(int engineId)
  54. {
  55. return await _board.AsQueryable()
  56. .Where(m => m.EngineId == engineId)
  57. .ToListAsync();
  58. }
  59. public async Task<TBoard> GetBoardByIdAsync(int id)
  60. {
  61. return await _board.AsQueryable()
  62. .Where(m => m.BoardId == id)
  63. .FirstAsync();
  64. }
  65. public async Task<bool> CreateBoardAsync(TBoard board)
  66. {
  67. return await _board.InsertAsync(board);
  68. }
  69. public async Task<bool> UpdateBoardAsync(TBoard board)
  70. {
  71. return await _board.UpdateAsync(board) == true;
  72. }
  73. public async Task<bool> DeleteBoardAsync(int id)
  74. {
  75. return await _board.DeleteByIdAsync(id) == true;
  76. }
  77. // Nozzle操作
  78. public async Task<List<TNozzle>> GetNozzlesAsync()
  79. {
  80. return await _nozzle.AsQueryable().ToListAsync();
  81. }
  82. public async Task<List<TNozzle>> GetNozzlesByBoardAsync(int boardId)
  83. {
  84. return await _nozzle.AsQueryable()
  85. .Where(n => n.BoardId == boardId)
  86. .ToListAsync();
  87. }
  88. public async Task<TNozzle> GetNozzleByIdAsync(int id)
  89. {
  90. return await _nozzle.AsQueryable()
  91. .Where(n => n.NozzleId == id)
  92. .FirstAsync();
  93. }
  94. public async Task<bool> CreateNozzleAsync(TNozzle nozzle)
  95. {
  96. return await _nozzle.InsertAsync(nozzle);
  97. }
  98. public async Task<bool> UpdateNozzleAsync(TNozzle nozzle)
  99. {
  100. return await _nozzle.UpdateAsync(nozzle) == true;
  101. }
  102. public async Task<bool> DeleteNozzleAsync(int id)
  103. {
  104. return await _nozzle.DeleteByIdAsync(id) == true;
  105. }
  106. // 获取完整数据结构
  107. public async Task<List<TEngine>> GetEnginesWithDetailsAsync()
  108. {
  109. var engines = await _engine.AsQueryable().ToListAsync();
  110. var boards = await _board.AsQueryable().ToListAsync();
  111. var nozzles = await _nozzle.AsQueryable().ToListAsync();
  112. foreach (var engine in engines)
  113. {
  114. engine.boards = boards
  115. .Where(m => m.EngineId == engine.EngineId)
  116. .ToList();
  117. foreach (var board in engine.boards)
  118. {
  119. board.nozzles = nozzles
  120. .Where(n => n.BoardId == board.BoardId)
  121. .ToList();
  122. }
  123. }
  124. return engines;
  125. }
  126. }
  127. }