作者 庄敏学

排名图排序

... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"sort"
"strconv"
"strings"
)
... ... @@ -51,6 +52,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
//排序
orderField := ""
orderBy := ""
fieldType := "string"
for _, item := range req.Condition {
if item.Order != "" {
orderField = item.FieldName
... ... @@ -58,10 +60,25 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
break
}
}
for _, item := range response.Fields {
if orderField == item.SQLName {
fieldType = item.SQLType
}
}
fieldType = strings.ToLower(fieldType)
if orderField != "" && orderBy != "" {
sort.Slice(response.Grid.List, func(i, j int) bool {
if _, ok := response.Grid.List[i][orderField]; ok {
if _, ok := response.Grid.List[j][orderField]; ok {
if fieldType == "bigint" || fieldType == "int" || fieldType == "float" {
idata, _ := strconv.ParseFloat(response.Grid.List[i][orderField], 64)
jdata, _ := strconv.ParseFloat(response.Grid.List[j][orderField], 64)
if strings.ToLower(orderBy) == "asc" {
return idata < jdata
} else {
return idata > jdata
}
} else {
if strings.ToLower(orderBy) == "asc" {
return response.Grid.List[i][orderField] < response.Grid.List[j][orderField]
} else {
... ... @@ -69,6 +86,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
}
}
}
}
return true
})
}
... ...