feat:完善项目管理
This commit is contained in:
19
app/api/website/api/sys.go
Normal file
19
app/api/website/api/sys.go
Normal file
@ -0,0 +1,19 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/controller"
|
||||
"SciencesServer/app/basic/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Sys struct{}
|
||||
|
||||
func (*Sys) Platform(c *gin.Context) {
|
||||
data, err := controller.NewPlatform()().Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) Navigation(c *gin.Context) {
|
||||
data, err := controller.NewNavigation()().Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
@ -1,11 +1,17 @@
|
||||
package controller
|
||||
|
||||
import "SciencesServer/app/service"
|
||||
import (
|
||||
"SciencesServer/app/service"
|
||||
)
|
||||
|
||||
type Config struct{ *service.Session }
|
||||
|
||||
type ConfigHandle func(session *service.Session) *Config
|
||||
|
||||
func (c *Config) Platform() {
|
||||
|
||||
}
|
||||
|
||||
func NewConfig() ConfigHandle {
|
||||
return func(session *service.Session) *Config {
|
||||
return &Config{Session: session}
|
||||
|
49
app/api/website/controller/navigation.go
Normal file
49
app/api/website/controller/navigation.go
Normal file
@ -0,0 +1,49 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type Navigation struct{}
|
||||
|
||||
type NavigationHandle func() *Navigation
|
||||
|
||||
type NavigationInfo struct {
|
||||
Title string `json:"title"`
|
||||
Link string `json:"link"`
|
||||
Children []*NavigationInfo `json:"children"`
|
||||
}
|
||||
|
||||
// tree 树状
|
||||
func (c *Navigation) tree(src []*model2.SysNavigation, parentID uint64) []*NavigationInfo {
|
||||
out := make([]*NavigationInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &NavigationInfo{
|
||||
Title: v.Title,
|
||||
Link: v.Link,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 导航栏信息
|
||||
func (c *Navigation) Instance() ([]*NavigationInfo, error) {
|
||||
mSysNavigation := model.NewSysNavigation()
|
||||
out, err := mSysNavigation.Navigation()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
func NewNavigation() NavigationHandle {
|
||||
return func() *Navigation {
|
||||
return &Navigation{}
|
||||
}
|
||||
}
|
49
app/api/website/controller/platform.go
Normal file
49
app/api/website/controller/platform.go
Normal file
@ -0,0 +1,49 @@
|
||||
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{}
|
||||
}
|
||||
}
|
28
app/api/website/model/sys_navigation.go
Normal file
28
app/api/website/model/sys_navigation.go
Normal file
@ -0,0 +1,28 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
)
|
||||
|
||||
type SysNavigation struct {
|
||||
*model.SysNavigation
|
||||
}
|
||||
|
||||
// Navigation 导航信息
|
||||
func (m *SysNavigation) Navigation() ([]*model.SysNavigation, error) {
|
||||
out := make([]*model.SysNavigation, 0)
|
||||
|
||||
err := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "parent_id", "title", "link").
|
||||
Where("status = ?", model.SysNavigationStatusForShow).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot).
|
||||
Order("sort " + model.OrderModeToDesc).
|
||||
Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func NewSysNavigation() *SysNavigation {
|
||||
return &SysNavigation{model.NewSysNavigation()}
|
||||
}
|
27
app/api/website/model/sys_platform.go
Normal file
27
app/api/website/model/sys_platform.go
Normal file
@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
)
|
||||
|
||||
type SysPlatform struct {
|
||||
*model.SysPlatform
|
||||
}
|
||||
|
||||
// Platform 平台信息
|
||||
func (m *SysPlatform) Platform() ([]*model.SysPlatform, error) {
|
||||
out := make([]*model.SysPlatform, 0)
|
||||
|
||||
err := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "parent_id", "`key`", "`code`", "title", "link").
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot).
|
||||
Order("sort " + model.OrderModeToDesc).
|
||||
Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func NewSysPlatform() *SysPlatform {
|
||||
return &SysPlatform{model.NewSysPlatform()}
|
||||
}
|
@ -113,6 +113,7 @@ func initModel() {
|
||||
}
|
||||
return out
|
||||
}},
|
||||
&synchronized{iModel: model.NewSysPlatform()}, &synchronized{iModel: model.NewSysNavigation()},
|
||||
// 日志管理
|
||||
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
||||
// 用户管理
|
||||
|
22
app/common/model/sys_platform.go
Normal file
22
app/common/model/sys_platform.go
Normal file
@ -0,0 +1,22 @@
|
||||
package model
|
||||
|
||||
// SysPlatform 平台配置数据模型
|
||||
type SysPlatform struct {
|
||||
Model
|
||||
ParentID uint64 `gorm:"column:parent_id;type:int;default:0;comment:父级ID" json:"parent_id"`
|
||||
Key string `gorm:"column:key;uniqueIndex:idx_sys_platform_key;type:varchar(15);default:'';comment:唯一标识" json:"key"`
|
||||
Code string `gorm:"column:code;type:varchar(10);default:'';comment:区域编码" json:"code"`
|
||||
Title string `gorm:"column:title;type:varchar(10);default:'';comment:区域名称" json:"title"`
|
||||
Link string `gorm:"column:link;type:varchar(255);default:'';comment:访问地址" json:"link"`
|
||||
Sort int `gorm:"column:sort;type:tinyint(3);default:0;comment:排序,从大到小" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *SysPlatform) TableName() string {
|
||||
return "sys_platform"
|
||||
}
|
||||
|
||||
func NewSysPlatform() *SysPlatform {
|
||||
return &SysPlatform{}
|
||||
}
|
@ -29,6 +29,13 @@ func registerAPI(app *gin.Engine) {
|
||||
activityV1.POST("/detail", _api.Detail)
|
||||
activityV1.POST("/join", _api.Join)
|
||||
}
|
||||
// Sys 平台信息故哪里
|
||||
sysV1 := v1.Group("/sys")
|
||||
{
|
||||
_api := new(api2.Sys)
|
||||
sysV1.GET("/platform", _api.Platform)
|
||||
sysV1.GET("/navigation", _api.Navigation)
|
||||
}
|
||||
// Docking 对接信息管理
|
||||
dockingV1 := v1.Group("/docking")
|
||||
{
|
||||
|
Reference in New Issue
Block a user