130 lines
3.6 KiB
Go
130 lines
3.6 KiB
Go
package manage
|
|
|
|
import (
|
|
"SciencesServer/app/api/enterprise/model"
|
|
"SciencesServer/app/basic/controller"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/session"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type Research struct {
|
|
*session.Enterprise
|
|
local string
|
|
}
|
|
|
|
type ResearchHandle func(session *session.Enterprise, local string) *Research
|
|
|
|
type (
|
|
// ResearchLaboratory 科研机构下实验室信息
|
|
ResearchLaboratory struct {
|
|
ID string `json:"id"`
|
|
*model.ManageLaboratoryInfo
|
|
Industrys []string `json:"industrys"`
|
|
}
|
|
// ResearchVisit 浏览信息
|
|
ResearchVisit struct {
|
|
ID string `json:"id"`
|
|
*model.ManageExpertCompanyVisitInfo
|
|
}
|
|
)
|
|
|
|
// Laboratory 实验室信息
|
|
func (c *Research) Laboratory(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
|
// 查询用户科研机构信息
|
|
mUserResearch := model.NewUserResearch()
|
|
|
|
isExist, err := model2.FirstField(mUserResearch.UserResearch, []string{"id", "research_id"},
|
|
model2.NewWhere("uid", c.UID), model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else if !isExist {
|
|
return nil, errors.New("操作错误,无权限查看")
|
|
}
|
|
where := []*model2.ModelWhere{model2.NewWhere("research_id", mUserResearch.ResearchID)}
|
|
|
|
if title != "" {
|
|
where = append(where, model2.NewWhereLike("title", title))
|
|
}
|
|
mManageLaboratory := model.NewManageLaboratory()
|
|
|
|
out := make([]*model.ManageLaboratoryInfo, 0)
|
|
|
|
var count int64
|
|
|
|
if out, err = mManageLaboratory.Laboratory(page, pageSize, &count, where...); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ResearchLaboratory, 0)
|
|
|
|
for _, v := range out {
|
|
mManageLaboratory.Industry = v.Industry
|
|
|
|
list = append(list, &ResearchLaboratory{
|
|
ID: v.GetEncodeID(),
|
|
ManageLaboratoryInfo: v,
|
|
Industrys: mManageLaboratory.GetIndustryAttribute(),
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
// Visit 访问记录
|
|
func (c *Research) Visit(page, pageSize int) (*controller.ReturnPages, error) {
|
|
// 获取当前科研机构下所有的专家人员
|
|
mUserResearch := model.NewUserResearch()
|
|
|
|
isExist, err := model2.FirstField(mUserResearch.UserResearch, []string{"id", "research_id"},
|
|
model2.NewWhere("uid", c.UID), model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else if !isExist {
|
|
return nil, errors.New("操作错误,无权限查看")
|
|
}
|
|
// 查询科研机构下所有实验室
|
|
mManageLaboratory := model.NewManageLaboratory()
|
|
// 用String去接受参数
|
|
laboratoryIDs := make([]string, 0)
|
|
|
|
if err = model2.Pluck(mManageLaboratory.ManageLaboratory, "id", &laboratoryIDs,
|
|
model2.NewWhere("research_id", mUserResearch.ResearchID)); err != nil {
|
|
return nil, err
|
|
}
|
|
where := make([]*model2.ModelWhere, 0)
|
|
|
|
where = append(where, model2.NewWhere("e.research_id = ?", mUserResearch.ResearchID),
|
|
model2.NewWhereValue(fmt.Sprintf("(e.laboratory_id = %d) OR (e.laboratory_id IN (%v))",
|
|
0, strings.Join(laboratoryIDs, ","))))
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
var count int64
|
|
|
|
out := make([]*model.ManageExpertCompanyVisitInfo, 0)
|
|
|
|
if out, err = mManageExpert.CompanyVisit(page, pageSize, &count, where...); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ResearchVisit, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &ResearchVisit{
|
|
ID: v.GetEncodeID(),
|
|
ManageExpertCompanyVisitInfo: v,
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, err
|
|
}
|
|
|
|
func NewResearch() ResearchHandle {
|
|
return func(session *session.Enterprise, local string) *Research {
|
|
return &Research{
|
|
Enterprise: session,
|
|
local: local,
|
|
}
|
|
}
|
|
}
|