| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package configuration
- import (
- "git.sxidc.com/go-framework/baize/api"
- "git.sxidc.com/go-framework/baize/binding"
- "git.sxidc.com/go-framework/baize/binding/request"
- "git.sxidc.com/go-framework/baize/binding/response"
- "git.sxidc.com/go-framework/baize/convenient/value_object"
- "git.sxidc.com/go-framework/baize/domain"
- "git.sxidc.com/go-framework/baize/infrastructure"
- "git.sxidc.com/go-framework/baize/infrastructure/database"
- "git.sxidc.com/go-framework/baize/infrastructure/database/sql"
- "git.sxidc.com/go-tools/utils/strutils"
- "git.sxidc.com/service-supports/fserr"
- )
- func BindConfiguration(binder *binding.Binder, opts ...Option) {
- options := new(Options)
- for _, opt := range opts {
- opt(options)
- }
- configurationTableName := tableName
- if strutils.IsStringNotEmpty(options.schema) {
- configurationTableName = options.schema + "." + tableName
- }
- value_object.BindSimple(binder, &value_object.Simple[any]{
- ValueObject: &Entity{},
- TableName: configurationTableName,
- DomainPath: "/configuration",
- CreateJsonBody: &AddConfigurationJsonBody{},
- DeleteQueryParams: &RemoveConfigurationJsonBody{},
- }, value_object.WithDisableQuery[any]())
- binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
- Path: "/configuration/values",
- ResponseFunc: response.SendMapResponse,
- RequestParams: &GetConfigurationValuesQueryParams{},
- Objects: []domain.Object{&Entity{}},
- 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].(*Entity)
- if !ok {
- return map[string]any{
- "values": make([]string, 0),
- }, fserr.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,
- SelectColumns: []string{ColumnValue},
- Conditions: conditions,
- })
- if err != nil {
- return map[string]any{
- "values": make([]string, 0),
- }, err
- }
- values := make([]string, 0)
- for _, result := range results {
- values = append(values, result.ColumnValueString(ColumnValue))
- }
- return map[string]any{
- "values": values,
- }, nil
- },
- })
- }
- type Option func(options *Options)
- type Options struct {
- schema string
- }
- func WithSchema(schema string) Option {
- return func(options *Options) {
- options.schema = schema
- }
- }
|