feat:完善项目信息
This commit is contained in:
@ -2,16 +2,72 @@ package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ManageCompany struct {
|
||||
*model.ManageCompany
|
||||
}
|
||||
|
||||
func (m *ManageCompany) Companys(page, pageSize int, count *int64, where ...*model.ModelWhere) {
|
||||
type (
|
||||
// ManageCompanyBasic 公司企业基本信息
|
||||
ManageCompanyBasic struct {
|
||||
*model.ManageCompany
|
||||
model.Area
|
||||
}
|
||||
// ManageCompanyInfo 公司企业信息
|
||||
ManageCompanyInfo struct {
|
||||
model.Model
|
||||
Kind model.ManageCompanyKind `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Industry string `json:"industry"`
|
||||
Address string `json:"address"`
|
||||
*model.Examine
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
model.Area
|
||||
}
|
||||
)
|
||||
|
||||
// Company 公司企业信息
|
||||
func (m *ManageCompany) Company(id uint64) (*ManageCompanyBasic, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS c").
|
||||
Select("c.*", "t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON c.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("c.id = ?", id)
|
||||
|
||||
out := new(ManageCompanyBasic)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (m *ManageCompany) Companys(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageCompanyInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS c").
|
||||
Select("c.id", "c.kind", "c.name", "c.code", "c.industry", "c.address", "c.examine_status", "c.created_at",
|
||||
"t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON c.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("c.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageCompanyInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("c.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageCompany() *ManageCompany {
|
||||
return &ManageCompany{}
|
||||
return &ManageCompany{model.NewManageCompany()}
|
||||
}
|
||||
|
@ -10,24 +10,45 @@ type ManageExpert struct {
|
||||
*model.ManageExpert
|
||||
}
|
||||
|
||||
type ManageExpertInfo struct {
|
||||
*model.ManageExpert
|
||||
Name string `json:"name"`
|
||||
ResearchName string `json:"research_name"`
|
||||
LaboratoryName string `json:"laboratory_name"`
|
||||
type (
|
||||
// ManageExpertBasic 专家基本信息
|
||||
ManageExpertBasic struct {
|
||||
*model.ManageExpert
|
||||
model.Area
|
||||
}
|
||||
// ManageExpertInfo 专家信息
|
||||
ManageExpertInfo struct {
|
||||
*model.ManageExpert
|
||||
Name string `json:"name"`
|
||||
ResearchName string `json:"research_name"`
|
||||
LaboratoryName string `json:"laboratory_name"`
|
||||
model.Area
|
||||
}
|
||||
)
|
||||
|
||||
// Expert 专家信息
|
||||
func (m *ManageExpert) Expert(id uint64) (*ManageExpertBasic, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.*", "t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON e.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("e.id = ?", id)
|
||||
|
||||
out := new(ManageExpertBasic)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Experts 专家信息
|
||||
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
|
||||
mUserInstance := model.NewUserInstance()
|
||||
mSysTenant := model.NewSysTenant()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.*", "u.name", "l.name AS laboratory_name", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON e.uid = u.uuid", mUserInstance.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.tenant_id = l.id", mSysTenant.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON l.parent_id = r.id", mSysTenant.TableName())).
|
||||
Where("")
|
||||
Select("e.id", "e.name", "e.industry", "r.name AS research_name", "l.name AS laboratory_name",
|
||||
"t.province", "t.city", "e.address", "e.created_at").
|
||||
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())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON e.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("e.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
@ -39,6 +60,7 @@ func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := db.Order("e.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user