From a512713ba68de1650547490bd84c9ebbf740e47a Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 13 Dec 2021 11:22:19 +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=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/enterprise/model/manage_expert.go | 17 ++++++++++------- app/api/enterprise/model/manage_laboratory.go | 2 +- app/api/enterprise/model/technology_product.go | 4 ++-- .../model/technology_product_visit.go | 7 +++++-- app/common/model/manage_expert_collect.go | 18 ++++++++++++++++++ app/common/model/manage_expert_visit.go | 1 + app/common/model/manage_laboratory_visit.go | 1 + app/common/model/technology_prodcut_visit.go | 2 +- 8 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 app/common/model/manage_expert_collect.go diff --git a/app/api/enterprise/model/manage_expert.go b/app/api/enterprise/model/manage_expert.go index 1958457..e85c278 100644 --- a/app/api/enterprise/model/manage_expert.go +++ b/app/api/enterprise/model/manage_expert.go @@ -14,19 +14,22 @@ type ManageExpert struct { // ManageExpertInfo 专家信息 type ManageExpertInfo struct { model.Model - Name string `json:"name"` - Mobile string `json:"mobile"` - Industry string `json:"-"` - VisitCount int `json:"visit_count"` - SettledAt time.Time `json:"settled_at"` + Name string `json:"name"` + Mobile string `json:"mobile"` + Industry string `json:"-"` + VisitCount int `json:"visit_count"` + CollectCount int `json:"collect_count"` + SettledAt time.Time `json:"settled_at"` } // Experts 专家信息 func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) { db := orm.GetDB().Table(m.TableName()+" e"). Select("e.id", "e.name", "e.mobile", "e.industry", "v.count AS visit_count", "e.examine_at AS settled_at"). - Joins(fmt.Sprintf("LEFT JOIN %s AS v ON e.id = v.expert_id AND v.is_deleted = %d", - model.NewManageExpertVisit().TableName(), model.DeleteStatusForNot)) + Joins(fmt.Sprintf("LEFT JOIN (SELECT expert_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY expert_id) AS v ON e.id = v.expert_id", + model.NewManageExpertVisit().TableName(), model.DeleteStatusForNot)). + Joins(fmt.Sprintf("LEFT JOIN (SELECT expert_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY expert_id) AS c ON e.id = c.expert_id", + model.NewManageExpertCollect().TableName(), model.DeleteStatusForNot)) if len(where) > 0 { for _, v := range where { diff --git a/app/api/enterprise/model/manage_laboratory.go b/app/api/enterprise/model/manage_laboratory.go index fdf2c3a..1806f92 100644 --- a/app/api/enterprise/model/manage_laboratory.go +++ b/app/api/enterprise/model/manage_laboratory.go @@ -25,7 +25,7 @@ func (m *ManageLaboratory) Laboratory(page, pageSize int, count *int64, where .. db := orm.GetDB().Table(m.TableName()+" AS l"). Select("l.id", "l.name", "l.industry", "u.name AS username", "u.mobile", "v.count AS visit_count", "c.count AS collect_count"). Joins(fmt.Sprintf("LEFT JOIN %s AS u ON l.uid = u.uuid", model.NewUserInstance().TableName())). - Joins(fmt.Sprintf("LEFT JOIN %s AS v ON l.id = v.laboratory_id AND v.is_deleted = %d", + Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY laboratory_id) AS v ON l.id = v.laboratory_id", model.NewManageLaboratoryVisit().TableName(), model.DeleteStatusForNot)). Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY laboratory_id) AS c ON l.id = c.laboratory_id", model.NewManageLaboratoryCollect().TableName(), model.DeleteStatusForNot)) diff --git a/app/api/enterprise/model/technology_product.go b/app/api/enterprise/model/technology_product.go index a7a2bdd..4db547a 100644 --- a/app/api/enterprise/model/technology_product.go +++ b/app/api/enterprise/model/technology_product.go @@ -30,9 +30,9 @@ func (m *TechnologyProduct) Product(page, pageSize int, count *int64, where ...* db := orm.GetDB().Table(m.TableName()+" AS p"). Select("p.id", "p.title", "p.image", "p.maturity", "p.industry", "p.cooperation_mode", "p.keyword", "v.count AS v visit_count", "c.count AS collect_count"). - Joins(fmt.Sprintf("(SELECT company_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY company_id) AS v ON p.id = v.company_id", + Joins(fmt.Sprintf("LEFT JOIN (SELECT product_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY product_id) AS v ON p.id = v.product_id", model.NewTechnologyProductVisit().TableName(), model.DeleteStatusForNot)). - Joins(fmt.Sprintf("(SELECT company_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY company_id) AS c ON p.id = c.company_id", + Joins(fmt.Sprintf("LEFT JOIN (SELECT product_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY product_id) AS c ON p.id = c.product_id", model.NewTechnologyProductCollect().TableName(), model.DeleteStatusForNot)) out := make([]*TechnologyProductInfo, 0) diff --git a/app/api/enterprise/model/technology_product_visit.go b/app/api/enterprise/model/technology_product_visit.go index 1966f9f..2531728 100644 --- a/app/api/enterprise/model/technology_product_visit.go +++ b/app/api/enterprise/model/technology_product_visit.go @@ -21,8 +21,11 @@ func (m *TechnologyProductVisit) Visit(page, pageSize int, count *int64, where . db := orm.GetDB().Table(m.TableName()+" AS v"). Select("v.id", "v.visit_at", "c.id AS company_id", "c.name AS company_name", "c.image AS company_image", "c.kind AS company_kind", "c.url AS company_url"). - Joins(fmt.Sprintf("LEFT JOIN %s AS c ON v.company_id = c.id", model.NewManageCompany().TableName())). - Where("v.is_deleted = ?", model.DeleteStatusForNot) + Joins(fmt.Sprintf("LEFT JOIN %s AS u_c ON v.uid = c.uid AND u_c.invalid_status = %d AND u_c.is_deleted = %d", + model.NewUserCompany().TableName(), model.InvalidStatusForNot, model.DeleteStatusForNot)). + Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u_c.company_id = c.id", model.NewManageCompany().TableName())). + Where("v.is_deleted = ?", model.DeleteStatusForNot). + Where("u_c.id > ?", 0) out := make([]*TechnologyProductVisitInfo, 0) diff --git a/app/common/model/manage_expert_collect.go b/app/common/model/manage_expert_collect.go new file mode 100644 index 0000000..e322507 --- /dev/null +++ b/app/common/model/manage_expert_collect.go @@ -0,0 +1,18 @@ +package model + +// ManageExpertCollect 专家收藏数据模型 +type ManageExpertCollect struct { + Model + UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` + ExpertID uint64 `gorm:"column:expert_id;type:int(11);default:0;comment:专家ID" json:"-"` + ModelDeleted + ModelAt +} + +func (m *ManageExpertCollect) TableName() string { + return "manage_expert_collect" +} + +func NewManageExpertCollect() *ManageExpertCollect { + return &ManageExpertCollect{} +} diff --git a/app/common/model/manage_expert_visit.go b/app/common/model/manage_expert_visit.go index 4095430..753951c 100644 --- a/app/common/model/manage_expert_visit.go +++ b/app/common/model/manage_expert_visit.go @@ -5,6 +5,7 @@ import "time" // ManageExpertVisit 专家浏览记录数据模型 type ManageExpertVisit struct { Model + UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` ExpertID uint64 `gorm:"column:expert_id;index:idx_expert_visit_expert;type:int(11);default:0;comment:专家ID" json:"-"` Count int `gorm:"column:count;type:int(8);default:0;comment:浏览次数" json:"count"` Date time.Time `gorm:"column:date;type:datetime;not null;comment:浏览时间" json:"date"` diff --git a/app/common/model/manage_laboratory_visit.go b/app/common/model/manage_laboratory_visit.go index db1d203..87abd60 100644 --- a/app/common/model/manage_laboratory_visit.go +++ b/app/common/model/manage_laboratory_visit.go @@ -5,6 +5,7 @@ import "time" // ManageLaboratoryVisit 实验室浏览记录数据模型 type ManageLaboratoryVisit struct { Model + UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` LaboratoryID uint64 `gorm:"column:laboratory_id;index:idx_laboratory_visit_laboratory;type:int(11);default:0;comment:实验室ID" json:"-"` Count int `gorm:"column:count;type:int(8);default:0;comment:浏览次数" json:"count"` Date time.Time `gorm:"column:date;type:datetime;not null;comment:浏览时间" json:"date"` diff --git a/app/common/model/technology_prodcut_visit.go b/app/common/model/technology_prodcut_visit.go index 5c6babd..e4725a9 100644 --- a/app/common/model/technology_prodcut_visit.go +++ b/app/common/model/technology_prodcut_visit.go @@ -5,8 +5,8 @@ import "time" // TechnologyProductVisit 技术产品访问数据模型 type TechnologyProductVisit struct { Model + UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` ProductID uint64 `gorm:"column:product_id;index:idx_product_visit_product;type:int(11);default:0;comment:科技产品ID" json:"product_id"` - CompanyID uint64 `gorm:"column:company_id;type:int(11);default:0;comment:公司ID" json:"company_id"` Count int `gorm:"column:count;type:int(8);default:0;comment:浏览次数" json:"count"` Date time.Time `gorm:"column:date;type:datetime;not null;comment:浏览时间" json:"date"` ModelDeleted