100 lines
3.4 KiB
Go
100 lines
3.4 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
)
|
|
|
|
type TechnologyPatent struct {
|
|
*model.TechnologyPatent
|
|
}
|
|
|
|
type TechnologyPatentInfo struct {
|
|
model.Model
|
|
Kind model.SysParentKind `json:"kind"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
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 {
|
|
for _, v := range where {
|
|
db = db.Where(v.Condition, v.Value)
|
|
}
|
|
}
|
|
out := make([]*TechnologyPatentInfo, 0)
|
|
|
|
if err := db.Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Patents 专利信息
|
|
func (m *TechnologyPatent) Patents(page, pageSize int, count *int64, 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 {
|
|
for _, v := range where {
|
|
db = db.Where(v.Condition, v.Value)
|
|
}
|
|
}
|
|
out := make([]*TechnologyPatentInfo, 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
|
|
}
|
|
|
|
// Distribution 分布信息
|
|
func (m *TechnologyPatent) Distribution() ([]*DataAreaDistributionInfo, error) {
|
|
out := make([]*DataAreaDistributionInfo, 0)
|
|
|
|
err := orm.GetDB().Table(m.TableName()+" AS p").
|
|
Select("e.province", "e.city", "e.district", "GROUP_CONCAT(p_c.industry_detail SEPARATOR '&') AS industry").
|
|
Joins(fmt.Sprintf("RIGHT JOIN %s AS p_c ON p.ipc_code = p_c.ipc AND p_c.is_deleted = %d",
|
|
model.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
|
|
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
|
|
return out, err
|
|
}
|
|
|
|
func NewTechnologyPatent() *TechnologyPatent {
|
|
return &TechnologyPatent{model.NewTechnologyPatent()}
|
|
}
|