| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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 = tableName + "." + options.schema
- }
- value_object.BindSimple(binder, &value_object.Simple[any]{
- ValueObject: &Entity{},
- TableName: configurationTableName,
- DomainPath: "/configuration",
- CreateJsonBody: &AddConfigurationJsonBody{},
- DeleteQueryParams: &RemoveConfigurationQueryParams{},
- }, value_object.WithDisableQuery[any]())
- binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
- Path: "/configuration/values",
- ResponseFunc: response.SendMapResponse,
- RequestParams: &GetConfigurationValuesQueryParams{},
- Objects: []domain.Object{&Entity{}},
- Infrastructure: binder.Infrastructure(),
- 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("传递的实体不是该领域的实体")
- }
- results, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{
- TableName: configurationTableName,
- SelectColumns: []string{ColumnValue},
- Conditions: sql.NewConditions().
- Equal(ColumnGroup, e.Group),
- })
- 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
- }
- }
|