Files

93 lines
2.2 KiB
Go
Raw Normal View History

2021-12-22 14:11:14 +08:00
package technology
import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
2021-12-22 14:11:14 +08:00
"errors"
)
type Patent struct{}
type PatentHandle func() *Patent
type (
// PatentInfo 专利信息
PatentInfo struct {
ID string `json:"id"`
*model.TechnologyPatentInfo
2021-12-22 14:11:14 +08:00
}
// PatentDetailInfo 专利详细信息
PatentDetailInfo struct {
ID string `json:"id"`
*model2.TechnologyPatent
2021-12-22 14:11:14 +08:00
}
)
// Instance 查询信息
func (c *Patent) Instance(title, industry string, page, pageSize int) (*controller.ReturnPages, error) {
// TODO缺少会员判断标准
// ES标准判定
2022-01-21 10:14:56 +08:00
manage := service.NewESPatent()
if title != "" {
service.WithPatentTitle(title)(manage)
}
if industry != "" {
service.WithPatentIndustry(industry)(manage)
}
out, count1, err := manage.Search(page, pageSize)
2021-12-22 14:11:14 +08:00
list := make([]*PatentInfo, 0)
2021-12-22 14:11:14 +08:00
var count int64
if err != nil {
return nil, err
} else if out == nil {
return &controller.ReturnPages{Data: list, Count: count}, nil
2021-12-22 14:11:14 +08:00
}
mTechnologyPatent := model.NewTechnologyPatent()
2021-12-22 14:11:14 +08:00
ids := make([]uint64, 0)
for _, v := range out.([]interface{}) {
val := v.(*service.ESPatent)
ids = append(ids, val.ID)
}
ret := make([]*model.TechnologyPatentInfo, 0)
if ret, err = mTechnologyPatent.Patents(page, pageSize, &count, model2.NewWhereIn("p.id", ids)); err != nil {
return nil, err
}
for _, v := range ret {
2021-12-22 14:11:14 +08:00
list = append(list, &PatentInfo{
ID: v.GetEncodeID(),
TechnologyPatentInfo: v,
2021-12-22 14:11:14 +08:00
})
}
2022-01-20 11:51:02 +08:00
return &controller.ReturnPages{Data: list, Count: count1}, nil
2021-12-22 14:11:14 +08:00
}
// Detail 详细信息
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
2021-12-22 14:11:14 +08:00
isExist, err := model2.First(mTechnologyPatent.TechnologyPatent)
2021-12-22 14:11:14 +08:00
if err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,专利信息不存在或已被删除")
}
return &PatentDetailInfo{ID: mTechnologyPatent.GetEncodeID(), TechnologyPatent: mTechnologyPatent.TechnologyPatent}, nil
2021-12-22 14:11:14 +08:00
}
func NewPatent() PatentHandle {
return func() *Patent {
return &Patent{}
}
}