fix bug
Signed-off-by: jagger <cossjie@foxmail.com> Former-commit-id: afd3e450e10a2fc1d7779633540d4f1bf8b8478f
This commit is contained in:
parent
91e71e1b80
commit
321a054df2
|
@ -955,6 +955,7 @@ type (
|
||||||
ParentId string `json:"parentId,omitempty"`
|
ParentId string `json:"parentId,omitempty"`
|
||||||
Status string `json:"status,omitempty" db:"status"`
|
Status string `json:"status,omitempty" db:"status"`
|
||||||
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||||
|
Children []DictItemInfo `json:"children,omitempty" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
DictItemReq {
|
DictItemReq {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dictionary
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
@ -38,6 +39,22 @@ func (l *ListDictItemByCodeLogic) ListDictItemByCode(req *types.DictCodeReq) (re
|
||||||
logx.Errorf("ListDictItemByCode()=> failed %s", err.Error())
|
logx.Errorf("ListDictItemByCode()=> failed %s", err.Error())
|
||||||
return nil, errors.New("description Failed to query dictionary entry data")
|
return nil, errors.New("description Failed to query dictionary entry data")
|
||||||
}
|
}
|
||||||
resp.List = dictList
|
|
||||||
|
// 找出第一级字典项,(父字典项id为0)
|
||||||
|
dictItemFormat := make([]types.DictItemInfo, 0)
|
||||||
|
for _, item := range dictList {
|
||||||
|
if item.ParentId == "0" {
|
||||||
|
dictItemFormat = append(dictItemFormat, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 排序
|
||||||
|
sort.Slice(dictItemFormat, func(i, j int) bool {
|
||||||
|
return dictItemFormat[i].SortOrder < dictItemFormat[j].SortOrder
|
||||||
|
})
|
||||||
|
|
||||||
|
// 递归找出一级路由下面的子路由
|
||||||
|
getTreeMap(dictItemFormat, dictList)
|
||||||
|
|
||||||
|
resp.List = dictItemFormat
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
@ -56,10 +57,44 @@ func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.Pa
|
||||||
db = db.Limit(limit).Offset(offset)
|
db = db.Limit(limit).Offset(offset)
|
||||||
err = db.Order("sort_order").Find(&dictList).Error
|
err = db.Order("sort_order").Find(&dictList).Error
|
||||||
|
|
||||||
resp.List = dictList
|
// 找出第一级字典项,(父字典项id为0)
|
||||||
|
dictItemFormat := make([]types.DictItemInfo, 0)
|
||||||
|
for _, item := range dictList {
|
||||||
|
if item.ParentId == "0" {
|
||||||
|
dictItemFormat = append(dictItemFormat, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 排序
|
||||||
|
sort.Slice(dictItemFormat, func(i, j int) bool {
|
||||||
|
return dictItemFormat[i].SortOrder < dictItemFormat[j].SortOrder
|
||||||
|
})
|
||||||
|
|
||||||
|
// 递归找出一级路由下面的子路由
|
||||||
|
getTreeMap(dictItemFormat, dictList)
|
||||||
|
|
||||||
|
resp.List = dictItemFormat
|
||||||
resp.PageSize = req.PageSize
|
resp.PageSize = req.PageSize
|
||||||
resp.PageNum = req.PageNum
|
resp.PageNum = req.PageNum
|
||||||
resp.Total = total
|
resp.Total = total
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTreeMap(dictItemFormat []types.DictItemInfo, dictItems []types.DictItemInfo) {
|
||||||
|
for index, itemF := range dictItemFormat {
|
||||||
|
for _, dictItem := range dictItems {
|
||||||
|
if itemF.Id == dictItem.ParentId {
|
||||||
|
// itemF 只是个复制值
|
||||||
|
//itemF.Children = append(itemF.Children, dictItem)
|
||||||
|
dictItemFormat[index].Children = append(dictItemFormat[index].Children, dictItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(dictItemFormat[index].Children) > 0 {
|
||||||
|
// 排序
|
||||||
|
sort.Slice(dictItemFormat[index].Children, func(i, j int) bool {
|
||||||
|
return dictItemFormat[index].Children[i].SortOrder < dictItemFormat[index].Children[j].SortOrder
|
||||||
|
})
|
||||||
|
getTreeMap(dictItemFormat[index].Children, dictItems)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -882,15 +882,16 @@ type Dicts struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DictItemInfo struct {
|
type DictItemInfo struct {
|
||||||
Id string `json:"id,omitempty"`
|
Id string `json:"id,omitempty"`
|
||||||
DictId string `json:"dictId,omitempty"`
|
DictId string `json:"dictId,omitempty"`
|
||||||
ItemText string `json:"itemText,omitempty"`
|
ItemText string `json:"itemText,omitempty"`
|
||||||
ItemValue string `json:"itemValue,omitempty"`
|
ItemValue string `json:"itemValue,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
SortOrder string `json:"sortOrder,omitempty"`
|
SortOrder string `json:"sortOrder,omitempty"`
|
||||||
ParentId string `json:"parentId,omitempty"`
|
ParentId string `json:"parentId,omitempty"`
|
||||||
Status string `json:"status,omitempty" db:"status"`
|
Status string `json:"status,omitempty" db:"status"`
|
||||||
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||||
|
Children []DictItemInfo `json:"children,omitempty" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DictItemReq struct {
|
type DictItemReq struct {
|
||||||
|
|
Loading…
Reference in New Issue