448 lines
12 KiB
Go
448 lines
12 KiB
Go
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"`
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Contact string `json:"contact" form:"contact"`
|
|
ContactMobile string `json:"contact_mobile" form:"contact_mobile"`
|
|
Content string `json:"content" form:"content"`
|
|
Papers []string `json:"papers" form:"papers"`
|
|
Patents []string `json:"patents" form:"patents"`
|
|
}
|
|
// equipmentForm 设备信息
|
|
equipmentForm struct {
|
|
Kind int `json:"kind" form:"kind" binding:"required"`
|
|
Code string `json:"code" form:"code" binding:"required"`
|
|
Title string `json:"title" form:"title" binding:"required"`
|
|
Params string `json:"params" form:"params"`
|
|
Description string `json:"description" form:"description"`
|
|
}
|
|
)
|
|
|
|
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 {
|
|
Name string `json:"name" form:"name"`
|
|
Mode int `json:"mode" form:"mode" binding:"required"`
|
|
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.GetTenantID()(c).(uint64)).
|
|
List(form.Name, form.Mode, 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.GetTenantID()(c).(uint64)).
|
|
Form(&manage.EnterpriseParams{Mode: form.Mode, Name: form.Name, Contact: form.Contact, ContactMobile: form.ContactMobile,
|
|
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.GetTenantID()(c).(uint64)).
|
|
Form(&manage.EnterpriseParams{ID: form.Convert(), Mode: form.Mode, Name: form.Name, Contact: form.Contact,
|
|
ContactMobile: form.ContactMobile, 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.GetTenantID()(c).(uint64)).
|
|
Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Manage) Equipment(c *gin.Context) {
|
|
form := &struct {
|
|
Kind int `json:"kind" form:"kind"`
|
|
Code string `json:"code" form:"code"`
|
|
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.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetTenantID()(c).(uint64)).
|
|
List(form.Kind, form.Code, form.Title, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) EquipmentAdd(c *gin.Context) {
|
|
form := new(equipmentForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetTenantID()(c).(uint64)).
|
|
Form(&manage.EquipmentParams{Kind: form.Kind, Code: form.Code, Title: form.Title, Params: form.Params, Description: form.Description})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Manage) EquipmentEdit(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
equipmentForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetTenantID()(c).(uint64)).
|
|
Form(&manage.EquipmentParams{ID: form.Convert(), Kind: form.Kind, Code: form.Code, Title: form.Title,
|
|
Params: form.Params, Description: form.Description})
|
|
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Manage) EquipmentDelete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetTenantID()(c).(uint64)).
|
|
Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Manage) CompanyDetail(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewCompany()(api.GetSession()(c).(*session.Enterprise)).Detail(form.Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) CompanyProduct(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewCompany()(api.GetSession()(c).(*session.Enterprise)).
|
|
Product(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
// 专家信息
|
|
|
|
func (*Manage) Expert(c *gin.Context) {
|
|
form := &struct {
|
|
Name string `json:"name" form:"name"`
|
|
Mobile string `json:"mobile" form:"mobile"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Enterprise)).
|
|
Instance(form.Name, form.Mobile, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ExpertAchievement(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Enterprise)).
|
|
Achievement(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ExpertProject(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Enterprise)).
|
|
Project(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ExpertPatent(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Enterprise)).
|
|
Patent(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ExpertPaper(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Enterprise)).
|
|
Paper(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ExpertCooperate(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Enterprise)).
|
|
Cooperate(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ResearchLaboratory(c *gin.Context) {
|
|
form := &struct {
|
|
Name string `json:"name" form:"name"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewResearch()(api.GetSession()(c).(*session.Enterprise)).
|
|
Laboratory(form.Name, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ResearchSelect(c *gin.Context) {
|
|
data, err := manage.NewResearch()(api.GetSession()(c).(*session.Enterprise)).Select()
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) ResearchVisit(c *gin.Context) {
|
|
form := &struct {
|
|
CompanyName string `json:"company_name" form:"company_name"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewResearch()(api.GetSession()(c).(*session.Enterprise)).
|
|
Visit(form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) LaboratoryAchievement(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Enterprise)).
|
|
Achievement(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) LaboratoryProject(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Enterprise)).
|
|
Project(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) LaboratoryPatent(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Enterprise)).
|
|
Patent(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) LaboratoryPaper(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Enterprise)).
|
|
Paper(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) LaboratoryCooperate(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Enterprise)).
|
|
Cooperate(form.Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) LaboratoryCooperateDetail(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Enterprise)).
|
|
CooperateDetail(form.Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) AgentCompany(c *gin.Context) {
|
|
form := &struct {
|
|
Name string `json:"name" form:"name"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewAgent()(api.GetSession()(c).(*session.Enterprise)).
|
|
Company(form.Name, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Manage) AgentCompanyAdd(c *gin.Context) {
|
|
form := &struct {
|
|
Name string `json:"name" form:"name"`
|
|
Industrys []string `json:"industrys" form:"industrys"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewAgent()(api.GetSession()(c).(*session.Enterprise)).
|
|
Form(0, form.Name, form.Industrys)
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Manage) AgentCompanyEdit(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
Name string `json:"name" form:"name"`
|
|
Industrys []string `json:"industrys" form:"industrys"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewAgent()(api.GetSession()(c).(*session.Enterprise)).
|
|
Form(form.Convert(), form.Name, form.Industrys)
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Manage) AgentCompanyDelete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewAgent()(api.GetSession()(c).(*session.Enterprise)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|