feat:优化项目信息

This commit is contained in:
henry
2022-02-09 17:35:31 +08:00
parent 2d8be509b7
commit 56e8243724
15 changed files with 357 additions and 54 deletions

View File

@ -58,9 +58,9 @@ func (m *ManageExpert) Detail(limit int, id uint64) (*ManageExpertInfo, error) {
"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 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.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 %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
Where("e.id = ?", id)

View File

@ -18,23 +18,12 @@ type TechnologyPatentInfo struct {
ApplyAt string `json:"apply_at"`
}
type (
// TechnologyPatentBasicInfo 专利信息
TechnologyPatentBasicInfo struct {
model.Model
Title string `json:"title"`
Description string `json:"description"`
ApplyAt string `json:"apply_at"`
}
)
// Instance 专利信息
func (m *TechnologyPatent) Instance(where ...*model.ModelWhere) ([]*TechnologyPatentInfo, 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.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
Where("p.shelf_status = ?", model.ShelfStatusForUp).
Where("p.is_deleted = ?", model.DeleteStatusForNot)
if len(where) > 0 {
@ -56,7 +45,6 @@ func (m *TechnologyPatent) Patents(page, pageSize int, count *int64, where ...*m
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.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
Where("p.shelf_status = ?", model.ShelfStatusForUp).
Where("p.is_deleted = ?", model.DeleteStatusForNot)
if len(where) > 0 {
@ -87,7 +75,6 @@ func (m *TechnologyPatent) Distribution() ([]*DataAreaDistributionInfo, error) {
Joins(fmt.Sprintf("LEFT JOIN %s AS u_e ON p.uid = u_e.uid", model.NewUserExpert().TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON u_e.expert_id = e.id", model.NewManageExpert().TableName())).
Where("p.is_deleted = ?", model.DeleteStatusForNot).
Where("p.shelf_status = ?", model.ShelfStatusForUp).
Group("e.province").Group("e.city").Group("e.district").
Order("e.province " + model.OrderModeToAsc).Order("e.city " + model.OrderModeToAsc).Order("e.district " + model.OrderModeToAsc).
Scan(&out).Error

View File

@ -0,0 +1,52 @@
package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
"strings"
)
type UserPatent struct {
*model.UserPatent
}
type UserPatentInfo struct {
model.Model
Title string `json:"title"`
ApplyAt string `json:"apply_at"`
Description string `json:"description"`
}
// Patents 专利信息
func (m *UserPatent) Patents(uid []uint64, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserPatentInfo, error) {
_uids := make([]string, 0)
for _, u := range uid {
_uids = append(_uids, fmt.Sprintf("%d", u))
}
db := orm.GetDB().Table(model.NewTechnologyPatent().TableName()+" AS p").
Select("p.id", "p.title", "p.apply_at", "p.description").
Joins(fmt.Sprintf("RIGHT JOIN (SELECT patent_id FROM %s WHERE uid IN (%v) is_deleted = %d patent_id) AS u ON p.id = u.patent_id",
model.NewTechnologyPatent().TableName(), strings.Join(_uids, ","), model.DeleteStatusForNot)).
Where("u.is_deleted = ?", model.DeleteStatusForNot)
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*UserPatentInfo, 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
}
func NewUserPatent() *UserPatent {
return &UserPatent{model.NewUserPatent()}
}