MapNodeRepository.cs
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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);
}
}
}