47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
)
|
|
|
|
type TechnologyPaper struct {
|
|
*model.TechnologyPaper
|
|
}
|
|
|
|
type TechnologyPaperInfo struct {
|
|
model.Model
|
|
model.ModelTenant
|
|
Title string `json:"title"`
|
|
Author string `json:"author"`
|
|
PublishAt string `json:"publish_at"`
|
|
model.Area
|
|
}
|
|
|
|
func (m *TechnologyPaper) Paper(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyPaperInfo, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS p").
|
|
Select("p.id", "p.title", "p.author", "a.publish_at", "p.tenant_id", "t.province", "t.city").
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON p.tanant_id = t.id", model.NewSysTenant().TableName())).
|
|
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
if len(where) > 0 {
|
|
for _, v := range where {
|
|
db = db.Where(v.Condition, v.Value)
|
|
}
|
|
}
|
|
out := make([]*TechnologyPaperInfo, 0)
|
|
|
|
if err := db.Count(count).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func NewTechnologyPaper() *TechnologyPaper {
|
|
return &TechnologyPaper{model.NewTechnologyPaper()}
|
|
}
|