|
|
@ -202,3 +202,43 @@ func HttpBuildStringQuery(data map[string]string) string { |
|
|
|
|
|
|
|
return strings.Trim(query, "&") |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 对map切片 按值进行顺序 |
|
|
|
* @param order desc/asc MapDate []map[string]interface{} |
|
|
|
* @2022/10/27 |
|
|
|
* @lo |
|
|
|
*/ |
|
|
|
func MapSort(order, val string, MapDate []map[string]interface{}) ([]map[string]interface{}, error) { |
|
|
|
type KVPair struct { |
|
|
|
Key int |
|
|
|
Val string |
|
|
|
} |
|
|
|
res := []map[string]interface{}{} |
|
|
|
if order != "desc" && order != "asc" { |
|
|
|
return res, errors.New("order parameter err") |
|
|
|
} |
|
|
|
if val == "" { |
|
|
|
return res, errors.New("val parameter err") |
|
|
|
} |
|
|
|
if len(MapDate) < 1 { |
|
|
|
return res, errors.New("MapDate parameter err") |
|
|
|
} |
|
|
|
tmpList := []KVPair{} |
|
|
|
for k, item := range MapDate { |
|
|
|
tmpList = append(tmpList, KVPair{Key: k, Val: ToStr(item[val])}) |
|
|
|
} |
|
|
|
if order == "desc" { |
|
|
|
sort.Slice(tmpList, func(i, j int) bool { |
|
|
|
return tmpList[i].Val > tmpList[j].Val // 降序
|
|
|
|
}) |
|
|
|
} else { |
|
|
|
sort.Slice(tmpList, func(i, j int) bool { |
|
|
|
return tmpList[i].Val < tmpList[j].Val // 升序
|
|
|
|
}) |
|
|
|
} |
|
|
|
for _, tmp := range tmpList { |
|
|
|
res = append(res, MapDate[tmp.Key]) |
|
|
|
} |
|
|
|
return res, nil |
|
|
|
} |