feat:完善项目信息

This commit is contained in:
henry
2022-01-04 15:37:00 +08:00
parent 40841a4a27
commit d2b182952c
8 changed files with 343 additions and 26 deletions

View File

@ -30,6 +30,41 @@ type TechnologyAchievementInstance struct {
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.TechnologyAchievementStatusForAgree).
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").