|
|
@@ -1,11 +1,17 @@
|
|
|
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) {
|
|
|
@@ -20,15 +26,9 @@ func BindConfiguration(binder *binding.Binder, opts ...Option) {
|
|
|
configurationTableName = tableName + "." + options.schema
|
|
|
}
|
|
|
|
|
|
- dbExecutorType := binding.DBExecutorOperations
|
|
|
- if strutils.IsStringNotEmpty(options.dbExecutorType) {
|
|
|
- dbExecutorType = options.dbExecutorType
|
|
|
- }
|
|
|
-
|
|
|
value_object.BindSimple(binder, &value_object.Simple[any]{
|
|
|
ValueObject: &Entity{},
|
|
|
TableName: configurationTableName,
|
|
|
- DBExecutorType: dbExecutorType,
|
|
|
DomainPath: "/configuration",
|
|
|
CreateJsonBody: &AddConfigurationJsonBody{},
|
|
|
DeleteQueryParams: &RemoveConfigurationQueryParams{},
|
|
|
@@ -36,19 +36,48 @@ func BindConfiguration(binder *binding.Binder, opts ...Option) {
|
|
|
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[map[string]any]{
|
|
|
Path: "/configuration/values",
|
|
|
+ ResponseFunc: response.SendMapResponse,
|
|
|
RequestParams: &GetConfigurationValuesQueryParams{},
|
|
|
Objects: []domain.Object{&Entity{}},
|
|
|
- Infrastructure: binder.ChooseDBExecutor(dbExecutorType),
|
|
|
- ServiceFunc: nil,
|
|
|
- ResponseFunc: response.SendMapResponse,
|
|
|
+ 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
|
|
|
- dbExecutorType string
|
|
|
+ schema string
|
|
|
}
|
|
|
|
|
|
func WithSchema(schema string) Option {
|
|
|
@@ -56,9 +85,3 @@ func WithSchema(schema string) Option {
|
|
|
options.schema = schema
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-func WithDBExecutorType(dbExecutorType string) Option {
|
|
|
- return func(options *Options) {
|
|
|
- options.dbExecutorType = dbExecutorType
|
|
|
- }
|
|
|
-}
|