feat:完善用户专利数据模型
This commit is contained in:
@ -1,12 +1,29 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// SysPatent 专利信息
|
||||
type SysPatent struct {
|
||||
*model.SysPatent
|
||||
}
|
||||
|
||||
func (m *SysPatent) 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 NewSysPatent() *SysPatent {
|
||||
return &SysPatent{model.NewSysPatent()}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type TechnologyPatent struct {
|
||||
*model.TechnologyPatent
|
||||
}
|
||||
|
||||
func NewTechnologyPatent() *TechnologyPatent {
|
||||
return &TechnologyPatent{TechnologyPatent: model.NewTechnologyPatent()}
|
||||
}
|
@ -1,11 +1,38 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type UserPatent struct {
|
||||
*model.UserPatent
|
||||
}
|
||||
|
||||
// Patents 专利信息
|
||||
func (m *UserPatent) Patents(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*model.SysPatent, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u").
|
||||
Select("u.id", "p.title", "p.apply_code", "p.apply_name", "p.apply_at", "shelf", "status", "u.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u.patent_id = p.id", model.NewSysPatent().TableName())).
|
||||
Where("u.is_deleted = ? AND p.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*model.SysPatent, 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