实现
This commit is contained in:
		@@ -48,7 +48,9 @@ type PlanRepository interface {
 | 
			
		||||
	GetPlansByIDs(ids []uint) ([]models.Plan, error)
 | 
			
		||||
	// CreatePlan 创建一个新的计划
 | 
			
		||||
	CreatePlan(plan *models.Plan) error
 | 
			
		||||
	// UpdatePlan 更新计划,包括子计划和任务
 | 
			
		||||
	// UpdatePlanMetadataAndStructure 更新计划的元数据和结构,但不包括状态等运行时信息
 | 
			
		||||
	UpdatePlanMetadataAndStructure(plan *models.Plan) error
 | 
			
		||||
	// UpdatePlan 更新计划的所有字段
 | 
			
		||||
	UpdatePlan(plan *models.Plan) error
 | 
			
		||||
	// UpdatePlanStatus 更新指定计划的状态
 | 
			
		||||
	UpdatePlanStatus(id uint, status models.PlanStatus) error
 | 
			
		||||
@@ -259,15 +261,20 @@ func (r *gormPlanRepository) CreatePlan(plan *models.Plan) error {
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdatePlan 是更新计划的公共入口点
 | 
			
		||||
// UpdatePlan 更新计划
 | 
			
		||||
func (r *gormPlanRepository) UpdatePlan(plan *models.Plan) error {
 | 
			
		||||
	return r.db.Save(plan).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdatePlanMetadataAndStructure 是更新计划元数据和结构的公共入口点
 | 
			
		||||
func (r *gormPlanRepository) UpdatePlanMetadataAndStructure(plan *models.Plan) error {
 | 
			
		||||
	return r.db.Transaction(func(tx *gorm.DB) error {
 | 
			
		||||
		return r.updatePlanTx(tx, plan)
 | 
			
		||||
		return r.updatePlanMetadataAndStructureTx(tx, plan)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// updatePlanTx 在事务中协调整个更新过程
 | 
			
		||||
func (r *gormPlanRepository) updatePlanTx(tx *gorm.DB, plan *models.Plan) error {
 | 
			
		||||
// updatePlanMetadataAndStructureTx 在事务中协调整个更新过程
 | 
			
		||||
func (r *gormPlanRepository) updatePlanMetadataAndStructureTx(tx *gorm.DB, plan *models.Plan) error {
 | 
			
		||||
	if err := r.validatePlanTree(tx, plan); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user