feat:完善项目信息
This commit is contained in:
@ -3,11 +3,70 @@ package model
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ManageLaboratory struct {
|
||||
*model.ManageLaboratory
|
||||
}
|
||||
type (
|
||||
// ManageLaboratoryInfo 实验室信息
|
||||
ManageLaboratoryInfo struct {
|
||||
*model.ManageLaboratory
|
||||
ResearchName string `json:"research_name"`
|
||||
ExpertCount int `json:"expert_count"`
|
||||
CollectCount int `json:"collect_count"`
|
||||
VisitCount int `json:"visit_count"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 实验室信息
|
||||
func (m *ManageLaboratory) Instance(id uint64) (*ManageLaboratoryInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS l").
|
||||
Select("l.id", "l.image", "l.url", "l.industry", "l.keyword", "l.contact", "l.contact_mobile", "l.research", "l.introduce",
|
||||
"e.name AS research_name", "e.count AS expert_count", "c.count AS collect_count", "v.count AS visit_count").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON l.research_id = e.id", model.NewManageResearch().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(laboratory_id) AS count FROM %s WHERE examine_status = %d AND is_deleted = %d GROUP BY laboratory_id) AS e ON l.id = e.laboratory_id",
|
||||
model.NewManageExpert().TableName(), model.ExamineStatusForAgree, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON l.id = c.object_id",
|
||||
model.NewUserCollect().TableName(), model.UserCollectKindForLaboratory, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON l.id = v.object_id",
|
||||
model.NewUserVisit().TableName(), model.UserVisitKindForLaboratory, model.DeleteStatusForNot)).
|
||||
Where("l.id = ?", id)
|
||||
|
||||
out := new(ManageLaboratoryInfo)
|
||||
|
||||
err := db.Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Laboratory 实验室信息
|
||||
func (m *ManageLaboratory) Laboratory(where ...*model.ModelWhere) ([]*ManageLaboratoryInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS l").
|
||||
Select("l.id", "l.image", "l.url", "l.industry", "l.keyword", "l.contact", "l.contact_mobile", "l.research",
|
||||
"e.name AS research_name", "e.count AS expert_count", "c.count AS collect_count", "v.count AS visit_count").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON l.research_id = e.id", model.NewManageResearch().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(laboratory_id) AS count FROM %s WHERE examine_status = %d AND is_deleted = %d GROUP BY laboratory_id) AS e ON l.id = e.laboratory_id",
|
||||
model.NewManageExpert().TableName(), model.ExamineStatusForAgree, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON l.id = c.object_id",
|
||||
model.NewUserCollect().TableName(), model.UserCollectKindForLaboratory, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON l.id = v.object_id",
|
||||
model.NewUserVisit().TableName(), model.UserVisitKindForLaboratory, model.DeleteStatusForNot)).
|
||||
Where("l.examine_status = ?", model.ExamineStatusForAgree).
|
||||
Where("l.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageLaboratoryInfo, 0)
|
||||
|
||||
err := db.Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Distribution 分布信息
|
||||
func (m *ManageLaboratory) Distribution() ([]*DataAreaDistributionInfo, error) {
|
||||
|
Reference in New Issue
Block a user