Files
cas_tt_cloud_backend/app/api/admin/model/technology_patent.go

69 lines
1.9 KiB
Go
Raw Normal View History

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