diff --git a/app/api/admin/controller/account.go b/app/api/admin/controller/account.go new file mode 100644 index 0000000..b0b429f --- /dev/null +++ b/app/api/admin/controller/account.go @@ -0,0 +1 @@ +package controller diff --git a/app/api/admin/controller/tenant.go b/app/api/admin/controller/tenant.go new file mode 100644 index 0000000..b0b429f --- /dev/null +++ b/app/api/admin/controller/tenant.go @@ -0,0 +1 @@ +package controller diff --git a/app/api/enterprise/controller/manage/common.go b/app/api/enterprise/controller/manage/common.go new file mode 100644 index 0000000..b89e357 --- /dev/null +++ b/app/api/enterprise/controller/manage/common.go @@ -0,0 +1,253 @@ +package manage + +import ( + "SciencesServer/app/api/website/controller/technology" + "SciencesServer/app/api/website/model" + "SciencesServer/app/basic/controller" + model2 "SciencesServer/app/common/model" + "errors" +) + +// 公用参数信息 + +type ( + // AchievementInfo 成果信息 + AchievementInfo struct { + *model.TechnologyAchievementInfo + ChargeInfo *model2.TechnologyAchievementChargeInfo `json:"charge_info"` + } + // ProjectInfo 项目信息 + ProjectInfo struct { + ID string `json:"id"` + *model2.TechnologyProject + } + // PatentInfo 专利信息 + PatentInfo struct { + ID string `json:"id"` + *model.PatentInfo + } + // PaperInfo 论文信息 + PaperInfo struct { + ID string `json:"id"` + *model2.TechnologyPaper + Keywords []string `json:"keywords"` + } + // CooperateInfo 合作的企业信息 + CooperateInfo struct { + ID string `json:"id"` + Title string `json:"title"` + PatentCount int `json:"patent_count"` + PaperCount int `json:"paper_count"` + } + // CooperateDetailInfo 合作的企业详细信息 + CooperateDetailInfo struct { + Title string `json:"title"` + Patent []*technology.PatentInfo `json:"patent"` + Paper []*technology.PaperInfo `json:"paper"` + } + EquipmentInfo struct { + ID string `json:"id"` + *model2.ManageEquipment + } +) + +// achievement 技术成果信息 +func achievement(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) { + mTechnologyAchievement := model.NewTechnologyAchievement() + + var count int64 + + out, err := mTechnologyAchievement.Achievement(page, pageSize, &count, model2.NewWhereIn("uid", uids)) + + if err != nil { + return nil, err + } + list := make([]*AchievementInfo, 0) + + for _, v := range out { + list = append(list, &AchievementInfo{ + TechnologyAchievementInfo: v, + ChargeInfo: v.GetChargeInfoAttribute(), + }) + } + return &controller.ReturnPages{Data: list, Count: count}, nil +} + +// project 项目信息 +func project(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) { + mTechnologyProject := model.NewTechnologyProject() + out := make([]*model2.TechnologyProject, 0) + + var count int64 + + if err := model2.Pages(mTechnologyProject.TechnologyProject, &out, page, pageSize, &count, + &model2.ModelWhereOrder{ + Where: model2.NewWhereIn("uid", uids), + Order: model2.NewOrder("id", model2.OrderModeToDesc), + }, &model2.ModelWhereOrder{ + Where: model2.NewWhere("shelf_status", model2.ShelfStatusForUp), + }); err != nil { + return nil, err + } + list := make([]*ProjectInfo, 0) + + for _, v := range out { + list = append(list, &ProjectInfo{ + ID: v.GetEncodeID(), + TechnologyProject: v, + }) + } + return &controller.ReturnPages{Data: list, Count: count}, nil +} + +// patent 专利信息 +func patent(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) { + mUserPatent := model.NewUserPatent() + var count int64 + + out, err := mUserPatent.Patent(page, pageSize, &count, model2.NewWhereIn("u_p.uid", uids)) + + if err != nil { + return nil, err + } + list := make([]*PatentInfo, 0) + + for _, v := range out { + list = append(list, &PatentInfo{ + ID: v.GetEncodeID(), + PatentInfo: v, + }) + } + return &controller.ReturnPages{Data: list, Count: count}, nil +} +func paper(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) { + mTechnologyPaper := model.NewTechnologyPaper() + + out := make([]*model2.TechnologyPaper, 0) + + var count int64 + + if err := model2.PagesFields(mTechnologyPaper.TechnologyPaper, &out, []string{"id", "title", "ext", "keyword"}, + page, pageSize, &count, &model2.ModelWhereOrder{ + Where: model2.NewWhereIn("uid", uids), + Order: model2.NewOrder("id", model2.OrderModeToDesc), + }); err != nil { + return nil, err + } + list := make([]*PaperInfo, 0) + + for _, v := range out { + list = append(list, &PaperInfo{ + ID: v.GetEncodeID(), + TechnologyPaper: v, + Keywords: v.GetKeywordAttribute(), + }) + } + return &controller.ReturnPages{Data: list, Count: count}, nil +} + +// cooperate 合作的信息 +func cooperate(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) { + mUserCooperateEnterprise := model.NewUserCooperateEnterprise() + + out := make([]*model2.UserCooperateEnterprise, 0) + + var count int64 + + if err := model2.PagesFields(mUserCooperateEnterprise.UserCooperateEnterprise, &out, []string{"id", "title", "paper", "patent"}, + page, pageSize, &count, &model2.ModelWhereOrder{ + Where: model2.NewWhereIn("uid", uids), + Order: model2.NewOrder("id", model2.OrderModeToDesc), + }, &model2.ModelWhereOrder{ + Where: model2.NewWhere("kind", model2.UserCooperateEnterpriseModeForCooperateAlready)}); err != nil { + return nil, err + } + + list := make([]*CooperateInfo, 0) + + for _, v := range out { + list = append(list, &CooperateInfo{ + ID: v.GetEncodeID(), + Title: v.Title, + PatentCount: len(v.GetPatentAttribute()), + PaperCount: len(v.GetPaperAttribute()), + }) + } + return &controller.ReturnPages{Data: list, Count: count}, nil +} + +// cooperateDetail 合作企业详情 +func cooperateDetail(id uint64) (*CooperateDetailInfo, error) { + mUserCooperateEnterprise := model.NewUserCooperateEnterprise() + mUserCooperateEnterprise.ID = id + + isExist, err := model2.FirstField(mUserCooperateEnterprise.UserCooperateEnterprise, []string{"id", "title", "paper", "patent"}) + + if err != nil { + return nil, err + } else if !isExist { + return nil, errors.New("操作错误,企业信息不存在或已被删除") + } + out := &CooperateDetailInfo{ + Title: mUserCooperateEnterprise.Title, + Patent: make([]*technology.PatentInfo, 0), + Paper: make([]*technology.PaperInfo, 0), + } + // 专利信息 + mSysPatent := model.NewSysPatent() + + patents := make([]*model.SysPatentInfo, 0) + + if patents, err = mSysPatent.Instance(model2.NewWhereIn("p.id", mUserCooperateEnterprise.GetPatentAttribute())); err != nil { + return nil, err + } + for _, v := range patents { + out.Patent = append(out.Patent, &technology.PatentInfo{ + ID: v.GetEncodeID(), + SysPatentInfo: v, + }) + } + // 论文信息 + mTechnologyPaper := model.NewTechnologyPaper() + + papers := make([]*model2.TechnologyPaper, 0) + + if err = model2.ScanFields(mTechnologyPaper.TechnologyPaper, &papers, []string{"id", "title", "ext", "keyword"}, + &model2.ModelWhereOrder{ + Where: model2.NewWhereIn("id", mUserCooperateEnterprise.GetPaperAttribute()), + Order: model2.NewOrder("id", model2.OrderModeToDesc), + }); err != nil { + return nil, err + } + for _, v := range papers { + out.Paper = append(out.Paper, &technology.PaperInfo{ + ID: v.GetEncodeID(), Title: v.Title, Ext: v.Ext, Keywords: v.GetKeywordAttribute(), + }) + } + return out, nil +} + +// equipment 设备信息 +func equipment(kind model2.ManageEquipmentKind, uids []uint64, page, pageSize int) (*controller.ReturnPages, error) { + mManageEquipment := model.NewManageEquipment() + + out := make([]*model2.ManageEquipment, 0) + + var count int64 + + if err := model2.Pages(mManageEquipment.ManageEquipment, &out, page, pageSize, &count, &model2.ModelWhereOrder{ + Where: model2.NewWhere("kind", kind), + Order: model2.NewOrder("id", model2.OrderModeToDesc), + }, &model2.ModelWhereOrder{Where: model2.NewWhereIn("uid", uids)}); err != nil { + return nil, err + } + list := make([]*EquipmentInfo, 0) + + for _, v := range out { + list = append(list, &EquipmentInfo{ + ID: v.GetEncodeID(), + ManageEquipment: v, + }) + } + return &controller.ReturnPages{Data: list, Count: count}, nil +} diff --git a/app/api/enterprise/controller/manage/equipment.go b/app/api/enterprise/controller/manage/equipment.go index 6e5881c..59f035b 100644 --- a/app/api/enterprise/controller/manage/equipment.go +++ b/app/api/enterprise/controller/manage/equipment.go @@ -17,7 +17,7 @@ type Equipment struct { type EquipmentHandle func(session *session.Enterprise, local string) *Equipment type ( - EquipmentInfo struct { + EquipmentInstance struct { ID string `json:"id"` *model2.ManageEquipment } @@ -58,10 +58,10 @@ func (c *Equipment) List(kind int, code, title string, page, pageSize int) (*con if err := model2.Pages(mManageEquipment.ManageEquipment, &out, page, pageSize, &count, where...); err != nil { return nil, err } - list := make([]*EquipmentInfo, 0) + list := make([]*EquipmentInstance, 0) for _, v := range out { - list = append(list, &EquipmentInfo{ + list = append(list, &EquipmentInstance{ ID: v.GetEncodeID(), ManageEquipment: v, }) } diff --git a/app/api/enterprise/controller/manage/expert.go b/app/api/enterprise/controller/manage/expert.go index df97e5f..8bc5ab6 100644 --- a/app/api/enterprise/controller/manage/expert.go +++ b/app/api/enterprise/controller/manage/expert.go @@ -5,6 +5,7 @@ import ( "SciencesServer/app/basic/config" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" + "SciencesServer/app/service" "SciencesServer/app/session" "errors" "fmt" @@ -18,10 +19,40 @@ type Expert struct { type ExpertHandle func(session *session.Enterprise, local string) *Expert -type ExpertInfo struct { - ID string `json:"id"` - *model.ManageExpertInfo - Industrys []string `json:"industrys"` +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"` + PatentTitles []string `json:"patent_titles"` + } + // 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 研究机构专家信息 @@ -131,6 +162,137 @@ func (c *Expert) Instance(name, mobile string, page, pageSize int) (*controller. return &controller.ReturnPages{Data: list, Count: count}, nil } +// Match 匹配信息 +func (c *Expert) Match(title string, industrys, keywords []string) ([]*ExpertMatchInfo, error) { + params := strings.Join([]string{ + title, strings.Join(industrys, ","), strings.Join(keywords, ","), + }, ",") + + manage := service.NewESManage( + service.WithManageIdentity(config.TenantUserIdentityForExpert), + ) + out, 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(), + PatentTitles: strings.Split(v.PatentTitle, "&&"), + }) + } + return list, 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(), + PatentTitles: 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(uids, 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, local string) *Expert { return &Expert{ diff --git a/app/api/enterprise/controller/technology/patent.go b/app/api/enterprise/controller/technology/patent.go index 4cf6b18..50bece3 100644 --- a/app/api/enterprise/controller/technology/patent.go +++ b/app/api/enterprise/controller/technology/patent.go @@ -192,7 +192,7 @@ func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page return &controller.ReturnPages{Data: list, Count: count}, nil } -// Search 搜索信息 +// Match 搜索信息 func (c *Patent) Match(title string, industrys, keywords []string) ([]*PatentMatchInfo, error) { params := strings.Join([]string{ title, strings.Join(industrys, ","), strings.Join(keywords, ","), diff --git a/app/api/enterprise/model/manage_expert.go b/app/api/enterprise/model/manage_expert.go index 0374027..117df03 100644 --- a/app/api/enterprise/model/manage_expert.go +++ b/app/api/enterprise/model/manage_expert.go @@ -28,6 +28,69 @@ type ManageExpertCompanyVisitInfo struct { VisitAt time.Time `json:"visit_at"` } +type ManageExpertInstanceInfo struct { + *model.ManageExpert + PatentTitle string `json:"-"` + Research string `json:"-"` + Introduce string `json:"introduce"` +} + +// Expert 专家信息 +func (m *ManageExpert) Instance(limit int, where ...*model.ModelWhere) ([]*ManageExpertInstanceInfo, error) { + // 专利信息 + mSysPatent := model.NewSysPatent() + // 用户专利信息 + mUserPatent := model.NewUserPatent() + + db := orm.GetDB().Table(m.TableName()+" AS e"). + Select("e.id", "e.name", "e.industry", "e.school", "e.major", "e.keyword", + "p.title AS patent_title"). + Joins(fmt.Sprintf("LEFT JOIN %s AS e_u ON e.id = p.patent_id AND e_u.invalid_status = %d AND e_u.is_deleted = %d", + model.NewUserExpert().TableName(), model.InvalidStatusForNot, model.DeleteStatusForNot)). + Joins(fmt.Sprintf(`LEFT JOIN (SELECT u.uid, SUBSTRING_INDEX(GROUP_CONCAT(p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title +FROM %s AS u LEFT JOIN %s AS p ON u.parent_id = p.id WHERE u.is_deleted = %d AND p.shelf_status = %d) AS p ON e_u.uid = p.uid`, + limit, mUserPatent.TableName(), mSysPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)). + Where("e.examine_status = ?", model.ExamineStatusForAgree). + Where("e.is_deleted = ?", model.DeleteStatusForNot) + + if len(where) > 0 { + for _, v := range where { + db = db.Where(v.Condition, v.Value) + } + } + out := make([]*ManageExpertInstanceInfo, 0) + + if err := db.Order("e.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil { + return nil, err + } + return out, nil +} + +// Detail 专家信息 +func (m *ManageExpert) Detail(limit int, id uint64) (*ManageExpertInstanceInfo, error) { + // 专利信息 + mSysPatent := model.NewSysPatent() + // 用户专利信息 + mUserPatent := model.NewUserPatent() + + db := orm.GetDB().Table(m.TableName()+" AS e"). + Select("e.id", "e.name", "e.industry", "e.school", "e.major", "e.keyword", "e.research", "e.introduce", + "p.title AS patent_title"). + Joins(fmt.Sprintf("LEFT JOIN %s AS e_u ON e.id = p.patent_id AND e_u.invalid_status = %d AND e_u.is_deleted = %d", + model.NewUserExpert().TableName(), model.InvalidStatusForNot, model.DeleteStatusForNot)). + Joins(fmt.Sprintf(`LEFT JOIN (SELECT u.uid, SUBSTRING_INDEX(GROUP_CONCAT(p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title +FROM %s AS u LEFT JOIN %s AS p ON u.parent_id = p.id WHERE u.is_deleted = %d AND p.shelf_status = %d) AS p ON e_u.uid = p.uid`, + limit, mUserPatent.TableName(), mSysPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)). + Where("e.id = ?", id) + + out := new(ManageExpertInstanceInfo) + + if err := db.Scan(&out).Error; err != nil { + return nil, err + } + return out, nil +} + // Experts 专家信息 func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) { db := orm.GetDB().Table(m.TableName()+" e"). diff --git a/app/api/website/controller/manage/expert.go b/app/api/website/controller/manage/expert.go index 778ae35..2ccb58d 100644 --- a/app/api/website/controller/manage/expert.go +++ b/app/api/website/controller/manage/expert.go @@ -98,7 +98,7 @@ func (c *Expert) Patent(id uint64, page, pageSize int) (*controller.ReturnPages, return nil, err } - return paper(uids, page, pageSize) + return patent(uids, page, pageSize) } // Paper 论文信息 diff --git a/app/api/website/controller/manage/search.go b/app/api/website/controller/manage/search.go index 82f2ea2..9ebc583 100644 --- a/app/api/website/controller/manage/search.go +++ b/app/api/website/controller/manage/search.go @@ -111,7 +111,7 @@ func (c *Search) Launch(identity int, param, industry string, page, pageSize int service.WithManageKeyword(param), service.WithManageResearch(param), ) - out, err := manage.Search(page, pageSize) + out, err := manage.Search(page, pageSize, nil) if err != nil { return nil, err diff --git a/app/service/es_manage.go b/app/service/es_manage.go index 662815e..f01e348 100644 --- a/app/service/es_manage.go +++ b/app/service/es_manage.go @@ -30,7 +30,7 @@ func (this *ESManage) Create() error { return es.Create(this.Index(), _bytes) } -func (this *ESManage) Search(page, pageSize int) (interface{}, error) { +func (this *ESManage) Search(page, pageSize int, params map[string]interface{}) (interface{}, error) { termParams := make(map[string]interface{}, 0) shouldParams := make(map[string]interface{}, 0) @@ -46,6 +46,11 @@ func (this *ESManage) Search(page, pageSize int) (interface{}, error) { if this.Research != "" { shouldParams["research"] = this.Research } + if len(params) > 0 { + for k, v := range params { + shouldParams[k] = v + } + } out, err := es.Search(this, this.Index(), &es.SearchParams{ TermParams: termParams, ShouldParams: shouldParams,