feat:完善项目
This commit is contained in:
55
app/api/website/controller/sys/industry.go
Normal file
55
app/api/website/controller/sys/industry.go
Normal file
@ -0,0 +1,55 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Industry struct {
|
||||
}
|
||||
|
||||
type IndustryHandle func() *Industry
|
||||
|
||||
type (
|
||||
// IndustryInfo 行业领域信息
|
||||
IndustryInfo struct {
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
Children []*IndustryInfo `json:"children"`
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Industry) tree(src []*model2.SysIndustry, parentID uint64) []*IndustryInfo {
|
||||
out := make([]*IndustryInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &IndustryInfo{
|
||||
ID: fmt.Sprintf("%d", v.ID),
|
||||
ParentID: fmt.Sprintf("%d", v.ParentID),
|
||||
Name: v.Name,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Industry) Instance() ([]*IndustryInfo, error) {
|
||||
mSysIndustry := model.NewSysIndustry()
|
||||
out := make([]*model2.SysIndustry, 0)
|
||||
|
||||
if err := model2.ScanFields(mSysIndustry.SysIndustry, &out, []string{"id", "parent_id", "name"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
func NewIndustry() IndustryHandle {
|
||||
return func() *Industry {
|
||||
return &Industry{}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user