feat:完善项目信息
This commit is contained in:
@ -71,7 +71,7 @@ func (*Account) Logout(c *gin.Context) {
|
|||||||
|
|
||||||
_session := session.NewEnterprise()
|
_session := session.NewEnterprise()
|
||||||
|
|
||||||
_ = service.NewAuthToken(token).Auth(_session)
|
_ = service.NewAuthToken(token).Auth(config.RedisKeyForAccountEnterprise, _session)
|
||||||
|
|
||||||
err := account.NewLogout()(_session).Launch()
|
err := account.NewLogout()(_session).Launch()
|
||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
|
@ -518,7 +518,7 @@ func (*Technology) Product(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err := technology2.NewProduct()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
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)
|
api.APIResponse(err, data)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func (c *Instance) Login() InstanceLoginCallback {
|
|||||||
_session.Identity = params.Identity
|
_session.Identity = params.Identity
|
||||||
_session.SelectIdentity = params.SelectIdentity
|
_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}
|
return &InstanceLoginReturn{Token: token, TokenEffectTime: config.SettingInfo.TokenEffectTime}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ type LogoutHandle func(session *session.Enterprise) *Logout
|
|||||||
|
|
||||||
func (c *Logout) Launch() error {
|
func (c *Logout) Launch() error {
|
||||||
if c.Enterprise != nil && c.UID > 0 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@ import (
|
|||||||
"SciencesServer/app/basic/config"
|
"SciencesServer/app/basic/config"
|
||||||
"SciencesServer/app/basic/controller"
|
"SciencesServer/app/basic/controller"
|
||||||
model2 "SciencesServer/app/common/model"
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/service"
|
||||||
"SciencesServer/app/session"
|
"SciencesServer/app/session"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,6 +27,14 @@ type (
|
|||||||
*model.TechnologyAchievementInfo
|
*model.TechnologyAchievementInfo
|
||||||
Industrys []string `json:"industrys"`
|
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 成果详情
|
||||||
AchievementDetail struct {
|
AchievementDetail struct {
|
||||||
ID string `json:"id"`
|
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
|
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 详情信息
|
// Detail 详情信息
|
||||||
func (c *Achievement) Detail(id uint64) (*AchievementDetail, error) {
|
func (c *Achievement) Detail(id uint64) (*AchievementDetail, error) {
|
||||||
mTechnologyAchievement := model.NewTechnologyAchievement()
|
mTechnologyAchievement := model.NewTechnologyAchievement()
|
||||||
|
@ -5,10 +5,12 @@ import (
|
|||||||
"SciencesServer/app/api/enterprise/model"
|
"SciencesServer/app/api/enterprise/model"
|
||||||
"SciencesServer/app/api/manage/controller"
|
"SciencesServer/app/api/manage/controller"
|
||||||
model2 "SciencesServer/app/common/model"
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/service"
|
||||||
"SciencesServer/app/session"
|
"SciencesServer/app/session"
|
||||||
"SciencesServer/serve/orm"
|
"SciencesServer/serve/orm"
|
||||||
"errors"
|
"errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,6 +29,14 @@ type (
|
|||||||
ShelfStatus model2.ShelfStatusKind
|
ShelfStatus model2.ShelfStatusKind
|
||||||
Status model2.SysParentStatus
|
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 专利详细信息
|
||||||
PatentDetailInfo struct {
|
PatentDetailInfo struct {
|
||||||
ID string `json:"id"`
|
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
|
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 详细信息
|
// Detail 详细信息
|
||||||
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
|
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
|
||||||
mUserPatent := model.NewUserPatent()
|
mUserPatent := model.NewUserPatent()
|
||||||
|
@ -23,7 +23,7 @@ type (
|
|||||||
// ProductInfo 产品信息
|
// ProductInfo 产品信息
|
||||||
ProductInfo struct {
|
ProductInfo struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
*model2.TechnologyProduct
|
*model.TechnologyProductInfo
|
||||||
}
|
}
|
||||||
// ProductDetailInfo 产品详细信息
|
// ProductDetailInfo 产品详细信息
|
||||||
ProductDetailInfo struct {
|
ProductDetailInfo struct {
|
||||||
@ -49,44 +49,60 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// List 列表信息
|
var matchHandle = map[int]func(title string, industrys, keywords []string) (interface{}, error){
|
||||||
func (c *Product) List(title string, status, page, pageSize int) ([]*ProductInfo, 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()
|
mTechnologyProduct := model.NewTechnologyProduct()
|
||||||
|
|
||||||
where := []*model2.ModelWhereOrder{
|
where := []*model2.ModelWhere{model2.NewWhere("p.uid", c.UID), model2.NewWhere("p.status", status)}
|
||||||
&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)
|
|
||||||
|
|
||||||
|
if title != "" {
|
||||||
|
where = append(where, model2.NewWhereLike("p.title", title))
|
||||||
|
}
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
if err := model2.PagesFields(mTechnologyProduct.TechnologyProduct, &out, []string{},
|
out, err := mTechnologyProduct.Product(page, pageSize, &count, where...)
|
||||||
page, pageSize, &count, where...); err != nil {
|
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
list := make([]*ProductInfo, 0)
|
list := make([]*ProductInfo, 0)
|
||||||
|
|
||||||
for _, v := range out {
|
for _, v := range out {
|
||||||
list = append(list, &ProductInfo{
|
list = append(list, &ProductInfo{
|
||||||
ID: v.GetEncodeID(),
|
ID: v.GetEncodeID(), TechnologyProductInfo: v,
|
||||||
TechnologyProduct: v,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return list, nil
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detail 产品详情
|
// Detail 产品详情
|
||||||
@ -110,8 +126,13 @@ func (c *Product) Detail(id uint64) (*ProductDetailInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match 匹配结果
|
// 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 访问信息
|
// Visit 访问信息
|
||||||
|
@ -236,7 +236,7 @@ func (c *Identity) Switch(identity int) error {
|
|||||||
}
|
}
|
||||||
c.IdentityUID = mUserIdentity.UUID
|
c.IdentityUID = mUserIdentity.UUID
|
||||||
c.SelectIdentity = identity
|
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 nil
|
||||||
}
|
}
|
||||||
return errors.New("操作错误,无效的身份信息")
|
return errors.New("操作错误,无效的身份信息")
|
||||||
|
@ -17,13 +17,13 @@ type Withdrawal struct {
|
|||||||
type WithdrawalHandle func(session *session.Enterprise) *Withdrawal
|
type WithdrawalHandle func(session *session.Enterprise) *Withdrawal
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// WithdrawalBasic 基本信息
|
// WithdrawalInfo 基本信息
|
||||||
WithdrawalBasic struct {
|
WithdrawalInfo struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
*model.UserWithdrawalInfo
|
*model.UserWithdrawalInfo
|
||||||
}
|
}
|
||||||
// WithdrawalInfo 提现数据信息
|
// WithdrawalPageInfo 提现数据信息
|
||||||
WithdrawalInfo struct {
|
WithdrawalPageInfo struct {
|
||||||
controller.ReturnPages
|
controller.ReturnPages
|
||||||
TotalAmount float64 `json:"total_amount"`
|
TotalAmount float64 `json:"total_amount"`
|
||||||
TotalActualAmount float64 `json:"total_actual_amount"`
|
TotalActualAmount float64 `json:"total_actual_amount"`
|
||||||
@ -36,10 +36,10 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Instance 数据信息
|
// 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()
|
mUserWithdrawal := model.NewUserWithdrawal()
|
||||||
|
|
||||||
out := new(WithdrawalInfo)
|
out := new(WithdrawalPageInfo)
|
||||||
|
|
||||||
where := []*model2.ModelWhere{model2.NewWhere("w.uid", c.UID), model2.NewWhere("w.status", status)}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
list := make([]*WithdrawalBasic, 0)
|
list := make([]*WithdrawalInfo, 0)
|
||||||
|
|
||||||
for _, v := range ret {
|
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
|
out.Data = list
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"SciencesServer/app/basic/config"
|
||||||
"SciencesServer/app/common/model"
|
"SciencesServer/app/common/model"
|
||||||
"SciencesServer/serve/orm"
|
"SciencesServer/serve/orm"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -20,6 +21,39 @@ type TechnologyAchievementInfo struct {
|
|||||||
CreatedAt time.Time `json:"created_at"`
|
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 成果信息
|
// Achievement 成果信息
|
||||||
func (m *TechnologyAchievement) Achievement(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) {
|
func (m *TechnologyAchievement) Achievement(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) {
|
||||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||||
|
@ -84,7 +84,7 @@ func (a *Account) Logout(c *gin.Context) {
|
|||||||
|
|
||||||
_session := session.NewManage()
|
_session := session.NewManage()
|
||||||
|
|
||||||
_ = service.NewAuthToken(token).Auth(_session)
|
_ = service.NewAuthToken(token).Auth(config.RedisKeyForAccountManage, _session)
|
||||||
|
|
||||||
err := controller.NewAccount()(_session).Logout()
|
err := controller.NewAccount()(_session).Logout()
|
||||||
APIResponse(err)(c)
|
APIResponse(err)(c)
|
||||||
|
@ -40,7 +40,7 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
|||||||
if !mSysUser.ValidatePassword(password) {
|
if !mSysUser.ValidatePassword(password) {
|
||||||
return nil, errors.New("密码错误")
|
return nil, errors.New("密码错误")
|
||||||
}
|
}
|
||||||
_session := service.NewSession()
|
_session := session.NewManage()
|
||||||
_session.UID = mSysUser.UUID
|
_session.UID = mSysUser.UUID
|
||||||
_session.Name = mSysUser.Name
|
_session.Name = mSysUser.Name
|
||||||
_session.Mobile = mSysUser.Mobile
|
_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})
|
_session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: uid})
|
||||||
|
|
||||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, uid, _session)
|
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccountManage, uid, _session)
|
||||||
service.Publish(config.EventForAccountLoginProduce, _session.TenantID, _session.UID, equipment, ip)
|
service.Publish(config.EventForAccountLoginProduce, 0, _session.UID, equipment, ip)
|
||||||
|
|
||||||
return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
|
return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
|||||||
// Logout 退出请求
|
// Logout 退出请求
|
||||||
func (c *Account) Logout() error {
|
func (c *Account) Logout() error {
|
||||||
if c.Manage != nil && c.UID > 0 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ type AuthToken struct {
|
|||||||
Token string `json:"token"`
|
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)
|
tokenInfo := utils.JWTDecrypt(this.Token)
|
||||||
|
|
||||||
if tokenInfo == nil || len(tokenInfo) <= 0 {
|
if tokenInfo == nil || len(tokenInfo) <= 0 {
|
||||||
@ -28,7 +28,7 @@ func (this *AuthToken) Auth(session logic.ISession) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("登陆错误,Token过期")
|
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 == "" {
|
if cache == "" {
|
||||||
return errors.New("登陆错误,用户未登录或已退出")
|
return errors.New("登陆错误,用户未登录或已退出")
|
||||||
|
85
app/service/es_achievement.go
Normal file
85
app/service/es_achievement.go
Normal 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
|
||||||
|
}
|
@ -26,9 +26,6 @@ func (this *ESManage) Index() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *ESManage) Create() error {
|
func (this *ESManage) Create() error {
|
||||||
if this.Industry != "" {
|
|
||||||
this.Title = this.Industry + " - " + this.Title
|
|
||||||
}
|
|
||||||
_bytes, _ := json.Marshal(this)
|
_bytes, _ := json.Marshal(this)
|
||||||
return es.Create(this.Index(), _bytes)
|
return es.Create(this.Index(), _bytes)
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"SciencesServer/serve/es"
|
"SciencesServer/serve/es"
|
||||||
"SciencesServer/serve/logger"
|
"SciencesServer/serve/logger"
|
||||||
"SciencesServer/utils"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ESPatent struct {
|
type ESPatent struct {
|
||||||
@ -29,13 +27,11 @@ func (this *ESPatent) Search(page, pageSize int) (interface{}, error) {
|
|||||||
termParams := make(map[string]interface{}, 0)
|
termParams := make(map[string]interface{}, 0)
|
||||||
mustParams := make(map[string]interface{}, 0)
|
mustParams := make(map[string]interface{}, 0)
|
||||||
|
|
||||||
fmt.Println(utils.AnyToJSON(this))
|
|
||||||
|
|
||||||
if this.Title != "" {
|
if this.Title != "" {
|
||||||
mustParams["title"] = this.Title
|
mustParams["title"] = this.Title
|
||||||
}
|
}
|
||||||
if this.Industry != "" {
|
if this.Industry != "" {
|
||||||
termParams["title"] = this.Industry
|
termParams["industry"] = this.Industry
|
||||||
}
|
}
|
||||||
out, err := es.Search(this, this.Index(), &es.SearchParams{
|
out, err := es.Search(this, this.Index(), &es.SearchParams{
|
||||||
TermParams: termParams,
|
TermParams: termParams,
|
||||||
|
@ -6,9 +6,10 @@ const (
|
|||||||
RedisKeyForTaskQueue string = "task_queue"
|
RedisKeyForTaskQueue string = "task_queue"
|
||||||
RedisKeyForTaskQueueBody string = "task_queue_body"
|
RedisKeyForTaskQueueBody string = "task_queue_body"
|
||||||
|
|
||||||
RedisKeyForAccount string = "account"
|
RedisKeyForAccountManage string = "account:manage"
|
||||||
RedisKeyForTenant string = "tenant:instance"
|
RedisKeyForAccountEnterprise string = "account:enterprise"
|
||||||
RedisKeyForTenantKeys string = "tenant:keys"
|
RedisKeyForTenant string = "tenant:instance"
|
||||||
|
RedisKeyForTenantKeys string = "tenant:keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
api2 "SciencesServer/app/api/website/api"
|
api2 "SciencesServer/app/api/website/api"
|
||||||
"SciencesServer/app/basic/api"
|
"SciencesServer/app/basic/api"
|
||||||
"SciencesServer/app/session"
|
"SciencesServer/app/session"
|
||||||
|
"SciencesServer/config"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ func registerAdminAPI(app *gin.Engine) {
|
|||||||
g := app.Group(apiPrefix)
|
g := app.Group(apiPrefix)
|
||||||
|
|
||||||
// 登录验证
|
// 登录验证
|
||||||
g.Use(NeedLogin(session.NewManage(), AddSkipperURL([]string{
|
g.Use(NeedLogin(config.RedisKeyForAccountManage, session.NewManage(), AddSkipperURL([]string{
|
||||||
apiPrefix + "/captcha",
|
apiPrefix + "/captcha",
|
||||||
apiPrefix + "/account/login",
|
apiPrefix + "/account/login",
|
||||||
apiPrefix + "/account/logout",
|
apiPrefix + "/account/logout",
|
||||||
@ -229,7 +230,7 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
|||||||
apiPrefix := "/enterprise"
|
apiPrefix := "/enterprise"
|
||||||
g := app.Group(apiPrefix)
|
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/login",
|
||||||
apiPrefix + "/v1/account/register",
|
apiPrefix + "/v1/account/register",
|
||||||
apiPrefix + "/v1/account/authorize",
|
apiPrefix + "/v1/account/authorize",
|
||||||
|
@ -24,7 +24,7 @@ func AddSkipperURL(url ...string) SkipperURL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NeedLogin 需要登录
|
// 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) {
|
return func(c *gin.Context) {
|
||||||
if len(skipperURL) > 0 && skipperURL[0](c) {
|
if len(skipperURL) > 0 && skipperURL[0](c) {
|
||||||
c.Next()
|
c.Next()
|
||||||
@ -37,7 +37,7 @@ func NeedLogin(session logic.ISession, skipperURL ...SkipperURL) gin.HandlerFunc
|
|||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := service.NewAuthToken(token).Auth(session)
|
err := service.NewAuthToken(token).Auth(key, session)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"message": err.Error()})
|
c.JSON(http.StatusUnauthorized, gin.H{"message": err.Error()})
|
||||||
|
@ -29,3 +29,56 @@ func TestArrayStrings(t *testing.T) {
|
|||||||
t.Log(b)
|
t.Log(b)
|
||||||
t.Log(reflect.TypeOf(b).String())
|
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))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user