refactor(core): 模型路由与画布 - 收敛渠道模型映射并优化交互
This commit is contained in:
1 parent
52424543ea
commit
d47975f9bc
34 files changed
+601
-901
No files matched your search
@@ -21,6 +21,7 @@ var (
|
||||
ErrBillingStateConflict = errors.New("billing state conflict")
|
||||
ErrBillingUsageUnavailable = errors.New("billing usage unavailable")
|
||||
ErrBillingUnderreserved = errors.New("billing amount exceeds reservation")
|
||||
ErrChannelModelInUse = errors.New("channel model is in use")
|
||||
)
|
||||
|
||||
// 先抢占唯一业务键再更新账户,确保注册和签到奖励在多实例并发下只入账一次。
|
||||
@@ -105,6 +106,24 @@ func (r *Repository) SaveChannelModel(item *model.ChannelModel) error {
|
||||
|
||||
func (r *Repository) DeleteChannelModel(channelID string, id string, modelsJSON string, now time.Time) error {
|
||||
return r.db.Transaction(func(tx *gorm.DB) error {
|
||||
var activeReferences int64
|
||||
if err := tx.Table("logical_model_routes AS route").
|
||||
Joins("JOIN logical_models AS logical_model ON logical_model.active_revision_id = route.logical_model_revision_id").
|
||||
Where("route.channel_model_id = ?", id).
|
||||
Count(&activeReferences).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if activeReferences > 0 {
|
||||
return ErrChannelModelInUse
|
||||
}
|
||||
if err := tx.Model(&model.Task{}).
|
||||
Where("channel_model_id = ? AND status IN ?", id, []model.TaskStatus{model.TaskStatusQueued, model.TaskStatusRunning}).
|
||||
Count(&activeReferences).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if activeReferences > 0 {
|
||||
return ErrChannelModelInUse
|
||||
}
|
||||
result := tx.Model(&model.ChannelModel{}).
|
||||
Where("id = ? AND channel_id = ?", id, channelID).
|
||||
Updates(map[string]any{"enabled": false, "price_version": gorm.Expr("price_version + 1"), "updated_at": now})
|
||||
@@ -231,7 +250,7 @@ func (r *Repository) RetryTaskWithBilling(userID string, prepared *model.Task, o
|
||||
"provider_cancel_requested_at": nil, "provider_cancelled_at": nil, "provider_cancel_next_check_at": nil,
|
||||
"route_run": gorm.Expr("route_run + ?", 1),
|
||||
"logical_model_revision_id": prepared.LogicalModelRevisionID, "route_id": prepared.RouteID,
|
||||
"physical_variant_id": prepared.PhysicalVariantID, "input_json": prepared.InputJSON,
|
||||
"channel_model_id": prepared.ChannelModelID, "input_json": prepared.InputJSON,
|
||||
"model": prepared.Model, "provider": prepared.Provider,
|
||||
"lease_owner": "", "lease_expires_at": nil, "updated_at": time.Now(),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user