feat:完善信息
This commit is contained in:
@ -55,6 +55,19 @@ type (
|
|||||||
DemandBenefit string `json:"demand_benefit" form:"demand_benefit"` // 效益
|
DemandBenefit string `json:"demand_benefit" form:"demand_benefit"` // 效益
|
||||||
Status int `json:"status" form:"status"`
|
Status int `json:"status" form:"status"`
|
||||||
}
|
}
|
||||||
|
// topicForm 课题参数
|
||||||
|
topicForm struct {
|
||||||
|
Title string `json:"title" form:"title" binding:"required"`
|
||||||
|
Emcee string `json:"emcee" form:"emcee" binding:"required"`
|
||||||
|
Mechanism string `json:"mechanism" form:"mechanism" binding:"required"`
|
||||||
|
Code string `json:"code" form:"code" 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 int `json:"source" form:"source" binding:"required"`
|
||||||
|
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||||
|
Keywords []string `json:"keywords" form:"keywords"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *Technology) Paper(c *gin.Context) {
|
func (a *Technology) Paper(c *gin.Context) {
|
||||||
@ -268,3 +281,71 @@ func (a *Technology) DemandDelete(c *gin.Context) {
|
|||||||
Delete(form.Convert())
|
Delete(form.Convert())
|
||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Technology) Topic(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
Status int `json:"status" form:"status"`
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||||
|
List(form.Status, form.Page, form.PageSize)
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Technology) TopicDetail(c *gin.Context) {
|
||||||
|
form := new(api.IDStringForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||||
|
Detail(form.Convert())
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Technology) TopicAdd(c *gin.Context) {
|
||||||
|
form := new(topicForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||||
|
Form(&technology2.TopicParams{Title: form.Title, Emcee: form.Emcee, Mechanism: form.Mechanism, Code: form.Code,
|
||||||
|
BeginAt: form.BeginAt, FinishAt: form.FinishAt, Amount: form.Amount, Source: form.Source, Kind: form.Kind,
|
||||||
|
Keywords: form.Keywords})
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Technology) TopicEdit(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
api.IDStringForm
|
||||||
|
topicForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||||
|
Form(&technology2.TopicParams{ID: form.Convert(), Title: form.Title, Emcee: form.Emcee, Mechanism: form.Mechanism,
|
||||||
|
Code: form.Code, BeginAt: form.BeginAt, FinishAt: form.FinishAt, Amount: form.Amount, Source: form.Source,
|
||||||
|
Kind: form.Kind, Keywords: form.Keywords})
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Technology) TopicDelete(c *gin.Context) {
|
||||||
|
form := new(api.IDStringForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||||
|
Delete(form.Convert())
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
152
app/api/enterprise/controller/technology/topic.go
Normal file
152
app/api/enterprise/controller/technology/topic.go
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
package technology
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/enterprise/model"
|
||||||
|
"SciencesServer/app/api/manage/controller"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/service"
|
||||||
|
"SciencesServer/utils"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Topic struct {
|
||||||
|
*service.SessionEnterprise
|
||||||
|
local string
|
||||||
|
}
|
||||||
|
|
||||||
|
type TopicHandle func(enterprise *service.SessionEnterprise, local string) *Topic
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TopicInfo 课题信息
|
||||||
|
TopicInfo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Kind model2.TechnologyTopicKind `json:"kind"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
// TopicDetailInfo 课题详细信息
|
||||||
|
TopicDetailInfo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
*model2.TechnologyTopic
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
}
|
||||||
|
// TopicParams 课题参数信息
|
||||||
|
TopicParams struct {
|
||||||
|
ID uint64
|
||||||
|
Title, Emcee, Mechanism, Code, BeginAt, FinishAt string
|
||||||
|
Amount float64
|
||||||
|
Source, Kind int
|
||||||
|
Keywords []string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// List 列表信息
|
||||||
|
func (c *Topic) List(status int, page, pageSize int) (*controller.ReturnPages, error) {
|
||||||
|
mTechnologyTopic := model.NewTechnologyTopic()
|
||||||
|
|
||||||
|
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||||
|
Where: model2.NewWhere("status", status),
|
||||||
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||||
|
}, &model2.ModelWhereOrder{Where: model2.NewWhere("uid", c.ManageUID)}}
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
out := make([]*model2.TechnologyTopic, 0)
|
||||||
|
|
||||||
|
if err := model2.PagesFields(mTechnologyTopic.TechnologyTopic, &out, []string{"id", "title", "kind", "keyword", "created_at"},
|
||||||
|
page, pageSize, &count, where...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list := make([]*TopicInfo, 0)
|
||||||
|
|
||||||
|
for _, v := range out {
|
||||||
|
list = append(list, &TopicInfo{
|
||||||
|
ID: v.GetEncodeID(), Title: v.Title, Kind: v.Kind, Keywords: v.GetKeywordAttribute(),
|
||||||
|
CreatedAt: v.CreatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detail 详细信息
|
||||||
|
func (c *Topic) Detail(id uint64) (*TopicDetailInfo, error) {
|
||||||
|
mTechnologyTopic := model.NewTechnologyTopic()
|
||||||
|
mTechnologyTopic.ID = id
|
||||||
|
|
||||||
|
isExist, err := model2.First(mTechnologyTopic.TechnologyTopic)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if !isExist {
|
||||||
|
return nil, errors.New("操作错误,课题信息不存在")
|
||||||
|
}
|
||||||
|
return &TopicDetailInfo{
|
||||||
|
ID: mTechnologyTopic.GetEncodeID(), TechnologyTopic: mTechnologyTopic.TechnologyTopic,
|
||||||
|
Keywords: mTechnologyTopic.GetKeywordAttribute(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Form 数据处理
|
||||||
|
func (c *Topic) Form(params *TopicParams) error {
|
||||||
|
mTechnologyTopic := model.NewTechnologyTopic()
|
||||||
|
|
||||||
|
if params.ID > 0 {
|
||||||
|
mTechnologyTopic.ID = params.ID
|
||||||
|
isExist, err := model2.FirstField(mTechnologyTopic.TechnologyTopic, []string{"id", "uid", "status"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !isExist {
|
||||||
|
return errors.New("操作错误,课题信息不存在")
|
||||||
|
} else if mTechnologyTopic.UID != c.ManageUID {
|
||||||
|
return errors.New("无权限操作")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mTechnologyTopic.Title = params.Title
|
||||||
|
mTechnologyTopic.Emcee = params.Emcee
|
||||||
|
mTechnologyTopic.Mechanism = params.Mechanism
|
||||||
|
mTechnologyTopic.Code = params.Code
|
||||||
|
mTechnologyTopic.Amount = params.Amount
|
||||||
|
mTechnologyTopic.Source = model2.TechnologyTopicSource(params.Source)
|
||||||
|
mTechnologyTopic.Kind = model2.TechnologyTopicKind(params.Kind)
|
||||||
|
mTechnologyTopic.SetKeywordAttribute(params.Keywords)
|
||||||
|
mTechnologyTopic.BeginAt = utils.DataTimeToDate(params.BeginAt)
|
||||||
|
mTechnologyTopic.FinishAt = utils.DataTimeToDate(params.FinishAt)
|
||||||
|
|
||||||
|
if mTechnologyTopic.ID > 0 {
|
||||||
|
mTechnologyTopic.UpdatedAt = time.Now()
|
||||||
|
return model2.Updates(mTechnologyTopic.TechnologyTopic, mTechnologyTopic.TechnologyTopic)
|
||||||
|
}
|
||||||
|
mTechnologyTopic.TenantID = c.TenantID
|
||||||
|
mTechnologyTopic.Local.Local = c.local
|
||||||
|
mTechnologyTopic.UID = c.ManageUID
|
||||||
|
return model2.Create(mTechnologyTopic.TechnologyTopic)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除处理
|
||||||
|
func (c *Topic) Delete(id uint64) error {
|
||||||
|
mTechnologyTopic := model.NewTechnologyTopic()
|
||||||
|
mTechnologyTopic.ID = id
|
||||||
|
|
||||||
|
isExist, err := model2.FirstField(mTechnologyTopic.TechnologyTopic, []string{"id", "uid", "status"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !isExist {
|
||||||
|
return errors.New("操作错误,课题信息不存在")
|
||||||
|
} else if mTechnologyTopic.UID != c.ManageUID {
|
||||||
|
return errors.New("无权限操作")
|
||||||
|
}
|
||||||
|
return model2.Delete(mTechnologyTopic.TechnologyTopic)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTopic() TopicHandle {
|
||||||
|
return func(enterprise *service.SessionEnterprise, local string) *Topic {
|
||||||
|
return &Topic{
|
||||||
|
SessionEnterprise: enterprise,
|
||||||
|
local: local,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
app/api/enterprise/model/technology_topic.go
Normal file
11
app/api/enterprise/model/technology_topic.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "SciencesServer/app/common/model"
|
||||||
|
|
||||||
|
type TechnologyTopic struct {
|
||||||
|
*model.TechnologyTopic
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTechnologyTopic() *TechnologyTopic {
|
||||||
|
return &TechnologyTopic{model.NewTechnologyTopic()}
|
||||||
|
}
|
63
app/common/model/technology_topic.go
Normal file
63
app/common/model/technology_topic.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/utils"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TechnologyTopic 技术课题数据模型
|
||||||
|
type TechnologyTopic struct {
|
||||||
|
Model
|
||||||
|
ModelTenant
|
||||||
|
Local
|
||||||
|
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||||
|
Title string `gorm:"column:title;type:varchar(100);default:null;comment:名称" json:"title"`
|
||||||
|
Code string `gorm:"column:code;type:varchar(30);default:null;comment:编号" json:"code"`
|
||||||
|
Emcee string `gorm:"column:emcee;type:varchar(30);default:null;comment:主持人" json:"emcee"`
|
||||||
|
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"`
|
||||||
|
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"`
|
||||||
|
ModelDeleted
|
||||||
|
ModelAt
|
||||||
|
}
|
||||||
|
|
||||||
|
// TechnologyTopicSource 技术课题资助来源
|
||||||
|
type TechnologyTopicSource int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// TechnologyTopicSourceForCity 市级
|
||||||
|
TechnologyTopicSourceForCity TechnologyTopicSource = iota + 1
|
||||||
|
// TechnologyTopicSourceForProvince 省级
|
||||||
|
TechnologyTopicSourceForProvince
|
||||||
|
// TechnologyTopicSourceForCountry 国家级
|
||||||
|
TechnologyTopicSourceForCountry
|
||||||
|
)
|
||||||
|
|
||||||
|
// TechnologyTopicKind 技术课题类型
|
||||||
|
type TechnologyTopicKind int
|
||||||
|
|
||||||
|
const (
|
||||||
|
//TechnologyTopicKindFor
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *TechnologyTopic) TableName() string {
|
||||||
|
return m.NewTableName("technology_topic")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TechnologyTopic) GetKeywordAttribute() []string {
|
||||||
|
keywords := make([]string, 0)
|
||||||
|
_ = utils.FromJSON(m.Keyword, &keywords)
|
||||||
|
return keywords
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TechnologyTopic) SetKeywordAttribute(keywords []string) {
|
||||||
|
m.Keyword = utils.AnyToJSON(keywords)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTechnologyTopic() *TechnologyTopic {
|
||||||
|
return &TechnologyTopic{}
|
||||||
|
}
|
@ -142,5 +142,9 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
|||||||
technology.POST("/demand/add", _api.DemandAdd)
|
technology.POST("/demand/add", _api.DemandAdd)
|
||||||
technology.POST("/demand/edit", _api.DemandEdit)
|
technology.POST("/demand/edit", _api.DemandEdit)
|
||||||
technology.POST("/demand/delete", _api.DemandDelete)
|
technology.POST("/demand/delete", _api.DemandDelete)
|
||||||
|
technology.POST("/topic", _api.Topic)
|
||||||
|
technology.POST("/topic/add", _api.TopicAdd)
|
||||||
|
technology.POST("/topic/edit", _api.TopicEdit)
|
||||||
|
technology.POST("/topic/delete", _api.TopicDelete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
serve/es/serve.go
Normal file
5
serve/es/serve.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package es
|
||||||
|
|
||||||
|
func Set() {
|
||||||
|
esClient.Search()
|
||||||
|
}
|
Reference in New Issue
Block a user