78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"SciencesServer/serve/es"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type ESAchievement struct {
|
|
ID uint64 `json:"id"` // 成果ID
|
|
Title string `json:"title"` // 成果名称
|
|
Industry string `json:"industry"` // 行业领域
|
|
Keyword string `json:"keyword"` // 关键词
|
|
}
|
|
|
|
type ESAchievementOption func(achievement *ESAchievement)
|
|
|
|
func (this *ESAchievement) Index() string {
|
|
return "es_achievement_index"
|
|
}
|
|
|
|
func (this *ESAchievement) Create() error {
|
|
_bytes, _ := json.Marshal(this)
|
|
return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
|
|
}
|
|
|
|
func (this *ESAchievement) Search(page, pageSize int) (interface{}, int64, error) {
|
|
termParams := make(map[string]interface{}, 0)
|
|
mustParams := make(map[string]interface{}, 0)
|
|
|
|
if this.Title != "" {
|
|
mustParams["title"] = this.Title
|
|
}
|
|
if this.Industry != "" {
|
|
termParams["industry"] = this.Industry
|
|
}
|
|
if this.Keyword != "" {
|
|
mustParams["keyword"] = this.Keyword
|
|
}
|
|
return es.Search(this, this.Index(), &es.SearchParams{
|
|
TermParams: termParams,
|
|
MustParams: mustParams,
|
|
}, page, pageSize)
|
|
}
|
|
|
|
func WithAchievementID(id uint64) ESAchievementOption {
|
|
return func(achievement *ESAchievement) {
|
|
achievement.ID = id
|
|
}
|
|
}
|
|
|
|
func WithAchievementTitle(title string) ESAchievementOption {
|
|
return func(achievement *ESAchievement) {
|
|
achievement.Title = title
|
|
}
|
|
}
|
|
|
|
func WithAchievementIndustry(industry string) ESAchievementOption {
|
|
return func(achievement *ESAchievement) {
|
|
achievement.Industry = industry
|
|
}
|
|
}
|
|
|
|
func WithAchievementKeyword(keyword string) ESAchievementOption {
|
|
return func(achievement *ESAchievement) {
|
|
achievement.Industry = keyword
|
|
}
|
|
}
|
|
|
|
func NewESAchievement(options ...ESAchievementOption) *ESAchievement {
|
|
out := new(ESAchievement)
|
|
|
|
for _, v := range options {
|
|
v(out)
|
|
}
|
|
return out
|
|
}
|