|
|
@@ -1,7 +1,6 @@
|
|
|
package one2one
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
"git.sxidc.com/go-framework/baize/convenient/binding"
|
|
|
"git.sxidc.com/go-framework/baize/convenient/binding/request"
|
|
|
"git.sxidc.com/go-framework/baize/framwork/api"
|
|
|
@@ -11,6 +10,7 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/framwork/infrastructure/database/sql"
|
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
|
"git.sxidc.com/service-supports/fserr"
|
|
|
+ "github.com/mitchellh/mapstructure"
|
|
|
"reflect"
|
|
|
)
|
|
|
|
|
|
@@ -195,6 +195,11 @@ func Query[TI any](fromTableName string, toTableName string, toRelationColumnNam
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+type WithInfo[FI any, TI any] struct {
|
|
|
+ Self FI `json:"self" mapstructure:"self"`
|
|
|
+ With TI `json:"with" mapstructure:"with"`
|
|
|
+}
|
|
|
+
|
|
|
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
|
|
|
@@ -214,18 +219,11 @@ func QueryWithOtherInfo[FI any, TI any](fromTableName string, toTableName string
|
|
|
|
|
|
outputToZero = outputToZeroValue.Interface().(TI)
|
|
|
|
|
|
- zeroInfo := &struct {
|
|
|
- Self FI `json:"self"`
|
|
|
- With TI `json:"with"`
|
|
|
- }{Self: outputFromZero, With: outputToZero}
|
|
|
-
|
|
|
- zeroInfoJson, err := json.Marshal(zeroInfo)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
zeroRetMap := make(map[string]any)
|
|
|
- err = json.Unmarshal(zeroInfoJson, &zeroRetMap)
|
|
|
+ err := mapstructure.Decode(WithInfo[FI, TI]{
|
|
|
+ Self: outputFromZero,
|
|
|
+ With: outputToZero,
|
|
|
+ }, &zeroRetMap)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
@@ -297,21 +295,11 @@ func QueryWithOtherInfo[FI any, TI any](fromTableName string, toTableName string
|
|
|
return zeroRetMap, err
|
|
|
}
|
|
|
|
|
|
- info := &struct {
|
|
|
- Self FI `json:"self"`
|
|
|
- With TI `json:"with"`
|
|
|
- }{Self: fromInfo, With: toInfo}
|
|
|
-
|
|
|
- infoJson, err := json.Marshal(info)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
retMap := make(map[string]any)
|
|
|
- err = json.Unmarshal(infoJson, &retMap)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
+ err = mapstructure.Decode(WithInfo[FI, TI]{
|
|
|
+ Self: fromInfo,
|
|
|
+ With: toInfo,
|
|
|
+ }, &retMap)
|
|
|
|
|
|
return retMap, nil
|
|
|
}
|