Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-09-14 14:59:48 +08:00
commit e0a851ba25
4 changed files with 69 additions and 51 deletions

View File

@ -6,6 +6,17 @@ Timeout: 15000 #服务超时时间
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: true
BLMService:
Url: "http://18.119.109.254:8999"
LogoCombine:
#Url: "http://192.168.1.7:8999/LogoCombine"
Url: "http://18.119.109.254:8999/LogoCombine"
AWS:
S3:
Credentials:
AccessKeyID: AKIAZB2JKUXDPNRP4YT2
Secret: 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
Token:
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -11,4 +11,19 @@ type Config struct {
SourceMysql string
Auth types.Auth
ReplicaId uint64
AWS struct {
S3 struct {
Credentials struct {
AccessKeyID string
Secret string
Token string
}
}
}
BLMService struct {
Url string
LogoCombine struct {
Url string
}
}
}

View File

@ -3,15 +3,13 @@ package logic
import (
"context"
"encoding/json"
"errors"
"fusenapi/model/gmodel"
"fusenapi/server/product-template-tag/internal/svc"
"fusenapi/server/product-template-tag/internal/types"
"fusenapi/service/repositories"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
"fusenapi/server/product-template-tag/internal/svc"
"fusenapi/server/product-template-tag/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
@ -47,31 +45,16 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
productTemplateTags []gmodel.FsProductTemplateTags
err error
)
//白板用户
if !userinfo.IsUser() && !userinfo.IsGuest() {
// 返回固定模板标签列表
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 1, "`id` DESC")
//获取用户需要渲染logo
logoInfo, err := l.svcCtx.Repositories.ImageHandle.LogoInfo(l.ctx, &repositories.LogoInfoReq{
UserId: userinfo.UserId,
GuestId: userinfo.GuestId,
})
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
return
}
} else {
//获取用户元数据
userMaterial, err := l.svcCtx.AllModels.FsUserMaterial.FindLatestOne(l.ctx, userinfo.UserId, userinfo.GuestId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get ai recommend product template tag list")
}
// 返回固定模板A1a
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 1, "`id` DESC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
}
} else {
//元数据是空的
if userMaterial.Metadata == nil {
if logoInfo.Metadata == nil || *logoInfo.Metadata == "" {
// 返回固定模板A1a
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 1, "`id` DESC")
if err != nil {
@ -81,7 +64,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
} else {
//解析元数据
var metaData map[string]interface{}
if err = json.Unmarshal(*userMaterial.Metadata, &metaData); err != nil {
if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
}
@ -97,8 +80,6 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
}
}
}
}
//资源id集合
resourceIds := make([]string, 0, 5)
for _, v := range productTemplateTags {

View File

@ -5,6 +5,9 @@ import (
"fmt"
"fusenapi/server/product-template-tag/internal/config"
"fusenapi/shared"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"net/http"
"fusenapi/initalize"
@ -20,17 +23,25 @@ type ServiceContext struct {
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
Repositories *initalize.Repositories
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql)
// StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
config := aws.Config{
Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token),
}
return &ServiceContext{
Config: c,
MysqlConn: conn,
SharedState: nil,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
BLMServiceUrl: &c.BLMService.Url,
AwsSession: session.Must(session.NewSession(&config)),
}),
}
}