|
|
@@ -8,6 +8,7 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/framwork/infrastructure"
|
|
|
"git.sxidc.com/go-framework/baize/framwork/infrastructure/database"
|
|
|
"git.sxidc.com/go-framework/baize/framwork/infrastructure/database/sql"
|
|
|
+ "git.sxidc.com/go-tools/utils/reflectutils"
|
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
|
"git.sxidc.com/service-supports/fserr"
|
|
|
"reflect"
|
|
|
@@ -127,14 +128,7 @@ func Update(fromTableName string, fromRelationFieldName string, fromRelationColu
|
|
|
|
|
|
func Query[TI any](fromTableName string, toTableName string, toRelationColumnName string) binding.ServiceFunc[TI] {
|
|
|
return func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (TI, error) {
|
|
|
- var outputZero TI
|
|
|
-
|
|
|
- outputZeroValue := reflect.New(reflect.TypeOf(outputZero)).Elem()
|
|
|
- if outputZeroValue.Kind() == reflect.Pointer {
|
|
|
- outputZeroValue.Set(reflect.New(outputZeroValue.Type().Elem()))
|
|
|
- }
|
|
|
-
|
|
|
- outputZero = outputZeroValue.Interface().(TI)
|
|
|
+ outputZero := reflectutils.Zero[TI]()
|
|
|
|
|
|
dbExecutor := i.DBExecutor()
|
|
|
|
|
|
@@ -177,11 +171,11 @@ func Query[TI any](fromTableName string, toTableName string, toRelationColumnNam
|
|
|
return outputZero, err
|
|
|
}
|
|
|
|
|
|
- var info TI
|
|
|
+ info := reflectutils.Zero[TI]()
|
|
|
var infoPointer any
|
|
|
|
|
|
infoPointer = &info
|
|
|
- if outputZeroValue.Kind() == reflect.Pointer {
|
|
|
+ if reflect.TypeOf(info).Kind() == reflect.Pointer {
|
|
|
infoPointer = info
|
|
|
}
|
|
|
|
|
|
@@ -196,22 +190,8 @@ func Query[TI any](fromTableName string, toTableName string, toRelationColumnNam
|
|
|
|
|
|
func QueryWithOtherInfo[FI any, TI any](fromTableName string, toTableName string, toRelationColumnName string) binding.ServiceFunc[map[string]any] {
|
|
|
return func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (map[string]any, error) {
|
|
|
- var outputFromZero FI
|
|
|
- var outputToZero TI
|
|
|
-
|
|
|
- outputFromZeroValue := reflect.New(reflect.TypeOf(outputFromZero)).Elem()
|
|
|
- if outputFromZeroValue.Kind() == reflect.Pointer {
|
|
|
- outputFromZeroValue.Set(reflect.New(outputFromZeroValue.Type().Elem()))
|
|
|
- }
|
|
|
-
|
|
|
- outputFromZero = outputFromZeroValue.Interface().(FI)
|
|
|
-
|
|
|
- outputToZeroValue := reflect.New(reflect.TypeOf(outputToZero)).Elem()
|
|
|
- if outputToZeroValue.Kind() == reflect.Pointer {
|
|
|
- outputToZeroValue.Set(reflect.New(outputToZeroValue.Type().Elem()))
|
|
|
- }
|
|
|
-
|
|
|
- outputToZero = outputToZeroValue.Interface().(TI)
|
|
|
+ outputFromZero := reflectutils.Zero[FI]()
|
|
|
+ outputToZero := reflectutils.Zero[TI]()
|
|
|
|
|
|
zeroRetMap := map[string]any{
|
|
|
"self": outputFromZero,
|
|
|
@@ -259,11 +239,11 @@ func QueryWithOtherInfo[FI any, TI any](fromTableName string, toTableName string
|
|
|
return zeroRetMap, err
|
|
|
}
|
|
|
|
|
|
- var fromInfo FI
|
|
|
+ fromInfo := reflectutils.Zero[FI]()
|
|
|
var fromInfoPointer any
|
|
|
|
|
|
fromInfoPointer = &fromInfo
|
|
|
- if outputFromZeroValue.Kind() == reflect.Pointer {
|
|
|
+ if reflect.TypeOf(fromInfo).Kind() == reflect.Pointer {
|
|
|
fromInfoPointer = fromInfo
|
|
|
}
|
|
|
|
|
|
@@ -272,11 +252,11 @@ func QueryWithOtherInfo[FI any, TI any](fromTableName string, toTableName string
|
|
|
return zeroRetMap, err
|
|
|
}
|
|
|
|
|
|
- var toInfo TI
|
|
|
+ toInfo := reflectutils.Zero[FI]()
|
|
|
var toInfoPointer any
|
|
|
|
|
|
toInfoPointer = &toInfo
|
|
|
- if outputToZeroValue.Kind() == reflect.Pointer {
|
|
|
+ if reflect.TypeOf(toInfo).Kind() == reflect.Pointer {
|
|
|
toInfoPointer = toInfo
|
|
|
}
|
|
|
|