156 lines
4.8 KiB
Go
156 lines
4.8 KiB
Go
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 Topic struct {
|
|
*session.Enterprise
|
|
local string
|
|
}
|
|
|
|
type TopicHandle func(session *session.Enterprise, 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("无权限操作")
|
|
} else if mTechnologyTopic.Status != model2.TechnologyTopicStatusForDraft &&
|
|
mTechnologyTopic.Status != model2.TechnologyTopicStatusForRefuse {
|
|
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(session *session.Enterprise, local string) *Topic {
|
|
return &Topic{
|
|
Enterprise: session,
|
|
local: local,
|
|
}
|
|
}
|
|
}
|