feat:优化项目信息

This commit is contained in:
henry
2022-02-08 16:11:59 +08:00
parent 166753d811
commit 17dd9bea7f
7 changed files with 109 additions and 21 deletions

View File

@ -10,6 +10,7 @@ type ESPatent struct {
ID uint64 `json:"id"`
Title string `json:"title"`
Industry string `json:"industry"` // 行业领域
IsShow int `json:"is_show"` // 展示
}
type ESPatentOption func(patent *ESPatent)
@ -24,8 +25,22 @@ func (this *ESPatent) Create() error {
}
func (this *ESPatent) Update() error {
_bytes, _ := json.Marshal(this)
return es.Update(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
_map := make(map[string]interface{}, 0)
if this.Title != "" {
_map["title"] = this.Title
}
if this.Industry != "" {
_map["industry"] = this.Industry
}
if this.IsShow != 0 {
_map["is_show"] = this.IsShow
}
return es.Update(this.Index(), fmt.Sprintf("%d", this.ID), _map)
}
func (this *ESPatent) Delete() error {
return es.Delete(this.Index(), fmt.Sprintf("%d", this.ID))
}
func (this *ESPatent) Search(page, pageSize int) (interface{}, int64, error) {
@ -38,6 +53,8 @@ func (this *ESPatent) Search(page, pageSize int) (interface{}, int64, error) {
if this.Industry != "" {
termParams["industry"] = this.Industry
}
termParams["is_show"] = 1
return es.Search(this, this.Index(), &es.SearchParams{
TermParams: termParams,
MustParams: mustParams,
@ -62,6 +79,12 @@ func WithPatentIndustry(industry string) ESPatentOption {
}
}
func WithPatentShow(show int) ESPatentOption {
return func(patent *ESPatent) {
patent.IsShow = show
}
}
func NewESPatent(options ...ESPatentOption) *ESPatent {
out := new(ESPatent)