RobotSubTaskRepository.cs
3.33 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
73
74
75
76
77
78
79
80
using Microsoft.EntityFrameworkCore;
using Rcs.Domain.Entities;
using Rcs.Domain.Repositories;
using Rcs.Infrastructure.DB.MsSql;
using TaskStatus = Rcs.Domain.Entities.TaskStatus;
namespace Rcs.Infrastructure.DB.Repositories
{
/// <summary>
/// 子任务仓储实现
/// @author zzy
/// </summary>
public class RobotSubTaskRepository : Repository<RobotSubTask>, IRobotSubTaskRepository
{
public RobotSubTaskRepository(AppDbContext context) : base(context)
{
}
public async Task<IEnumerable<RobotSubTask>> GetByTaskIdAsync(Guid taskId, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(s => s.TaskId == taskId)
.OrderBy(s => s.Sequence)
.ToListAsync(cancellationToken);
}
public async Task<IEnumerable<RobotSubTask>> GetByRobotIdAsync(Guid robotId, CancellationToken cancellationToken = default)
{
return await _dbSet.Where(s => s.RobotId == robotId).ToListAsync(cancellationToken);
}
public async Task<RobotSubTask?> GetNextPendingSubTaskAsync(Guid taskId, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(s => s.TaskId == taskId && s.Status == TaskStatus.Pending)
.OrderBy(s => s.Sequence)
.FirstOrDefaultAsync(cancellationToken);
}
public async Task<RobotSubTask?> GetByIdWithDetailsAsync(Guid subTaskId, CancellationToken cancellationToken = default)
{
return await _dbSet
// 第一层:直接导航属性
.Include(s => s.Task)
.ThenInclude(t => t!.BeginLocation)
.ThenInclude(bl => bl!.LocationType)
.Include(s => s.Task)
.ThenInclude(t => t!.EndLocation)
.ThenInclude(el => el!.LocationType)
.Include(s => s.Task)
.ThenInclude(t => t!.TaskTemplate)
.Include(s => s.Task)
.ThenInclude(t => t!.Robot)
.ThenInclude(r => r!.Map)
.Include(s => s.Task)
.ThenInclude(t => t!.Robot)
.ThenInclude(r => r!.MapNode)
.Include(s => s.Robot)
.ThenInclude(r => r!.Map)
.Include(s => s.Robot)
.ThenInclude(r => r!.MapNode)
.Include(s => s.BeginNode)
.ThenInclude(bn => bn!.Map)
.Include(s => s.BeginNode)
.ThenInclude(bn => bn!.StorageLocationType)
.Include(s => s.EndNode)
.ThenInclude(en => en!.Map)
.Include(s => s.EndNode)
.ThenInclude(en => en!.StorageLocationType)
// 第二层到第五层:继续展开嵌套属性
.Include(s => s.BeginNode)
.ThenInclude(bn => bn!.StorageLocations)
.ThenInclude(sl => sl.LocationType)
.Include(s => s.EndNode)
.ThenInclude(en => en!.StorageLocations)
.ThenInclude(sl => sl.LocationType)
.FirstOrDefaultAsync(s => s.SubTaskId == subTaskId, cancellationToken);
}
}
}