- 去掉dao对于jxutils的依赖
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LoopStoreMapInfo struct {
|
type LoopStoreMapInfo struct {
|
||||||
@@ -134,7 +135,7 @@ func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.I
|
|||||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
cat := batchItemList[0].(*model.SkuCategory)
|
cat := batchItemList[0].(*model.SkuCategory)
|
||||||
updateFields := []string{syncStatusFieldName}
|
updateFields := []string{syncStatusFieldName}
|
||||||
syncStatus := jxutils.GetObjFieldByName(cat, syncStatusFieldName).(int8)
|
syncStatus := refutil.GetObjFieldByName(cat, syncStatusFieldName).(int8)
|
||||||
if (syncStatus & model.SyncFlagDeletedMask) != 0 { //删除
|
if (syncStatus & model.SyncFlagDeletedMask) != 0 { //删除
|
||||||
err = multiStoresHandler.DeleteCategory(db, cat, userName)
|
err = multiStoresHandler.DeleteCategory(db, cat, userName)
|
||||||
} else if (syncStatus & model.SyncFlagNewMask) != 0 { // 新增
|
} else if (syncStatus & model.SyncFlagNewMask) != 0 { // 新增
|
||||||
@@ -147,7 +148,7 @@ func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.I
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
jxutils.SetObjFieldByName(cat, syncStatusFieldName, int8(0))
|
refutil.SetObjFieldByName(cat, syncStatusFieldName, int8(0))
|
||||||
_, err = dao.UpdateEntity(db, cat, updateFields...)
|
_, err = dao.UpdateEntity(db, cat, updateFields...)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -274,7 +275,7 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI
|
|||||||
ORDER BY IF(spec_unit IN('kg', 'L'), 1000, 1) * spec_quality
|
ORDER BY IF(spec_unit IN('kg', 'L'), 1000, 1) * spec_quality
|
||||||
`, dbField), skuName.ID); err == nil && len(skuList) > 0 {
|
`, dbField), skuName.ID); err == nil && len(skuList) > 0 {
|
||||||
for _, sku := range skuList {
|
for _, sku := range skuList {
|
||||||
syncStatus := jxutils.GetObjFieldByName(sku, syncStatusFieldName).(int8)
|
syncStatus := refutil.GetObjFieldByName(sku, syncStatusFieldName).(int8)
|
||||||
globals.SugarLogger.Debugf("SyncSku trackInfo:%s, skuID:%d, syncStatus:%d", ctx.GetTrackInfo(), sku.ID, syncStatus)
|
globals.SugarLogger.Debugf("SyncSku trackInfo:%s, skuID:%d, syncStatus:%d", ctx.GetTrackInfo(), sku.ID, syncStatus)
|
||||||
if (skuID == -1 || skuID == sku.ID) && (syncStatus != 0) {
|
if (skuID == -1 || skuID == sku.ID) && (syncStatus != 0) {
|
||||||
updateFields := []string{syncStatusFieldName}
|
updateFields := []string{syncStatusFieldName}
|
||||||
@@ -296,7 +297,7 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI
|
|||||||
err = multiStoresHandler.UpdateSku(db, sku, userName)
|
err = multiStoresHandler.UpdateSku(db, sku, userName)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
jxutils.SetObjFieldByName(sku, syncStatusFieldName, int8(0))
|
refutil.SetObjFieldByName(sku, syncStatusFieldName, int8(0))
|
||||||
if _, err = dao.UpdateEntity(db, sku, updateFields...); err != nil {
|
if _, err = dao.UpdateEntity(db, sku, updateFields...); err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -305,7 +306,7 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
jxutils.SetObjFieldByName(skuName, syncStatusFieldName, int8(0))
|
refutil.SetObjFieldByName(skuName, syncStatusFieldName, int8(0))
|
||||||
_, err = dao.UpdateEntity(db, skuName, syncStatusFieldName)
|
_, err = dao.UpdateEntity(db, skuName, syncStatusFieldName)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
||||||
"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"
|
||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
)
|
)
|
||||||
@@ -52,7 +52,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 = jxutils.FlatMap(structs.Map(valueInfo.Index(i).Interface()))
|
mapData = refutil.FlatMap(structs.Map(valueInfo.Index(i).Interface()))
|
||||||
} else {
|
} else {
|
||||||
mapData = valueInfo.Index(i).Interface().(map[string]interface{})
|
mapData = valueInfo.Index(i).Interface().(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
"git.rosy.net.cn/baseapi/utils/routinepool"
|
||||||
@@ -343,63 +341,6 @@ func SplitSkuName(skuName string) (prefix, name, comment, specUnit, unit string,
|
|||||||
return prefix, name, comment, specUnit, unit, specQuality
|
return prefix, name, comment, specUnit, unit, specQuality
|
||||||
}
|
}
|
||||||
|
|
||||||
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 := structs.Map(obj)
|
|
||||||
return FlatMap(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo 这里看是否需要将key值转换成标准格式(即字母大写),因为beego orm不区分,不转换也可以
|
|
||||||
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)
|
|
||||||
for _, v := range excludedFields {
|
|
||||||
excludedMap[v] = 1
|
|
||||||
}
|
|
||||||
m := Struct2FlatMap(obj)
|
|
||||||
valid = make(map[string]interface{})
|
|
||||||
invalid = make(map[string]interface{})
|
|
||||||
for k, v := range mapData {
|
|
||||||
if m[k] != nil && excludedMap[k] == 0 && v != nil && (!isCheckValue || !IsValueEqual(m[k], v)) {
|
|
||||||
valid[k] = v
|
|
||||||
} else {
|
|
||||||
invalid[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return valid, invalid
|
|
||||||
}
|
|
||||||
|
|
||||||
func FilterMapByFieldList(mapData map[string]interface{}, fields []string) (valid map[string]interface{}, invalid map[string]interface{}) {
|
|
||||||
valid = make(map[string]interface{})
|
|
||||||
invalid = make(map[string]interface{})
|
|
||||||
for _, field := range fields {
|
|
||||||
if mapData[field] != nil {
|
|
||||||
valid[field] = mapData[field]
|
|
||||||
} else {
|
|
||||||
invalid[field] = mapData[field]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return valid, invalid
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeValidationMapFromSlice(validValues []string, flag int) map[string]int {
|
func MakeValidationMapFromSlice(validValues []string, flag int) map[string]int {
|
||||||
retVal := make(map[string]int)
|
retVal := make(map[string]int)
|
||||||
for _, v := range validValues {
|
for _, v := range validValues {
|
||||||
@@ -452,7 +393,3 @@ func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsValueEqual(value1, value2 interface{}) bool {
|
|
||||||
return fmt.Sprint(value1) == fmt.Sprint(value2)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package jxutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/gob"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CheckAndGetStructValue(item interface{}) *reflect.Value {
|
|
||||||
value := reflect.ValueOf(item)
|
|
||||||
if value.Kind() == reflect.Ptr {
|
|
||||||
value = value.Elem()
|
|
||||||
} else {
|
|
||||||
panic("item ust be ptr type")
|
|
||||||
}
|
|
||||||
return &value
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetObjFieldByName(obj interface{}, fieldName string) interface{} {
|
|
||||||
return reflect.Indirect(reflect.ValueOf(obj)).FieldByName(fieldName).Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetObjFieldByName(obj interface{}, fieldName string, value interface{}) {
|
|
||||||
refValue := CheckAndGetStructValue(obj)
|
|
||||||
refValue.FieldByName(fieldName).Set(reflect.ValueOf(value))
|
|
||||||
}
|
|
||||||
|
|
||||||
func SerializeData(data interface{}) (strValue string, err error) {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
enc := gob.NewEncoder(&buf)
|
|
||||||
if err = enc.Encode(data); err == nil {
|
|
||||||
strValue = base64.StdEncoding.EncodeToString(buf.Bytes())
|
|
||||||
return strValue, nil
|
|
||||||
}
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeSerializeData(strValue string, dataPtr interface{}) (err error) {
|
|
||||||
byteData, err := base64.StdEncoding.DecodeString(strValue)
|
|
||||||
if err == nil {
|
|
||||||
dec := gob.NewDecoder(bytes.NewReader(byteData))
|
|
||||||
return dec.Decode(dataPtr)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ func UpdateEntityByKV(db *DaoDB, item interface{}, kvs map[string]interface{}, c
|
|||||||
}
|
}
|
||||||
qs := db.db.QueryTable(item)
|
qs := db.db.QueryTable(item)
|
||||||
if conditions == nil {
|
if conditions == nil {
|
||||||
qs = qs.Filter(model.FieldID, jxutils.GetObjFieldByName(item, model.FieldID))
|
qs = qs.Filter(model.FieldID, refutil.GetObjFieldByName(item, model.FieldID))
|
||||||
} else {
|
} else {
|
||||||
for k, v := range conditions {
|
for k, v := range conditions {
|
||||||
qs = qs.Filter(k, v)
|
qs = qs.Filter(k, v)
|
||||||
@@ -77,7 +77,7 @@ func UpdateEntityLogicallyAndUpdateSyncStatus(db *DaoDB, item interface{}, kvs m
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
conditions = map[string]interface{}{
|
conditions = map[string]interface{}{
|
||||||
model.FieldID: jxutils.GetObjFieldByName(item, model.FieldID),
|
model.FieldID: refutil.GetObjFieldByName(item, model.FieldID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typeInfo := reflect.TypeOf(item)
|
typeInfo := reflect.TypeOf(item)
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IDCULDFilterMapByStructObject(mapData map[string]interface{}, obj interface{}, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) {
|
func IDCULDFilterMapByStructObject(mapData map[string]interface{}, obj interface{}, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||||
// 这里必须用首字母小写,因为是用于访问map,是用于访问map,是需要完全匹配的
|
// 这里必须用首字母小写,因为是用于访问map,是用于访问map,是需要完全匹配的
|
||||||
return jxutils.FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "updatedAt", "finishedAt", "deletedAt", "syncStatus", "lastOperator"}, isCheckValue)
|
return refutil.FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "updatedAt", "finishedAt", "deletedAt", "syncStatus", "lastOperator"}, isCheckValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NormalMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) {
|
func NormalMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) {
|
||||||
@@ -27,7 +27,7 @@ func StrictMakeMapByStructObject(mapData map[string]interface{}, obj interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NormalMakeMapByFieldList(mapData map[string]interface{}, fields []string, userName string) (retVal map[string]interface{}) {
|
func NormalMakeMapByFieldList(mapData map[string]interface{}, fields []string, userName string) (retVal map[string]interface{}) {
|
||||||
retVal, _ = jxutils.FilterMapByFieldList(mapData, fields)
|
retVal, _ = refutil.FilterMapByFieldList(mapData, fields)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ func WrapAddIDCULEntity(item interface{}, lastOperator string) interface{} {
|
|||||||
mapData[model.FieldUpdatedAt] = now
|
mapData[model.FieldUpdatedAt] = now
|
||||||
mapData[model.FieldLastOperator] = lastOperator
|
mapData[model.FieldLastOperator] = lastOperator
|
||||||
} else {
|
} else {
|
||||||
value := jxutils.CheckAndGetStructValue(item)
|
value := refutil.CheckAndGetStructValue(item)
|
||||||
nowValue := reflect.ValueOf(now)
|
nowValue := reflect.ValueOf(now)
|
||||||
value.FieldByName(model.FieldID).SetInt(0)
|
value.FieldByName(model.FieldID).SetInt(0)
|
||||||
value.FieldByName(model.FieldCreatedAt).Set(nowValue)
|
value.FieldByName(model.FieldCreatedAt).Set(nowValue)
|
||||||
@@ -53,7 +53,7 @@ func WrapAddIDCULDEntity(item interface{}, lastOperator string) interface{} {
|
|||||||
if mapData, ok := item.(map[string]interface{}); ok {
|
if mapData, ok := item.(map[string]interface{}); ok {
|
||||||
mapData[model.FieldDeletedAt] = utils.DefaultTimeValue
|
mapData[model.FieldDeletedAt] = utils.DefaultTimeValue
|
||||||
} else {
|
} else {
|
||||||
value := jxutils.CheckAndGetStructValue(item)
|
value := refutil.CheckAndGetStructValue(item)
|
||||||
value.FieldByName(model.FieldDeletedAt).Set(reflect.ValueOf(utils.DefaultTimeValue))
|
value.FieldByName(model.FieldDeletedAt).Set(reflect.ValueOf(utils.DefaultTimeValue))
|
||||||
}
|
}
|
||||||
return WrapAddIDCULEntity(item, lastOperator)
|
return WrapAddIDCULEntity(item, lastOperator)
|
||||||
@@ -65,7 +65,7 @@ func WrapUpdateULEntity(item interface{}, lastOperator string) interface{} {
|
|||||||
mapData[model.FieldUpdatedAt] = now
|
mapData[model.FieldUpdatedAt] = now
|
||||||
mapData[model.FieldLastOperator] = lastOperator
|
mapData[model.FieldLastOperator] = lastOperator
|
||||||
} else {
|
} else {
|
||||||
value := jxutils.CheckAndGetStructValue(item)
|
value := refutil.CheckAndGetStructValue(item)
|
||||||
nowValue := reflect.ValueOf(now)
|
nowValue := reflect.ValueOf(now)
|
||||||
value.FieldByName(model.FieldUpdatedAt).Set(nowValue)
|
value.FieldByName(model.FieldUpdatedAt).Set(nowValue)
|
||||||
value.FieldByName(model.FieldLastOperator).SetString(lastOperator)
|
value.FieldByName(model.FieldLastOperator).SetString(lastOperator)
|
||||||
|
|||||||
111
globals/refutil/refutil.go
Normal file
111
globals/refutil/refutil.go
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
package refutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/gob"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"github.com/fatih/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckAndGetStructValue(item interface{}) *reflect.Value {
|
||||||
|
value := reflect.ValueOf(item)
|
||||||
|
if value.Kind() == reflect.Ptr {
|
||||||
|
value = value.Elem()
|
||||||
|
} else {
|
||||||
|
panic("item ust be ptr type")
|
||||||
|
}
|
||||||
|
return &value
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetObjFieldByName(obj interface{}, fieldName string) interface{} {
|
||||||
|
return reflect.Indirect(reflect.ValueOf(obj)).FieldByName(fieldName).Interface()
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetObjFieldByName(obj interface{}, fieldName string, value interface{}) {
|
||||||
|
refValue := CheckAndGetStructValue(obj)
|
||||||
|
refValue.FieldByName(fieldName).Set(reflect.ValueOf(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func SerializeData(data interface{}) (strValue string, err error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
enc := gob.NewEncoder(&buf)
|
||||||
|
if err = enc.Encode(data); err == nil {
|
||||||
|
strValue = base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||||
|
return strValue, nil
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeSerializeData(strValue string, dataPtr interface{}) (err error) {
|
||||||
|
byteData, err := base64.StdEncoding.DecodeString(strValue)
|
||||||
|
if err == nil {
|
||||||
|
dec := gob.NewDecoder(bytes.NewReader(byteData))
|
||||||
|
return dec.Decode(dataPtr)
|
||||||
|
}
|
||||||
|
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 := structs.Map(obj)
|
||||||
|
return FlatMap(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo 这里看是否需要将key值转换成标准格式(即字母大写),因为beego orm不区分,不转换也可以
|
||||||
|
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)
|
||||||
|
for _, v := range excludedFields {
|
||||||
|
excludedMap[v] = 1
|
||||||
|
}
|
||||||
|
m := Struct2FlatMap(obj)
|
||||||
|
valid = make(map[string]interface{})
|
||||||
|
invalid = make(map[string]interface{})
|
||||||
|
for k, v := range mapData {
|
||||||
|
if m[k] != nil && excludedMap[k] == 0 && v != nil && (!isCheckValue || !IsValueEqual(m[k], v)) {
|
||||||
|
valid[k] = v
|
||||||
|
} else {
|
||||||
|
invalid[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valid, invalid
|
||||||
|
}
|
||||||
|
|
||||||
|
func FilterMapByFieldList(mapData map[string]interface{}, fields []string) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||||
|
valid = make(map[string]interface{})
|
||||||
|
invalid = make(map[string]interface{})
|
||||||
|
for _, field := range fields {
|
||||||
|
if mapData[field] != nil {
|
||||||
|
valid[field] = mapData[field]
|
||||||
|
} else {
|
||||||
|
invalid[field] = mapData[field]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valid, invalid
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsValueEqual(value1, value2 interface{}) bool {
|
||||||
|
return fmt.Sprint(value1) == fmt.Sprint(value2)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user