MapNodeRepository.cs 2.6 KB
using Microsoft.EntityFrameworkCore;
using Rcs.Domain.Entities;
using Rcs.Domain.Repositories;
using Rcs.Infrastructure.DB.MsSql;

namespace Rcs.Infrastructure.DB.Repositories
{
    /// <summary>
    /// 地图资源仓储实现
    /// </summary>
    public class MapNodeRepository : Repository<MapNode>, IMapNodeRepository
    {
        public MapNodeRepository(AppDbContext context) : base(context)
        {
        }


        public async Task<IEnumerable<MapNode>> GetByMapIdAsync(Guid mapId, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.MapId == mapId && r.Active)
                .OrderBy(r => r.NodeCode)
                .ToListAsync(cancellationToken);
        }

        public async Task<MapNode?> GetByNodeCodeAsync(string nodeCode, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.NodeCode == nodeCode)
                .FirstOrDefaultAsync(cancellationToken);
        }

        public async Task<MapNode?> GetByMapIdAndNodeCodeAsync(Guid mapId, string nodeCode, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.MapId == mapId)
                .Where(r => r.NodeCode == nodeCode)
                .FirstOrDefaultAsync(cancellationToken);
        }

        public async Task<IEnumerable<MapNode>> GetByTypeAsync(MapNodeTYPE type, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.Type == type)
                .ToListAsync(cancellationToken);
        }

        public async Task<IEnumerable<MapNode>> GetByMapIdAndTypeAsync(Guid mapId, MapNodeTYPE type, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.MapId == mapId)
                .Where(r => r.Type == type)
                .ToListAsync(cancellationToken);
        }

        public async Task<IEnumerable<MapNode>> GetChargerNodesAsync(Guid mapId, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.MapId == mapId)
                .Where(r => r.Type == MapNodeTYPE.charger)
                .ToListAsync(cancellationToken);
        }

        public async Task<IEnumerable<MapNode>> GetParkingNodesAsync(Guid mapId, CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(r => r.MapId == mapId)
                .Where(r => r.Type == MapNodeTYPE.parking)
                .ToListAsync(cancellationToken);
        }
    }
}