Files
2022-01-20 11:51:02 +08:00

65 lines
1.8 KiB
Go

package search
import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"fmt"
"time"
)
type (
// DemandInfo 需求信息
DemandInfo struct {
ID string `json:"id"`
Title string `json:"title"`
Kind string `json:"kind"`
Industrys []string `json:"industrys"`
Budget float64 `json:"budget"`
BudgetMode model2.TechnologyDemandBudgetMode `json:"budget_mode"`
Deadline time.Time `json:"deadline"`
CompanyKind int `json:"company_kind"`
}
)
// searchDemand 需求搜索
func searchDemand(page, pageSize int, keyword, industry string, params map[string]interface{}) (*controller.ReturnPages, error) {
mTechnologyDemand := model.NewTechnologyDemand()
where := make([]*model2.ModelWhere, 0)
if keyword != "" {
where = append(where, model2.NewWhereLike("d.title", keyword))
}
if industry != "" {
where = append(where, model2.NewWhereCondition("d.industry", "LIKE", "%"+fmt.Sprintf(`"%v`, industry)+"%"))
}
if len(params) > 0 {
for k, v := range params {
where = append(where, model2.NewWhere(k, v))
}
}
var count int64
out, err := mTechnologyDemand.Demand(page, pageSize, &count, where...)
if err != nil {
return nil, err
}
list := make([]*DemandInfo, 0)
for _, v := range out {
list = append(list, &DemandInfo{
ID: v.GetEncodeID(), Title: v.Title,
Kind: v.Kind,
Industrys: v.GetIndustryAttribute(),
Budget: v.Budget,
BudgetMode: v.BudgetMode,
Deadline: v.Deadline,
CompanyKind: v.CompanyKind,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}