feat:增加用户企业管理信息
This commit is contained in:
102
app/api/enterprise/api/manage.go
Normal file
102
app/api/enterprise/api/manage.go
Normal file
@ -0,0 +1,102 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/controller/manage"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Manage struct{}
|
||||
|
||||
type (
|
||||
// enterpriseForm 企业信息
|
||||
enterpriseForm struct {
|
||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Content string `json:"content" form:"content"`
|
||||
Papers []string `json:"papers" form:"papers"`
|
||||
Patents []string `json:"patents" form:"patents"`
|
||||
}
|
||||
)
|
||||
|
||||
func (a *enterpriseForm) paperInfo() []uint64 {
|
||||
out := make([]uint64, 0)
|
||||
obj := new(api.IDStringForm)
|
||||
|
||||
for _, v := range a.Papers {
|
||||
obj.ID = v
|
||||
out = append(out, obj.Convert())
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (a *enterpriseForm) PatentInfo() []uint64 {
|
||||
out := make([]uint64, 0)
|
||||
obj := new(api.IDStringForm)
|
||||
|
||||
for _, v := range a.Patents {
|
||||
obj.ID = v
|
||||
out = append(out, obj.Convert())
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (*Manage) Enterprise(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||
Title string `json:"title" form:"title"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewEnterprise()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Mode, form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EnterpriseAdd(c *gin.Context) {
|
||||
form := new(enterpriseForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEnterprise()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&manage.EnterpriseParams{Mode: form.Mode, Title: form.Title, Name: form.Name, Mobile: form.Mobile,
|
||||
Papers: form.paperInfo(), Patents: form.PatentInfo(), Content: form.Content,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EnterpriseEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
enterpriseForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEnterprise()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&manage.EnterpriseParams{ID: form.Convert(), Mode: form.Mode, Title: form.Title, Name: form.Name,
|
||||
Mobile: form.Mobile, Papers: form.paperInfo(), Patents: form.PatentInfo(), Content: form.Content,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EnterpriseDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEnterprise()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
Reference in New Issue
Block a user