159 lines
4.8 KiB
Go
159 lines
4.8 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"
|
|
"SciencesServer/utils"
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Expert struct {
|
|
*session.Admin
|
|
}
|
|
|
|
type ExpertHandle func(session *session.Admin) *Expert
|
|
|
|
type (
|
|
// ExpertInstance 专家信息
|
|
ExpertInstance struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Industrys []string `json:"industrys"`
|
|
ResearchName string `json:"research_name"`
|
|
LaboratoryName string `json:"laboratory_name"`
|
|
Address string `json:"address"`
|
|
ExamineStatus model2.ExamineStatusKind `json:"examine_status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Area string `json:"area"`
|
|
}
|
|
// ExpertDetail 专家详细信息
|
|
ExpertDetail struct {
|
|
ID string `json:"id"`
|
|
*model2.ManageExpert
|
|
Industrys []string `json:"industrys"`
|
|
Keywords []string `json:"keywords"`
|
|
Researchs []string `json:"researchs"`
|
|
Area string `json:"area"`
|
|
}
|
|
// ExpertParams 专家参数信息
|
|
ExpertParams struct {
|
|
ID, TenantID uint64
|
|
}
|
|
)
|
|
|
|
// Instance 首页信息
|
|
func (c *Expert) Instance(tenantID uint64, name string, examineStatus int, page, pageSize int) (*controller.ReturnPages, error) {
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
where := make([]*model2.ModelWhere, 0)
|
|
|
|
if c.TenantID > 0 {
|
|
where = append(where, model2.NewWhere("e.tenant_id", c.TenantID))
|
|
}
|
|
if tenantID > 0 {
|
|
where = append(where, model2.NewWhere("e.tenant_id", tenantID))
|
|
}
|
|
if name != "" {
|
|
where = append(where, model2.NewWhereLike("e.name", name))
|
|
}
|
|
if examineStatus > 0 {
|
|
where = append(where, model2.NewWhere("e.examine_status", examineStatus))
|
|
}
|
|
var count int64
|
|
|
|
out, err := mManageExpert.Experts(page, pageSize, &count, where...)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*ExpertInstance, 0)
|
|
|
|
for _, v := range out {
|
|
_industrys := make([]string, 0)
|
|
|
|
for _, v := range strings.Split(v.Industry, ";") {
|
|
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/"))
|
|
}
|
|
// 研究机构,实验室
|
|
list = append(list, &ExpertInstance{ID: v.GetEncodeID(), Name: v.Name, Industrys: _industrys,
|
|
ResearchName: v.ResearchName, LaboratoryName: v.LaboratoryName, ExamineStatus: v.ExamineStatus,
|
|
Address: v.FormatBasic(), CreatedAt: v.CreatedAt, Area: v.FormatBasic(),
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
// Detail 详细信息
|
|
func (*Expert) Detail(id uint64) (*ExpertDetail, error) {
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
out, err := mManageExpert.Expert(id)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else if out.ManageExpert == nil {
|
|
return nil, errors.New("操作错误,专家信息不存在或已被删除")
|
|
}
|
|
return &ExpertDetail{
|
|
ID: out.GetEncodeID(),
|
|
ManageExpert: out.ManageExpert,
|
|
Industrys: out.GetIndustryAttribute(),
|
|
Keywords: out.GetKeywordAttribute(),
|
|
Researchs: out.GetResearchAttribute(),
|
|
Area: out.FormatBasic(),
|
|
}, nil
|
|
}
|
|
|
|
// Form 数据操作
|
|
func (*Expert) Form(params *BasicParams, other *config.IdentityForExpert) error {
|
|
mManageExpert := model.NewManageExpert()
|
|
|
|
if params.ID > 0 {
|
|
mManageExpert.ID = params.ID
|
|
|
|
isExist, err := model2.FirstField(mManageExpert.ManageExpert, []string{"id", "examine_status", "created_at"})
|
|
|
|
if err != nil {
|
|
return err
|
|
} else if !isExist {
|
|
return errors.New("操作错误,专家信息不存在或已被删除")
|
|
}
|
|
}
|
|
mManageExpert.TenantID = params.TenantID
|
|
mManageExpert.ResearchID = other.ConvertResearch()
|
|
mManageExpert.LaboratoryID = other.ConvertLaboratory()
|
|
mManageExpert.Image.Image = params.Image
|
|
mManageExpert.Area = model2.Area{
|
|
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
|
}
|
|
mManageExpert.School = other.School
|
|
mManageExpert.Major = other.Major
|
|
mManageExpert.Job = other.Job
|
|
mManageExpert.Title = other.Title
|
|
mManageExpert.Gender = model2.Gender{Gender: model2.GenderKind(other.Gender)}
|
|
mManageExpert.WorkAt = utils.DataTimeToDate(other.WorkAt)
|
|
mManageExpert.SetIndustryAttribute(params.Industrys)
|
|
mManageExpert.SetKeywordAttribute(params.Keywords)
|
|
mManageExpert.SetResearchAttribute(other.Researchs)
|
|
mManageExpert.Introduce = params.Introduce
|
|
|
|
if mManageExpert.ID > 0 {
|
|
return model2.Updates(mManageExpert.ManageExpert, mManageExpert.ManageExpert)
|
|
}
|
|
mManageExpert.Name = params.Name
|
|
mManageExpert.Mobile = params.Mobile
|
|
|
|
return model2.Create(mManageExpert.ManageExpert)
|
|
}
|
|
|
|
func NewExpert() ExpertHandle {
|
|
return func(session *session.Admin) *Expert {
|
|
return &Expert{session}
|
|
}
|
|
}
|