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()}
|
||||
}
|
26
app/common/init2.go
Normal file
26
app/common/init2.go
Normal file
@ -0,0 +1,26 @@
|
||||
package common
|
||||
|
||||
type Model struct {
|
||||
TableName string
|
||||
}
|
||||
|
||||
type Option func(model *Model)
|
||||
|
||||
func withModel(tableName string) Option {
|
||||
return func(model *Model) {
|
||||
model.TableName = tableName
|
||||
}
|
||||
}
|
||||
|
||||
func NewModel(option ...Option) *Model {
|
||||
out := new(Model)
|
||||
|
||||
for _, v := range option {
|
||||
v(out)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func Test() {
|
||||
NewModel(withModel(""))
|
||||
}
|
38
app/common/model/technology_project.go
Normal file
38
app/common/model/technology_project.go
Normal file
@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// TechnologyProject 技术科研项目数据模型
|
||||
type TechnologyProject struct {
|
||||
Model
|
||||
Local
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Kind string `gorm:"column:kind;type:varchar(100);default:null;comment:类型" json:"kind"`
|
||||
Role TechnologyProjectRole `gorm:"column:role;type:tinyint(1);default:1;comment:课题角色(1:承担单位,2:参与单位)" json:"role"`
|
||||
Title string `gorm:"column:title;type:varchar(100);default:null;comment:名称" json:"title"`
|
||||
Amount float64 `gorm:"column:amount;decimal(10,2);default:0;comment:经费" json:"amount"`
|
||||
Source string `gorm:"column:source;type:varchar(100);default:null;comment:来源" json:"source"`
|
||||
Director string `gorm:"column:director;type:varchar(100);default:null;comment:负责人" json:"director"`
|
||||
BeginAt time.Time `gorm:"column:begin_at;type:datetime;not null;comment:开始时间" json:"begin_at"`
|
||||
FinishAt time.Time `gorm:"column:finish_at;type:datetime;not null;comment:结束时间" json:"finish_at"`
|
||||
ShelfStatus
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
type TechnologyProjectRole int
|
||||
|
||||
const (
|
||||
// TechnologyProjectRoleForBear 承担
|
||||
TechnologyProjectRoleForBear TechnologyProjectRole = iota + 1
|
||||
// TechnologyProjectRoleForJoin 参与
|
||||
TechnologyProjectRoleForJoin
|
||||
)
|
||||
|
||||
func (m *TechnologyProject) TableName() string {
|
||||
return "technology_project"
|
||||
}
|
||||
|
||||
func NewTechnologyProject() *TechnologyProject {
|
||||
return &TechnologyProject{}
|
||||
}
|
@ -17,7 +17,7 @@ type TechnologyTopic struct {
|
||||
Mechanism string `gorm:"column:mechanism;type:varchar(30);default:null;comment:机构" json:"mechanism"`
|
||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:null;comment:关键词" json:"-"`
|
||||
Amount float64 `gorm:"column:amount;decimal(10,2);default:0;comment:经费" json:"amount"`
|
||||
Source TechnologyTopicSource `gorm:"column:source;type:tinyint(1);default:0comment:来源" json:"source"`
|
||||
Source TechnologyTopicSource `gorm:"column:source;type:tinyint(1);default:0;comment:来源" json:"source"`
|
||||
Kind TechnologyTopicKind `gorm:"column:kind;type:tinyint(1);default:0comment:类型" json:"kind"`
|
||||
BeginAt time.Time `gorm:"column:begin_at;type:datetime;not null;comment:开始时间" json:"begin_at"`
|
||||
FinishAt time.Time `gorm:"column:finish_at;type:datetime;not null;comment:结束时间" json:"finish_at"`
|
||||
|
@ -185,6 +185,11 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
technologyV1.POST("/product/edit", _api.ProductEdit)
|
||||
technologyV1.POST("/product/shelf", _api.ProductShelf)
|
||||
technologyV1.POST("/product/delete", _api.ProductDelete)
|
||||
technologyV1.POST("/project", _api.Project)
|
||||
technologyV1.POST("/project/add", _api.ProjectAdd)
|
||||
technologyV1.POST("/project/edit", _api.ProjectEdit)
|
||||
technologyV1.POST("/project/shelf", _api.ProjectShelf)
|
||||
technologyV1.POST("/project/delete", _api.ProjectDelete)
|
||||
}
|
||||
// Identity 身份信息
|
||||
identityV1 := v1.Group("/config")
|
||||
|
Reference in New Issue
Block a user