Files

89 lines
2.5 KiB
Go
Raw Normal View History

2022-01-18 16:29:29 +08:00
package search
import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/config"
2022-01-20 11:51:02 +08:00
"SciencesServer/app/basic/controller"
2022-01-18 16:29:29 +08:00
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
config2 "SciencesServer/config"
2022-01-25 16:37:12 +08:00
"SciencesServer/utils"
"fmt"
"strings"
2022-01-18 16:29:29 +08:00
)
type (
// ExpertInfo 专家信息
ExpertInfo struct {
2022-01-25 16:37:12 +08:00
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
School string `json:"school"`
Major string `json:"major"`
ResearchName string `json:"research_name"`
PatentTitle []string `json:"patent_title"`
Industrys []string `json:"industrys"`
Keywords []string `json:"keywords"`
2022-01-18 16:29:29 +08:00
}
)
// searchExpert 专家搜索
2022-01-20 11:51:02 +08:00
func searchExpert(page, pageSize int, keyword, industry string, params map[string]interface{}) (*controller.ReturnPages, error) {
2022-01-18 16:29:29 +08:00
manage := service.NewESManage(
service.WithManageIdentity(config.TenantUserIdentityForExpert),
service.WithManageTitle(keyword),
service.WithManageKeyword(keyword),
service.WithManageResearch(keyword),
)
if industry != "" {
service.WithManageIndustry(industry)(manage)
}
2022-01-20 11:51:02 +08:00
out, count, err := manage.Search(page, pageSize, nil)
2022-01-18 16:29:29 +08:00
if err != nil {
return nil, err
}
ids := make([]uint64, 0)
for _, v := range out.([]interface{}) {
val := v.(*service.ESManage)
ids = append(ids, val.ID)
}
if len(ids) <= 0 {
return nil, nil
}
mManageExpert := model.NewManageExpert()
experts := make([]*model.ManageExpertInfo, 0)
if experts, err = mManageExpert.Expert(3, model2.NewWhereIn("e.id", ids)); err != nil {
return nil, err
}
list := make([]*ExpertInfo, 0)
2022-01-25 16:37:12 +08:00
mSysPatent := model.NewSysPatent()
2022-01-18 16:29:29 +08:00
for _, v := range experts {
_industrys := make([]string, 0)
for _, v := range v.GetIndustryAttribute() {
2022-01-20 09:43:26 +08:00
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/").Value)
2022-01-18 16:29:29 +08:00
}
2022-01-25 16:37:12 +08:00
patentTitles := make([]string, 0)
2022-01-18 16:29:29 +08:00
2022-01-25 16:37:12 +08:00
if v.PatentTitle != "" {
for _, val := range strings.Split(v.PatentTitle, "&&") {
objs := strings.Split(val, "$$")
mSysPatent.Kind = model2.SysParentKind(utils.StringToInt(objs[0]))
patentTitles = append(patentTitles, fmt.Sprintf("【%s】%s", mSysPatent.KindTitle(), objs[1]))
}
}
2022-01-18 16:29:29 +08:00
list = append(list, &ExpertInfo{
2022-01-25 16:37:12 +08:00
ID: v.GetEncodeID(), Name: v.Name, Image: v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain]),
School: v.School, Major: v.Major, ResearchName: v.ResearchName, PatentTitle: patentTitles,
2022-01-18 16:29:29 +08:00
Industrys: _industrys, Keywords: v.GetKeywordAttribute(),
})
}
2022-01-20 11:51:02 +08:00
return &controller.ReturnPages{Data: list, Count: count}, nil
2022-01-18 16:29:29 +08:00
}