package technology import ( "SciencesServer/app/api/website/model" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" "errors" "fmt" ) type Patent struct{} type PatentHandle func() *Patent type ( // PatentInfo 专利信息 PatentInfo struct { ID string `json:"id"` *model.SysPatentInfo } // PatentDetailInfo 专利详细信息 PatentDetailInfo struct { ID string `json:"id"` *model2.SysPatent } ) // Instance 查询信息 func (c *Patent) Instance(title, industry string, page, pageSize int) (*controller.ReturnPages, error) { // TODO:缺少会员判断标准 mSysPatent := model.NewSysPatent() where := make([]*model2.ModelWhere, 0) if title != "" { where = append(where, model2.NewWhereLike("p.title", title)) } if industry != "" { where = append(where, model2.NewWhereCondition("c.industry_detail", "LIKE", "%"+fmt.Sprintf(`"%v`, industry)+"%")) } var count int64 out, err := mSysPatent.Patent(page, pageSize, &count, where...) if err != nil { return nil, err } list := make([]*PatentInfo, 0) for _, v := range out { list = append(list, &PatentInfo{ ID: v.GetEncodeID(), SysPatentInfo: v, }) } return &controller.ReturnPages{Data: list, Count: count}, nil } // Detail 详细信息 func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) { mSysPatent := model.NewSysPatent() mSysPatent.ID = id isExist, err := model2.First(mSysPatent.SysPatent) if err != nil { return nil, err } else if !isExist { return nil, errors.New("操作错误,专利信息不存在或已被删除") } return &PatentDetailInfo{ID: mSysPatent.GetEncodeID(), SysPatent: mSysPatent.SysPatent}, nil } func NewPatent() PatentHandle { return func() *Patent { return &Patent{} } }