216 lines
5.5 KiB
Go
216 lines
5.5 KiB
Go
package manage
|
|
|
|
import (
|
|
"SciencesServer/app/api/website/model"
|
|
"SciencesServer/app/basic/controller"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/session"
|
|
"strings"
|
|
)
|
|
|
|
type Expert struct {
|
|
*session.Enterprise
|
|
}
|
|
|
|
type ExpertHandle func(session *session.Enterprise) *Expert
|
|
|
|
type (
|
|
// ExpertBasicInfo 基本信息
|
|
ExpertBasicInfo struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
School string `json:"school"`
|
|
Major string `json:"major"`
|
|
Industrys []string `json:"industrys"`
|
|
Keywords []string `json:"keywords"`
|
|
PatentTitles []string `json:"patent_titles"`
|
|
}
|
|
// ExpertInstanceInfo 专家信息
|
|
ExpertInstanceInfo struct {
|
|
ExpertBasicInfo
|
|
Researchs []string `json:"researchs"`
|
|
Introduce string `json:"introduce"`
|
|
}
|
|
// ExpertAchievementInfo 专家成果信息
|
|
ExpertAchievementInfo struct {
|
|
*model.TechnologyAchievementInfo
|
|
ChargeInfo *model2.TechnologyAchievementChargeInfo `json:"charge_info"`
|
|
}
|
|
// ExpertProjectInfo 专家项目信息
|
|
ExpertProjectInfo struct {
|
|
ID string `json:"id"`
|
|
*model2.TechnologyProject
|
|
}
|
|
// ExpertPatentInfo 专利信息
|
|
ExpertPatentInfo struct {
|
|
ID string `json:"id"`
|
|
*model.PatentInfo
|
|
}
|
|
|
|
// ExpertPaperInfo 论文信息
|
|
ExpertPaperInfo struct {
|
|
ID string `json:"id"`
|
|
*model2.TechnologyPaper
|
|
Keywords []string `json:"keywords"`
|
|
}
|
|
)
|
|
|
|
func (c *Expert) user(id uint64) ([]uint64, error) {
|
|
mUserExpert := model.NewUserExpert()
|
|
|
|
uids := make([]uint64, 0)
|
|
|
|
err := model2.Pluck(mUserExpert.UserExpert, "uid", &uids, model2.NewWhere("expert_id", id))
|
|
|
|
return uids, err
|
|
}
|
|
|
|
// Instance 专家信息
|
|
func (c *Expert) Instance(id uint64) (*ExpertInstanceInfo, error) {
|
|
mManageExpert := model.NewManageExpert()
|
|
out, err := mManageExpert.Detail(3, id)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ExpertInstanceInfo{
|
|
ExpertBasicInfo: ExpertBasicInfo{
|
|
ID: out.GetEncodeID(),
|
|
Name: out.Name,
|
|
School: out.School,
|
|
Major: out.Major,
|
|
Industrys: out.GetIndustryAttribute(),
|
|
Keywords: out.GetKeywordAttribute(),
|
|
PatentTitles: strings.Split(out.PatentTitle, "&&"),
|
|
},
|
|
Researchs: out.GetResearchAttribute(),
|
|
Introduce: out.Introduce,
|
|
}, nil
|
|
}
|
|
|
|
// Achievement 成果信息
|
|
func (c *Expert) Achievement(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
|
uids, err := c.user(id)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
var count int64
|
|
|
|
out := make([]*model.TechnologyAchievementInfo, 0)
|
|
|
|
if out, err = mTechnologyAchievement.Achievement(page, pageSize, &count, model2.NewWhereIn("uid", uids)); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ExpertAchievementInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &ExpertAchievementInfo{
|
|
TechnologyAchievementInfo: v,
|
|
ChargeInfo: v.GetChargeInfoAttribute(),
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
// Project 项目信息
|
|
func (c *Expert) Project(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
|
// 查询专家身份下用户信息
|
|
uids, err := c.user(id)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mTechnologyProject := model.NewTechnologyProject()
|
|
out := make([]*model2.TechnologyProject, 0)
|
|
|
|
var count int64
|
|
|
|
if err = model2.Pages(mTechnologyProject.TechnologyProject, &out, page, pageSize, &count,
|
|
&model2.ModelWhereOrder{
|
|
Where: model2.NewWhereIn("uid", uids),
|
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
|
}, &model2.ModelWhereOrder{
|
|
Where: model2.NewWhere("shelf_status", model2.ShelfStatusForUp),
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ExpertProjectInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &ExpertProjectInfo{
|
|
ID: v.GetEncodeID(),
|
|
TechnologyProject: v,
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
// Patent 专利信息
|
|
func (c *Expert) Patent(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
|
// 查询专家身份下用户信息
|
|
uids, err := c.user(id)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mUserPatent := model.NewUserPatent()
|
|
var count int64
|
|
|
|
out := make([]*model.PatentInfo, 0)
|
|
|
|
if out, err = mUserPatent.Patent(page, pageSize, &count, model2.NewWhereIn("u_p.uid", uids)); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ExpertPatentInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &ExpertPatentInfo{
|
|
ID: v.GetEncodeID(),
|
|
PatentInfo: v,
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
// Paper 论文信息
|
|
func (c *Expert) Paper(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
|
// 查询专家身份下用户信息
|
|
uids, err := c.user(id)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mTechnologyPaper := model.NewTechnologyPaper()
|
|
|
|
out := make([]*model2.TechnologyPaper, 0)
|
|
|
|
var count int64
|
|
|
|
if err = model2.PagesFields(mTechnologyPaper.TechnologyPaper, &out, []string{"id", "title", "ext", "keyword"},
|
|
page, pageSize, &count, &model2.ModelWhereOrder{
|
|
Where: model2.NewWhereIn("uid", uids),
|
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ExpertPaperInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &ExpertPaperInfo{
|
|
ID: v.GetEncodeID(),
|
|
TechnologyPaper: v,
|
|
Keywords: v.GetKeywordAttribute(),
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
func NewExpert() ExpertHandle {
|
|
return func(session *session.Enterprise) *Expert {
|
|
return &Expert{session}
|
|
}
|
|
}
|