Files

65 lines
1.8 KiB
Go
Raw Normal View History

2022-01-18 16:29:29 +08:00
package search
import (
"SciencesServer/app/api/website/model"
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"
"fmt"
"time"
)
type (
// DemandInfo 需求信息
DemandInfo struct {
2022-01-18 17:31:20 +08:00
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"`
2022-01-18 16:29:29 +08:00
}
)
// searchDemand 需求搜索
2022-01-20 11:51:02 +08:00
func searchDemand(page, pageSize int, keyword, industry string, params map[string]interface{}) (*controller.ReturnPages, error) {
2022-01-18 16:29:29 +08:00
mTechnologyDemand := model.NewTechnologyDemand()
2022-01-18 17:31:20 +08:00
where := make([]*model2.ModelWhere, 0)
2022-01-18 16:29:29 +08:00
if keyword != "" {
2022-01-18 17:31:20 +08:00
where = append(where, model2.NewWhereLike("d.title", keyword))
2022-01-18 16:29:29 +08:00
}
if industry != "" {
2022-01-18 17:31:20 +08:00
where = append(where, model2.NewWhereCondition("d.industry", "LIKE", "%"+fmt.Sprintf(`"%v`, industry)+"%"))
2022-01-18 16:29:29 +08:00
}
if len(params) > 0 {
for k, v := range params {
2022-01-18 17:31:20 +08:00
where = append(where, model2.NewWhere(k, v))
2022-01-18 16:29:29 +08:00
}
}
2022-01-20 11:51:02 +08:00
var count int64
out, err := mTechnologyDemand.Demand(page, pageSize, &count, where...)
2022-01-18 16:29:29 +08:00
2022-01-18 17:31:20 +08:00
if err != nil {
2022-01-18 16:29:29 +08:00
return nil, err
}
list := make([]*DemandInfo, 0)
for _, v := range out {
list = append(list, &DemandInfo{
ID: v.GetEncodeID(), Title: v.Title,
2022-01-18 17:31:20 +08:00
Kind: v.Kind,
Industrys: v.GetIndustryAttribute(),
Budget: v.Budget,
BudgetMode: v.BudgetMode,
Deadline: v.Deadline,
CompanyKind: v.CompanyKind,
2022-01-18 16:29:29 +08:00
})
}
2022-01-20 11:51:02 +08:00
return &controller.ReturnPages{Data: list, Count: count}, nil
2022-01-18 16:29:29 +08:00
}