60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
![]() |
package search
|
||
|
|
||
|
import (
|
||
|
"SciencesServer/app/api/website/model"
|
||
|
model2 "SciencesServer/app/common/model"
|
||
|
"SciencesServer/app/service"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
// PatentInfo 专利信息
|
||
|
PatentInfo struct {
|
||
|
ID string `json:"id"`
|
||
|
Kind model2.SysParentKind `json:"kind"`
|
||
|
Title string `json:"title"`
|
||
|
ApplyAt string `json:"apply_at"`
|
||
|
Description string `json:"description"`
|
||
|
}
|
||
|
)
|
||
|
|
||
|
// searchPatent 专利搜索
|
||
|
func searchPatent(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) {
|
||
|
manage := service.NewESPatent(
|
||
|
service.WithPatentTitle(keyword),
|
||
|
)
|
||
|
if industry != "" {
|
||
|
service.WithPatentIndustry(industry)(manage)
|
||
|
}
|
||
|
out, err := manage.Search(page, pageSize)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
ids := make([]uint64, 0)
|
||
|
|
||
|
for _, v := range out.([]interface{}) {
|
||
|
val := v.(*service.ESPatent)
|
||
|
ids = append(ids, val.ID)
|
||
|
}
|
||
|
if len(ids) <= 0 {
|
||
|
return nil, nil
|
||
|
}
|
||
|
mSysPatent := model.NewSysPatent()
|
||
|
|
||
|
patents := make([]*model2.SysPatent, 0)
|
||
|
|
||
|
if err = model2.ScanFields(mSysPatent.SysPatent, &patents, []string{"id", "kind", "title", "apply_at", "description"},
|
||
|
&model2.ModelWhereOrder{Where: model2.NewWhereIn("id", ids)}); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
list := make([]*PatentInfo, 0)
|
||
|
|
||
|
for _, v := range patents {
|
||
|
|
||
|
list = append(list, &PatentInfo{
|
||
|
ID: v.GetEncodeID(), Kind: v.Kind, Title: v.Title, ApplyAt: v.ApplyAt, Description: v.Description,
|
||
|
})
|
||
|
}
|
||
|
return list, nil
|
||
|
}
|