StorageLocationRepository.cs
2.18 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
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 StorageLocationRepository : Repository<StorageLocation>, IStorageLocationRepository
{
public StorageLocationRepository(AppDbContext context) : base(context)
{
}
public async Task<IEnumerable<StorageLocation>> GetByAreaIdAsync(Guid areaId, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(l => l.AreaId == areaId && l.IsActive)
.OrderBy(l => l.LocationCode)
.ToListAsync(cancellationToken);
}
public async Task<StorageLocation?> GetByLocationCodeAsync(string locationCode, CancellationToken cancellationToken = default)
{
return await _dbSet
.FirstOrDefaultAsync(l => l.LocationCode == locationCode, cancellationToken);
}
public async Task<StorageLocation?> GetByMapNodeIdAsync(Guid mapNodeId, CancellationToken cancellationToken = default)
{
return await _dbSet
.Include(l => l.StorageArea)
.FirstOrDefaultAsync(l => l.MapNodeId == mapNodeId, cancellationToken);
}
public async Task<IEnumerable<StorageLocation>> GetByStatusAsync(StorageLocationStatus status, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(l => l.Status == status && l.IsActive)
.ToListAsync(cancellationToken);
}
/// <summary>
/// 根据地图ID获取库位列表(通过MapNode关联)
/// @author zzy
/// </summary>
public async Task<IEnumerable<StorageLocation>> GetByMapIdAsync(Guid mapId, CancellationToken cancellationToken = default)
{
return await _dbSet
.Include(l => l.MapNode)
.Where(l => l.MapNode != null && l.MapNode.MapId == mapId && l.IsActive)
.ToListAsync(cancellationToken);
}
}
}