Files

138 lines
3.8 KiB
Go

package manage
import (
"SciencesServer/app/api/enterprise/model"
"SciencesServer/app/basic/config"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"fmt"
"strings"
)
type Expert struct {
*session.Enterprise
local string
}
type ExpertHandle func(session *session.Enterprise, local string) *Expert
type ExpertInfo struct {
ID string `json:"id"`
*model.ManageExpertInfo
Industrys []string `json:"industrys"`
}
// research 研究机构专家信息
func (c *Expert) research(page, pageSize int, count *int64, where ...*model2.ModelWhere) ([]*model.ManageExpertInfo, error) {
if len(where) <= 0 {
where = make([]*model2.ModelWhere, 0)
}
// 研究科技下存在专家
// 实验室下存在专家
mUserResearch := model.NewUserResearch()
_, 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
}
// 查询科研机构下所有实验室
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 = 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()
out := make([]*model.ManageExpertInfo, 0)
if out, err = mManageExpert.Experts(page, pageSize, count, where...); err != nil {
return nil, err
}
return out, nil
}
// laboratory 实验室专家信息
func (c *Expert) laboratory(page, pageSize int, count *int64, where ...*model2.ModelWhere) ([]*model.ManageExpertInfo, error) {
if len(where) <= 0 {
where = make([]*model2.ModelWhere, 0)
}
// 实验室信息
mManageLaboratory := model.NewManageLaboratory()
_, err := model2.FirstField(mManageLaboratory.ManageLaboratory, []string{"id", "research_id"},
model2.NewWhere("uid", c.UID), model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
if err != nil {
return nil, err
}
where = append(where, model2.NewWhere("e.laboratory_id = ?", mManageLaboratory.ID))
mManageExpert := model.NewManageExpert()
out := make([]*model.ManageExpertInfo, 0)
if out, err = mManageExpert.Experts(page, pageSize, count, where...); err != nil {
return nil, err
}
return out, nil
}
// Instance 专家信息
func (c *Expert) Instance(name, mobile string, page, pageSize int) (*controller.ReturnPages, error) {
where := make([]*model2.ModelWhere, 0)
if name != "" {
where = append(where, model2.NewWhereLike("e.name", name))
}
if mobile != "" {
where = append(where, model2.NewWhereLike("e.mobile", mobile))
}
out := make([]*model.ManageExpertInfo, 0)
var err error
var count int64
// 科研机构
if c.Identity == config.TenantUserIdentityForResearch {
out, err = c.research(page, pageSize, &count, where...)
// 实验室
} else if c.Identity == config.TenantUserIdentityForLaboratory {
}
if err != nil {
return nil, err
}
list := make([]*ExpertInfo, 0)
mManageExpert := model.NewManageExpert()
for _, v := range out {
mManageExpert.Industry = v.Industry
list = append(list, &ExpertInfo{
ID: v.GetEncodeID(),
ManageExpertInfo: v,
Industrys: mManageExpert.GetIndustryAttribute(),
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
func NewExpert() ExpertHandle {
return func(session *session.Enterprise, local string) *Expert {
return &Expert{
Enterprise: session,
local: local,
}
}
}