feat:完善项目信息
This commit is contained in:
49
app/api/website/model/user_patent.go
Normal file
49
app/api/website/model/user_patent.go
Normal file
@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type UserPatent struct {
|
||||
*model.UserPatent
|
||||
}
|
||||
|
||||
type (
|
||||
// PatentInfo 专利信息
|
||||
PatentInfo struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
}
|
||||
)
|
||||
|
||||
// Patent 专利信息
|
||||
func (m *UserPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*PatentInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u_p").
|
||||
Select("p.id", "p.title", "p.apply_at", "p.description").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u_p.patent_id = p.id",
|
||||
model.NewSysPatent().TableName())).
|
||||
Where("u_p.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Where("p.shelf_status = ?", model.ShelfStatusForUp)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*PatentInfo, 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 NewUserPatent() *UserPatent {
|
||||
return &UserPatent{model.NewUserPatent()}
|
||||
}
|
Reference in New Issue
Block a user