作者 庄敏学

字库排序报错,改为数据获取后再进行排序

@@ -2,13 +2,13 @@ package table @@ -2,13 +2,13 @@ package table
2 2
3 import ( 3 import (
4 "context" 4 "context"
5 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"  
6 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"  
7 - 5 + "github.com/zeromicro/go-zero/core/logx"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
10 -  
11 - "github.com/zeromicro/go-zero/core/logx" 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"
  10 + "sort"
  11 + "strings"
12 ) 12 )
13 13
14 type SearchTableDataLogic struct { 14 type SearchTableDataLogic struct {
@@ -48,6 +48,28 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest @@ -48,6 +48,28 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
48 if err != nil { 48 if err != nil {
49 return resp, xerr.NewErr(err) 49 return resp, xerr.NewErr(err)
50 } 50 }
  51 + //排序
  52 + orderField := ""
  53 + orderBy := ""
  54 + for _, item := range req.Condition {
  55 + if item.Order != "" {
  56 + orderField = item.FieldName
  57 + orderBy = item.Order
  58 + break
  59 + }
  60 + }
  61 + sort.Slice(response.Grid.List, func(i, j int) bool {
  62 + if _, ok := response.Grid.List[i][orderField]; ok {
  63 + if _, ok := response.Grid.List[j][orderField]; ok {
  64 + if strings.ToLower(orderBy) == "asc" {
  65 + return response.Grid.List[i][orderField] < response.Grid.List[j][orderField]
  66 + } else {
  67 + return response.Grid.List[i][orderField] > response.Grid.List[j][orderField]
  68 + }
  69 + }
  70 + }
  71 + return true
  72 + })
51 resp = map[string]interface{}{ 73 resp = map[string]interface{}{
52 "objectId": response.ObjectId, 74 "objectId": response.ObjectId,
53 "fields": removeIdField(response.Fields), 75 "fields": removeIdField(response.Fields),
@@ -58,18 +58,16 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere { @@ -58,18 +58,16 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere {
58 //if order == "" { 58 //if order == "" {
59 // order = "ASC" 59 // order = "ASC"
60 //} 60 //}
61 - order := ""  
62 - if c.Order != "" {  
63 - order = c.FieldName + " " + order 61 + if c.Like != "" || len(c.In) > 0 {
  62 + where.Conditions = append(where.Conditions, &bytelib.TableQueryCondition{
  63 + Field: &bytelib.Field{
  64 + Name: c.FieldName,
  65 + },
  66 + Like: c.Like,
  67 + In: c.In,
  68 + //Order: order,
  69 + })
64 } 70 }
65 - where.Conditions = append(where.Conditions, &bytelib.TableQueryCondition{  
66 - Field: &bytelib.Field{  
67 - Name: c.FieldName,  
68 - },  
69 - Like: c.Like,  
70 - In: c.In,  
71 - Order: order,  
72 - })  
73 } 71 }
74 return where 72 return where
75 } 73 }