feat:完善项目信息

This commit is contained in:
henry
2022-01-04 11:59:58 +08:00
parent c3da1ebc51
commit e29371da3e
20 changed files with 357 additions and 62 deletions

View File

@ -15,7 +15,7 @@ type AuthToken struct {
Token string `json:"token"`
}
func (this *AuthToken) Auth(session logic.ISession) error {
func (this *AuthToken) Auth(key string, session logic.ISession) error {
tokenInfo := utils.JWTDecrypt(this.Token)
if tokenInfo == nil || len(tokenInfo) <= 0 {
@ -28,7 +28,7 @@ func (this *AuthToken) Auth(session logic.ISession) error {
if !ok {
return errors.New("登陆错误Token过期")
}
cache, _ := cache2.Cache.HGet(config.RedisKeyForAccount, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
cache, _ := cache2.Cache.HGet(key, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
if cache == "" {
return errors.New("登陆错误,用户未登录或已退出")

View File

@ -0,0 +1,85 @@
package service
import (
"SciencesServer/serve/es"
"SciencesServer/serve/logger"
"encoding/json"
)
type ESAchievement struct {
ID uint64 `json:"id"` // 成果ID
Title string `json:"title"` // 成果名称
Industry string `json:"industry"` // 行业领域
Keyword string `json:"keyword"` // 关键词
}
type ESAchievementOption func(achievement *ESAchievement)
func (this *ESAchievement) Index() string {
return "es_achievement_index"
}
func (this *ESAchievement) Create() error {
if this.Industry != "" {
this.Title = this.Industry + " - " + this.Title
}
_bytes, _ := json.Marshal(this)
return es.Create(this.Index(), _bytes)
}
func (this *ESAchievement) Search(page, pageSize int) (interface{}, error) {
termParams := make(map[string]interface{}, 0)
mustParams := make(map[string]interface{}, 0)
if this.Title != "" {
mustParams["title"] = this.Title
}
if this.Industry != "" {
termParams["industry"] = this.Industry
}
if this.Keyword != "" {
mustParams["keyword"] = this.Keyword
}
out, err := es.Search(this, this.Index(), &es.SearchParams{
TermParams: termParams,
MustParams: mustParams,
}, page, pageSize)
if err != nil {
logger.ErrorF("查询ES信息错误【%s】", err)
}
return out, nil
}
func WithAchievementID(id uint64) ESAchievementOption {
return func(achievement *ESAchievement) {
achievement.ID = id
}
}
func WithAchievementTitle(title string) ESAchievementOption {
return func(achievement *ESAchievement) {
achievement.Title = title
}
}
func WithAchievementIndustry(industry string) ESAchievementOption {
return func(achievement *ESAchievement) {
achievement.Industry = industry
}
}
func WithAchievementKeyword(keyword string) ESAchievementOption {
return func(achievement *ESAchievement) {
achievement.Industry = keyword
}
}
func NewESAchievement(options ...ESAchievementOption) *ESAchievement {
out := new(ESAchievement)
for _, v := range options {
v(out)
}
return out
}

View File

@ -26,9 +26,6 @@ func (this *ESManage) Index() string {
}
func (this *ESManage) Create() error {
if this.Industry != "" {
this.Title = this.Industry + " - " + this.Title
}
_bytes, _ := json.Marshal(this)
return es.Create(this.Index(), _bytes)
}

View File

@ -3,9 +3,7 @@ package service
import (
"SciencesServer/serve/es"
"SciencesServer/serve/logger"
"SciencesServer/utils"
"encoding/json"
"fmt"
)
type ESPatent struct {
@ -29,13 +27,11 @@ func (this *ESPatent) Search(page, pageSize int) (interface{}, error) {
termParams := make(map[string]interface{}, 0)
mustParams := make(map[string]interface{}, 0)
fmt.Println(utils.AnyToJSON(this))
if this.Title != "" {
mustParams["title"] = this.Title
}
if this.Industry != "" {
termParams["title"] = this.Industry
termParams["industry"] = this.Industry
}
out, err := es.Search(this, this.Index(), &es.SearchParams{
TermParams: termParams,