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"
|
2021-12-23 18:12:33 +08:00
|
|
|
|
"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"`
|
2022-02-06 18:01:32 +08:00
|
|
|
|
*model.TechnologyPatentInfo
|
2021-12-22 14:11:14 +08:00
|
|
|
|
}
|
|
|
|
|
// PatentDetailInfo 专利详细信息
|
|
|
|
|
PatentDetailInfo struct {
|
|
|
|
|
ID string `json:"id"`
|
2022-02-06 18:01:32 +08:00
|
|
|
|
*model2.TechnologyPatent
|
2021-12-22 14:11:14 +08:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Instance 查询信息
|
|
|
|
|
func (c *Patent) Instance(title, industry string, page, pageSize int) (*controller.ReturnPages, error) {
|
2021-12-22 17:16:13 +08:00
|
|
|
|
// TODO:缺少会员判断标准
|
2021-12-23 18:12:33 +08:00
|
|
|
|
// 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
|
|
|
|
|
2021-12-23 18:12:33 +08:00
|
|
|
|
list := make([]*PatentInfo, 0)
|
2021-12-22 14:11:14 +08:00
|
|
|
|
|
|
|
|
|
var count int64
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2021-12-23 18:12:33 +08:00
|
|
|
|
} else if out == nil {
|
|
|
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
2021-12-22 14:11:14 +08:00
|
|
|
|
}
|
2022-02-06 18:01:32 +08:00
|
|
|
|
mTechnologyPatent := model.NewTechnologyPatent()
|
2021-12-22 14:11:14 +08:00
|
|
|
|
|
2021-12-23 18:12:33 +08:00
|
|
|
|
ids := make([]uint64, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range out.([]interface{}) {
|
|
|
|
|
val := v.(*service.ESPatent)
|
|
|
|
|
ids = append(ids, val.ID)
|
|
|
|
|
}
|
2022-02-06 18:01:32 +08:00
|
|
|
|
ret := make([]*model.TechnologyPatentInfo, 0)
|
2021-12-23 18:12:33 +08:00
|
|
|
|
|
2022-02-06 18:01:32 +08:00
|
|
|
|
if ret, err = mTechnologyPatent.Patents(page, pageSize, &count, model2.NewWhereIn("p.id", ids)); err != nil {
|
2021-12-23 18:12:33 +08:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
for _, v := range ret {
|
2021-12-22 14:11:14 +08:00
|
|
|
|
list = append(list, &PatentInfo{
|
2022-02-06 18:01:32 +08:00
|
|
|
|
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) {
|
2022-02-06 18:01:32 +08:00
|
|
|
|
mTechnologyPatent := model.NewTechnologyPatent()
|
|
|
|
|
mTechnologyPatent.ID = id
|
2021-12-22 14:11:14 +08:00
|
|
|
|
|
2022-02-06 18:01:32 +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("操作错误,专利信息不存在或已被删除")
|
|
|
|
|
}
|
2022-02-06 18:01:32 +08:00
|
|
|
|
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{}
|
|
|
|
|
}
|
|
|
|
|
}
|