feat:完善项目管理,增加技术成果数据
This commit is contained in:
49
app/api/enterprise/model/technology_achievement.go
Normal file
49
app/api/enterprise/model/technology_achievement.go
Normal file
@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"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"`
|
||||
}
|
||||
|
||||
// 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 achievement_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d) AS v ON a.id = v.achievement_id",
|
||||
model.NewTechnologyAchievementVisit().TableName(), 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()}
|
||||
}
|
Reference in New Issue
Block a user