2021-12-22 17:16:13 +08:00
|
|
|
|
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"`
|
|
|
|
|
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
|
|
|
|
|
|
2022-01-18 16:29:29 +08:00
|
|
|
|
out, err := mTechnologyAchievement.Achievements(page, pageSize, &count, where...)
|
2021-12-22 17:16:13 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
list := make([]*AchievementInfo, 0)
|
|
|
|
|
|
|
|
|
|
for _, v := range out {
|
|
|
|
|
list = append(list, &AchievementInfo{
|
|
|
|
|
ID: v.GetEncodeID(),
|
|
|
|
|
Title: v.Title,
|
2022-01-17 09:57:57 +08:00
|
|
|
|
Image: v.Image.Analysis(config.SystemConfig[config.SysImageDomain]),
|
2021-12-22 17:16:13 +08:00
|
|
|
|
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("操作错误,成果信息不存在或已被删除")
|
|
|
|
|
}
|
2021-12-27 11:48:44 +08:00
|
|
|
|
//var uid uint64 = 0
|
2021-12-22 17:16:13 +08:00
|
|
|
|
|
|
|
|
|
if c.Enterprise != nil {
|
2021-12-27 11:48:44 +08:00
|
|
|
|
//uid = c.UID
|
2021-12-22 17:16:13 +08:00
|
|
|
|
}
|
2021-12-27 11:48:44 +08:00
|
|
|
|
// 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)})
|
2021-12-22 17:16:13 +08:00
|
|
|
|
|
|
|
|
|
return &AchievementDetailInfo{
|
|
|
|
|
AchievementInfo: AchievementInfo{
|
|
|
|
|
ID: out.GetEncodeID(),
|
|
|
|
|
Title: out.Title,
|
2022-01-17 09:57:57 +08:00
|
|
|
|
Image: out.Image.Analysis(config.SystemConfig[config.SysImageDomain]),
|
2021-12-22 17:16:13 +08:00
|
|
|
|
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}
|
|
|
|
|
}
|
|
|
|
|
}
|