From d2b182952c842113d1e7b78834fcf7a6afc080d8 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 4 Jan 2022 15:37:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enterprise/controller/manage/common.go | 33 ++-- .../controller/manage/laboratory.go | 171 ++++++++++++++++++ .../enterprise/controller/technology/paper.go | 6 + .../controller/technology/patent.go | 5 + app/api/enterprise/model/manage_laboratory.go | 55 +++++- app/api/enterprise/model/sys_patent.go | 30 +++ .../model/technology_achievement.go | 35 ++++ app/api/enterprise/model/user_patent.go | 34 ++++ 8 files changed, 343 insertions(+), 26 deletions(-) diff --git a/app/api/enterprise/controller/manage/common.go b/app/api/enterprise/controller/manage/common.go index b89e357..f19e002 100644 --- a/app/api/enterprise/controller/manage/common.go +++ b/app/api/enterprise/controller/manage/common.go @@ -1,8 +1,8 @@ package manage import ( - "SciencesServer/app/api/website/controller/technology" - "SciencesServer/app/api/website/model" + "SciencesServer/app/api/enterprise/controller/technology" + "SciencesServer/app/api/enterprise/model" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" "errors" @@ -13,7 +13,7 @@ import ( type ( // AchievementInfo 成果信息 AchievementInfo struct { - *model.TechnologyAchievementInfo + *model.TechnologyAchievementsInfo ChargeInfo *model2.TechnologyAchievementChargeInfo `json:"charge_info"` } // ProjectInfo 项目信息 @@ -24,7 +24,7 @@ type ( // PatentInfo 专利信息 PatentInfo struct { ID string `json:"id"` - *model.PatentInfo + *model.PatentInstance } // PaperInfo 论文信息 PaperInfo struct { @@ -41,9 +41,9 @@ type ( } // CooperateDetailInfo 合作的企业详细信息 CooperateDetailInfo struct { - Title string `json:"title"` - Patent []*technology.PatentInfo `json:"patent"` - Paper []*technology.PaperInfo `json:"paper"` + Title string `json:"title"` + Patent []*technology.PatentInstance `json:"patent"` + Paper []*technology.PaperInstance `json:"paper"` } EquipmentInfo struct { ID string `json:"id"` @@ -57,7 +57,7 @@ func achievement(uids []uint64, page, pageSize int) (*controller.ReturnPages, er var count int64 - out, err := mTechnologyAchievement.Achievement(page, pageSize, &count, model2.NewWhereIn("uid", uids)) + out, err := mTechnologyAchievement.Achievements(page, pageSize, &count, model2.NewWhereIn("uid", uids)) if err != nil { return nil, err @@ -66,8 +66,8 @@ func achievement(uids []uint64, page, pageSize int) (*controller.ReturnPages, er for _, v := range out { list = append(list, &AchievementInfo{ - TechnologyAchievementInfo: v, - ChargeInfo: v.GetChargeInfoAttribute(), + TechnologyAchievementsInfo: v, + ChargeInfo: v.GetChargeInfoAttribute(), }) } return &controller.ReturnPages{Data: list, Count: count}, nil @@ -105,7 +105,7 @@ 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)) + out, err := mUserPatent.Instance(page, pageSize, &count, model2.NewWhereIn("u_p.uid", uids)) if err != nil { return nil, err @@ -114,8 +114,7 @@ func patent(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) for _, v := range out { list = append(list, &PatentInfo{ - ID: v.GetEncodeID(), - PatentInfo: v, + ID: v.GetEncodeID(), PatentInstance: v, }) } return &controller.ReturnPages{Data: list, Count: count}, nil @@ -190,8 +189,8 @@ func cooperateDetail(id uint64) (*CooperateDetailInfo, error) { } out := &CooperateDetailInfo{ Title: mUserCooperateEnterprise.Title, - Patent: make([]*technology.PatentInfo, 0), - Paper: make([]*technology.PaperInfo, 0), + Patent: make([]*technology.PatentInstance, 0), + Paper: make([]*technology.PaperInstance, 0), } // 专利信息 mSysPatent := model.NewSysPatent() @@ -202,7 +201,7 @@ func cooperateDetail(id uint64) (*CooperateDetailInfo, error) { return nil, err } for _, v := range patents { - out.Patent = append(out.Patent, &technology.PatentInfo{ + out.Patent = append(out.Patent, &technology.PatentInstance{ ID: v.GetEncodeID(), SysPatentInfo: v, }) @@ -220,7 +219,7 @@ func cooperateDetail(id uint64) (*CooperateDetailInfo, error) { return nil, err } for _, v := range papers { - out.Paper = append(out.Paper, &technology.PaperInfo{ + out.Paper = append(out.Paper, &technology.PaperInstance{ ID: v.GetEncodeID(), Title: v.Title, Ext: v.Ext, Keywords: v.GetKeywordAttribute(), }) } diff --git a/app/api/enterprise/controller/manage/laboratory.go b/app/api/enterprise/controller/manage/laboratory.go index 9baac03..957b0dd 100644 --- a/app/api/enterprise/controller/manage/laboratory.go +++ b/app/api/enterprise/controller/manage/laboratory.go @@ -1,8 +1,13 @@ 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" + "strings" ) type Laboratory struct { @@ -12,6 +17,29 @@ type Laboratory struct { type LaboratoryHandle func(session *session.Enterprise, local string) *Laboratory +type ( + // LaboratoryMatchInfo 实验室匹配信息 + LaboratoryMatchInfo struct { + ID string `json:"id"` + *model.ManageLaboratoryInstance + Industrys []string `json:"industrys"` + Keywords []string `json:"keywords"` + Researchs []string `json:"researchs"` + } +) + +// expert 所有专家信息 +func (c *Laboratory) expert(id uint64) ([]uint64, error) { + mManageExpert := model.NewManageExpert() + + uids := make([]uint64, 0) + + err := model2.Pluck(mManageExpert.ManageExpert, "uid", &uids, model2.NewWhere("laboratory_id", id), + model2.NewWhere("examine_status", model2.ExamineStatusForAgree)) + + return uids, err +} + func (c *Laboratory) Instance() (*controller.ReturnPages, error) { //mManageLaboratory := model.NewManageLaboratory() @@ -22,6 +50,149 @@ func (c *Laboratory) Instance() (*controller.ReturnPages, error) { return nil, nil } +// Match 匹配信息 +func (c *Laboratory) Match(title string, industrys, keywords []string) ([]*LaboratoryMatchInfo, error) { + params := strings.Join([]string{ + title, strings.Join(industrys, ","), strings.Join(keywords, ","), + }, ",") + manage := service.NewESManage( + service.WithManageIdentity(config.TenantUserIdentityForLaboratory), + ) + 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) + } + mManageLaboratory := model.NewManageLaboratory() + + laboratorys := make([]*model.ManageLaboratoryInstance, 0) + + if laboratorys, err = mManageLaboratory.Instance(model2.NewWhereIn("l.id", ids)); err != nil { + return nil, err + } + list := make([]*LaboratoryMatchInfo, 0) + + for _, v := range laboratorys { + list = append(list, &LaboratoryMatchInfo{ + ID: v.GetEncodeID(), + ManageLaboratoryInstance: v, + Industrys: v.GetIndustryAttribute(), + Keywords: v.GetKeywordAttribute(), + Researchs: v.GetResearchAttribute(), + }) + } + return list, nil +} + +// Instance 实验室信息 +func (c *Laboratory) Detail(id uint64) (*LaboratoryMatchInfo, error) { + mManageLaboratory := model.NewManageLaboratory() + out, err := mManageLaboratory.Instance(model2.NewWhere("l.id", id)) + + if err != nil { + return nil, err + } + if len(out) <= 0 { + return nil, nil + } + _out := out[0] + + return &LaboratoryMatchInfo{ + ID: _out.GetEncodeID(), + ManageLaboratoryInstance: &model.ManageLaboratoryInstance{ + ManageLaboratory: _out.ManageLaboratory, + ResearchName: _out.ResearchName, + ExpertCount: _out.ExpertCount, + CollectCount: _out.CollectCount, + VisitCount: _out.VisitCount, + }, + Industrys: _out.GetIndustryAttribute(), + Keywords: _out.GetKeywordAttribute(), + Researchs: _out.GetResearchAttribute(), + }, nil +} + +// Achievement 成果信息 +func (c *Laboratory) Achievement(id uint64, page, pageSize int) (*controller.ReturnPages, error) { + uids, err := c.expert(id) + + if err != nil { + return nil, err + } + return achievement(uids, page, pageSize) +} + +// Project 项目信息 +func (c *Laboratory) Project(id uint64, page, pageSize int) (*controller.ReturnPages, error) { + // 查询专家身份下用户信息 + uids, err := c.expert(id) + + if err != nil { + return nil, err + } + + return project(uids, page, pageSize) +} + +// Patent 专利信息 +func (c *Laboratory) Patent(id uint64, page, pageSize int) (*controller.ReturnPages, error) { + // 查询专家身份下用户信息 + uids, err := c.expert(id) + + if err != nil { + return nil, err + } + + return paper(uids, page, pageSize) +} + +// Paper 论文信息 +func (c *Laboratory) Paper(id uint64, page, pageSize int) (*controller.ReturnPages, error) { + // 查询专家身份下用户信息 + uids, err := c.expert(id) + + if err != nil { + return nil, err + } + + return paper(uids, page, pageSize) +} + +// Cooperate 企业信息 +func (c *Laboratory) Cooperate(id uint64, page, pageSize int) (*controller.ReturnPages, error) { + // 查询专家身份下用户信息 + uids, err := c.expert(id) + + if err != nil { + return nil, err + } + + return cooperate(uids, page, pageSize) +} + +// CooperateDetail 公司企业详细信息 +func (c *Laboratory) CooperateDetail(id uint64) (*CooperateDetailInfo, error) { + return cooperateDetail(id) +} + +// Equipment 设备信息 +func (c *Laboratory) Equipment(id uint64, page, pageSize int) (*controller.ReturnPages, error) { + // 查询专家身份下用户信息 + uids, err := c.expert(id) + + if err != nil { + return nil, err + } + return equipment(model2.ManageEquipmentKindForExperiment, uids, page, pageSize) +} + func NewLaboratory() LaboratoryHandle { return func(session *session.Enterprise, local string) *Laboratory { return &Laboratory{ diff --git a/app/api/enterprise/controller/technology/paper.go b/app/api/enterprise/controller/technology/paper.go index 7f6ca9a..8cb3ff2 100644 --- a/app/api/enterprise/controller/technology/paper.go +++ b/app/api/enterprise/controller/technology/paper.go @@ -24,6 +24,12 @@ type ( *model2.TechnologyPaper Tags []string `json:"tags"` } + PaperInstance struct { + ID string `json:"id"` + Title string `json:"title"` + Ext string `json:"ext"` + Keywords []string `json:"keywords"` + } PaperParams struct { ID uint64 Title, Ext, Author, PublishAt, Remark string diff --git a/app/api/enterprise/controller/technology/patent.go b/app/api/enterprise/controller/technology/patent.go index 50bece3..cb133c3 100644 --- a/app/api/enterprise/controller/technology/patent.go +++ b/app/api/enterprise/controller/technology/patent.go @@ -37,6 +37,11 @@ type ( Description string `json:"description"` ApplyAt string `json:"apply_at"` } + // PatentInstance 专利信息 + PatentInstance struct { + ID string `json:"id"` + *model.SysPatentInfo + } // PatentDetailInfo 专利详细信息 PatentDetailInfo struct { ID string `json:"id"` diff --git a/app/api/enterprise/model/manage_laboratory.go b/app/api/enterprise/model/manage_laboratory.go index a6d0859..c1506df 100644 --- a/app/api/enterprise/model/manage_laboratory.go +++ b/app/api/enterprise/model/manage_laboratory.go @@ -11,15 +11,52 @@ type ManageLaboratory struct { *model.ManageLaboratory } -type ManageLaboratoryInfo struct { - model.Model - Name string `json:"name"` - Industry string `json:"-"` - Username string `json:"username"` - Mobile string `json:"mobile"` - VisitCount int `json:"visit_count"` - CollectCount int `json:"collect_count"` - SettledAt time.Time `json:"settled_at"` +type ( + ManageLaboratoryInfo struct { + model.Model + Name string `json:"name"` + Industry string `json:"-"` + Username string `json:"username"` + Mobile string `json:"mobile"` + VisitCount int `json:"visit_count"` + CollectCount int `json:"collect_count"` + SettledAt time.Time `json:"settled_at"` + } + // ManageLaboratoryInstance 实验室信息 + ManageLaboratoryInstance struct { + *model.ManageLaboratory + ResearchName string `json:"research_name"` + ExpertCount int `json:"expert_count"` + CollectCount int `json:"collect_count"` + VisitCount int `json:"visit_count"` + } +) + +// Instance 实验室信息 +func (m *ManageLaboratory) Instance(where ...*model.ModelWhere) ([]*ManageLaboratoryInstance, error) { + db := orm.GetDB().Table(m.TableName()+" AS l"). + Select("l.id", "l.image", "l.url", "l.industry", "l.keyword", "l.contact", "l.contact_mobile", "l.research", + "e.name AS research_name", "e.count AS expert_count", "c.count AS collect_count", "v.count AS visit_count"). + Joins(fmt.Sprintf("LEFT JOIN %s AS e ON l.research_id = e.id", model.NewManageResearch().TableName())). + Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(laboratory_id) AS count FROM %s WHERE examine_status = %d AND is_deleted = %d GROUP BY laboratory_id) AS e ON l.id = e.laboratory_id", + model.NewManageExpert().TableName(), model.ExamineStatusForAgree, model.DeleteStatusForNot)). + Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON l.id = c.object_id", + model.NewUserCollect().TableName(), model.UserCollectKindForLaboratory, model.DeleteStatusForNot)). + Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON l.id = v.object_id", + model.NewUserVisit().TableName(), model.UserVisitKindForLaboratory, model.DeleteStatusForNot)). + Where("l.examine_status = ?", model.ExamineStatusForAgree). + Where("l.is_deleted = ?", model.DeleteStatusForNot) + + if len(where) > 0 { + for _, wo := range where { + db = db.Where(wo.Condition, wo.Value) + } + } + out := make([]*ManageLaboratoryInstance, 0) + + err := db.Scan(&out).Error + + return out, err } // Laboratory 实验室信息 diff --git a/app/api/enterprise/model/sys_patent.go b/app/api/enterprise/model/sys_patent.go index 4e20551..49264d5 100644 --- a/app/api/enterprise/model/sys_patent.go +++ b/app/api/enterprise/model/sys_patent.go @@ -11,6 +11,36 @@ type SysPatent struct { *model.SysPatent } +type SysPatentInfo struct { + model.Model + Kind model.SysParentKind `json:"kind"` + Title string `json:"title"` + Description string `json:"description"` + ApplyAt string `json:"apply_at"` +} + +// Instance 专利信息 +func (m *SysPatent) Instance(where ...*model.ModelWhere) ([]*SysPatentInfo, error) { + db := orm.GetDB().Table(m.TableName()+" AS p"). + Select("p.id", "p.title", "LEFT(p.description, 80) AS description", "p.apply_at"). + Joins(fmt.Sprintf("LEFT JOIN %s AS c ON p.ipc_code = c.ipc AND c.is_deleted = %d", + model.NewSysPatentClassify().TableName(), model.DeleteStatusForNot)). + Where("p.shelf_status = ?", model.ShelfStatusForUp). + Where("p.is_deleted = ?", model.DeleteStatusForNot) + + if len(where) > 0 { + for _, v := range where { + db = db.Where(v.Condition, v.Value) + } + } + out := make([]*SysPatentInfo, 0) + + if err := db.Scan(&out).Error; err != nil { + return nil, err + } + return out, nil +} + func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) { var count int64 db := orm.GetDB().Table(m.TableName()) diff --git a/app/api/enterprise/model/technology_achievement.go b/app/api/enterprise/model/technology_achievement.go index b05dda4..b2f039a 100644 --- a/app/api/enterprise/model/technology_achievement.go +++ b/app/api/enterprise/model/technology_achievement.go @@ -30,6 +30,41 @@ type TechnologyAchievementInstance struct { CollectCount int `json:"collect_count"` } +// TechnologyAchievementsInfo 技术成果信息 +type TechnologyAchievementsInfo struct { + *model.TechnologyAchievement + VisitCount int `json:"visit_count"` + CollectCount int `json:"collect_count"` +} + +// Achievements 成果信息 +func (m *TechnologyAchievement) Achievements(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementsInfo, error) { + db := orm.GetDB().Table(m.TableName()+" AS a"). + Select("a.id", "a.title", "a.mode", "a.image", "a.charge_info", "a.industry", "a.customer", "a.maturity", + "a.cooperation_mode", "a.keyword", "v.count AS visit_count", "c.count AS collect_count"). + Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON a.id = v.object_id", + model.NewUserVisit().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)). + Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON a.id = c.object_id", + model.NewUserCollect().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)). + Where("a.status = ?", model.TechnologyAchievementStatusForAgree). + Where("a.is_deleted = ?", model.DeleteStatusForNot) + + if len(where) > 0 { + for _, v := range where { + db = db.Where(v.Condition, v.Value) + } + } + out := make([]*TechnologyAchievementsInfo, 0) + + if err := db.Count(count).Error; err != nil { + return nil, err + } + if err := db.Order("a.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil { + return nil, err + } + return out, nil +} + // Instance 成果信息 func (m *TechnologyAchievement) Instance(where ...*model.ModelWhere) ([]*TechnologyAchievementInstance, error) { db := orm.GetDB().Table(m.TableName()+" AS a"). diff --git a/app/api/enterprise/model/user_patent.go b/app/api/enterprise/model/user_patent.go index 4140ccb..e8b6482 100644 --- a/app/api/enterprise/model/user_patent.go +++ b/app/api/enterprise/model/user_patent.go @@ -10,6 +10,40 @@ type UserPatent struct { *model.UserPatent } +type ( + // PatentInstance 专利信息 + PatentInstance struct { + model.Model + Title string `json:"title"` + ApplyAt string `json:"apply_at"` + } +) + +// Patent 专利信息 +func (m *UserPatent) Instance(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*PatentInstance, error) { + db := orm.GetDB().Table(m.TableName()+" AS u_p"). + Select("p.id", "p.title", "p.apply_at", "p.description"). + Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u_p.patent_id = p.id", + model.NewSysPatent().TableName())). + Where("u_p.is_deleted = ?", model.DeleteStatusForNot). + Where("p.shelf_status = ?", model.ShelfStatusForUp) + + if len(where) > 0 { + for _, wo := range where { + db = db.Where(wo.Condition, wo.Value) + } + } + out := make([]*PatentInstance, 0) + + if err := db.Count(count).Error; err != nil { + return nil, err + } + if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil { + return nil, err + } + return out, nil +} + // Patents 专利信息 func (m *UserPatent) Patents(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*model.SysPatent, error) { db := orm.GetDB().Table(m.TableName()+" AS u").