- 使用utils.Struct2MapByJson替代直接使用structs.Map
This commit is contained in:
@@ -6,10 +6,10 @@ import (
|
||||
"io"
|
||||
"reflect"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
"github.com/fatih/structs"
|
||||
)
|
||||
|
||||
type Obj2ExcelSheetConfig struct {
|
||||
@@ -52,7 +52,7 @@ func Obj2Excel(sheetList []*Obj2ExcelSheetConfig) []byte {
|
||||
for i := 0; i < valueInfo.Len(); i++ {
|
||||
var mapData map[string]interface{}
|
||||
if typeInfo.Kind() == reflect.Struct {
|
||||
mapData = refutil.FlatMap(structs.Map(valueInfo.Index(i).Interface()))
|
||||
mapData = refutil.FlatMap(utils.Struct2MapByJson(valueInfo.Index(i).Interface()))
|
||||
} else {
|
||||
mapData = valueInfo.Index(i).Interface().(map[string]interface{})
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func IDCULDFilterMapByStructObject(mapData map[string]interface{}, obj interface{}, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||
// 这里必须用首字母小写,因为是用于访问map,是用于访问map,是需要完全匹配的
|
||||
// 这里必须用首字母小写,因为是用于访问map,是需要完全匹配的
|
||||
return refutil.FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "updatedAt", "finishedAt", "deletedAt", "syncStatus", "lastOperator"}, isCheckValue)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"reflect"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"github.com/fatih/structs"
|
||||
)
|
||||
|
||||
func CheckAndGetStructValue(item interface{}) *reflect.Value {
|
||||
@@ -70,7 +69,7 @@ func FlatMap(in map[string]interface{}) map[string]interface{} {
|
||||
}
|
||||
|
||||
func Struct2FlatMap(obj interface{}) map[string]interface{} {
|
||||
m := structs.Map(obj)
|
||||
m := utils.Struct2MapByJson(obj)
|
||||
return FlatMap(m)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user