This commit is contained in:
2025-11-16 21:44:50 +08:00
parent 148fa1f2bb
commit aa94b47773
6 changed files with 31 additions and 19 deletions

View File

@@ -36,6 +36,9 @@ const (
// ListPlansOptions 定义了查询计划时的可选参数
type ListPlansOptions struct {
PlanType PlanTypeFilter
// IncludeAssociations 控制是否预加载关联的任务和子计划,以便计算 HasTasks 和 HasSubPlans 字段。
IncludeAssociations bool
}
// TaskListOptions 定义了查询任务时的可选参数
@@ -154,6 +157,11 @@ func (r *gormPlanRepository) ListPlans(ctx context.Context, opts ListPlansOption
query = query.Where("plan_type = ?", models.PlanTypeCustom)
}
// 如果需要包含关联,则进行预加载
if opts.IncludeAssociations {
query = query.Preload("Tasks").Preload("SubPlans")
}
if err := query.Count(&total).Error; err != nil {
return nil, 0, err
}