feat:完善项目信息

This commit is contained in:
henry
2022-01-19 22:13:28 +08:00
parent f0a450b2e5
commit 641e738033
7 changed files with 416 additions and 22 deletions

View File

@ -46,7 +46,7 @@ func (m *ManageExpert) Expert(id uint64) (*ManageExpertDetail, error) {
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS e").
Select("e.id", "e.name", "e.industry", "r.name AS research_name", "l.name AS laboratory_name",
"e.province", "e.city", "e.address", "e.created_at",
"e.province", "e.city", "e.created_at",
"t.province AS tenant_province", "t.city AS tenant_city").
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.laboratory_id = l.id", model.NewManageLaboratory().TableName())).

View File

@ -1,11 +1,77 @@
package model
import "SciencesServer/app/common/model"
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
"time"
)
type ManageLaboratory struct {
*model.ManageLaboratory
}
type (
// ManageLaboratoryInfo 实验室信息
ManageLaboratoryInfo struct {
model.Model
Name string `json:"name"`
Industry string `json:"industry"`
ResearchName string `json:"research_name"`
model.Image
model.Area
CreatedAt time.Time `json:"created_at"`
TenantProvince string `json:"-"`
TenantCity string `json:"-"`
}
// ManageLaboratoryDetail 实验室详细信息
ManageLaboratoryDetail struct {
*model.ManageLaboratory
model.Area
}
)
// Laboratory 实验室信息
func (m *ManageLaboratory) Laboratory(id uint64) (*ManageLaboratoryDetail, error) {
db := orm.GetDB().Table(m.TableName()+" AS l").
Select("l.*", "t.province", "t.city").
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON l.tenant_id = t.id", model.NewSysTenant().TableName())).
Where("l.id = ?", id)
out := new(ManageLaboratoryDetail)
err := db.Scan(out).Error
return out, err
}
// Laboratorys 实验室信息
func (m *ManageLaboratory) Laboratorys(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", "l.name AS research_name", "l.image",
"l.province", "l.city", "l.created_at",
"t.province AS tenant_province", "t.city AS tenant_city").
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON l.research_id = r.id", model.NewManageResearch().TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON l.tenant_id = t.id", model.NewSysTenant().TableName())).
Where("e.is_deleted = ?", 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()}
}