feat:优化信息,增加技术成果搜索
This commit is contained in:
@ -60,3 +60,29 @@ func (*Technology) DemandDetail(c *gin.Context) {
|
||||
data, err := technology.NewDemand()(nil).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) Achievement(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
Industry string `json:"industry" form:"industry"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology.NewAchievement()(nil).Instance(form.Title, form.Industry, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) AchievementDetail(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology.NewAchievement()(nil).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
126
app/api/website/controller/technology/achievement.go
Normal file
126
app/api/website/controller/technology/achievement.go
Normal file
@ -0,0 +1,126 @@
|
||||
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}
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ type (
|
||||
|
||||
// Instance 查询信息
|
||||
func (c *Patent) Instance(title, industry string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
// TODO:缺少会员判断标准
|
||||
mSysPatent := model.NewSysPatent()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
@ -10,6 +10,59 @@ type TechnologyAchievement struct {
|
||||
*model.TechnologyAchievement
|
||||
}
|
||||
|
||||
// TechnologyAchievementInfo 技术成果信息
|
||||
type TechnologyAchievementInfo struct {
|
||||
*model.TechnologyAchievement
|
||||
VisitCount int `json:"visit_count"`
|
||||
CollectCount int `json:"collect_count"`
|
||||
}
|
||||
|
||||
// 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.mode", "a.image", "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 achievement_id, SUM(count) AS count FROM %s WHERE is_deleted = %d GROUP BY achievement_id) AS v ON a.id = v.achievement_id",
|
||||
model.NewTechnologyAchievementVisit().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT achievement_id, SUM(count) AS count FROM %s WHERE is_deleted = %d GROUP BY achievement_id) AS c ON a.id = c.achievement_id",
|
||||
model.NewTechnologyAchievementCollect().TableName(), 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([]*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
|
||||
}
|
||||
|
||||
// Detail 成果详细信息
|
||||
func (m *TechnologyAchievement) Detail(id uint64) (*TechnologyAchievementInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.*", "v.count AS visit_count", "c.count AS collect_count").
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT achievement_id, SUM(count) AS count FROM %s WHERE is_deleted = %d GROUP BY achievement_id) AS v ON a.id = v.achievement_id",
|
||||
model.NewTechnologyAchievementVisit().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT achievement_id, SUM(count) AS count FROM %s WHERE is_deleted = %d GROUP BY achievement_id) AS c ON a.id = c.achievement_id",
|
||||
model.NewTechnologyAchievementCollect().TableName(), model.DeleteStatusForNot)).
|
||||
Where("a.id = ?", id)
|
||||
|
||||
out := new(TechnologyAchievementInfo)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Distribution 分布信息
|
||||
func (m *TechnologyAchievement) Distribution() ([]*DataAreaDistributionInfo, error) {
|
||||
out := make([]*DataAreaDistributionInfo, 0)
|
||||
|
11
app/api/website/model/technology_achievement_collect.go
Normal file
11
app/api/website/model/technology_achievement_collect.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type TechnologyAchievementCollect struct {
|
||||
*model.TechnologyAchievementCollect
|
||||
}
|
||||
|
||||
func NewTechnologyAchievementCollect() *TechnologyAchievementCollect {
|
||||
return &TechnologyAchievementCollect{model.NewTechnologyAchievementCollect()}
|
||||
}
|
@ -14,7 +14,7 @@ type TechnologyAchievement struct {
|
||||
Title string `gorm:"column:title;type:varchar(100);default:'';comment:成果名称" json:"title"`
|
||||
Image
|
||||
File string `gorm:"column:file;type:varchar(255);default:'';comment:证明材料" json:"file"`
|
||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:所属领域;行业信息" json:"industry"`
|
||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:所属领域;行业信息" json:"-"`
|
||||
Customer string `gorm:"column:customer;type:varchar(255);default:'';comment:应用客户" json:"-"`
|
||||
Maturity config.TechnologyMaturity `gorm:"column:maturity;type:tinyint(1);default:0;comment:技术成熟度" json:"maturity"`
|
||||
LeadStandard TechnologyProductLeadStandard `gorm:"column:lead_standard;type:tinyint(1);default:0;comment:领先标准" json:"lead_standard"`
|
||||
|
18
app/common/model/technology_achievement_collect.go
Normal file
18
app/common/model/technology_achievement_collect.go
Normal file
@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
// TechnologyAchievementCollect 科技成果收藏数据模型
|
||||
type TechnologyAchievementCollect struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
AchievementID uint64 `gorm:"column:achievement_id;type:int(11);default:0;comment:科技成果ID" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *TechnologyAchievementCollect) TableName() string {
|
||||
return "technology_achievement_collect"
|
||||
}
|
||||
|
||||
func NewTechnologyAchievementCollect() *TechnologyAchievementCollect {
|
||||
return &TechnologyAchievementCollect{}
|
||||
}
|
@ -74,6 +74,8 @@ func registerAPI(app *gin.Engine) {
|
||||
technologyV1.POST("/patent/detail", _api.PatentDetail)
|
||||
technologyV1.POST("/demand", _api.Demand)
|
||||
technologyV1.POST("/demand/detail", _api.DemandDetail)
|
||||
technologyV1.POST("/achievement", _api.Achievement)
|
||||
technologyV1.POST("/achievement/detail", _api.AchievementDetail)
|
||||
}
|
||||
// About 关于我们管理
|
||||
aboutV1 := v1.Group("/about")
|
||||
|
Reference in New Issue
Block a user