- fixed TestDictKeysMan bug
- order api added.
This commit is contained in:
@@ -1,5 +1,25 @@
|
||||
package jdapi
|
||||
|
||||
func (j JDAPI) OrderQuery(jdParams map[string]string) ([]interface{}, error) {
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func (j JDAPI) OrderQuery(jdParams map[string]string) (retVal []interface{}, err error) {
|
||||
retVal, err = j.accessJDQueryHavePage("order/es/query", jdParams, nil, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
func (j JDAPI) QuerySignleOrder(orderId string) ([]interface{}, error) {
|
||||
jdParams := make(map[string]string)
|
||||
jdParams["orderId"] = orderId
|
||||
return j.accessJDQueryHavePage("order/es/query", jdParams, nil, nil, nil)
|
||||
}
|
||||
|
||||
func (j JDAPI) OrderAcceptOperate(orderId string, isAgreed bool) (interface{}, error) {
|
||||
jdParams := map[string]string{
|
||||
"orderId": orderId,
|
||||
"isAgreed": utils.Bool2String(isAgreed),
|
||||
"operator": getJDOperator(),
|
||||
}
|
||||
return j.accessJDQueryNoPage("order/es/query", jdParams, nil, nil)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,17 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func GetConcretValue(value reflect.Value) reflect.Value {
|
||||
for {
|
||||
if value.Kind() == reflect.Interface || value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func DictKeysMan(data interface{}, keysToRemove []string, keysToKeep []string) interface{} {
|
||||
if data == nil || (keysToKeep == nil && keysToRemove == nil) {
|
||||
return data
|
||||
@@ -37,10 +48,7 @@ func DictKeysMan(data interface{}, keysToRemove []string, keysToKeep []string) i
|
||||
retVal := make([]interface{}, valueOfData.Len())
|
||||
|
||||
for index := 0; index < valueOfData.Len(); index++ {
|
||||
realV := valueOfData.Index(index)
|
||||
if realV.Kind() == reflect.Interface || realV.Kind() == reflect.Ptr {
|
||||
realV = realV.Elem()
|
||||
}
|
||||
realV := GetConcretValue(valueOfData.Index(index))
|
||||
if keysToRemoveMap != nil || keysToKeepMap != nil {
|
||||
mapV := make(map[string]interface{})
|
||||
for _, key := range realV.MapKeys() {
|
||||
@@ -56,7 +64,7 @@ func DictKeysMan(data interface{}, keysToRemove []string, keysToKeep []string) i
|
||||
}
|
||||
}
|
||||
if wantThisField {
|
||||
mapV[fieldName] = realV.MapIndex(key)
|
||||
mapV[fieldName] = GetConcretValue(realV.MapIndex(key)).Interface()
|
||||
}
|
||||
}
|
||||
retVal[index] = mapV
|
||||
@@ -76,3 +84,10 @@ func UnmarshalUseNumber(data []byte, result interface{}) error {
|
||||
d.UseNumber()
|
||||
return d.Decode(result)
|
||||
}
|
||||
|
||||
func Bool2String(value bool) string {
|
||||
if value {
|
||||
return "true"
|
||||
}
|
||||
return "false"
|
||||
}
|
||||
|
||||
@@ -15,16 +15,22 @@ func (t TT) foo() {
|
||||
|
||||
}
|
||||
func TestDictKeysMan(t *testing.T) {
|
||||
testData := map[string]string{"k1": "v1", "k2": "v2"}
|
||||
testData := map[string]interface{}{"k1": "v1", "k2": "v2"}
|
||||
result1 := DictKeysMan(testData, []string{"k1"}, nil).(map[string]interface{})
|
||||
if _, ok := result1["k1"]; ok {
|
||||
t.Error("Params keysToRemove can not remove key!")
|
||||
}
|
||||
if _, ok := result1["k2"]; !ok {
|
||||
if k2Value, ok := result1["k2"]; !ok {
|
||||
t.Error("Params keysToRemove removed wrong key!")
|
||||
} else {
|
||||
k2ValueStr, _ := k2Value.(string)
|
||||
if k2ValueStr != "v2" {
|
||||
t.Logf("k2Value:%s", k2ValueStr)
|
||||
t.Error("wrong data when removeKeys")
|
||||
}
|
||||
}
|
||||
|
||||
result2 := DictKeysMan([]interface{}{testData}, nil, []string{"k1"}).([]interface{})
|
||||
result2 := DictKeysMan([]interface{}{testData, map[string]string{"k1": "v11", "k2": "v22"}}, nil, []string{"k1"}).([]interface{})
|
||||
result20 := result2[0].(map[string]interface{})
|
||||
if _, ok := result20["k1"]; !ok {
|
||||
t.Error("Params keysToKeep can not keep key!")
|
||||
|
||||
Reference in New Issue
Block a user