50 lines
981 B
Go
50 lines
981 B
Go
![]() |
package controller
|
||
|
|
||
|
import (
|
||
|
"SciencesServer/app/api/website/model"
|
||
|
model2 "SciencesServer/app/common/model"
|
||
|
)
|
||
|
|
||
|
type Platform struct{}
|
||
|
|
||
|
type PlatformHandle func() *Platform
|
||
|
|
||
|
type PlatformInfo struct {
|
||
|
Title string `json:"title"`
|
||
|
Link string `json:"link"`
|
||
|
Children []*PlatformInfo `json:"children"`
|
||
|
}
|
||
|
|
||
|
// tree 树状
|
||
|
func (c *Platform) tree(src []*model2.SysPlatform, parentID uint64) []*PlatformInfo {
|
||
|
out := make([]*PlatformInfo, 0)
|
||
|
|
||
|
for _, v := range src {
|
||
|
if v.ParentID == parentID {
|
||
|
out = append(out, &PlatformInfo{
|
||
|
Title: v.Title,
|
||
|
Link: v.Link,
|
||
|
Children: c.tree(src, v.ID),
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
return out
|
||
|
}
|
||
|
|
||
|
// Instance 平台信息
|
||
|
func (c *Platform) Instance() ([]*PlatformInfo, error) {
|
||
|
mSysPlatform := model.NewSysPlatform()
|
||
|
out, err := mSysPlatform.Platform()
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return c.tree(out, 0), nil
|
||
|
}
|
||
|
|
||
|
func NewPlatform() PlatformHandle {
|
||
|
return func() *Platform {
|
||
|
return &Platform{}
|
||
|
}
|
||
|
}
|