作者 庄敏学

排名图排序

@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
10 "sort" 10 "sort"
  11 + "strconv"
11 "strings" 12 "strings"
12 ) 13 )
13 14
@@ -51,6 +52,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest @@ -51,6 +52,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
51 //排序 52 //排序
52 orderField := "" 53 orderField := ""
53 orderBy := "" 54 orderBy := ""
  55 + fieldType := "string"
54 for _, item := range req.Condition { 56 for _, item := range req.Condition {
55 if item.Order != "" { 57 if item.Order != "" {
56 orderField = item.FieldName 58 orderField = item.FieldName
@@ -58,10 +60,25 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest @@ -58,10 +60,25 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
58 break 60 break
59 } 61 }
60 } 62 }
  63 + for _, item := range response.Fields {
  64 + if orderField == item.SQLName {
  65 + fieldType = item.SQLType
  66 + }
  67 + }
  68 + fieldType = strings.ToLower(fieldType)
61 if orderField != "" && orderBy != "" { 69 if orderField != "" && orderBy != "" {
62 sort.Slice(response.Grid.List, func(i, j int) bool { 70 sort.Slice(response.Grid.List, func(i, j int) bool {
63 if _, ok := response.Grid.List[i][orderField]; ok { 71 if _, ok := response.Grid.List[i][orderField]; ok {
64 if _, ok := response.Grid.List[j][orderField]; ok { 72 if _, ok := response.Grid.List[j][orderField]; ok {
  73 + if fieldType == "bigint" || fieldType == "int" || fieldType == "float" {
  74 + idata, _ := strconv.ParseFloat(response.Grid.List[i][orderField], 64)
  75 + jdata, _ := strconv.ParseFloat(response.Grid.List[j][orderField], 64)
  76 + if strings.ToLower(orderBy) == "asc" {
  77 + return idata < jdata
  78 + } else {
  79 + return idata > jdata
  80 + }
  81 + } else {
65 if strings.ToLower(orderBy) == "asc" { 82 if strings.ToLower(orderBy) == "asc" {
66 return response.Grid.List[i][orderField] < response.Grid.List[j][orderField] 83 return response.Grid.List[i][orderField] < response.Grid.List[j][orderField]
67 } else { 84 } else {
@@ -69,6 +86,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest @@ -69,6 +86,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
69 } 86 }
70 } 87 }
71 } 88 }
  89 + }
72 return true 90 return true
73 }) 91 })
74 } 92 }