package query_rule import ( "git.sxidc.com/go-framework/baize/convenient/value_object_crud" "git.sxidc.com/go-framework/baize/framework/binding" "git.sxidc.com/go-framework/baize/framework/core/api" "git.sxidc.com/go-framework/baize/framework/core/api/request" "git.sxidc.com/go-framework/baize/framework/core/api/response" "git.sxidc.com/go-framework/baize/framework/core/application" "git.sxidc.com/go-framework/baize/framework/core/domain" "git.sxidc.com/go-framework/baize/framework/core/infrastructure" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database/sql" ) // Simple Bind参数 type Simple struct { // schema Schema string } func (simple *Simple) bind(binder *binding.Binder) { queryRuleTableName := domain.TableName(simple.Schema, &ValueObject{}) value_object_crud.BindSimple(binder, &value_object_crud.Simple[any]{ ValueObject: &ValueObject{}, Schema: simple.Schema, CreateJsonBody: &AddQueryRuleJsonBody{}, DeleteJsonBody: &RemoveQueryRuleJsonBody{}, }, value_object_crud.WithDisableQuery[any]()) binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{ Path: "/queryRuleDefinition/get", SendResponseFunc: response.SendMapResponse, RequestParams: &GetQueryRuleDefinitionQueryParams{}, Objects: []domain.Object{&ValueObject{}}, ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (map[string]any, error) { errResponse := map[string]any{ "definition": make([]QueryRuleDefinitionItem, 0), } valueObject, err := domain.ToConcrete[*ValueObject](objects[0]) if err != nil { return errResponse, err } return map[string]any{ "definition": GetQueryRuleDefinition(valueObject.RuleDomainName), }, nil }, }) binding.PostBind(binder, &binding.SimpleBindItem[Info]{ Path: "/queryRule/get", SendResponseFunc: response.SendInfoResponse[Info], RequestParams: &GetQueryRuleQueryParams{}, Objects: []domain.Object{&ValueObject{}}, ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (Info, error) { dbExecutor := i.DBExecutor() valueObject, err := domain.ToConcrete[*ValueObject](objects[0]) if err != nil { return Info{}, err } result, err := database.QueryOne(dbExecutor, &sql.QueryOneExecuteParams{ TableName: queryRuleTableName, Conditions: sql.NewConditions(). Equal(ColumnScope, valueObject.Scope). Equal(ColumnDomainName, valueObject.RuleDomainName), }) if err != nil { return Info{}, err } info := new(Info) err = sql.ParseSqlResult(result, info) if err != nil { return Info{}, err } return *info, nil }, }) } func Bind(app *application.App, simple *Simple) { binder := binding.NewBinder(app.Api().ChooseRouter(api.RouterPrefix, ""), app.Infrastructure()) simple.bind(binder) }