feat:完善网站信息

This commit is contained in:
henry
2021-12-22 14:11:14 +08:00
parent b0a9ef3569
commit 332f67d1c1
14 changed files with 637 additions and 28 deletions

View File

@ -0,0 +1,78 @@
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) {
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{}
}
}