feat:完成首页搜索功能
This commit is contained in:
72
app/api/website/controller/search/company.go
Normal file
72
app/api/website/controller/search/company.go
Normal file
@ -0,0 +1,72 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
config2 "SciencesServer/config"
|
||||
)
|
||||
|
||||
type (
|
||||
CompanyInfo struct {
|
||||
ID string `json:"id"`
|
||||
Kind model2.ManageCompanyKind `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
Product string `json:"product"`
|
||||
Url string `json:"url"`
|
||||
Industrys []string `json:"industrys"`
|
||||
Keywords []string `json:"keywords"`
|
||||
}
|
||||
)
|
||||
|
||||
// searchCompany 公司搜索
|
||||
func searchCompany(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) {
|
||||
manage := service.NewESManage(
|
||||
service.WithManageIdentity(config.TenantUserIdentityForCompany),
|
||||
service.WithManageTitle(keyword),
|
||||
service.WithManageKeyword(keyword),
|
||||
service.WithManageResearch(keyword),
|
||||
)
|
||||
if industry != "" {
|
||||
service.WithManageIndustry(industry)(manage)
|
||||
}
|
||||
out, err := manage.Search(page, pageSize, nil)
|
||||
|
||||
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
|
||||
}
|
||||
mManageCompany := model.NewManageCompany()
|
||||
|
||||
companys := make([]*model2.ManageCompany, 0)
|
||||
|
||||
if err = model2.ScanFields(mManageCompany.ManageCompany, &companys, []string{"id", "name", "kind", "image", "product",
|
||||
"industry", "keyword", "url"}, &model2.ModelWhereOrder{Where: model2.NewWhereIn("id", ids)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*CompanyInfo, 0)
|
||||
|
||||
for _, v := range companys {
|
||||
_industrys := make([]string, 0)
|
||||
|
||||
for _, v := range v.GetIndustryAttribute() {
|
||||
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/"))
|
||||
}
|
||||
list = append(list, &CompanyInfo{
|
||||
ID: v.GetEncodeID(), Kind: v.Kind, Name: v.Name,
|
||||
Image: v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain]),
|
||||
Product: v.Product, Industrys: _industrys, Keywords: v.GetKeywordAttribute(),
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
Reference in New Issue
Block a user