|
|
@@ -1,6 +1,7 @@
|
|
|
package query_rule
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"git.sxidc.com/go-framework/baize/convenient/entity_crud"
|
|
|
"git.sxidc.com/go-framework/baize/framework/binding"
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/api"
|
|
|
@@ -78,6 +79,30 @@ func (simple *Simple) bind(binder *binding.Binder) {
|
|
|
|
|
|
queryRuleEntity.Enabled = true
|
|
|
|
|
|
+ return nil, nil
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ entity_crud.WithDeleteCallbacks(&entity_crud.DeleteCallbacks{
|
|
|
+ Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
|
|
|
+ queryRuleEntity, err := domain.ToConcrete[*Entity](e)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ hasExistQueryRule, err := database.CheckExist(i.DBExecutor(), &sql.CheckExistExecuteParams{
|
|
|
+ TableName: domain.TableName(simple.Schema, &Entity{}),
|
|
|
+ Conditions: sql.NewConditions().
|
|
|
+ Equal(entity.ColumnID, queryRuleEntity.ID).
|
|
|
+ Equal(ColumnEnabled, true),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if hasExistQueryRule {
|
|
|
+ return nil, errors.New("不能删除启用的规则")
|
|
|
+ }
|
|
|
+
|
|
|
return nil, nil
|
|
|
},
|
|
|
}))
|