Files
cas_tt_cloud_backend/app/service/es_achievement.go

109 lines
2.5 KiB
Go
Raw Normal View History

2022-01-04 11:59:58 +08:00
package service
import (
"SciencesServer/serve/es"
"encoding/json"
2022-01-18 09:20:18 +08:00
"fmt"
2022-01-04 11:59:58 +08:00
)
type ESAchievement struct {
ID uint64 `json:"id"` // 成果ID
Title string `json:"title"` // 成果名称
Industry string `json:"industry"` // 行业领域
Keyword string `json:"keyword"` // 关键词
2022-02-08 18:26:40 +08:00
IsShow int `json:"is_show"` // 展示
2022-01-04 11:59:58 +08:00
}
type ESAchievementOption func(achievement *ESAchievement)
func (this *ESAchievement) Index() string {
return "es_achievement_index"
}
func (this *ESAchievement) Create() error {
_bytes, _ := json.Marshal(this)
2022-01-18 09:20:18 +08:00
return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
2022-01-04 11:59:58 +08:00
}
2022-02-08 18:26:40 +08:00
func (this *ESAchievement) Update() error {
_map := make(map[string]interface{}, 0)
if this.Title != "" {
_map["title"] = this.Title
}
if this.Industry != "" {
_map["industry"] = this.Industry
}
if this.Keyword != "" {
_map["keyword"] = this.Keyword
}
if this.IsShow != 0 {
_map["is_show"] = this.IsShow
}
return es.Update(this.Index(), fmt.Sprintf("%d", this.ID), _map)
}
2022-01-20 11:51:02 +08:00
func (this *ESAchievement) Search(page, pageSize int) (interface{}, int64, error) {
2022-01-04 11:59:58 +08:00
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
}
2022-02-11 11:02:29 +08:00
//termParams["is_show"] = 1
2022-02-08 18:26:40 +08:00
2022-01-20 11:51:02 +08:00
return es.Search(this, this.Index(), &es.SearchParams{
2022-01-04 11:59:58 +08:00
TermParams: termParams,
MustParams: mustParams,
}, page, pageSize)
}
2022-02-08 18:26:40 +08:00
func (this *ESAchievement) Delete() error {
return es.Delete(this.Index(), fmt.Sprintf("%d", this.ID))
}
2022-01-04 11:59:58 +08:00
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
}
}
2022-02-08 18:26:40 +08:00
func WithAchievementShow(show int) ESAchievementOption {
return func(achievement *ESAchievement) {
achievement.IsShow = show
}
}
2022-01-04 11:59:58 +08:00
func NewESAchievement(options ...ESAchievementOption) *ESAchievement {
out := new(ESAchievement)
for _, v := range options {
v(out)
}
return out
}