feat:完善用户项目模块数据模型
This commit is contained in:
@ -111,6 +111,17 @@ type (
|
||||
Introduce string `json:"introduce" form:"introduce"`
|
||||
IsSubmit int `json:"is_submit" form:"is_submit"`
|
||||
}
|
||||
// projectForm 项目参数
|
||||
projectForm struct {
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Kind string `json:"kind" form:"kind" binding:"required"`
|
||||
Role int `json:"role" form:"v" binding:"required"`
|
||||
BeginAt string `json:"begin_at" form:"begin_at" binding:"required"`
|
||||
FinishAt string `json:"finish_at" form:"finish_at" binding:"required"`
|
||||
Amount float64 `json:"amount" form:"amount" binding:"required"`
|
||||
Source string `json:"source" form:"source" binding:"required"`
|
||||
Director string `json:"director" form:"director" binding:"required"`
|
||||
}
|
||||
)
|
||||
|
||||
func (a *instanceForm) FilterProveImages() string {
|
||||
@ -613,3 +624,75 @@ func (*Technology) ProductDelete(c *gin.Context) {
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) Project(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewProject()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) ProjectAdd(c *gin.Context) {
|
||||
form := new(projectForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewProject()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.ProjectParams{
|
||||
Title: form.Title, Kind: form.Kind, Source: form.Source, Director: form.Director,
|
||||
BeginAt: form.BeginAt, FinishAt: form.FinishAt, Amount: form.Amount, Role: form.Role,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) ProjectEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
projectForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewProject()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.ProjectParams{ID: form.Convert(),
|
||||
Title: form.Title, Kind: form.Kind, Source: form.Source, Director: form.Director,
|
||||
BeginAt: form.BeginAt, FinishAt: form.FinishAt, Amount: form.Amount, Role: form.Role,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) ProjectShelf(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewProject()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Shelf(form.Convert(), form.Status)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) ProjectDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewProject()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
140
app/api/enterprise/controller/technology/project.go
Normal file
140
app/api/enterprise/controller/technology/project.go
Normal file
@ -0,0 +1,140 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type ProjectHandle func(session *session.Enterprise, local string) *Project
|
||||
|
||||
type (
|
||||
// ProjectInfo 产品信息
|
||||
ProjectInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyProject
|
||||
}
|
||||
// ProjectParams 产品参数信息
|
||||
ProjectParams struct {
|
||||
ID uint64
|
||||
Title, Kind, Source, Director, BeginAt, FinishAt string
|
||||
Amount float64
|
||||
Role int
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Project) List(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyProject := model.NewTechnologyProject()
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("uid", c.ManageUID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc)}}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("title", title)})
|
||||
}
|
||||
var count int64
|
||||
|
||||
out := make([]*model2.TechnologyProject, 0)
|
||||
|
||||
if err := model2.Pages(mTechnologyProject.TechnologyProject, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ProjectInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ProjectInfo{
|
||||
ID: v.GetEncodeID(), TechnologyProject: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Form 数据处理
|
||||
func (c *Project) Form(params *ProjectParams) error {
|
||||
mTechnologyProject := model.NewTechnologyProject()
|
||||
|
||||
if params.ID > 0 {
|
||||
mTechnologyProject.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyProject.TechnologyProject, []string{"id", "uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,项目信息不存在或已被删除")
|
||||
} else if mTechnologyProject.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
}
|
||||
mTechnologyProject.Title = params.Title
|
||||
mTechnologyProject.Amount = params.Amount
|
||||
mTechnologyProject.Kind = params.Kind
|
||||
mTechnologyProject.Role = model2.TechnologyProjectRole(params.Role)
|
||||
mTechnologyProject.Source = params.Source
|
||||
mTechnologyProject.Director = params.Director
|
||||
mTechnologyProject.BeginAt = utils.DataTimeToDate(params.BeginAt)
|
||||
mTechnologyProject.FinishAt = utils.DataTimeToDate(params.FinishAt)
|
||||
|
||||
if mTechnologyProject.ID > 0 {
|
||||
return model2.Updates(mTechnologyProject.TechnologyProject, mTechnologyProject.TechnologyProject)
|
||||
}
|
||||
mTechnologyProject.Local.Local = c.local
|
||||
mTechnologyProject.UID = c.UID
|
||||
return model2.Create(mTechnologyProject.TechnologyProject)
|
||||
}
|
||||
|
||||
// Shelf 上下架操作
|
||||
func (c *Project) Shelf(id uint64, status int) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,项目信息不存在或已被删除")
|
||||
} else if mUserPatent.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = mUserPatent.PatentID
|
||||
|
||||
return model2.Updates(mSysPatent.SysPatent, map[string]interface{}{
|
||||
"shelf": status, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除处理
|
||||
func (c *Project) Delete(id uint64) error {
|
||||
mTechnologyProject := model.NewTechnologyProject()
|
||||
mTechnologyProject.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyProject.TechnologyProject, []string{"id", "uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,项目信息不存在或已被删除")
|
||||
} else if mTechnologyProject.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
return model2.Delete(mTechnologyProject.TechnologyProject)
|
||||
}
|
||||
|
||||
func NewProject() ProjectHandle {
|
||||
return func(session *session.Enterprise, local string) *Project {
|
||||
return &Project{Enterprise: session, local: local}
|
||||
}
|
||||
}
|
11
app/api/enterprise/model/technology_project.go
Normal file
11
app/api/enterprise/model/technology_project.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type TechnologyProject struct {
|
||||
*model.TechnologyProject
|
||||
}
|
||||
|
||||
func NewTechnologyProject() *TechnologyProject {
|
||||
return &TechnologyProject{model.NewTechnologyProject()}
|
||||
}
|
Reference in New Issue
Block a user