137 lines
4.7 KiB
Go
137 lines
4.7 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"
|
||
)
|
||
|
||
// 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"`
|
||
ModeTitle string `json:"mode_title"`
|
||
Image string `json:"image"`
|
||
Industrys []string `json:"industrys"`
|
||
Customers []string `json:"customers"`
|
||
Maturity config2.TechnologyMaturity `json:"maturity"`
|
||
MaturityTitle string `json:"maturity_title"`
|
||
CooperationMode config2.TechnologyCooperationMode `json:"cooperation_mode"`
|
||
CooperationModeTitle string `json:"cooperation_mode_title"`
|
||
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.Achievements(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,
|
||
ModeTitle: v.GetModeTitle(),
|
||
Image: v.Image.Analysis(config.SystemConfig[config.SysImageDomain]),
|
||
Industrys: v.GetIndustryAttribute(),
|
||
Customers: v.GetCustomerAttribute(),
|
||
Maturity: v.Maturity,
|
||
MaturityTitle: config2.GetTechnologyMaturityTitle(v.Maturity),
|
||
CooperationMode: v.CooperationMode,
|
||
CooperationModeTitle: config2.GetTechnologyCooperationModeTitle(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 == nil || out.ID <= 0 {
|
||
return nil, errors.New("操作错误,成果信息不存在或已被删除")
|
||
}
|
||
//var uid uint64 = 0
|
||
|
||
if c.Enterprise != nil {
|
||
//uid = c.UID
|
||
}
|
||
// TODO:缺少错误
|
||
//mUserCollect := model.NewUserCollect()
|
||
//
|
||
//_ = model2.UpdatesWhere(mUserCollect.UserCollect, map[string]interface{}{
|
||
// "count": gorm.Expr("count + ?", 1), "updated_at": time.Now(),
|
||
//}, []*model2.ModelWhere{model2.NewWhere("uid", uid),
|
||
// model2.NewWhere("kind", model2.UserCollectKindForTechnologyAchievement),
|
||
// model2.NewWhere("achievement_id", id)})
|
||
|
||
return &AchievementDetailInfo{
|
||
AchievementInfo: AchievementInfo{
|
||
ID: out.GetEncodeID(),
|
||
Title: out.Title,
|
||
ModeTitle: out.GetModeTitle(),
|
||
Image: out.Image.Analysis(config.SystemConfig[config.SysImageDomain]),
|
||
Industrys: out.GetIndustryAttribute(),
|
||
Customers: out.GetCustomerAttribute(),
|
||
Maturity: out.Maturity,
|
||
MaturityTitle: config2.GetTechnologyMaturityTitle(out.Maturity),
|
||
CooperationMode: out.CooperationMode,
|
||
CooperationModeTitle: config2.GetTechnologyCooperationModeTitle(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}
|
||
}
|
||
}
|