feat:完成首页搜索功能

This commit is contained in:
henry
2022-01-18 16:29:29 +08:00
parent 478182dcb0
commit 10224e8db6
21 changed files with 572 additions and 167 deletions

View File

@ -57,7 +57,7 @@ func achievement(uids []uint64, page, pageSize int) (*controller.ReturnPages, er
var count int64
out, err := mTechnologyAchievement.Achievement(page, pageSize, &count, model2.NewWhereIn("uid", uids))
out, err := mTechnologyAchievement.Achievements(page, pageSize, &count, model2.NewWhereIn("uid", uids))
if err != nil {
return nil, err

View File

@ -1,59 +0,0 @@
package controller
import (
"SciencesServer/app/basic/config"
"SciencesServer/app/service"
"errors"
)
type Search struct{}
type SearchHandle func() *Search
var searchHandle = map[int]func(int, int, string, string) (interface{}, error){
1: searchCompany,
}
// searchCompany 公司搜索
func searchCompany(page, pageSize int, keyword, industry string) (interface{}, error) {
manage := service.NewESManage(
service.WithManageIdentity(config.TenantUserIdentityForCompany),
service.WithManageTitle(keyword),
service.WithManageKeyword(keyword),
service.WithManageResearch(keyword),
)
if industry != "" {
manage.Industry = industry
}
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
}
return nil, nil
}
// Launch 发起搜索
func (c *Search) Launch(mode int, keyword, industry string, page, pageSize int) (interface{}, error) {
handle, has := searchHandle[mode]
if !has {
return nil, errors.New("操作错误,未知的搜索模式")
}
return handle(page, pageSize, keyword, industry)
}
func NewSearch() SearchHandle {
return func() *Search {
return &Search{}
}
}

View File

@ -0,0 +1,69 @@
package search
import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
config2 "SciencesServer/config"
)
type (
AchievementInfo struct {
ID string `json:"id"`
*model.TechnologyAchievementInfo
Customers []string `json:"customers"`
Industrys []string `json:"industrys"`
Keywords []string `json:"keywords"`
}
)
func achievementSearch(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) {
manage := service.NewESAchievement(
service.WithAchievementTitle(keyword),
service.WithAchievementKeyword(keyword),
)
if industry != "" {
service.WithAchievementIndustry(keyword)(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.ESAchievement)
ids = append(ids, val.ID)
}
if len(ids) <= 0 {
return nil, nil
}
mTechnologyAchievement := model.NewTechnologyAchievement()
achievements := make([]*model.TechnologyAchievementInfo, 0)
if achievements, err = mTechnologyAchievement.Achievement(model2.NewWhereIn("a.id", ids)); err != nil {
return nil, err
}
list := make([]*AchievementInfo, 0)
for _, v := range achievements {
_industrys := make([]string, 0)
for _, v := range v.GetIndustryAttribute() {
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/"))
}
v.Image.Image = v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain])
list = append(list, &AchievementInfo{
ID: v.GetEncodeID(), TechnologyAchievementInfo: v,
Customers: v.GetCustomerAttribute(),
Industrys: _industrys, Keywords: v.GetKeywordAttribute(),
})
}
return list, nil
}

View 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
}

View File

@ -0,0 +1,74 @@
package search
import (
"SciencesServer/app/api/website/model"
model2 "SciencesServer/app/common/model"
"fmt"
"time"
)
type (
// DemandInfo 需求信息
DemandInfo struct {
ID string `json:"id"`
Title string `json:"title"`
Mode string `json:"mode"`
Kind string `json:"kind"`
Industrys []string `json:"industrys"`
Budget float64 `json:"budget"`
BudgetMode model2.TechnologyDemandBudgetMode `json:"budget_mode"`
Deadline time.Time `json:"deadline"`
}
)
// searchDemand 需求搜索
func searchDemand(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) {
mTechnologyDemand := model.NewTechnologyDemand()
out := make([]*model2.TechnologyDemand, 0)
where := []*model2.ModelWhereOrder{
&model2.ModelWhereOrder{
Where: model2.NewWhere("status", model2.TechnologyDemandStatusForAgree),
Order: model2.NewOrder("id", model2.OrderModeToDesc),
},
}
if keyword != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("title", keyword),
})
}
if industry != "" {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereCondition("industry", "LIKE",
"%"+fmt.Sprintf(`"%v`, industry)+"%")})
}
if len(params) > 0 {
for k, v := range params {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhere(k, v),
})
}
}
var count int64
if err := model2.PagesFields(mTechnologyDemand.TechnologyDemand, &out, []string{"id", "title", "mode", "kind", "industry",
"budget", "budget_mode", "deadline"}, page, pageSize, &count, where...); err != nil {
return nil, err
}
list := make([]*DemandInfo, 0)
for _, v := range out {
list = append(list, &DemandInfo{
ID: v.GetEncodeID(), Title: v.Title,
Mode: v.Mode,
Kind: v.Kind,
Industrys: v.GetIndustryAttribute(),
Budget: v.Budget,
BudgetMode: v.BudgetMode,
Deadline: v.Deadline,
})
}
return list, nil
}

View File

@ -0,0 +1,70 @@
package search
import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
config2 "SciencesServer/config"
)
type (
// ExpertInfo 专家信息
ExpertInfo struct {
ID string `json:"id"`
*model.ManageExpertInfo
Industrys []string `json:"industrys"`
Keywords []string `json:"keywords"`
}
)
// searchExpert 专家搜索
func searchExpert(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) {
manage := service.NewESManage(
service.WithManageIdentity(config.TenantUserIdentityForExpert),
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
}
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)
for _, v := range experts {
_industrys := make([]string, 0)
for _, v := range v.GetIndustryAttribute() {
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/"))
}
v.Image.Image = v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain])
list = append(list, &ExpertInfo{
ID: v.GetEncodeID(), ManageExpertInfo: v,
Industrys: _industrys, Keywords: v.GetKeywordAttribute(),
})
}
return list, nil
}

View File

@ -0,0 +1,30 @@
package search
import (
"errors"
)
type Instance struct{}
type InstanceHandle func() *Instance
var instanceHandle = map[int]func(int, int, string, string, map[string]interface{}) (interface{}, error){
1: searchCompany, 2: achievementSearch, 3: searchLaboratory,
4: searchPatent, 5: searchExpert, 6: searchDemand,
}
// Launch 发起搜索
func (c *Instance) Launch(mode int, keyword, industry string, params map[string]interface{}, page, pageSize int) (interface{}, error) {
handle, has := instanceHandle[mode]
if !has {
return nil, errors.New("操作错误,未知的搜索模式")
}
return handle(page, pageSize, keyword, industry, params)
}
func NewInstance() InstanceHandle {
return func() *Instance {
return &Instance{}
}
}

View File

@ -0,0 +1,70 @@
package search
import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
config2 "SciencesServer/config"
)
type (
// LaboratoryInfo 实验室信息
LaboratoryInfo struct {
ID string `json:"id"`
*model.ManageLaboratoryInfo
Industrys []string `json:"industrys"`
Keywords []string `json:"keywords"`
}
)
// searchLaboratory 实验室搜索
func searchLaboratory(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) {
manage := service.NewESManage(
service.WithManageIdentity(config.TenantUserIdentityForLaboratory),
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.ESAchievement)
ids = append(ids, val.ID)
}
if len(ids) <= 0 {
return nil, nil
}
mManageLaboratory := model.NewManageLaboratory()
laboratorys := make([]*model.ManageLaboratoryInfo, 0)
if laboratorys, err = mManageLaboratory.Laboratory(model2.NewWhereIn("l.id", ids)); err != nil {
return nil, err
}
list := make([]*LaboratoryInfo, 0)
for _, v := range laboratorys {
_industrys := make([]string, 0)
for _, v := range v.GetIndustryAttribute() {
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/"))
}
v.Image.Image = v.Image.Analysis(config2.SystemConfig[config2.SysImageDomain])
list = append(list, &LaboratoryInfo{
ID: v.GetEncodeID(), ManageLaboratoryInfo: v,
Industrys: _industrys, Keywords: v.GetKeywordAttribute(),
})
}
return list, nil
}

View File

@ -0,0 +1,59 @@
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
}

View File

@ -54,7 +54,7 @@ func (c *Achievement) Instance(title, industry string, page, pageSize int) (*con
}
var count int64
out, err := mTechnologyAchievement.Achievement(page, pageSize, &count, where...)
out, err := mTechnologyAchievement.Achievements(page, pageSize, &count, where...)
if err != nil {
return nil, err

View File

@ -57,7 +57,7 @@ func (c *Patent) Instance(title, industry string, page, pageSize int) (*controll
}
ret := make([]*model.SysPatentInfo, 0)
if ret, err = mSysPatent.Patent(page, pageSize, &count, model2.NewWhereIn("p.id", ids)); err != nil {
if ret, err = mSysPatent.Patents(page, pageSize, &count, model2.NewWhereIn("p.id", ids)); err != nil {
return nil, err
}
for _, v := range ret {