package manage import ( "SciencesServer/app/api/enterprise/model" "SciencesServer/app/basic/config" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" "SciencesServer/app/service" "SciencesServer/app/session" "errors" "fmt" "strings" ) type Expert struct { *session.Enterprise } type ExpertHandle func(session *session.Enterprise) *Expert type ( // ExpertInfo 专家信息 ExpertInfo struct { ID string `json:"id"` *model.ManageExpertInfo Industrys []string `json:"industrys"` } // ExpertMatchInfo 专家匹配信息 ExpertMatchInfo 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"` PatentTitle []string `json:"patent_title"` } // ExpertDetailInfo 专家详细信息 ExpertDetailInfo struct { ExpertMatchInfo Researchs []string `json:"researchs"` Introduce string `json:"introduce"` } ) // user 用户信息 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 } // 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() 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 = 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 { out, err = c.laboratory(page, pageSize, &count, where...) } 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 } // Match 匹配信息 func (c *Expert) Match(title string, industrys, keywords []string) (*controller.ReturnPages, error) { params := strings.Join([]string{ title, strings.Join(industrys, ","), strings.Join(keywords, ","), }, ",") manage := service.NewESManage( service.WithManageIdentity(config.TenantUserIdentityForExpert), ) out, count, err := manage.Search(0, 0, map[string]interface{}{ "title": params, "industry": params, "keyword": params, "research": params, }) if err != nil { return nil, err } ids := make([]uint64, 0) for _, v := range out.([]interface{}) { val := v.(*service.ESManage) ids = append(ids, val.ID) } mManageExpert := model.NewManageExpert() experts := make([]*model.ManageExpertInstanceInfo, 0) if experts, err = mManageExpert.Instance(3, model2.NewWhereIn("e.id", ids)); err != nil { return nil, err } list := make([]*ExpertMatchInfo, 0) for _, v := range experts { list = append(list, &ExpertMatchInfo{ ID: v.GetEncodeID(), Name: v.Name, School: v.School, Major: v.Major, Industrys: v.GetIndustryAttribute(), Keywords: v.GetKeywordAttribute(), PatentTitle: strings.Split(v.PatentTitle, "&&"), }) } return &controller.ReturnPages{Data: list, Count: count}, nil } // Detail 详细信息 func (c *Expert) Detail(id uint64) (*ExpertDetailInfo, error) { mManageExpert := model.NewManageExpert() out, err := mManageExpert.Detail(3, id) if err != nil { return nil, err } return &ExpertDetailInfo{ ExpertMatchInfo: ExpertMatchInfo{ ID: out.GetEncodeID(), Name: out.Name, School: out.School, Major: out.Major, Industrys: out.GetIndustryAttribute(), Keywords: out.GetKeywordAttribute(), PatentTitle: 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 } return achievement(uids, page, pageSize) } // Project 项目信息 func (c *Expert) Project(id uint64, page, pageSize int) (*controller.ReturnPages, error) { // 查询专家身份下用户信息 uids, err := c.user(id) if err != nil { return nil, err } return project(uids, page, pageSize) } // Patent 专利信息 func (c *Expert) Patent(id uint64, page, pageSize int) (*controller.ReturnPages, error) { // 查询专家身份下用户信息 //uids, err := c.user(id) // //if err != nil { // return nil, err //} return patent(id, page, pageSize) } // Paper 论文信息 func (c *Expert) Paper(id uint64, page, pageSize int) (*controller.ReturnPages, error) { // 查询专家身份下用户信息 uids, err := c.user(id) if err != nil { return nil, err } return paper(uids, page, pageSize) } // Cooperate 企业信息 func (c *Expert) Cooperate(id uint64, page, pageSize int) (*controller.ReturnPages, error) { // 查询专家身份下用户信息 uids, err := c.user(id) if err != nil { return nil, err } return cooperate(uids, page, pageSize) } // CooperateDetail 公司企业详细信息 func (c *Expert) CooperateDetail(id uint64) (*CooperateDetailInfo, error) { return cooperateDetail(id) } func NewExpert() ExpertHandle { return func(session *session.Enterprise) *Expert { return &Expert{ Enterprise: session, } } }