feat:优化项目信息
This commit is contained in:
@ -11,6 +11,7 @@ type ESAchievement struct {
|
||||
Title string `json:"title"` // 成果名称
|
||||
Industry string `json:"industry"` // 行业领域
|
||||
Keyword string `json:"keyword"` // 关键词
|
||||
IsShow int `json:"is_show"` // 展示
|
||||
}
|
||||
|
||||
type ESAchievementOption func(achievement *ESAchievement)
|
||||
@ -24,6 +25,24 @@ func (this *ESAchievement) Create() error {
|
||||
return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (this *ESAchievement) Search(page, pageSize int) (interface{}, int64, error) {
|
||||
termParams := make(map[string]interface{}, 0)
|
||||
mustParams := make(map[string]interface{}, 0)
|
||||
@ -37,12 +56,18 @@ func (this *ESAchievement) Search(page, pageSize int) (interface{}, int64, error
|
||||
if this.Keyword != "" {
|
||||
mustParams["keyword"] = this.Keyword
|
||||
}
|
||||
termParams["is_show"] = 1
|
||||
|
||||
return es.Search(this, this.Index(), &es.SearchParams{
|
||||
TermParams: termParams,
|
||||
MustParams: mustParams,
|
||||
}, page, pageSize)
|
||||
}
|
||||
|
||||
func (this *ESAchievement) Delete() error {
|
||||
return es.Delete(this.Index(), fmt.Sprintf("%d", this.ID))
|
||||
}
|
||||
|
||||
func WithAchievementID(id uint64) ESAchievementOption {
|
||||
return func(achievement *ESAchievement) {
|
||||
achievement.ID = id
|
||||
@ -67,6 +92,12 @@ func WithAchievementKeyword(keyword string) ESAchievementOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithAchievementShow(show int) ESAchievementOption {
|
||||
return func(achievement *ESAchievement) {
|
||||
achievement.IsShow = show
|
||||
}
|
||||
}
|
||||
|
||||
func NewESAchievement(options ...ESAchievementOption) *ESAchievement {
|
||||
out := new(ESAchievement)
|
||||
|
||||
|
Reference in New Issue
Block a user