2021-12-14 13:34:42 +08:00
|
|
|
package technology
|
|
|
|
|
|
|
|
import (
|
|
|
|
"SciencesServer/app/api/enterprise/model"
|
|
|
|
"SciencesServer/app/basic/config"
|
|
|
|
"SciencesServer/app/basic/controller"
|
|
|
|
model2 "SciencesServer/app/common/model"
|
2022-01-04 11:59:58 +08:00
|
|
|
"SciencesServer/app/service"
|
2021-12-14 13:34:42 +08:00
|
|
|
"SciencesServer/app/session"
|
|
|
|
"errors"
|
2022-01-04 11:59:58 +08:00
|
|
|
"strings"
|
2021-12-14 13:34:42 +08:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Achievement 成果信息
|
|
|
|
type Achievement struct {
|
|
|
|
*session.Enterprise
|
2022-01-15 16:48:49 +08:00
|
|
|
tenantID uint64
|
2021-12-14 13:34:42 +08:00
|
|
|
}
|
|
|
|
|
2022-01-15 16:48:49 +08:00
|
|
|
type AchievementHandle func(session *session.Enterprise, tenantID uint64) *Achievement
|
2021-12-14 13:34:42 +08:00
|
|
|
|
|
|
|
type (
|
|
|
|
// AchievementInfo 成果信息
|
|
|
|
AchievementInfo struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
*model.TechnologyAchievementInfo
|
|
|
|
Industrys []string `json:"industrys"`
|
|
|
|
}
|
2022-01-04 11:59:58 +08:00
|
|
|
// AchievementMatchInfo 成果匹配信息
|
|
|
|
AchievementMatchInfo struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
*model.TechnologyAchievementInstance
|
|
|
|
Industrys []string `json:"industrys"`
|
|
|
|
Keywords []string `json:"keywords"`
|
|
|
|
Customers []string `json:"customers"`
|
|
|
|
}
|
2021-12-14 13:34:42 +08:00
|
|
|
// AchievementDetail 成果详情
|
|
|
|
AchievementDetail struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
*model2.TechnologyAchievement
|
2022-05-02 14:37:37 +08:00
|
|
|
Customers []string `json:"customers"`
|
|
|
|
Keywords []string `json:"keywords"`
|
|
|
|
Config *model2.TechnologyAchievementConfig `json:"config"`
|
2021-12-14 13:34:42 +08:00
|
|
|
}
|
|
|
|
// AchievementParams 成果参数信息
|
|
|
|
AchievementParams struct {
|
|
|
|
ID uint64
|
2022-02-15 17:19:23 +08:00
|
|
|
Title, Image, File, Introduce, Description string
|
2021-12-14 13:34:42 +08:00
|
|
|
Mode, Maturity, LeadStandard, CooperationMode int // 技术成熟度 领先标准 合作模式
|
|
|
|
Industrys, Customers, Keywords []string // 所属客户 关键词
|
2022-05-02 14:37:37 +08:00
|
|
|
VideoFile string // 视频文件
|
|
|
|
VideoPrice float64 // 视频价格
|
|
|
|
VideoFreeTime int
|
|
|
|
IsSubmit int // 是否提交审核
|
2021-12-14 13:34:42 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Instance 基本信息
|
|
|
|
func (c *Achievement) Instance(status, page, pageSize int) (*controller.ReturnPages, error) {
|
|
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
|
2022-05-05 20:38:23 +08:00
|
|
|
where := []*model2.ModelWhere{
|
|
|
|
model2.NewWhere("a.uid", c.UID),
|
|
|
|
model2.NewWhere("a.status", status),
|
|
|
|
}
|
2021-12-14 13:34:42 +08:00
|
|
|
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 {
|
|
|
|
mTechnologyAchievement.Introduce = v.Industry
|
|
|
|
|
|
|
|
list = append(list, &AchievementInfo{
|
|
|
|
ID: v.GetEncodeID(),
|
|
|
|
TechnologyAchievementInfo: v,
|
|
|
|
Industrys: mTechnologyAchievement.GetIndustryAttribute(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
|
|
}
|
|
|
|
|
2022-01-04 11:59:58 +08:00
|
|
|
// Match 匹配信息
|
2022-01-20 11:51:02 +08:00
|
|
|
func (c *Achievement) Match(title string, industrys, keywords []string) (*controller.ReturnPages, error) {
|
2022-01-04 11:59:58 +08:00
|
|
|
params := strings.Join([]string{
|
|
|
|
title, strings.Join(industrys, ","), strings.Join(keywords, ","),
|
|
|
|
}, ",")
|
|
|
|
achievement := service.NewESAchievement(
|
|
|
|
service.WithAchievementTitle(params),
|
|
|
|
service.WithAchievementIndustry(params),
|
|
|
|
service.WithAchievementKeyword(params),
|
|
|
|
)
|
2022-01-20 11:51:02 +08:00
|
|
|
out, count, err := achievement.Search(0, 0)
|
2022-01-04 11:59:58 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ids := make([]uint64, 0)
|
|
|
|
|
|
|
|
for _, v := range out.([]interface{}) {
|
|
|
|
val := v.(*service.ESAchievement)
|
|
|
|
ids = append(ids, val.ID)
|
|
|
|
}
|
|
|
|
achievements := make([]*model.TechnologyAchievementInstance, 0)
|
|
|
|
|
|
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
|
|
|
|
if achievements, err = mTechnologyAchievement.Instance(model2.NewWhereIn("a.id", ids),
|
|
|
|
model2.NewWhere("a.shelf_status", model2.ShelfStatusForUp)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
list := make([]*AchievementMatchInfo, 0)
|
|
|
|
|
|
|
|
for _, v := range achievements {
|
|
|
|
mTechnologyAchievement.Industry = v.Industry
|
|
|
|
mTechnologyAchievement.Keyword = v.Keyword
|
|
|
|
mTechnologyAchievement.Customer = v.Customer
|
|
|
|
|
|
|
|
list = append(list, &AchievementMatchInfo{
|
|
|
|
ID: v.GetEncodeID(),
|
|
|
|
TechnologyAchievementInstance: v,
|
|
|
|
Industrys: mTechnologyAchievement.GetIndustryAttribute(),
|
|
|
|
Keywords: mTechnologyAchievement.GetKeywordAttribute(),
|
|
|
|
Customers: mTechnologyAchievement.GetCustomerAttribute(),
|
|
|
|
})
|
|
|
|
}
|
2022-01-20 11:51:02 +08:00
|
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
2022-01-04 11:59:58 +08:00
|
|
|
}
|
|
|
|
|
2021-12-14 13:34:42 +08:00
|
|
|
// Detail 详情信息
|
|
|
|
func (c *Achievement) Detail(id uint64) (*AchievementDetail, error) {
|
|
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
mTechnologyAchievement.ID = id
|
|
|
|
|
|
|
|
isExist, err := model2.First(mTechnologyAchievement.TechnologyAchievement)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if !isExist {
|
|
|
|
return nil, errors.New("操作错误,成果信息不存在或已被删除")
|
|
|
|
}
|
|
|
|
return &AchievementDetail{
|
|
|
|
ID: mTechnologyAchievement.GetEncodeID(),
|
|
|
|
TechnologyAchievement: mTechnologyAchievement.TechnologyAchievement,
|
|
|
|
Customers: mTechnologyAchievement.GetCustomerAttribute(),
|
|
|
|
Keywords: mTechnologyAchievement.GetKeywordAttribute(),
|
2022-05-02 14:37:37 +08:00
|
|
|
Config: mTechnologyAchievement.GetConfigAttribute(),
|
2021-12-14 13:34:42 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form 数据操作
|
|
|
|
func (c *Achievement) Form(params *AchievementParams) error {
|
|
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
|
|
|
|
if params.ID > 0 {
|
|
|
|
mTechnologyAchievement.ID = params.ID
|
|
|
|
|
|
|
|
isExist, err := model2.FirstField(mTechnologyAchievement.TechnologyAchievement, []string{"id", "uid", "status", "created_at", "updated_at"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if !isExist {
|
|
|
|
return errors.New("操作错误,成果信息不存在或已被删除")
|
|
|
|
} else if mTechnologyAchievement.UID != c.UID {
|
|
|
|
return errors.New("无权限操作")
|
2022-01-21 11:42:58 +08:00
|
|
|
} else if mTechnologyAchievement.Status != model2.TechnologyStatusKindForRefuse &&
|
|
|
|
mTechnologyAchievement.Status != model2.TechnologyStatusKindForDraft {
|
2021-12-14 13:34:42 +08:00
|
|
|
return errors.New("操作错误,当前状态不允许修改")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mTechnologyAchievement.Mode = model2.TechnologyAchievementMode(params.Mode)
|
|
|
|
mTechnologyAchievement.Title = params.Title
|
|
|
|
mTechnologyAchievement.Image.Image = params.Image
|
|
|
|
mTechnologyAchievement.File = params.File
|
|
|
|
mTechnologyAchievement.SetIndustryAttribute(params.Industrys)
|
|
|
|
mTechnologyAchievement.SetCustomerAttribute(params.Customers)
|
|
|
|
mTechnologyAchievement.Maturity = config.TechnologyMaturity(params.Maturity)
|
|
|
|
mTechnologyAchievement.LeadStandard = model2.TechnologyProductLeadStandard(params.LeadStandard)
|
|
|
|
mTechnologyAchievement.CooperationMode = config.TechnologyCooperationMode(params.CooperationMode)
|
|
|
|
mTechnologyAchievement.SetKeywordAttribute(params.Keywords)
|
|
|
|
mTechnologyAchievement.Introduce = params.Introduce
|
2022-02-15 17:19:23 +08:00
|
|
|
mTechnologyAchievement.Description = params.Description
|
2022-05-02 14:37:37 +08:00
|
|
|
mTechnologyAchievement.SetConfigAttribute(&model2.TechnologyAchievementConfig{
|
|
|
|
VideoFile: params.VideoFile,
|
|
|
|
VideoPrice: params.VideoPrice,
|
|
|
|
VideoFreeTime: params.VideoFreeTime,
|
|
|
|
})
|
2021-12-14 13:34:42 +08:00
|
|
|
|
|
|
|
if mTechnologyAchievement.ID > 0 {
|
2022-01-21 11:42:58 +08:00
|
|
|
mTechnologyAchievement.Status = model2.TechnologyStatusKindForExamining
|
2021-12-14 13:34:42 +08:00
|
|
|
return model2.Updates(mTechnologyAchievement.TechnologyAchievement, mTechnologyAchievement.TechnologyAchievement)
|
|
|
|
}
|
2022-01-15 16:48:49 +08:00
|
|
|
mTechnologyAchievement.TenantID = c.tenantID
|
2021-12-14 13:34:42 +08:00
|
|
|
mTechnologyAchievement.UID = c.UID
|
|
|
|
|
|
|
|
if params.IsSubmit > 0 {
|
2022-01-21 11:42:58 +08:00
|
|
|
mTechnologyAchievement.Status = model2.TechnologyStatusKindForExamining
|
2021-12-14 13:34:42 +08:00
|
|
|
}
|
|
|
|
return model2.Create(mTechnologyAchievement.TechnologyAchievement)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shelf 上下架
|
|
|
|
func (c *Achievement) Shelf(id uint64, status int) error {
|
|
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
mTechnologyAchievement.ID = id
|
|
|
|
|
|
|
|
isExist, err := model2.FirstField(mTechnologyAchievement.TechnologyAchievement, []string{"id", "uid", "shelf_status", "status"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if !isExist {
|
|
|
|
return errors.New("操作错误,成果信息不存在或已被删除")
|
|
|
|
} else if mTechnologyAchievement.ShelfStatus == model2.ShelfStatusKind(status) {
|
|
|
|
return errors.New("操作错误,无需变更上下架状态")
|
|
|
|
}
|
2022-05-02 14:37:37 +08:00
|
|
|
//else if mTechnologyAchievement.UID != c.UID {
|
|
|
|
// return errors.New("无权限操作")
|
|
|
|
//}
|
2022-02-08 18:26:40 +08:00
|
|
|
|
|
|
|
if err = model2.Updates(mTechnologyAchievement.TechnologyAchievement, map[string]interface{}{
|
2021-12-14 13:34:42 +08:00
|
|
|
"shelf_status": status, "updated_at": time.Now(),
|
2022-02-08 18:26:40 +08:00
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
manage := service.NewESAchievement(
|
|
|
|
service.WithAchievementID(mTechnologyAchievement.ID),
|
|
|
|
service.WithAchievementShow(status),
|
|
|
|
)
|
|
|
|
return manage.Update()
|
2021-12-14 13:34:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete 删除操作
|
|
|
|
func (c *Achievement) Delete(id uint64) error {
|
|
|
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
|
|
|
mTechnologyAchievement.ID = id
|
|
|
|
|
|
|
|
isExist, err := model2.FirstField(mTechnologyAchievement.TechnologyAchievement, []string{"id", "uid"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if !isExist {
|
|
|
|
return errors.New("操作错误,成就信息不存在或已被删除")
|
|
|
|
} else if mTechnologyAchievement.UID != c.UID {
|
|
|
|
return errors.New("无权限操作")
|
|
|
|
}
|
2022-02-08 18:26:40 +08:00
|
|
|
|
|
|
|
if err = model2.Delete(mTechnologyAchievement.TechnologyAchievement); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
manage := service.NewESAchievement(
|
|
|
|
service.WithAchievementID(mTechnologyAchievement.ID),
|
|
|
|
)
|
|
|
|
return manage.Delete()
|
2021-12-14 13:34:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewAchievement() AchievementHandle {
|
2022-01-15 16:48:49 +08:00
|
|
|
return func(session *session.Enterprise, tenantID uint64) *Achievement {
|
2021-12-14 13:34:42 +08:00
|
|
|
return &Achievement{
|
|
|
|
Enterprise: session,
|
2022-01-15 16:48:49 +08:00
|
|
|
tenantID: tenantID,
|
2021-12-14 13:34:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|