| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using EasyTemplate.Tool.Entity.App;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection.PortableExecutable;
- using System.Text;
- using System.Threading.Tasks;
- using EasyTemplate.Tool.Entity.App;
- using EasyTemplate.Tool;
- using EasyTemplate.Tool.Entity;
- namespace EasyTemplate.Service
- {
- public class NozzleService
- {
- private readonly SqlSugarRepository<TEngine> _engine;
- private readonly SqlSugarRepository<TBoard> _board;
- private readonly SqlSugarRepository<TNozzle> _nozzle;
- public NozzleService(SqlSugarRepository<TEngine> engine, SqlSugarRepository<TBoard> board, SqlSugarRepository<TNozzle> nozzle)
- {
- _engine = engine;
- _board = board;
- _nozzle = nozzle;
- }
- // Engine操作
- public async Task<List<TEngine>> GetEnginesAsync()
- {
- return await _engine.AsQueryable().ToListAsync();
- }
- public async Task<TEngine> GetEngineByIdAsync(int id)
- {
- return await _engine.AsQueryable()
- .Where(m => m.EngineId == id)
- .FirstAsync();
- }
- public async Task<bool> CreateEngineAsync(TEngine engine)
- {
- return await _engine.InsertAsync(engine);
- }
- public async Task<bool> UpdateEngineAsync(TEngine engine)
- {
- return await _engine.UpdateAsync(engine) == true;
- }
- public async Task<bool> DeleteEngineAsync(int id)
- {
- return await _engine.DeleteByIdAsync(id) == true;
- }
- // Board操作
- public async Task<List<TBoard>> GetBoardsAsync()
- {
- return await _board.AsQueryable().OrderBy(b => b.EngineId).ToListAsync();
- }
- public async Task<List<TBoard>> GetboardsByEngineAsync(int engineId)
- {
- return await _board.AsQueryable()
- .Where(m => m.EngineId == engineId)
- .ToListAsync();
- }
- public async Task<TBoard> GetBoardByIdAsync(int id)
- {
- return await _board.AsQueryable()
- .Where(m => m.BoardId == id)
- .FirstAsync();
- }
- public async Task<bool> CreateBoardAsync(TBoard board)
- {
- return await _board.InsertAsync(board);
- }
- public async Task<bool> UpdateBoardAsync(TBoard board)
- {
- return await _board.UpdateAsync(board) == true;
- }
- public async Task<bool> DeleteBoardAsync(int id)
- {
- return await _board.DeleteByIdAsync(id) == true;
- }
- // Nozzle操作
- public async Task<List<TNozzle>> GetNozzlesAsync()
- {
- return await _nozzle.AsQueryable().ToListAsync();
- }
- public async Task<List<TNozzle>> GetNozzlesByBoardAsync(int boardId)
- {
- return await _nozzle.AsQueryable()
- .Where(n => n.BoardId == boardId)
- .ToListAsync();
- }
- public async Task<TNozzle> GetNozzleByIdAsync(int id)
- {
- return await _nozzle.AsQueryable()
- .Where(n => n.NozzleId == id)
- .FirstAsync();
- }
- public async Task<bool> CreateNozzleAsync(TNozzle nozzle)
- {
- return await _nozzle.InsertAsync(nozzle);
- }
- public async Task<bool> UpdateNozzleAsync(TNozzle nozzle)
- {
- return await _nozzle.UpdateAsync(nozzle) == true;
- }
- public async Task<bool> DeleteNozzleAsync(int id)
- {
- return await _nozzle.DeleteByIdAsync(id) == true;
- }
- // 获取完整数据结构
- public async Task<List<TEngine>> GetEnginesWithDetailsAsync()
- {
- var engines = await _engine.AsQueryable().ToListAsync();
- var boards = await _board.AsQueryable().ToListAsync();
- var nozzles = await _nozzle.AsQueryable().ToListAsync();
-
- foreach (var engine in engines)
- {
- engine.boards = boards
- .Where(m => m.EngineId == engine.EngineId)
- .ToList();
- foreach (var board in engine.boards)
- {
- board.nozzles = nozzles
- .Where(n => n.BoardId == board.BoardId)
- .ToList();
- }
- }
- return engines;
- }
- }
- }
|