From b62ee9c3d9915f21213b272516d3589225af1efc Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 23 Dec 2021 18:12:33 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BC=98=E5=8C=96=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=AE=8C=E5=96=84es=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E5=96=84=E7=BD=91=E7=AB=99=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=85=AC=E5=8F=B8=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/website/api/es.go | 35 +++++++++++------- app/api/website/controller/manage/search.go | 3 -- .../website/controller/technology/patent.go | 36 ++++++++++++------- app/service/es_patent.go | 24 +++++++++++-- 4 files changed, 68 insertions(+), 30 deletions(-) diff --git a/app/api/website/api/es.go b/app/api/website/api/es.go index 4ff564c..5447722 100644 --- a/app/api/website/api/es.go +++ b/app/api/website/api/es.go @@ -13,6 +13,7 @@ func (*ES) Create(c *gin.Context) { ID uint64 `json:"id" form:"id"` Identity int `json:"identity" form:"identity"` Title string `json:"title" form:"title"` + Industry string `json:"industry" form:"industry"` Keyword string `json:"keyword" form:"keyword"` Research string `json:"research" form:"research"` }{} @@ -20,12 +21,18 @@ func (*ES) Create(c *gin.Context) { api.APIFailure(err.(error))(c) return } - manage := service.NewESManage( - service.WithManageID(form.ID), - service.WithManageIdentity(form.Identity), - service.WithManageTitle(form.Title), - service.WithManageKeyword(form.Keyword), - service.WithManageResearch(form.Research), + //manage := service.NewESManage( + // service.WithManageID(form.ID), + // service.WithManageIdentity(form.Identity), + // service.WithManageTitle(form.Title), + // service.WithManageKeyword(form.Keyword), + // service.WithManageResearch(form.Research), + //) + manage := service.NewESPatent( + service.WithPatentID(form.ID), + //service.WithManageIdentity(form.Identity), + service.WithPatentTitle(form.Title), + service.WithPatentIndustry(form.Industry), ) api.APIResponse(manage.Create())(c) } @@ -40,11 +47,15 @@ func (*ES) Search(c *gin.Context) { api.APIFailure(err.(error))(c) return } - manage := service.NewESManage(service.WithManageIdentity(form.Identity), - service.WithManageTitle(form.Param), - service.WithManageIndustry(form.Industry), - service.WithManageKeyword(form.Param), - service.WithManageResearch(form.Param)) - data, err := manage.Search(1, 1) + //manage := service.NewESManage(service.WithManageIdentity(form.Identity), + // service.WithManageTitle(form.Param), + // service.WithManageIndustry(form.Industry), + // service.WithManageKeyword(form.Param), + // service.WithManageResearch(form.Param)) + manage := service.NewESPatent( + service.WithPatentTitle(form.Param), + service.WithPatentIndustry(form.Industry), + ) + data, err := manage.Search(1, 10) api.APIResponse(err, data)(c) } diff --git a/app/api/website/controller/manage/search.go b/app/api/website/controller/manage/search.go index c0d0ab9..6d94e71 100644 --- a/app/api/website/controller/manage/search.go +++ b/app/api/website/controller/manage/search.go @@ -117,9 +117,6 @@ func (c *Search) Launch(identity int, param, industry string, page, pageSize int ids := make([]uint64, 0) for _, v := range out.([]*service.ESManage) { - if v.Identity != identity { - continue - } ids = append(ids, v.ID) } handle, has := searchIdentityHandle[identity] diff --git a/app/api/website/controller/technology/patent.go b/app/api/website/controller/technology/patent.go index 795b145..2d16c65 100644 --- a/app/api/website/controller/technology/patent.go +++ b/app/api/website/controller/technology/patent.go @@ -4,6 +4,7 @@ import ( "SciencesServer/app/api/website/model" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" + "SciencesServer/app/service" "errors" "fmt" ) @@ -28,27 +29,38 @@ type ( // Instance 查询信息 func (c *Patent) Instance(title, industry string, page, pageSize int) (*controller.ReturnPages, error) { // TODO:缺少会员判断标准 - mSysPatent := model.NewSysPatent() + // ES标准判定 + s := service.NewESPatent( + service.WithPatentTitle(title), + service.WithPatentIndustry(industry), + ) + out, err := s.Search(page, pageSize) - where := make([]*model2.ModelWhere, 0) + list := make([]*PatentInfo, 0) - if title != "" { - where = append(where, model2.NewWhereLike("p.title", title)) - } - if industry != "" { - where = append(where, model2.NewWhereCondition("c.industry_detail", "LIKE", - "%"+fmt.Sprintf(`"%v`, industry)+"%")) - } var count int64 - out, err := mSysPatent.Patent(page, pageSize, &count, where...) + fmt.Println(out) if err != nil { return nil, err + } else if out == nil { + return &controller.ReturnPages{Data: list, Count: count}, nil } - list := make([]*PatentInfo, 0) + mSysPatent := model.NewSysPatent() - for _, v := range out { + ids := make([]uint64, 0) + + for _, v := range out.([]interface{}) { + val := v.(*service.ESPatent) + ids = append(ids, val.ID) + } + ret := make([]*model.SysPatentInfo, 0) + + if ret, err = mSysPatent.Patent(page, pageSize, &count, model2.NewWhereIn("p.id", ids)); err != nil { + return nil, err + } + for _, v := range ret { list = append(list, &PatentInfo{ ID: v.GetEncodeID(), SysPatentInfo: v, diff --git a/app/service/es_patent.go b/app/service/es_patent.go index 65670c8..397fc31 100644 --- a/app/service/es_patent.go +++ b/app/service/es_patent.go @@ -3,7 +3,9 @@ package service import ( "SciencesServer/serve/es" "SciencesServer/serve/logger" + "SciencesServer/utils" "encoding/json" + "fmt" ) type ESPatent struct { @@ -19,14 +21,30 @@ func (this *ESPatent) Index() string { } func (this *ESPatent) Create() error { + if this.Industry != "" { + this.Title = this.Industry + " - " + this.Title + } _bytes, _ := json.Marshal(this) return es.Create(this.Index(), _bytes) } -func (this *ESPatent) Search(page, pageSize int, params map[string]interface{}) (interface{}, error) { +func (this *ESPatent) Search(page, pageSize int) (interface{}, error) { + mustParams := make(map[string]interface{}, 0) + shouldParams := make(map[string]interface{}, 0) + + fmt.Println(utils.AnyToJSON(this)) + + if this.Title != "" { + shouldParams["title"] = this.Title + } + if this.Industry != "" { + mustParams["title"] = this.Industry + } + fmt.Println(mustParams) + fmt.Println(shouldParams) out, err := es.Search(this, this.Index(), &es.SearchParams{ - MustParams: nil, - ShouldParams: params, + MustParams: mustParams, + ShouldParams: shouldParams, }, page, pageSize) if err != nil {