feat:优化项目信息

This commit is contained in:
henry
2022-02-09 11:06:59 +08:00
parent 1cec70ebee
commit 2d8be509b7
15 changed files with 217 additions and 285 deletions

View 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()}
}