119 lines
4.8 KiB
Go
119 lines
4.8 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/basic/config"
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type TechnologyAchievement struct {
|
|
*model.TechnologyAchievement
|
|
}
|
|
|
|
type TechnologyAchievementInfo struct {
|
|
model.Model
|
|
Title string `json:"title"`
|
|
Industry string `json:"-"`
|
|
VisitCount int `json:"visit_count"`
|
|
model.Shelf
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type TechnologyAchievementInstance struct {
|
|
TechnologyAchievementInfo
|
|
Customer string `json:"-"`
|
|
LeadStandard model.TechnologyProductLeadStandard `json:"lead_standard"`
|
|
CooperationMode config.TechnologyCooperationMode `json:"cooperation_mode"`
|
|
Keyword string `json:"-"`
|
|
CollectCount int `json:"collect_count"`
|
|
}
|
|
|
|
// TechnologyAchievementsInfo 技术成果信息
|
|
type TechnologyAchievementsInfo struct {
|
|
*model.TechnologyAchievement
|
|
VisitCount int `json:"visit_count"`
|
|
CollectCount int `json:"collect_count"`
|
|
}
|
|
|
|
// Achievements 成果信息
|
|
func (m *TechnologyAchievement) Achievements(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementsInfo, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS a").
|
|
Select("a.id", "a.title", "a.mode", "a.image", "a.charge_info", "a.industry", "a.customer", "a.maturity",
|
|
"a.cooperation_mode", "a.keyword", "v.count AS visit_count", "c.count AS collect_count").
|
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON a.id = v.object_id",
|
|
model.NewUserVisit().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)).
|
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON a.id = c.object_id",
|
|
model.NewUserCollect().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)).
|
|
Where("a.status = ?", model.TechnologyStatusKindForAgree).
|
|
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
if len(where) > 0 {
|
|
for _, v := range where {
|
|
db = db.Where(v.Condition, v.Value)
|
|
}
|
|
}
|
|
out := make([]*TechnologyAchievementsInfo, 0)
|
|
|
|
if err := db.Count(count).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Order("a.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Instance 成果信息
|
|
func (m *TechnologyAchievement) Instance(where ...*model.ModelWhere) ([]*TechnologyAchievementInstance, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS a").
|
|
Select("a.id", "a.title", "a.industry", "v.count AS visit_count", "c.count AS collect_count",
|
|
"a.customer", "a.lead_standard", "a.cooperation_mode", "a.keyword", "a.created_at").
|
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON a.id = v.object_id",
|
|
model.NewUserVisit().TableName(), model.UserVisitKindForTechnologyAchievement, model.DeleteStatusForNot)).
|
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON a.id = c.object_id",
|
|
model.NewUserCollect().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)).
|
|
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
if len(where) > 0 {
|
|
for _, wo := range where {
|
|
db = db.Where(wo.Condition, wo.Value)
|
|
}
|
|
}
|
|
out := make([]*TechnologyAchievementInstance, 0)
|
|
|
|
if err := db.Order("a.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Achievement 成果信息
|
|
func (m *TechnologyAchievement) Achievement(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS a").
|
|
Select("a.id", "a.title", "a.industry", "v.count AS visit_count", "a.shelf_status", "a.created_at").
|
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON a.id = v.object_id",
|
|
model.NewUserVisit().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)).
|
|
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
if len(where) > 0 {
|
|
for _, wo := range where {
|
|
db = db.Where(wo.Condition, wo.Value)
|
|
}
|
|
}
|
|
out := make([]*TechnologyAchievementInfo, 0)
|
|
|
|
if err := db.Count(count).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Order("a.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func NewTechnologyAchievement() *TechnologyAchievement {
|
|
return &TechnologyAchievement{model.NewTechnologyAchievement()}
|
|
}
|