Files
2022-03-05 15:31:22 +08:00

65 lines
1.7 KiB
Go

package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
// TechnologyPatent 专利信息
type TechnologyPatent struct {
*model.TechnologyPatent
}
type TechnologyPatentInfo struct {
model.Model
Kind model.TechnologyPatentKind `json:"kind"`
Title string `json:"title"`
Description string `json:"description"`
ApplyAt string `json:"apply_at"`
}
type TechnologyPatentBasicInfo struct {
model.Model
Title string `json:"title"`
ApplyAt string `json:"apply_at"`
}
// Instance 专利信息
func (m *TechnologyPatent) Instance(where ...*model.ModelWhere) ([]*TechnologyPatentInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS p").
Select("p.id", "p.title", "LEFT(p.description, 80) AS description", "p.apply_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON p.ipc_code = c.ipc AND c.is_deleted = %d",
model.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
Where("p.is_deleted = ?", model.DeleteStatusForNot)
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*TechnologyPatentInfo, 0)
if err := db.Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
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
}
func NewTechnologyPatent() *TechnologyPatent {
return &TechnologyPatent{model.NewTechnologyPatent()}
}