127 lines
3.9 KiB
Go
127 lines
3.9 KiB
Go
![]() |
package technology
|
||
|
|
||
|
import (
|
||
|
"SciencesServer/app/api/website/model"
|
||
|
config2 "SciencesServer/app/basic/config"
|
||
|
"SciencesServer/app/basic/controller"
|
||
|
model2 "SciencesServer/app/common/model"
|
||
|
"SciencesServer/app/session"
|
||
|
"SciencesServer/config"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"gorm.io/gorm"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// Achievement 技术成果
|
||
|
type Achievement struct {
|
||
|
*session.Enterprise
|
||
|
}
|
||
|
|
||
|
type AchievementHandle func(session *session.Enterprise) *Achievement
|
||
|
|
||
|
type (
|
||
|
// AchievementInfo 技术成果信息
|
||
|
AchievementInfo struct {
|
||
|
ID string `json:"id"`
|
||
|
Title string `json:"title"`
|
||
|
Image string `json:"image"`
|
||
|
Industrys []string `json:"industrys"`
|
||
|
Customers []string `json:"customers"`
|
||
|
Maturity config2.TechnologyMaturity `json:"maturity"`
|
||
|
CooperationMode config2.TechnologyCooperationMode `json:"cooperation_mode"`
|
||
|
Keywords []string `json:"keywords"`
|
||
|
VisitCount int `json:"visit_count"`
|
||
|
CollectCount int `json:"collect_count"`
|
||
|
}
|
||
|
// AchievementDetailInfo 技术成果详细信息
|
||
|
AchievementDetailInfo struct {
|
||
|
AchievementInfo
|
||
|
Introduce string `json:"introduce"`
|
||
|
}
|
||
|
)
|
||
|
|
||
|
// Instance 基本信息
|
||
|
func (c *Achievement) Instance(title, industry string, page, pageSize int) (*controller.ReturnPages, error) {
|
||
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
||
|
|
||
|
where := make([]*model2.ModelWhere, 0)
|
||
|
|
||
|
if title != "" {
|
||
|
where = append(where, model2.NewWhere("title", title))
|
||
|
}
|
||
|
if industry != "" {
|
||
|
where = append(where, model2.NewWhereCondition("industry", "LIKE",
|
||
|
"%"+fmt.Sprintf(`"%v`, industry)+"%"))
|
||
|
}
|
||
|
var count int64
|
||
|
|
||
|
out, err := mTechnologyAchievement.Achievement(page, pageSize, &count, where...)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
list := make([]*AchievementInfo, 0)
|
||
|
|
||
|
for _, v := range out {
|
||
|
list = append(list, &AchievementInfo{
|
||
|
ID: v.GetEncodeID(),
|
||
|
Title: v.Title,
|
||
|
Image: v.Image.Analysis(config.SettingInfo.Domain),
|
||
|
Industrys: v.GetIndustryAttribute(),
|
||
|
Customers: v.GetCustomerAttribute(),
|
||
|
Maturity: v.Maturity,
|
||
|
CooperationMode: v.CooperationMode,
|
||
|
Keywords: v.GetKeywordAttribute(),
|
||
|
VisitCount: v.VisitCount,
|
||
|
CollectCount: v.CollectCount,
|
||
|
})
|
||
|
}
|
||
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||
|
}
|
||
|
|
||
|
// Detail 详细信息
|
||
|
func (c *Achievement) Detail(id uint64) (*AchievementDetailInfo, error) {
|
||
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
||
|
|
||
|
out, err := mTechnologyAchievement.Detail(id)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if out.ID <= 0 {
|
||
|
return nil, errors.New("操作错误,成果信息不存在或已被删除")
|
||
|
}
|
||
|
var uid uint64 = 0
|
||
|
|
||
|
if c.Enterprise != nil {
|
||
|
uid = c.UID
|
||
|
}
|
||
|
mTechnologyAchievementCollect := model.NewTechnologyAchievementCollect()
|
||
|
|
||
|
_ = model2.UpdatesWhere(mTechnologyAchievementCollect.TechnologyAchievementCollect, map[string]interface{}{
|
||
|
"count": gorm.Expr("count + ?", 1), "updated_at": time.Now(),
|
||
|
}, []*model2.ModelWhere{model2.NewWhere("uid", uid), model2.NewWhere("achievement_id", id)})
|
||
|
|
||
|
return &AchievementDetailInfo{
|
||
|
AchievementInfo: AchievementInfo{
|
||
|
ID: out.GetEncodeID(),
|
||
|
Title: out.Title,
|
||
|
Image: out.Image.Analysis(config.SettingInfo.Domain),
|
||
|
Industrys: out.GetIndustryAttribute(),
|
||
|
Customers: out.GetCustomerAttribute(),
|
||
|
Maturity: out.Maturity,
|
||
|
CooperationMode: out.CooperationMode,
|
||
|
Keywords: out.GetKeywordAttribute(),
|
||
|
VisitCount: out.VisitCount,
|
||
|
CollectCount: out.CollectCount,
|
||
|
},
|
||
|
Introduce: out.Introduce,
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
|
func NewAchievement() AchievementHandle {
|
||
|
return func(session *session.Enterprise) *Achievement {
|
||
|
return &Achievement{session}
|
||
|
}
|
||
|
}
|