|
|
@@ -1,7 +1,6 @@
|
|
|
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"
|
|
|
@@ -55,57 +54,7 @@ func (simple *Simple) bind(binder *binding.Binder) {
|
|
|
},
|
|
|
entity_crud.WithDisableUpdate(),
|
|
|
entity_crud.WithDisableQuery[any](),
|
|
|
- entity_crud.WithDisableGetByID[any](),
|
|
|
- entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
|
|
|
- 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(ColumnScope, queryRuleEntity.Scope).
|
|
|
- Equal(ColumnDomainName, queryRuleEntity.DomainName),
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- if hasExistQueryRule {
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
-
|
|
|
- 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
|
|
|
- },
|
|
|
- }))
|
|
|
+ entity_crud.WithDisableGetByID[any]())
|
|
|
|
|
|
binding.PostBind(binder, &binding.SimpleBindItem[response.InfosData[Info]]{
|
|
|
Path: "/queryRule/query",
|