feat:完善项目管理,增加科研机构下实验室列表信息

This commit is contained in:
henry
2021-12-13 10:55:53 +08:00
parent fdcd46bf49
commit b9cc39d37a
11 changed files with 216 additions and 10 deletions

View File

@ -24,7 +24,7 @@ type ManageExpertInfo struct {
// Experts 专家信息
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
db := orm.GetDB().Table(m.TableName()+" e").
Select("e.id", "e.name", "e.mobile", "e.industry", "v.visit_count", "e.examine_at AS settled_at").
Select("e.id", "e.name", "e.mobile", "e.industry", "v.count AS visit_count", "e.examine_at AS settled_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS v ON e.id = v.expert_id AND v.is_deleted = %d",
model.NewManageExpertVisit().TableName(), model.DeleteStatusForNot))

View File

@ -1,11 +1,51 @@
package model
import "SciencesServer/app/common/model"
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type ManageLaboratory struct {
*model.ManageLaboratory
}
type ManageLaboratoryInfo struct {
model.Model
Name string `json:"name"`
Industry string `json:"-"`
Username string `json:"username"`
Mobile string `json:"mobile"`
VisitCount int `json:"visit_count"`
CollectCount int `json:"collect_count"`
}
// Laboratory 实验室信息
func (m *ManageLaboratory) Laboratory(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageLaboratoryInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS l").
Select("l.id", "l.name", "l.industry", "u.name AS username", "u.mobile", "v.count AS visit_count", "c.count AS collect_count").
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON l.uid = u.uuid", model.NewUserInstance().TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS v ON l.id = v.laboratory_id AND v.is_deleted = %d",
model.NewManageLaboratoryVisit().TableName(), model.DeleteStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY laboratory_id) AS c ON l.id = c.laboratory_id",
model.NewManageLaboratoryCollect().TableName(), model.DeleteStatusForNot))
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*ManageLaboratoryInfo, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("l.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func NewManageLaboratory() *ManageLaboratory {
return &ManageLaboratory{model.NewManageLaboratory()}
}