157 lines
4.6 KiB
Go
157 lines
4.6 KiB
Go
package technology
|
||
|
||
import (
|
||
"SciencesServer/app/api/admin/model"
|
||
"SciencesServer/app/basic/config"
|
||
"SciencesServer/app/basic/controller"
|
||
model2 "SciencesServer/app/common/model"
|
||
"SciencesServer/app/service"
|
||
"SciencesServer/app/session"
|
||
"errors"
|
||
"strings"
|
||
)
|
||
|
||
type Achievement struct {
|
||
*session.Admin
|
||
}
|
||
|
||
type AchievementHandle func(session *session.Admin) *Achievement
|
||
|
||
type (
|
||
// AchievementInfo 成果信息
|
||
AchievementInfo struct {
|
||
ID string `json:"id"`
|
||
*model.TechnologyAchievementInfo
|
||
Area string `json:"area"`
|
||
}
|
||
// AchievementDetailInfo 成果详细信息
|
||
AchievementDetailInfo struct {
|
||
ID string `json:"id"`
|
||
TenantID string `json:"tenant_id"`
|
||
*model2.TechnologyAchievement
|
||
}
|
||
)
|
||
|
||
// Instance 首页信息
|
||
func (c *Achievement) Instance(tenantID uint64, title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||
mTechnologyAchievement := model.NewTechnologyAchievement()
|
||
|
||
where := make([]*model2.ModelWhere, 0)
|
||
|
||
if c.TenantID > 0 {
|
||
where = append(where, model2.NewWhere("p.tenant_id", c.TenantID))
|
||
}
|
||
if tenantID > 0 {
|
||
where = append(where, model2.NewWhere("p.tenant_id", tenantID))
|
||
}
|
||
if title != "" {
|
||
where = append(where, model2.NewWhereLike("p.title", title))
|
||
}
|
||
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(),
|
||
TechnologyAchievementInfo: v,
|
||
Area: v.FormatBasic(),
|
||
})
|
||
}
|
||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||
}
|
||
|
||
// Detail 详细信息
|
||
func (c *Achievement) Detail(id uint64) (*AchievementDetailInfo, 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 &AchievementDetailInfo{
|
||
ID: mTechnologyAchievement.GetEncodeID(),
|
||
TenantID: mTechnologyAchievement.GetEncodeTenantID(),
|
||
TechnologyAchievement: mTechnologyAchievement.TechnologyAchievement,
|
||
}, nil
|
||
}
|
||
|
||
// Examine 审核操作
|
||
func (c *Achievement) Examine(id uint64, status int, remark string) error {
|
||
mTechnologyAchievement := model.NewTechnologyAchievement()
|
||
mTechnologyAchievement.ID = id
|
||
|
||
isExist, err := model2.FirstField(mTechnologyAchievement.TechnologyAchievement, []string{"id", "tenant_id", "title",
|
||
"industry", "keyword", "status"})
|
||
|
||
if err != nil {
|
||
return err
|
||
} else if !isExist {
|
||
return errors.New("操作错误,成果品信息不存在或已被删除")
|
||
}
|
||
if c.TenantID > 0 && mTechnologyAchievement.TenantID != c.TenantID {
|
||
return errors.New("操作错误,无权限操作")
|
||
}
|
||
if mTechnologyAchievement.Status != model2.TechnologyStatusKindForExamining {
|
||
return errors.New("操作错误,当前成果状态不允许审核")
|
||
}
|
||
if err = handleExamine(mTechnologyAchievement.TechnologyAchievement, c.UID, model2.SysUserExamineLogKindForAchievement, status, remark, func() error {
|
||
if model2.ExamineStatusKind(status) == model2.ExamineStatusForAgree {
|
||
_industrys := make([]string, 0)
|
||
|
||
for _, v := range mTechnologyAchievement.GetIndustryAttribute() {
|
||
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "-").Value)
|
||
}
|
||
// 存放ES中
|
||
manage := service.NewESAchievement(
|
||
service.WithAchievementID(mTechnologyAchievement.ID),
|
||
service.WithAchievementTitle(mTechnologyAchievement.Title),
|
||
service.WithAchievementIndustry(strings.Join(_industrys, ";")),
|
||
service.WithAchievementKeyword(strings.Join(mTechnologyAchievement.GetKeywordAttribute(), ";")),
|
||
)
|
||
return manage.Create()
|
||
}
|
||
return nil
|
||
}); err != nil {
|
||
return err
|
||
}
|
||
|
||
return nil
|
||
}
|
||
|
||
// Shelf 上下架
|
||
func (c *Achievement) Shelf(id uint64) error {
|
||
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyAchievement(), id)
|
||
}
|
||
|
||
func (c *Achievement) Delete(id uint64) error {
|
||
mTechnologyAchievement := model.NewTechnologyAchievement()
|
||
mTechnologyAchievement.ID = id
|
||
|
||
isExist, err := model2.First(mTechnologyAchievement.TechnologyAchievement)
|
||
|
||
if err != nil {
|
||
return err
|
||
} else if !isExist {
|
||
return errors.New("操作错误,成果信息不存在或已被删除")
|
||
} else if c.TenantID > 0 && mTechnologyAchievement.TenantID != c.TenantID {
|
||
return errors.New("操作错误,无权限操作")
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func NewAchievement() AchievementHandle {
|
||
return func(session *session.Admin) *Achievement {
|
||
return &Achievement{session}
|
||
}
|
||
}
|