package model import ( "SciencesServer/app/common/model" "SciencesServer/serve/orm" "fmt" "time" ) // TechnologyPatent 专利信息 type TechnologyPatent struct { *model.TechnologyPatent } // TechnologyPatentInfo 专利信息 type TechnologyPatentInfo struct { model.Model model.ModelTenant 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"` 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) ([]*TechnologyPatentInfo, error) { db := orm.GetDB().Table(m.TableName()+" AS p"). 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) if len(where) > 0 { for _, wo := range where { db = db.Where(wo.Condition, wo.Value) } } out := make([]*TechnologyPatentInfo, 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()} }