- 将FlatMap,Struct2FlatMap从jxutils移到utils中

This commit is contained in:
gazebo
2019-04-03 10:47:47 +08:00
parent 03e4f9e979
commit 5f6d40caa1
2 changed files with 2 additions and 28 deletions

View File

@@ -8,7 +8,6 @@ import (
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/refutil"
"github.com/360EntSecGroup-Skylar/excelize" "github.com/360EntSecGroup-Skylar/excelize"
) )
@@ -52,7 +51,7 @@ func Obj2Excel(sheetList []*Obj2ExcelSheetConfig) []byte {
for i := 0; i < valueInfo.Len(); i++ { for i := 0; i < valueInfo.Len(); i++ {
var mapData map[string]interface{} var mapData map[string]interface{}
if typeInfo.Kind() == reflect.Struct { if typeInfo.Kind() == reflect.Struct {
mapData = refutil.FlatMap(utils.Struct2MapByJson(valueInfo.Index(i).Interface())) mapData = utils.FlatMap(utils.Struct2MapByJson(valueInfo.Index(i).Interface()))
} else { } else {
mapData = valueInfo.Index(i).Interface().(map[string]interface{}) mapData = valueInfo.Index(i).Interface().(map[string]interface{})
} }

View File

@@ -48,38 +48,13 @@ func DeSerializeData(strValue string, dataPtr interface{}) (err error) {
return err return err
} }
func FlatMap(in map[string]interface{}) map[string]interface{} {
keys := []string{}
maps := []map[string]interface{}{}
for k, v := range in {
if vMap, ok := v.(map[string]interface{}); ok {
vMap = FlatMap(vMap)
maps = append(maps, vMap)
keys = append(keys, k)
}
}
if len(maps) > 0 {
retVal := utils.MergeMaps(in, maps...)
for _, v := range keys {
delete(retVal, v)
}
return retVal
}
return in
}
func Struct2FlatMap(obj interface{}) map[string]interface{} {
m := utils.Struct2MapByJson(obj)
return FlatMap(m)
}
// todo 这里看是否需要将key值转换成标准格式即字母大写因为beego orm不区分不转换也可以 // todo 这里看是否需要将key值转换成标准格式即字母大写因为beego orm不区分不转换也可以
func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) { func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) {
excludedMap := make(map[string]int) excludedMap := make(map[string]int)
for _, v := range excludedFields { for _, v := range excludedFields {
excludedMap[v] = 1 excludedMap[v] = 1
} }
m := Struct2FlatMap(obj) m := utils.Struct2FlatMap(obj)
valid = make(map[string]interface{}) valid = make(map[string]interface{})
invalid = make(map[string]interface{}) invalid = make(map[string]interface{})
for k, v := range mapData { for k, v := range mapData {