11
This commit is contained in:
		
							parent
							
								
									794c416267
								
							
						
					
					
						commit
						93795ed6d2
					
				@ -6,6 +6,17 @@ Timeout: 15000 #服务超时时间
 | 
				
			|||||||
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
 | 
					SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
 | 
				
			||||||
Log:
 | 
					Log:
 | 
				
			||||||
    Stat: true
 | 
					    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: sjCEv0JxATnPCxno2KNLm0X8oDc7srUR+4vkYhvm
 | 
				
			||||||
 | 
					            Token:
 | 
				
			||||||
Auth:
 | 
					Auth:
 | 
				
			||||||
    AccessSecret: fusen2023
 | 
					    AccessSecret: fusen2023
 | 
				
			||||||
    AccessExpire: 2592000
 | 
					    AccessExpire: 2592000
 | 
				
			||||||
 | 
				
			|||||||
@ -11,4 +11,19 @@ type Config struct {
 | 
				
			|||||||
	SourceMysql string
 | 
						SourceMysql string
 | 
				
			||||||
	Auth        types.Auth
 | 
						Auth        types.Auth
 | 
				
			||||||
	ReplicaId   uint64
 | 
						ReplicaId   uint64
 | 
				
			||||||
 | 
						AWS         struct {
 | 
				
			||||||
 | 
							S3 struct {
 | 
				
			||||||
 | 
								Credentials struct {
 | 
				
			||||||
 | 
									AccessKeyID string
 | 
				
			||||||
 | 
									Secret      string
 | 
				
			||||||
 | 
									Token       string
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						BLMService struct {
 | 
				
			||||||
 | 
							Url         string
 | 
				
			||||||
 | 
							LogoCombine struct {
 | 
				
			||||||
 | 
								Url string
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -3,15 +3,13 @@ package logic
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"fusenapi/model/gmodel"
 | 
						"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/auth"
 | 
				
			||||||
	"fusenapi/utils/basic"
 | 
						"fusenapi/utils/basic"
 | 
				
			||||||
	"fusenapi/utils/s3url_to_s3id"
 | 
						"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"
 | 
						"github.com/zeromicro/go-zero/core/logx"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@ -47,56 +45,39 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
 | 
				
			|||||||
		productTemplateTags []gmodel.FsProductTemplateTags
 | 
							productTemplateTags []gmodel.FsProductTemplateTags
 | 
				
			||||||
		err                 error
 | 
							err                 error
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	//白板用户
 | 
						//获取用户需要渲染logo
 | 
				
			||||||
	if !userinfo.IsUser() && !userinfo.IsGuest() {
 | 
						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")
 | 
							productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 1, "`id` DESC")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			logx.Error(err)
 | 
								logx.Error(err)
 | 
				
			||||||
			return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
 | 
								return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} 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 err != nil {
 | 
				
			||||||
			if !errors.Is(err, gorm.ErrRecordNotFound) {
 | 
								logx.Error(err)
 | 
				
			||||||
				logx.Error(err)
 | 
								return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
 | 
				
			||||||
				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")
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//资源id集合
 | 
						//资源id集合
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,9 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"fusenapi/server/product-template-tag/internal/config"
 | 
						"fusenapi/server/product-template-tag/internal/config"
 | 
				
			||||||
	"fusenapi/shared"
 | 
						"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"
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"fusenapi/initalize"
 | 
						"fusenapi/initalize"
 | 
				
			||||||
@ -18,19 +21,27 @@ type ServiceContext struct {
 | 
				
			|||||||
	Config      config.Config
 | 
						Config      config.Config
 | 
				
			||||||
	SharedState *shared.SharedState
 | 
						SharedState *shared.SharedState
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	MysqlConn *gorm.DB
 | 
						MysqlConn    *gorm.DB
 | 
				
			||||||
	AllModels *gmodel.AllModelsGen
 | 
						AllModels    *gmodel.AllModelsGen
 | 
				
			||||||
 | 
						Repositories *initalize.Repositories
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewServiceContext(c config.Config) *ServiceContext {
 | 
					func NewServiceContext(c config.Config) *ServiceContext {
 | 
				
			||||||
	conn := initalize.InitMysql(c.SourceMysql)
 | 
						conn := initalize.InitMysql(c.SourceMysql)
 | 
				
			||||||
	// StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
 | 
						// 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{
 | 
						return &ServiceContext{
 | 
				
			||||||
		Config:      c,
 | 
							Config:      c,
 | 
				
			||||||
		MysqlConn:   conn,
 | 
							MysqlConn:   conn,
 | 
				
			||||||
		SharedState: nil,
 | 
							SharedState: nil,
 | 
				
			||||||
		AllModels:   gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
 | 
							AllModels:   gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
 | 
				
			||||||
 | 
							Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
 | 
				
			||||||
 | 
								GormDB:        conn,
 | 
				
			||||||
 | 
								BLMServiceUrl: &c.BLMService.Url,
 | 
				
			||||||
 | 
								AwsSession:    session.Must(session.NewSession(&config)),
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user