CreateDeviceThresholdAlarm
UpdateDeviceThresholdAlarm CreateAreaThresholdAlarm UpdateAreaThresholdAlarm
This commit is contained in:
@@ -49,6 +49,8 @@ type PlanRepository interface {
|
||||
GetPlanByID(ctx context.Context, id uint) (*models.Plan, error)
|
||||
// GetPlansByIDs 根据ID列表获取计划,不包含子计划和任务详情
|
||||
GetPlansByIDs(ctx context.Context, ids []uint) ([]models.Plan, error)
|
||||
// GetSystemPlanByName 根据计划名称获取系统计划,包含子计划和任务详情
|
||||
GetSystemPlanByName(ctx context.Context, planName models.PlanName) (*models.Plan, error)
|
||||
// CreatePlan 创建一个新的计划
|
||||
CreatePlan(ctx context.Context, plan *models.Plan) error
|
||||
// CreatePlanTx 在指定事务中创建一个新的计划
|
||||
@@ -164,6 +166,23 @@ func (r *gormPlanRepository) GetPlansByIDs(ctx context.Context, ids []uint) ([]m
|
||||
return plans, nil
|
||||
}
|
||||
|
||||
// GetSystemPlanByName 根据计划名称获取系统计划,包含子计划和任务详情, 系统任务不该有重名情况, 所以可以这么查询
|
||||
func (r *gormPlanRepository) GetSystemPlanByName(ctx context.Context, planName models.PlanName) (*models.Plan, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "GetSystemPlanByName")
|
||||
var plan models.Plan
|
||||
// 首先只查询计划的基本信息,获取其ID
|
||||
err := r.db.WithContext(repoCtx).Select("id").Where("name = ? AND plan_type = ?", planName, models.PlanTypeSystem).First(&plan).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil // 未找到系统计划不是错误
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询系统计划 '%s' 失败: %w", planName, err)
|
||||
}
|
||||
|
||||
// 如果找到了计划ID,则复用 GetPlanByID 来获取完整的计划详情
|
||||
return r.GetPlanByID(repoCtx, plan.ID)
|
||||
}
|
||||
|
||||
// GetPlanByID 根据ID获取计划,包含子计划和任务详情
|
||||
func (r *gormPlanRepository) GetPlanByID(ctx context.Context, id uint) (*models.Plan, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "GetPlanByID")
|
||||
|
||||
Reference in New Issue
Block a user