From e29371da3e36ed37032bcb3d077f04e84e1528e9 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 4 Jan 2022 11:59:58 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/enterprise/api/account.go | 2 +- app/api/enterprise/api/technology.go | 2 +- .../enterprise/controller/account/instance.go | 2 +- .../enterprise/controller/account/logout.go | 2 +- .../controller/technology/achievement.go | 57 +++++++++++++ .../controller/technology/patent.go | 50 +++++++++++ .../controller/technology/product.go | 75 ++++++++++------ .../enterprise/controller/user/identity.go | 2 +- .../enterprise/controller/user/withdrawal.go | 16 ++-- .../model/technology_achievement.go | 34 ++++++++ app/api/manage/api/account.go | 2 +- app/api/manage/controller/account.go | 8 +- app/service/authToken.go | 4 +- app/service/es_achievement.go | 85 +++++++++++++++++++ app/service/es_manage.go | 3 - app/service/es_patent.go | 6 +- config/const.go | 7 +- router/address.go | 5 +- router/auth.go | 4 +- utils/array_test.go | 53 ++++++++++++ 20 files changed, 357 insertions(+), 62 deletions(-) create mode 100644 app/service/es_achievement.go diff --git a/app/api/enterprise/api/account.go b/app/api/enterprise/api/account.go index 3f66e56..263f070 100644 --- a/app/api/enterprise/api/account.go +++ b/app/api/enterprise/api/account.go @@ -71,7 +71,7 @@ func (*Account) Logout(c *gin.Context) { _session := session.NewEnterprise() - _ = service.NewAuthToken(token).Auth(_session) + _ = service.NewAuthToken(token).Auth(config.RedisKeyForAccountEnterprise, _session) err := account.NewLogout()(_session).Launch() api.APIResponse(err)(c) diff --git a/app/api/enterprise/api/technology.go b/app/api/enterprise/api/technology.go index 083b1c7..1f7501d 100644 --- a/app/api/enterprise/api/technology.go +++ b/app/api/enterprise/api/technology.go @@ -518,7 +518,7 @@ func (*Technology) Product(c *gin.Context) { return } data, err := technology2.NewProduct()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)). - List(form.Title, form.Status, form.Page, form.PageSize) + Instance(form.Title, form.Status, form.Page, form.PageSize) api.APIResponse(err, data)(c) } diff --git a/app/api/enterprise/controller/account/instance.go b/app/api/enterprise/controller/account/instance.go index 9453924..ca0896a 100644 --- a/app/api/enterprise/controller/account/instance.go +++ b/app/api/enterprise/controller/account/instance.go @@ -51,7 +51,7 @@ func (c *Instance) Login() InstanceLoginCallback { _session.Identity = params.Identity _session.SelectIdentity = params.SelectIdentity - service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, _session.UIDToString(), _session) + service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccountEnterprise, _session.UIDToString(), _session) return &InstanceLoginReturn{Token: token, TokenEffectTime: config.SettingInfo.TokenEffectTime} } diff --git a/app/api/enterprise/controller/account/logout.go b/app/api/enterprise/controller/account/logout.go index 14ea295..0f17584 100644 --- a/app/api/enterprise/controller/account/logout.go +++ b/app/api/enterprise/controller/account/logout.go @@ -15,7 +15,7 @@ type LogoutHandle func(session *session.Enterprise) *Logout func (c *Logout) Launch() error { if c.Enterprise != nil && c.UID > 0 { - service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID)) + service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccountEnterprise, utils.UintToString(c.UID)) } return nil } diff --git a/app/api/enterprise/controller/technology/achievement.go b/app/api/enterprise/controller/technology/achievement.go index 8528e9c..476af11 100644 --- a/app/api/enterprise/controller/technology/achievement.go +++ b/app/api/enterprise/controller/technology/achievement.go @@ -5,8 +5,10 @@ import ( "SciencesServer/app/basic/config" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" + "SciencesServer/app/service" "SciencesServer/app/session" "errors" + "strings" "time" ) @@ -25,6 +27,14 @@ type ( *model.TechnologyAchievementInfo Industrys []string `json:"industrys"` } + // AchievementMatchInfo 成果匹配信息 + AchievementMatchInfo struct { + ID string `json:"id"` + *model.TechnologyAchievementInstance + Industrys []string `json:"industrys"` + Keywords []string `json:"keywords"` + Customers []string `json:"customers"` + } // AchievementDetail 成果详情 AchievementDetail struct { ID string `json:"id"` @@ -69,6 +79,53 @@ func (c *Achievement) Instance(status, page, pageSize int) (*controller.ReturnPa return &controller.ReturnPages{Data: list, Count: count}, nil } +// Match 匹配信息 +func (c *Achievement) Match(title string, industrys, keywords []string) ([]*AchievementMatchInfo, error) { + params := strings.Join([]string{ + title, strings.Join(industrys, ","), strings.Join(keywords, ","), + }, ",") + achievement := service.NewESAchievement( + service.WithAchievementTitle(params), + service.WithAchievementIndustry(params), + service.WithAchievementKeyword(params), + ) + out, err := achievement.Search(0, 0) + + 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(), + }) + } + return list, nil +} + // Detail 详情信息 func (c *Achievement) Detail(id uint64) (*AchievementDetail, error) { mTechnologyAchievement := model.NewTechnologyAchievement() diff --git a/app/api/enterprise/controller/technology/patent.go b/app/api/enterprise/controller/technology/patent.go index c670962..4cf6b18 100644 --- a/app/api/enterprise/controller/technology/patent.go +++ b/app/api/enterprise/controller/technology/patent.go @@ -5,10 +5,12 @@ import ( "SciencesServer/app/api/enterprise/model" "SciencesServer/app/api/manage/controller" model2 "SciencesServer/app/common/model" + "SciencesServer/app/service" "SciencesServer/app/session" "SciencesServer/serve/orm" "errors" "gorm.io/gorm" + "strings" "time" ) @@ -27,6 +29,14 @@ type ( ShelfStatus model2.ShelfStatusKind Status model2.SysParentStatus } + // PatentMatchInfo 专利匹配信息 + PatentMatchInfo struct { + ID string `json:"id"` + Kind model2.SysParentKind `json:"kind"` + Title string `json:"title"` + Description string `json:"description"` + ApplyAt string `json:"apply_at"` + } // PatentDetailInfo 专利详细信息 PatentDetailInfo struct { ID string `json:"id"` @@ -182,6 +192,46 @@ func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page return &controller.ReturnPages{Data: list, Count: count}, nil } +// Search 搜索信息 +func (c *Patent) Match(title string, industrys, keywords []string) ([]*PatentMatchInfo, error) { + params := strings.Join([]string{ + title, strings.Join(industrys, ","), strings.Join(keywords, ","), + }, ",") + patent := service.NewESPatent( + service.WithPatentTitle(params), + service.WithPatentIndustry(params), + ) + out, err := patent.Search(0, 0) + + if err != nil { + return nil, err + } + ids := make([]uint64, 0) + + for _, v := range out.([]interface{}) { + val := v.(*service.ESAchievement) + ids = append(ids, val.ID) + } + mSysPatent := model.NewSysPatent() + + patents := make([]*model2.SysPatent, 0) + + if err = model2.ScanFields(mSysPatent.SysPatent, &patents, []string{"id", "kind", "title", "description", "apply_at"}, &model2.ModelWhereOrder{ + Where: model2.NewWhereIn("id", ids), + Order: model2.NewOrder("id", model2.OrderModeToDesc), + }); err != nil { + return nil, err + } + list := make([]*PatentMatchInfo, 0) + + for _, v := range patents { + list = append(list, &PatentMatchInfo{ + ID: v.GetEncodeID(), Title: v.Title, Description: v.Description, ApplyAt: v.ApplyAt, + }) + } + return list, nil +} + // Detail 详细信息 func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) { mUserPatent := model.NewUserPatent() diff --git a/app/api/enterprise/controller/technology/product.go b/app/api/enterprise/controller/technology/product.go index 704f75b..744ca55 100644 --- a/app/api/enterprise/controller/technology/product.go +++ b/app/api/enterprise/controller/technology/product.go @@ -23,7 +23,7 @@ type ( // ProductInfo 产品信息 ProductInfo struct { ID string `json:"id"` - *model2.TechnologyProduct + *model.TechnologyProductInfo } // ProductDetailInfo 产品详细信息 ProductDetailInfo struct { @@ -49,44 +49,60 @@ type ( } ) -// List 列表信息 -func (c *Product) List(title string, status, page, pageSize int) ([]*ProductInfo, error) { +var matchHandle = map[int]func(title string, industrys, keywords []string) (interface{}, error){ + 1: matchAchievement, 2: matchPatent, 3: matchExpect, 4: matchLaboratory, 5: matchCompany, +} + +// matchAchievement 成果匹配 +func matchAchievement(title string, industrys, keywords []string) (interface{}, error) { + return (&Achievement{}).Match(title, industrys, keywords) +} + +// matchPatent 专利匹配 +func matchPatent(title string, industrys, keywords []string) (interface{}, error) { + return (&Patent{}).Match(title, industrys, keywords) +} + +// matchExpect 专家匹配 +func matchExpect(title string, industrys, keywords []string) (interface{}, error) { + return nil, nil + +} + +// matchLaboratory 实验室匹配 +func matchLaboratory(title string, industrys, keywords []string) (interface{}, error) { + return nil, nil +} + +// matchCompany 公司匹配 +func matchCompany(title string, industrys, keywords []string) (interface{}, error) { + return nil, nil +} + +// Instance 列表信息 +func (c *Product) Instance(title string, status, page, pageSize int) (*controller.ReturnPages, error) { mTechnologyProduct := model.NewTechnologyProduct() - where := []*model2.ModelWhereOrder{ - &model2.ModelWhereOrder{ - Where: model2.NewWhere("local", c.local), - Order: model2.NewOrder("id", model2.OrderModeToDesc), - }, - &model2.ModelWhereOrder{ - Where: model2.NewWhere("uid", c.UID), - }, - &model2.ModelWhereOrder{ - Where: model2.NewWhere("status", status), - }, - } - if title != "" { - where = append(where, &model2.ModelWhereOrder{ - Where: model2.NewWhereLike("title", title), - }) - } - out := make([]*model2.TechnologyProduct, 0) + where := []*model2.ModelWhere{model2.NewWhere("p.uid", c.UID), model2.NewWhere("p.status", status)} + if title != "" { + where = append(where, model2.NewWhereLike("p.title", title)) + } var count int64 - if err := model2.PagesFields(mTechnologyProduct.TechnologyProduct, &out, []string{}, - page, pageSize, &count, where...); err != nil { + out, err := mTechnologyProduct.Product(page, pageSize, &count, where...) + + if err != nil { return nil, err } list := make([]*ProductInfo, 0) for _, v := range out { list = append(list, &ProductInfo{ - ID: v.GetEncodeID(), - TechnologyProduct: v, + ID: v.GetEncodeID(), TechnologyProductInfo: v, }) } - return list, nil + return &controller.ReturnPages{Data: list, Count: count}, nil } // Detail 产品详情 @@ -110,8 +126,13 @@ func (c *Product) Detail(id uint64) (*ProductDetailInfo, error) { } // Match 匹配结果 -func (c *Product) Match(id uint64) { +func (c *Product) Match(kind int, title string, industrys, keywords []string) (interface{}, error) { + handle, has := matchHandle[kind] + if !has { + return nil, errors.New("操作错误,未知的匹配模式") + } + return handle(title, industrys, keywords) } // Visit 访问信息 diff --git a/app/api/enterprise/controller/user/identity.go b/app/api/enterprise/controller/user/identity.go index 00808ed..cd11b3e 100644 --- a/app/api/enterprise/controller/user/identity.go +++ b/app/api/enterprise/controller/user/identity.go @@ -236,7 +236,7 @@ func (c *Identity) Switch(identity int) error { } c.IdentityUID = mUserIdentity.UUID c.SelectIdentity = identity - service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.Enterprise) + service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccountEnterprise, c.UIDToString(), c.Enterprise) return nil } return errors.New("操作错误,无效的身份信息") diff --git a/app/api/enterprise/controller/user/withdrawal.go b/app/api/enterprise/controller/user/withdrawal.go index 5408e50..e6f1dc4 100644 --- a/app/api/enterprise/controller/user/withdrawal.go +++ b/app/api/enterprise/controller/user/withdrawal.go @@ -17,13 +17,13 @@ type Withdrawal struct { type WithdrawalHandle func(session *session.Enterprise) *Withdrawal type ( - // WithdrawalBasic 基本信息 - WithdrawalBasic struct { + // WithdrawalInfo 基本信息 + WithdrawalInfo struct { ID string `json:"id"` *model.UserWithdrawalInfo } - // WithdrawalInfo 提现数据信息 - WithdrawalInfo struct { + // WithdrawalPageInfo 提现数据信息 + WithdrawalPageInfo struct { controller.ReturnPages TotalAmount float64 `json:"total_amount"` TotalActualAmount float64 `json:"total_actual_amount"` @@ -36,10 +36,10 @@ type ( ) // Instance 数据信息 -func (c *Withdrawal) Instance(status int, createdAt string, page, pageSize int) (*WithdrawalInfo, error) { +func (c *Withdrawal) Instance(status int, createdAt string, page, pageSize int) (*WithdrawalPageInfo, error) { mUserWithdrawal := model.NewUserWithdrawal() - out := new(WithdrawalInfo) + out := new(WithdrawalPageInfo) where := []*model2.ModelWhere{model2.NewWhere("w.uid", c.UID), model2.NewWhere("w.status", status)} @@ -51,10 +51,10 @@ func (c *Withdrawal) Instance(status int, createdAt string, page, pageSize int) if err != nil { return nil, err } - list := make([]*WithdrawalBasic, 0) + list := make([]*WithdrawalInfo, 0) for _, v := range ret { - list = append(list, &WithdrawalBasic{ID: v.GetEncodeID(), UserWithdrawalInfo: v}) + list = append(list, &WithdrawalInfo{ID: v.GetEncodeID(), UserWithdrawalInfo: v}) } out.Data = list diff --git a/app/api/enterprise/model/technology_achievement.go b/app/api/enterprise/model/technology_achievement.go index 3afed66..b05dda4 100644 --- a/app/api/enterprise/model/technology_achievement.go +++ b/app/api/enterprise/model/technology_achievement.go @@ -1,6 +1,7 @@ package model import ( + "SciencesServer/app/basic/config" "SciencesServer/app/common/model" "SciencesServer/serve/orm" "fmt" @@ -20,6 +21,39 @@ type TechnologyAchievementInfo struct { CreatedAt time.Time `json:"created_at"` } +type TechnologyAchievementInstance struct { + TechnologyAchievementInfo + Customer string `json:"-"` + LeadStandard model.TechnologyProductLeadStandard `json:"lead_standard"` + CooperationMode config.TechnologyCooperationMode `json:"cooperation_mode"` + Keyword string `json:"-"` + CollectCount int `json:"collect_count"` +} + +// Instance 成果信息 +func (m *TechnologyAchievement) Instance(where ...*model.ModelWhere) ([]*TechnologyAchievementInstance, error) { + db := orm.GetDB().Table(m.TableName()+" AS a"). + Select("a.id", "a.title", "a.industry", "v.count AS visit_count", "c.count AS collect_count", + "a.customer", "a.lead_standard", "a.cooperation_mode", "a.keyword", "a.created_at"). + Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON a.id = v.object_id", + model.NewUserVisit().TableName(), model.UserVisitKindForTechnologyAchievement, model.DeleteStatusForNot)). + Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON a.id = c.object_id", + model.NewUserCollect().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)). + Where("a.is_deleted = ?", model.DeleteStatusForNot) + + if len(where) > 0 { + for _, wo := range where { + db = db.Where(wo.Condition, wo.Value) + } + } + out := make([]*TechnologyAchievementInstance, 0) + + if err := db.Order("a.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil { + return nil, err + } + return out, nil +} + // Achievement 成果信息 func (m *TechnologyAchievement) Achievement(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) { db := orm.GetDB().Table(m.TableName()+" AS a"). diff --git a/app/api/manage/api/account.go b/app/api/manage/api/account.go index 6cb030d..3937cbd 100644 --- a/app/api/manage/api/account.go +++ b/app/api/manage/api/account.go @@ -84,7 +84,7 @@ func (a *Account) Logout(c *gin.Context) { _session := session.NewManage() - _ = service.NewAuthToken(token).Auth(_session) + _ = service.NewAuthToken(token).Auth(config.RedisKeyForAccountManage, _session) err := controller.NewAccount()(_session).Logout() APIResponse(err)(c) diff --git a/app/api/manage/controller/account.go b/app/api/manage/controller/account.go index b30b43e..65cecf4 100644 --- a/app/api/manage/controller/account.go +++ b/app/api/manage/controller/account.go @@ -40,7 +40,7 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment, if !mSysUser.ValidatePassword(password) { return nil, errors.New("密码错误") } - _session := service.NewSession() + _session := session.NewManage() _session.UID = mSysUser.UUID _session.Name = mSysUser.Name _session.Mobile = mSysUser.Mobile @@ -50,8 +50,8 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment, _session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: uid}) - service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, uid, _session) - service.Publish(config.EventForAccountLoginProduce, _session.TenantID, _session.UID, equipment, ip) + service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccountManage, uid, _session) + service.Publish(config.EventForAccountLoginProduce, 0, _session.UID, equipment, ip) return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil } @@ -59,7 +59,7 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment, // Logout 退出请求 func (c *Account) Logout() error { if c.Manage != nil && c.UID > 0 { - service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID)) + service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccountManage, utils.UintToString(c.UID)) } return nil } diff --git a/app/service/authToken.go b/app/service/authToken.go index 71c827c..dbadc00 100644 --- a/app/service/authToken.go +++ b/app/service/authToken.go @@ -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("登陆错误,用户未登录或已退出") diff --git a/app/service/es_achievement.go b/app/service/es_achievement.go new file mode 100644 index 0000000..7a8bbec --- /dev/null +++ b/app/service/es_achievement.go @@ -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 +} diff --git a/app/service/es_manage.go b/app/service/es_manage.go index 1e11bd2..662815e 100644 --- a/app/service/es_manage.go +++ b/app/service/es_manage.go @@ -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) } diff --git a/app/service/es_patent.go b/app/service/es_patent.go index d0d9f37..5ef4f6d 100644 --- a/app/service/es_patent.go +++ b/app/service/es_patent.go @@ -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, diff --git a/config/const.go b/config/const.go index 1e65169..4a5007e 100644 --- a/config/const.go +++ b/config/const.go @@ -6,9 +6,10 @@ const ( RedisKeyForTaskQueue string = "task_queue" RedisKeyForTaskQueueBody string = "task_queue_body" - RedisKeyForAccount string = "account" - RedisKeyForTenant string = "tenant:instance" - RedisKeyForTenantKeys string = "tenant:keys" + RedisKeyForAccountManage string = "account:manage" + RedisKeyForAccountEnterprise string = "account:enterprise" + RedisKeyForTenant string = "tenant:instance" + RedisKeyForTenantKeys string = "tenant:keys" ) const ( diff --git a/router/address.go b/router/address.go index af368e3..4c35156 100644 --- a/router/address.go +++ b/router/address.go @@ -6,6 +6,7 @@ import ( api2 "SciencesServer/app/api/website/api" "SciencesServer/app/basic/api" "SciencesServer/app/session" + "SciencesServer/config" "github.com/gin-gonic/gin" ) @@ -121,7 +122,7 @@ func registerAdminAPI(app *gin.Engine) { g := app.Group(apiPrefix) // 登录验证 - g.Use(NeedLogin(session.NewManage(), AddSkipperURL([]string{ + g.Use(NeedLogin(config.RedisKeyForAccountManage, session.NewManage(), AddSkipperURL([]string{ apiPrefix + "/captcha", apiPrefix + "/account/login", apiPrefix + "/account/logout", @@ -229,7 +230,7 @@ func registerEnterpriseAPI(app *gin.Engine) { apiPrefix := "/enterprise" g := app.Group(apiPrefix) - g.Use(NeedLogin(session.NewEnterprise(), AddSkipperURL([]string{ + g.Use(NeedLogin(config.RedisKeyForAccountEnterprise, session.NewEnterprise(), AddSkipperURL([]string{ apiPrefix + "/v1/account/login", apiPrefix + "/v1/account/register", apiPrefix + "/v1/account/authorize", diff --git a/router/auth.go b/router/auth.go index 418b956..d5840b3 100644 --- a/router/auth.go +++ b/router/auth.go @@ -24,7 +24,7 @@ func AddSkipperURL(url ...string) SkipperURL { } // NeedLogin 需要登录 -func NeedLogin(session logic.ISession, skipperURL ...SkipperURL) gin.HandlerFunc { +func NeedLogin(key string, session logic.ISession, skipperURL ...SkipperURL) gin.HandlerFunc { return func(c *gin.Context) { if len(skipperURL) > 0 && skipperURL[0](c) { c.Next() @@ -37,7 +37,7 @@ func NeedLogin(session logic.ISession, skipperURL ...SkipperURL) gin.HandlerFunc c.Abort() return } - err := service.NewAuthToken(token).Auth(session) + err := service.NewAuthToken(token).Auth(key, session) if err != nil { c.JSON(http.StatusUnauthorized, gin.H{"message": err.Error()}) diff --git a/utils/array_test.go b/utils/array_test.go index 2153867..08c26c6 100644 --- a/utils/array_test.go +++ b/utils/array_test.go @@ -29,3 +29,56 @@ func TestArrayStrings(t *testing.T) { t.Log(b) t.Log(reflect.TypeOf(b).String()) } + +type Tree struct { + ID uint64 `json:"id"` + Checked bool `json:"checked"` + Children []*Tree `json:"children"` +} + +func show(src []*Tree, parent *Tree) { + for _, v := range src { + if !v.Checked && parent != nil { + parent.Checked = false + } + if len(v.Children) > 0 { + show(v.Children, v) + } + } +} + +func input(src []*Tree, out map[uint64]uint64) { + for _, v := range src { + out[v.ID] = v.ID + + if len(v.Children) > 0 { + input(v.Children, out) + } + } +} + +func TestInArray(t *testing.T) { + src := []*Tree{ + &Tree{ + ID: 1, + Checked: false, + Children: []*Tree{ + &Tree{ + ID: 2, + Checked: true, + Children: nil, + }, + &Tree{ + ID: 3, + Checked: false, + Children: nil, + }, + }, + }, + } + out := make(map[uint64]uint64, 0) + input(src, out) + + //show(out, nil) + t.Log(AnyToJSON(out)) +}