StorageAreaRepository.cs
1.55 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
using Microsoft.EntityFrameworkCore;
using Rcs.Domain.Entities;
using Rcs.Domain.Repositories;
using Rcs.Infrastructure.DB.MsSql;
namespace Rcs.Infrastructure.DB.Repositories
{
/// <summary>
/// 库区仓储实现
/// @author zzy
/// </summary>
public class StorageAreaRepository : Repository<StorageArea>, IStorageAreaRepository
{
public StorageAreaRepository(AppDbContext context) : base(context)
{
}
public async Task<StorageArea?> GetByAreaCodeAsync(string areaCode, CancellationToken cancellationToken = default)
{
return await _dbSet.Include(a => a.StorageLocations)
.FirstOrDefaultAsync(a => a.AreaCode == areaCode, cancellationToken);
}
/// <summary>
/// 根据地图ID获取库区列表(通过库位的MapNode关联)
/// @author zzy
/// </summary>
public async Task<IEnumerable<StorageArea>> GetByMapIdAsync(Guid mapId, CancellationToken cancellationToken)
{
return await _dbSet
.Include(a => a.StorageLocations)
.Where(a => a.StorageLocations.Any(l => l.MapNodeId != null && l.MapNode.MapId == mapId))
.ToListAsync(cancellationToken);
}
public async Task<StorageArea?> GetWithLocationsAsync(Guid areaId, CancellationToken cancellationToken = default)
{
return await _dbSet
.Include(a => a.StorageLocations)
.FirstOrDefaultAsync(a => a.AreaId == areaId, cancellationToken);
}
}
}