feat:优化项目信息,待测试修改
This commit is contained in:
@ -35,21 +35,19 @@ type ManageExpertInstanceInfo struct {
|
||||
Introduce string `json:"introduce"`
|
||||
}
|
||||
|
||||
// Expert 专家信息
|
||||
// Instance 专家信息
|
||||
func (m *ManageExpert) Instance(limit int, where ...*model.ModelWhere) ([]*ManageExpertInstanceInfo, error) {
|
||||
// 专利信息
|
||||
mSysPatent := model.NewSysPatent()
|
||||
// 用户专利信息
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
|
||||
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)).
|
||||
Joins(fmt.Sprintf(`LEFT JOIN (SELECT uid, SUBSTRING_INDEX(GROUP_CONCAT(title ORDER BY id DESC SEPARATOR '&&'), '&&', %d) AS title
|
||||
FROM %s WHERE is_deleted = %d AND shelf_status = %d) AS p ON e_u.uid = p.uid`,
|
||||
limit, mTechnologyPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
|
||||
Where("e.examine_status = ?", model.ExamineStatusForAgree).
|
||||
Where("e.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
@ -69,18 +67,16 @@ FROM %s AS u LEFT JOIN %s AS p ON u.parent_id = p.id WHERE u.is_deleted = %d AND
|
||||
// Detail 专家信息
|
||||
func (m *ManageExpert) Detail(limit int, id uint64) (*ManageExpertInstanceInfo, error) {
|
||||
// 专利信息
|
||||
mSysPatent := model.NewSysPatent()
|
||||
// 用户专利信息
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
|
||||
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)).
|
||||
Joins(fmt.Sprintf(`LEFT JOIN (SELECT uid, SUBSTRING_INDEX(GROUP_CONCAT(title ORDER BY id DESC SEPARATOR '&&'), '&&', %d) AS title
|
||||
FROM %s WHERE is_deleted = %d AND shelf_status = %d) AS p ON e_u.uid = p.uid`,
|
||||
limit, mTechnologyPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
|
||||
Where("e.id = ?", id)
|
||||
|
||||
out := new(ManageExpertInstanceInfo)
|
||||
|
@ -6,12 +6,12 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// SysPatent 专利信息
|
||||
type SysPatent struct {
|
||||
*model.SysPatent
|
||||
// TechnologyPatent 专利信息
|
||||
type TechnologyPatent struct {
|
||||
*model.TechnologyPatent
|
||||
}
|
||||
|
||||
type SysPatentInfo struct {
|
||||
type TechnologyPatentInfo struct {
|
||||
model.Model
|
||||
Kind model.SysParentKind `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
@ -19,12 +19,18 @@ type SysPatentInfo struct {
|
||||
ApplyAt string `json:"apply_at"`
|
||||
}
|
||||
|
||||
type TechnologyPatentBasicInfo struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
}
|
||||
|
||||
// Instance 专利信息
|
||||
func (m *SysPatent) Instance(where ...*model.ModelWhere) ([]*SysPatentInfo, error) {
|
||||
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.NewSysPatentClassify().TableName(), model.DeleteStatusForNot)).
|
||||
model.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
|
||||
Where("p.shelf_status = ?", model.ShelfStatusForUp).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
@ -33,7 +39,7 @@ func (m *SysPatent) Instance(where ...*model.ModelWhere) ([]*SysPatentInfo, erro
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysPatentInfo, 0)
|
||||
out := make([]*TechnologyPatentInfo, 0)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
@ -41,7 +47,7 @@ func (m *SysPatent) Instance(where ...*model.ModelWhere) ([]*SysPatentInfo, erro
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
|
||||
func (m *TechnologyPatent) IsExistParams(params map[string]interface{}) (bool, error) {
|
||||
var count int64
|
||||
db := orm.GetDB().Table(m.TableName())
|
||||
|
||||
@ -54,6 +60,6 @@ func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
func NewSysPatent() *SysPatent {
|
||||
return &SysPatent{model.NewSysPatent()}
|
||||
func NewTechnologyPatent() *TechnologyPatent {
|
||||
return &TechnologyPatent{model.NewTechnologyPatent()}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
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").
|
||||
Select("u.id", "p.title", "p.apply_code", "p.apply_name", "p.apply_at", "shelf", "status", "u.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u.patent_id = p.id", model.NewSysPatent().TableName())).
|
||||
Where("u.is_deleted = ? AND p.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*model.SysPatent, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u.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()}
|
||||
}
|
Reference in New Issue
Block a user