Merge pull request 'fix bug' (#206) from devad/pcm-coordinator:master into master
Former-commit-id: 36aa756e181fd39d838c792e8cf71f309280787c
This commit is contained in:
commit
378ed17411
|
@ -955,6 +955,7 @@ type (
|
|||
ParentId string `json:"parentId,omitempty"`
|
||||
Status string `json:"status,omitempty" db:"status"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||
Children []DictItemInfo `json:"children,omitempty" gorm:"-"`
|
||||
}
|
||||
|
||||
DictItemReq {
|
||||
|
|
|
@ -3,6 +3,7 @@ package dictionary
|
|||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"sort"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"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())
|
||||
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
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
"sort"
|
||||
|
||||
"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)
|
||||
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.PageNum = req.PageNum
|
||||
resp.Total = total
|
||||
|
||||
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 {
|
||||
Id string `json:"id,omitempty"`
|
||||
DictId string `json:"dictId,omitempty"`
|
||||
ItemText string `json:"itemText,omitempty"`
|
||||
ItemValue string `json:"itemValue,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
SortOrder string `json:"sortOrder,omitempty"`
|
||||
ParentId string `json:"parentId,omitempty"`
|
||||
Status string `json:"status,omitempty" db:"status"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||
Id string `json:"id,omitempty"`
|
||||
DictId string `json:"dictId,omitempty"`
|
||||
ItemText string `json:"itemText,omitempty"`
|
||||
ItemValue string `json:"itemValue,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
SortOrder string `json:"sortOrder,omitempty"`
|
||||
ParentId string `json:"parentId,omitempty"`
|
||||
Status string `json:"status,omitempty" db:"status"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||
Children []DictItemInfo `json:"children,omitempty" gorm:"-"`
|
||||
}
|
||||
|
||||
type DictItemReq struct {
|
||||
|
|
Loading…
Reference in New Issue