97 lines
2.3 KiB
Go
97 lines
2.3 KiB
Go
package manage
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/model"
|
|
"SciencesServer/app/basic/config"
|
|
"SciencesServer/app/basic/controller"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/session"
|
|
"gorm.io/gorm"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Instance struct {
|
|
*session.Admin
|
|
gorm.Model
|
|
local string
|
|
}
|
|
|
|
type InstanceHandle func(session *session.Admin, local string) *Instance
|
|
|
|
type (
|
|
// InstanceForExpert 专家信息
|
|
InstanceForExpert struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Industry []string `json:"industry"`
|
|
ResearchName string `json:"research_name"`
|
|
LaboratoryName string `json:"laboratory_name"`
|
|
Address string `json:"address"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
)
|
|
|
|
func (c *Instance) Company(name string, status int, page, pageSize int) {
|
|
mManageCompany := model.NewManageCompany()
|
|
|
|
where := make([]*model2.ModelWhere, 0)
|
|
|
|
if name != "" {
|
|
where = append(where, model2.NewWhereLike("name", name))
|
|
}
|
|
|
|
var count int64
|
|
|
|
mManageCompany.Companys(page, pageSize, &count)
|
|
}
|
|
|
|
// Expert 专家信息
|
|
func (c *Instance) Expert(name string, status int, page, pageSize int) (*controller.ReturnPages, error) {
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
where := make([]*model2.ModelWhere, 0)
|
|
|
|
if name != "" {
|
|
where = append(where, model2.NewWhereLike("name", name))
|
|
}
|
|
var count int64
|
|
|
|
out, err := mManageExpert.Experts(page, pageSize, &count, where...)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*InstanceForExpert, 0)
|
|
|
|
for _, v := range out {
|
|
industry := make([]string, 0)
|
|
|
|
for _, v := range strings.Split(v.Industry, ";") {
|
|
industry = append(industry, config.GetIndustryInfo(v, "-"))
|
|
}
|
|
// 研究机构,实验室
|
|
researchName := v.LaboratoryName
|
|
laboratoryName := ""
|
|
|
|
if v.LaboratoryName != "" {
|
|
researchName = v.ResearchName
|
|
laboratoryName = v.LaboratoryName
|
|
}
|
|
list = append(list, &InstanceForExpert{ID: v.GetEncodeID(), Name: v.Name, Industry: industry,
|
|
ResearchName: researchName, LaboratoryName: laboratoryName,
|
|
Address: v.FormatBasic(), CreatedAt: v.CreatedAt,
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
func NewInstance() InstanceHandle {
|
|
return func(session *session.Admin, local string) *Instance {
|
|
return &Instance{
|
|
Admin: session,
|
|
local: local,
|
|
}
|
|
}
|
|
}
|