146 lines
3.7 KiB
Go
146 lines
3.7 KiB
Go
package manage
|
|
|
|
import (
|
|
"SciencesServer/app/api/website/model"
|
|
"SciencesServer/app/basic/config"
|
|
"SciencesServer/app/basic/controller"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/service"
|
|
config2 "SciencesServer/config"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
type Search struct{}
|
|
|
|
type SearchHandle func() *Search
|
|
|
|
type (
|
|
// SearchParams 搜索参数
|
|
SearchParams struct {
|
|
}
|
|
)
|
|
|
|
// searchIdentityHandle 搜索信息处理
|
|
var searchIdentityHandle = map[int]func(ids []uint64) (interface{}, error){
|
|
config.TenantUserIdentityForCompany: company,
|
|
config.TenantUserIdentityForExpert: expert,
|
|
config.TenantUserIdentityForLaboratory: laboratory,
|
|
}
|
|
|
|
// company 公司信息
|
|
func company(ids []uint64) (interface{}, error) {
|
|
mManageCompany := model.NewManageCompany()
|
|
out := make([]*model2.ManageCompany, 0)
|
|
|
|
if err := model2.ScanFields(mManageCompany.ManageCompany, &out, []string{"id", "kind", "name", "image", "url", "keyword"},
|
|
&model2.ModelWhereOrder{
|
|
Where: model2.NewWhereIn("id", ids),
|
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
|
}, &model2.ModelWhereOrder{
|
|
Where: model2.NewWhere("examine_status", model2.ExamineStatusForAgree),
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*CompanyBasicInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &CompanyBasicInfo{
|
|
ID: v.GetEncodeID(), Kind: v.Kind, Name: v.Name,
|
|
Image: v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain]),
|
|
Url: v.Url,
|
|
Keywords: v.GetKeywordAttribute(),
|
|
})
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
// expert 专家信息
|
|
func expert(ids []uint64) (interface{}, error) {
|
|
mManageExpert := model.NewManageExpert()
|
|
out, err := mManageExpert.Expert(3, model2.NewWhereIn("e.id", ids))
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ExpertBasicInfo, 0)
|
|
|
|
for _, v := range out {
|
|
v.Image.Image = v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain])
|
|
|
|
list = append(list, &ExpertBasicInfo{
|
|
ID: v.GetEncodeID(),
|
|
Name: v.Name,
|
|
School: v.School,
|
|
Major: v.Major,
|
|
Industrys: v.GetIndustryAttribute(),
|
|
Keywords: v.GetKeywordAttribute(),
|
|
PatentTitle: strings.Split(v.PatentTitle, "&&"),
|
|
})
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
// laboratory 实验室信息
|
|
func laboratory(ids []uint64) (interface{}, error) {
|
|
mManageLaboratory := model.NewManageLaboratory()
|
|
|
|
out, err := mManageLaboratory.Laboratory(model2.NewWhereIn("id", ids))
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*LaboratoryBasicInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &LaboratoryBasicInfo{
|
|
ID: v.GetEncodeID(),
|
|
ManageLaboratoryInfo: v,
|
|
Industrys: v.GetIndustryAttribute(),
|
|
Keywords: v.GetKeywordAttribute(),
|
|
Researchs: v.GetResearchAttribute(),
|
|
})
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (c *Search) Launch(identity int, param, industry string, page, pageSize int) (*controller.ReturnPages, error) {
|
|
manage := service.NewESManage(
|
|
service.WithManageIdentity(identity),
|
|
service.WithManageTitle(param),
|
|
service.WithManageIndustry(industry),
|
|
service.WithManageKeyword(param),
|
|
service.WithManageResearch(param),
|
|
)
|
|
out, count, err := manage.Search(page, pageSize, nil)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else if out == nil {
|
|
return nil, nil
|
|
}
|
|
ids := make([]uint64, 0)
|
|
|
|
for _, v := range out.([]interface{}) {
|
|
val := v.(*service.ESManage)
|
|
ids = append(ids, val.ID)
|
|
}
|
|
handle, has := searchIdentityHandle[identity]
|
|
|
|
if !has {
|
|
return nil, errors.New("操作错误,未知的身份信息")
|
|
}
|
|
var data interface{}
|
|
|
|
if data, err = handle(ids); err != nil {
|
|
return nil, err
|
|
}
|
|
return &controller.ReturnPages{Data: data, Count: count}, nil
|
|
}
|
|
|
|
func NewSearch() SearchHandle {
|
|
return func() *Search {
|
|
return &Search{}
|
|
}
|
|
}
|