作者 庄敏学

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

... ... @@ -2,13 +2,13 @@ package table
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"sort"
"strings"
)
type SearchTableDataLogic struct {
... ... @@ -48,6 +48,28 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
if err != nil {
return resp, xerr.NewErr(err)
}
//排序
orderField := ""
orderBy := ""
for _, item := range req.Condition {
if item.Order != "" {
orderField = item.FieldName
orderBy = item.Order
break
}
}
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 strings.ToLower(orderBy) == "asc" {
return response.Grid.List[i][orderField] < response.Grid.List[j][orderField]
} else {
return response.Grid.List[i][orderField] > response.Grid.List[j][orderField]
}
}
}
return true
})
resp = map[string]interface{}{
"objectId": response.ObjectId,
"fields": removeIdField(response.Fields),
... ...
... ... @@ -58,18 +58,16 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere {
//if order == "" {
// order = "ASC"
//}
order := ""
if c.Order != "" {
order = c.FieldName + " " + order
}
if c.Like != "" || len(c.In) > 0 {
where.Conditions = append(where.Conditions, &bytelib.TableQueryCondition{
Field: &bytelib.Field{
Name: c.FieldName,
},
Like: c.Like,
In: c.In,
Order: order,
//Order: order,
})
}
}
return where
}
... ...