feat:完善项目
This commit is contained in:
46
app/api/admin/model/technology_paper.go
Normal file
46
app/api/admin/model/technology_paper.go
Normal file
@ -0,0 +1,46 @@
|
||||
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()}
|
||||
}
|
||||
Reference in New Issue
Block a user