diff --git a/server/product-template-tag/etc/product-template-tag.yaml b/server/product-template-tag/etc/product-template-tag.yaml index b3705478..ee6eaf29 100644 --- a/server/product-template-tag/etc/product-template-tag.yaml +++ b/server/product-template-tag/etc/product-template-tag.yaml @@ -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 diff --git a/server/product-template-tag/internal/config/config.go b/server/product-template-tag/internal/config/config.go index 0fe5458e..7e5aa4b1 100644 --- a/server/product-template-tag/internal/config/config.go +++ b/server/product-template-tag/internal/config/config.go @@ -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 + } + } } diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index d5ed4cdb..4a24ce61 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -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,56 +45,39 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu productTemplateTags []gmodel.FsProductTemplateTags err error ) - //白板用户 - if !userinfo.IsUser() && !userinfo.IsGuest() { - // 返回固定模板标签列表 + //获取用户需要渲染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 + } + 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 { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") } } else { - //获取用户元数据 - userMaterial, err := l.svcCtx.AllModels.FsUserMaterial.FindLatestOne(l.ctx, userinfo.UserId, userinfo.GuestId) + //解析元数据 + var metaData map[string]interface{} + if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") + } + var templateTagNameList []string + b, _ := json.Marshal(metaData["template_tagid"]) + if err = json.Unmarshal(b, &templateTagNameList); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid") + } + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC") 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 { - // 返回固定模板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 { - //解析元数据 - var metaData map[string]interface{} - if err = json.Unmarshal(*userMaterial.Metadata, &metaData); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") - } - var templateTagNameList []string - b, _ := json.Marshal(metaData["template_tagid"]) - if err = json.Unmarshal(b, &templateTagNameList); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid") - } - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") - } - } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") } } //资源id集合 diff --git a/server/product-template-tag/internal/svc/servicecontext.go b/server/product-template-tag/internal/svc/servicecontext.go index 4491d5f5..0b418961 100644 --- a/server/product-template-tag/internal/svc/servicecontext.go +++ b/server/product-template-tag/internal/svc/servicecontext.go @@ -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" @@ -18,19 +21,27 @@ type ServiceContext struct { Config config.Config SharedState *shared.SharedState - MysqlConn *gorm.DB - AllModels *gmodel.AllModelsGen + 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)), + }), } }