Files
cas_tt_cloud_backend/app/api/admin/model/technology_patent.go
2022-02-06 18:01:32 +08:00

67 lines
1.7 KiB
Go

package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
"time"
)
// TechnologyPatent 专利信息
type TechnologyPatent struct {
*model.TechnologyPatent
}
// SysPatentInfo 专利信息
type SysPatentInfo struct {
model.Model
model.ModelTenant
Title string `json:"title"`
ApplyCode string `json:"apply_code"`
ApplyAt string `json:"apply_at"`
ApplyName string `json:"apply_name"`
Inventor string `json:"inventor"`
model.Shelf
UID uint64 `json:"-"`
CreatedAt time.Time `json:"created_at"`
}
func (m *TechnologyPatent) IsExistParams(params map[string]interface{}) (bool, error) {
var count int64
db := orm.GetDB().Table(m.TableName())
if len(params) > 0 {
for k, v := range params {
db = db.Or(fmt.Sprintf("%s = %v AND is_deleted = %d", k, v, model.DeleteStatusForNot))
}
}
err := db.Count(&count).Error
return count > 0, err
}
// Patent 专利信息
func (m *TechnologyPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysPatentInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS p").
Select("p.id", "p.title", "p.apply_code", "p.inventor", "p.apply_name", "p.apply_at", "u.uid",
"p.shelf_status", "p.created_at")
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*SysPatentInfo, 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 NewTechnologyPatent() *TechnologyPatent {
return &TechnologyPatent{model.NewTechnologyPatent()}
}