Files
cas_tt_cloud_backend/app/api/website/model/technology_demand.go

62 lines
2.1 KiB
Go
Raw Normal View History

package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type TechnologyDemand struct {
*model.TechnologyDemand
}
2022-01-18 17:31:20 +08:00
type TechnologyDemandInfo struct {
*model.TechnologyDemand
CompanyKind int `json:"company_kind"`
}
2022-01-20 11:51:02 +08:00
func (m *TechnologyDemand) Demand(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyDemandInfo, error) {
2022-01-18 17:31:20 +08:00
out := make([]*TechnologyDemandInfo, 0)
db := orm.GetDB().Table(m.TableName()+" AS d").
Select("d.id", "d.title", "d.kind", "d.industry", "d.budget", "d.budget_mode", "d.deadline",
"c.kind AS company_kind").
Joins(fmt.Sprintf("LEFT JOIN %s AS u_c ON d.uid = u_c.uid AND u_c.is_deleted = %d",
model.NewUserCompany().TableName(), model.DeleteStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u_c.company_id = c.id", model.NewManageCompany().TableName())).
Where("d.status = ?", model.TechnologyDemandStatusForAgree)
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
2022-01-20 11:51:02 +08:00
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("d.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
2022-01-18 17:31:20 +08:00
}
// Distribution 分布信息
func (m *TechnologyDemand) Distribution() ([]*DataAreaDistributionInfo, error) {
out := make([]*DataAreaDistributionInfo, 0)
err := orm.GetDB().Table(m.TableName()+" AS d").
2022-01-06 10:43:27 +08:00
Select("e.province", "e.city", "e.district", "GROUP_CONCAT(d.industry SEPARATOR '&') AS industry").
Joins(fmt.Sprintf("LEFT JOIN %s AS u_e ON d.uid = u_e.uid", model.NewUserExpert().TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON u_e.expert_id = e.id", model.NewManageExpert().TableName())).
2022-01-06 10:43:27 +08:00
Group("e.province").Group("e.city").Group("e.district").
Order("e.province "+model.OrderModeToAsc).Order("e.city "+model.OrderModeToAsc).Order("e.district "+model.OrderModeToAsc).
Where("d.status = ?", model.TechnologyDemandStatusForAgree).
Scan(&out).Error
return out, err
}
func NewTechnologyDemand() *TechnologyDemand {
return &TechnologyDemand{model.NewTechnologyDemand()}
}