package configuration 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" "git.sxidc.com/go-tools/utils/strutils" "github.com/pkg/errors" ) // Simple Bind参数 type Simple struct { // schema Schema string } func (simple *Simple) bind(binder *binding.Binder) { configurationTableName := domain.TableName(simple.Schema, &ValueObject{}) value_object_crud.BindSimple(binder, &value_object_crud.Simple[any]{ ValueObject: &ValueObject{}, Schema: simple.Schema, CreateJsonBody: &AddConfigurationJsonBody{}, DeleteJsonBody: &RemoveConfigurationJsonBody{}, }, value_object_crud.WithDisableQuery[any]()) binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{ Path: "/configuration/values", SendResponseFunc: response.SendMapResponse, RequestParams: &GetConfigurationValuesQueryParams{}, Objects: []domain.Object{&ValueObject{}}, ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (map[string]any, error) { dbExecutor := i.DBExecutor() e, ok := objects[0].(*ValueObject) if !ok { return map[string]any{ "values": make([]string, 0), }, errors.New("传递的实体不是该领域的实体") } conditions := sql.NewConditions() if strutils.IsStringNotEmpty(e.Scope) { conditions.Equal(ColumnScope, e.Scope) } if strutils.IsStringNotEmpty(e.Group) { conditions.Equal(ColumnGroup, e.Group) } results, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{ TableName: configurationTableName, SelectClauses: []string{ColumnValue}, Conditions: conditions, }) if err != nil { return map[string]any{ "values": make([]string, 0), }, err } values := make([]string, 0) err = sql.ParseSqlResult(results, &values) if err != nil { return map[string]any{ "values": make([]string, 0), }, err } return map[string]any{ "values": values, }, nil }, }) } func Bind(app *application.App, simple *Simple) { binder := binding.NewBinder(app.Api().ChooseRouter(api.RouterPrefix, ""), app.Infrastructure()) simple.bind(binder) }