feat:优化项目信息
This commit is contained in:
51
app/api/enterprise/model/user_patent.go
Normal file
51
app/api/enterprise/model/user_patent.go
Normal file
@ -0,0 +1,51 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserPatent struct {
|
||||
*model.UserPatent
|
||||
}
|
||||
|
||||
// UserPatentInfo 用户专利信息
|
||||
type UserPatentInfo struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
ApplyCode string `json:"apply_code"`
|
||||
ApplyName string `json:"apply_name"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
model.Shelf
|
||||
Status model.TechnologyPatentStatus `json:"status"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// Patent 专利信息
|
||||
func (m *UserPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserPatentInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u").
|
||||
Select("u.id", "p.title", "p.apply_code", "p.apply_name", "p.apply_at", "p.status", "p.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u.patent_id = p.id", model.NewTechnologyPatent().TableName())).
|
||||
Where("u.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*UserPatentInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u.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