76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ManageResearch struct {
|
|
*model.ManageResearch
|
|
}
|
|
|
|
type (
|
|
// ManageResearchInfo 基本信息
|
|
ManageResearchInfo struct {
|
|
model.Model
|
|
Name string `json:"name"`
|
|
Code string `json:"code"`
|
|
Industry string `json:"-"`
|
|
Research string `json:"-"`
|
|
ExamineStatus string `json:"examine_status"`
|
|
model.Area
|
|
TenantProvince string `json:"-"`
|
|
TenantCity string `json:"-"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
// ManageResearchDetail 详细信息
|
|
ManageResearchDetail struct {
|
|
*model.ManageResearch
|
|
model.Area
|
|
}
|
|
)
|
|
|
|
// Research 科研机构信息
|
|
func (m *ManageResearch) Research(id uint64) (*model.ManageResearch, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS r").
|
|
Select("r.*").
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON r.tenant_id = t.id", model.NewSysTenant().TableName())).
|
|
Where("r.id = ?", id)
|
|
|
|
out := new(model.ManageResearch)
|
|
|
|
err := db.Scan(out).Error
|
|
|
|
return out, err
|
|
}
|
|
|
|
// Researchs 科研机构信息
|
|
func (m *ManageResearch) Researchs(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageResearchInfo, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS r").
|
|
Select("r.id", "r.name", "r.code", "r.industry", "r.research", "r.province", "r.city", "r.district",
|
|
"r.examine_status", "t.province AS tenant_province", "t.city AS tenant_city", "r.created_at").
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON r.tenant_id = t.id", model.NewSysTenant().TableName())).
|
|
Where("r.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
out := make([]*ManageResearchInfo, 0)
|
|
|
|
if len(where) > 0 {
|
|
for _, wo := range where {
|
|
db = db.Where(wo.Condition, wo.Value)
|
|
}
|
|
}
|
|
if err := db.Count(count).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Order("r.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func NewManageResearch() *ManageResearch {
|
|
return &ManageResearch{model.NewManageResearch()}
|
|
}
|