feat:完善项目信息
This commit is contained in:
@ -9,6 +9,39 @@ import (
|
||||
|
||||
type Sys struct{}
|
||||
|
||||
func (*Sys) Industry(c *gin.Context) {
|
||||
data, err := sys.NewIndustry()(api.GetSession()(c).(*session.Admin)).Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) IndustryForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Name string `json:"name" form:"name"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := sys.NewIndustry()(api.GetSession()(c).(*session.Admin)).Form(&sys.IndustryParams{
|
||||
ID: form.IDStringForm.Convert(), PatentID: (&api.IDStringForm{ID: form.ParentID}).Convert(),
|
||||
Name: form.Name,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Sys) IndustryDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := sys.NewIndustry()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Sys) Navigation(c *gin.Context) {
|
||||
form := new(api.TenantIDStringForm)
|
||||
|
||||
|
99
app/api/admin/controller/sys/industry.go
Normal file
99
app/api/admin/controller/sys/industry.go
Normal file
@ -0,0 +1,99 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Industry struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type IndustryHandle func(session *session.Admin) *Industry
|
||||
|
||||
type (
|
||||
// IndustryInfo 行业领域信息
|
||||
IndustryInfo struct {
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
Children []*IndustryInfo `json:"children"`
|
||||
}
|
||||
// IndustryParams 行业领域参数信息
|
||||
IndustryParams struct {
|
||||
ID, PatentID uint64
|
||||
Name string
|
||||
}
|
||||
)
|
||||
|
||||
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: v.GetEncodeID(),
|
||||
ParentID: (&model2.Model{ID: v.ParentID}).GetEncodeID(),
|
||||
Name: v.Name,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Industry) Instance() ([]*IndustryInfo, error) {
|
||||
mSysIndustry := new(model.SysIndustry)
|
||||
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
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Industry) Form(params *IndustryParams) error {
|
||||
mSysIndustry := model.NewSysIndustry()
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysIndustry.ID = params.ID
|
||||
|
||||
if isExist, err := model2.First(mSysIndustry.SysIndustry); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,行业信息不存在或已被删除")
|
||||
}
|
||||
}
|
||||
mSysIndustry.ParentID = params.PatentID
|
||||
mSysIndustry.Name = params.Name
|
||||
|
||||
if mSysIndustry.ID > 0 {
|
||||
return model2.Updates(mSysIndustry.SysIndustry, mSysIndustry.SysIndustry)
|
||||
}
|
||||
return model2.Create(mSysIndustry.SysIndustry)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Industry) Delete(id uint64) error {
|
||||
mSysIndustry := new(model.SysIndustry)
|
||||
mSysIndustry.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysIndustry.SysIndustry, []string{"id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,行业信息不存在或已被删除")
|
||||
}
|
||||
return model2.Delete(mSysIndustry.SysIndustry)
|
||||
}
|
||||
|
||||
func NewIndustry() IndustryHandle {
|
||||
return func(session *session.Admin) *Industry {
|
||||
return &Industry{session}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
"SciencesServer/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -25,7 +26,7 @@ func (a *Config) Industry(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data := controller.NewConfig().Industry((&IDStringForm{ID: form.ParentID}).Convert())
|
||||
data := controller.NewConfig().Industry(utils.StringToUnit64(form.ParentID))
|
||||
APISuccess(data)(c)
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
config2 "SciencesServer/config"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Config struct{}
|
||||
@ -52,7 +53,8 @@ func (c *Config) Industry(parentID uint64) []*IndustryInfo {
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &IndustryInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
//ID: v.GetEncodeID(),
|
||||
ID: fmt.Sprintf("%d", v.ID),
|
||||
Name: v.Name,
|
||||
})
|
||||
}
|
||||
|
@ -176,6 +176,10 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
{
|
||||
_api := new(api1.Sys)
|
||||
// 导航信息
|
||||
sys.GET("/industry", _api.Industry)
|
||||
sys.GET("/industry/add", _api.NavigationForm)
|
||||
sys.GET("/industry/edit", _api.NavigationForm)
|
||||
sys.GET("/industry/delete", _api.NavigationDelete)
|
||||
sys.GET("/navigation", _api.Navigation)
|
||||
sys.POST("/navigation/add", _api.NavigationForm)
|
||||
sys.POST("/navigation/edit", _api.NavigationForm)
|
||||
|
Reference in New Issue
Block a user