feat:优化项目信息

This commit is contained in:
henry
2022-02-09 18:38:32 +08:00
parent 56e8243724
commit 957a4436a8
12 changed files with 134 additions and 119 deletions

View File

@ -26,11 +26,9 @@ func (m *ManageExpert) Expert(limit int, where ...*model.ModelWhere) ([]*ManageE
db := orm.GetDB().Table(m.TableName()+" AS e").
Select("e.id", "e.name", "e.industry", "e.image", "e.school", "e.major", "e.keyword",
"p.title AS patent_title", "r.name AS research_name").
Joins(fmt.Sprintf("LEFT JOIN %s AS e_u ON e.id = e_u.expert_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 uid, SUBSTRING_INDEX(GROUP_CONCAT(kind, '$$', title ORDER BY id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s WHERE is_deleted = %d AND shelf_status = %d GROUP BY uid) AS p ON e_u.uid = p.uid`,
limit, mTechnologyPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
Joins(fmt.Sprintf(`LEFT JOIN (SELECT u.expert_id, SUBSTRING_INDEX(GROUP_CONCAT(p.kind, '$$', p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s AS u LEFT JOIN %s AS p ON u.patent_id = p.id WHERE u.is_deleted = %d GROUP BY u.expert_id) AS p ON e.id = p.expert_id`,
limit, model.NewTechnologyPatentExpert().TableName(), mTechnologyPatent.TableName(), model.DeleteStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
Where("e.examine_status = ?", model.ExamineStatusForAgree).
Where("e.is_deleted = ?", model.DeleteStatusForNot)
@ -56,11 +54,9 @@ func (m *ManageExpert) Detail(limit int, id uint64) (*ManageExpertInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS e").
Select("e.id", "e.name", "e.industry", "e.image", "e.school", "e.major", "e.keyword", "e.research",
"e.introduce", "p.title AS patent_title", "r.name AS research_name").
Joins(fmt.Sprintf("LEFT JOIN %s AS e_u ON e.id = e_u.expert_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.kind, '$$', p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s AS u LEFT JOIN %s AS p ON u.patent_id = p.id WHERE u.is_deleted = %d GROUP BY u.uid) AS p ON e_u.uid = p.uid`,
limit, model.NewUserPatent().TableName(), mTechnologyPatent.TableName(), model.DeleteStatusForNot)).
Joins(fmt.Sprintf(`LEFT JOIN (SELECT u.expert_id, SUBSTRING_INDEX(GROUP_CONCAT(p.kind, '$$', p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s AS u LEFT JOIN %s AS p ON u.patent_id = p.id WHERE u.is_deleted = %d GROUP BY u.expert_id) AS p ON e.id = p.expert_id`,
limit, model.NewTechnologyPatentExpert().TableName(), mTechnologyPatent.TableName(), model.DeleteStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
Where("e.id = ?", id)

View File

@ -7,11 +7,11 @@ import (
"strings"
)
type UserPatent struct {
*model.UserPatent
type TechnologyPatentExpert struct {
*model.TechnologyPatentExpert
}
type UserPatentInfo struct {
type TechnologyPatentExpertInfo struct {
model.Model
Title string `json:"title"`
ApplyAt string `json:"apply_at"`
@ -19,7 +19,7 @@ type UserPatentInfo struct {
}
// Patents 专利信息
func (m *UserPatent) Patents(uid []uint64, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserPatentInfo, error) {
func (m *TechnologyPatentExpert) Patents(uid []uint64, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyPatentExpertInfo, error) {
_uids := make([]string, 0)
for _, u := range uid {
@ -36,7 +36,7 @@ func (m *UserPatent) Patents(uid []uint64, page, pageSize int, count *int64, whe
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*UserPatentInfo, 0)
out := make([]*TechnologyPatentExpertInfo, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
@ -47,6 +47,6 @@ func (m *UserPatent) Patents(uid []uint64, page, pageSize int, count *int64, whe
return out, nil
}
func NewUserPatent() *UserPatent {
return &UserPatent{model.NewUserPatent()}
func NewTechnologyPatentExpert() *TechnologyPatentExpert {
return &TechnologyPatentExpert{model.NewTechnologyPatentExpert()}
}