From 6e8d47ae919ff8578842ecb604fbc88fd135f4e6 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 10 Oct 2023 14:58:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=AE=97=E6=B3=95=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- initalize/service.go | 11 +++-- server/resource/internal/config/config.go | 7 ++- .../resource/internal/svc/servicecontext.go | 7 +-- server/upload/internal/config/config.go | 8 ++- server/upload/internal/svc/servicecontext.go | 7 +-- service/repositories/image_handle.go | 49 +++++++++++++++---- 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/initalize/service.go b/initalize/service.go index 5b42b40a..3805f5d9 100644 --- a/initalize/service.go +++ b/initalize/service.go @@ -16,15 +16,16 @@ type Repositories struct { } type NewAllRepositorieData struct { - GormDB *gorm.DB - BLMServiceUrl *string - AwsSession *session.Session - DelayQueue *queue.DelayMessage + GormDB *gorm.DB + BLMServiceUrl *string + BLMServicePorts []string + AwsSession *session.Session + DelayQueue *queue.DelayMessage } func NewAllRepositories(newData *NewAllRepositorieData) *Repositories { return &Repositories{ - ImageHandle: repositories.NewImageHandle(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession), + ImageHandle: repositories.NewImageHandle(newData.GormDB, newData.BLMServiceUrl, newData.BLMServicePorts, newData.AwsSession), NewShoppingCart: repositories.NewShoppingCart(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession), NewResource: repositories.NewResource(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession), NewOrder: repositories.NewOrder(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession, newData.DelayQueue), diff --git a/server/resource/internal/config/config.go b/server/resource/internal/config/config.go index e8569f26..d1e72bcf 100644 --- a/server/resource/internal/config/config.go +++ b/server/resource/internal/config/config.go @@ -21,9 +21,8 @@ type Config struct { } } BLMService struct { - Url string - LogoCombine struct { - Url string - } + Version string + Url string + Ports []string } } diff --git a/server/resource/internal/svc/servicecontext.go b/server/resource/internal/svc/servicecontext.go index 75846bd7..8c968bb7 100644 --- a/server/resource/internal/svc/servicecontext.go +++ b/server/resource/internal/svc/servicecontext.go @@ -42,9 +42,10 @@ func NewServiceContext(c config.Config) *ServiceContext { RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), AwsSession: session.Must(session.NewSession(&config)), Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ - GormDB: initalize.InitMysql(c.SourceMysql), - BLMServiceUrl: &c.BLMService.Url, - AwsSession: session.Must(session.NewSession(&config)), + GormDB: initalize.InitMysql(c.SourceMysql), + BLMServiceUrl: &c.BLMService.Url, + BLMServicePorts: c.BLMService.Ports, + AwsSession: session.Must(session.NewSession(&config)), }), Tracing: middleware.NewTracingMiddleware().Handle, } diff --git a/server/upload/internal/config/config.go b/server/upload/internal/config/config.go index ad24a1cd..43af4859 100644 --- a/server/upload/internal/config/config.go +++ b/server/upload/internal/config/config.go @@ -22,10 +22,8 @@ type Config struct { } } BLMService struct { - Version string - Url string - ImageProcess struct { - Url string - } + Version string + Url string + Ports []string } } diff --git a/server/upload/internal/svc/servicecontext.go b/server/upload/internal/svc/servicecontext.go index 6f9c644a..dbd93498 100644 --- a/server/upload/internal/svc/servicecontext.go +++ b/server/upload/internal/svc/servicecontext.go @@ -41,9 +41,10 @@ func NewServiceContext(c config.Config) *ServiceContext { AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), AwsSession: session.Must(session.NewSession(&config)), Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ - GormDB: initalize.InitMysql(c.SourceMysql), - BLMServiceUrl: &c.BLMService.Url, - AwsSession: session.Must(session.NewSession(&config)), + GormDB: initalize.InitMysql(c.SourceMysql), + BLMServiceUrl: &c.BLMService.Url, + BLMServicePorts: c.BLMService.Ports, + AwsSession: session.Must(session.NewSession(&config)), }), } } diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 9c8c647e..2cef8578 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/curl" @@ -18,19 +19,23 @@ import ( "gorm.io/gorm" ) -func NewImageHandle(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session) ImageHandle { +var globalBLMServiceIndex int + +func NewImageHandle(gormDB *gorm.DB, bLMServiceUrl *string, bLMServicePorts []string, awsSession *session.Session) ImageHandle { return &defaultImageHandle{ - MysqlConn: gormDB, - BLMServiceUrl: bLMServiceUrl, - AwsSession: awsSession, + MysqlConn: gormDB, + BLMServiceUrl: bLMServiceUrl, + BLMServicePorts: bLMServicePorts, + AwsSession: awsSession, } } type ( defaultImageHandle struct { - MysqlConn *gorm.DB - BLMServiceUrl *string - AwsSession *session.Session + MysqlConn *gorm.DB + BLMServiceUrl *string + BLMServicePorts []string + AwsSession *session.Session } ImageHandle = interface { @@ -168,6 +173,14 @@ type ( ) func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) { + fmt.Println("算法请求轮训下标:", globalBLMServiceIndex) + var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex] + if len(l.BLMServicePorts) == globalBLMServiceIndex { + globalBLMServiceIndex = 0 + } else { + globalBLMServiceIndex = globalBLMServiceIndex + 1 + } + var resultBLM constants.BLMServiceUrlResult postMap := make(map[string]string, 2) postMap["logo_url"] = in.LogoUrl @@ -175,7 +188,7 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq logc.Infof(ctx, "算法请求--LOGO基础信息--开始时间:%v", time.Now().UTC()) err := curl.NewClient(ctx, &curl.Config{ - BaseUrl: *l.BLMServiceUrl, + BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort, Url: constants.BLMServiceUrlLogoFeatureExtraction, }).PostJson(postMap, &resultBLM) logc.Infof(ctx, "算法请求--LOGO基础信息--结束时间:%v", time.Now().UTC()) @@ -226,6 +239,14 @@ type TemplateTagColor struct { } func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { + fmt.Println("算法请求轮训下标:", globalBLMServiceIndex) + var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex] + if len(l.BLMServicePorts) == globalBLMServiceIndex { + globalBLMServiceIndex = 0 + } else { + globalBLMServiceIndex = globalBLMServiceIndex + 1 + } + logoResourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(in.LogoUrl) if logoResourceId == "" { return nil, errors.New("invalid logo url") @@ -319,7 +340,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq var resultBLM constants.BLMServiceUrlResult err = curl.NewClient(ctx, &curl.Config{ - BaseUrl: *l.BLMServiceUrl, + BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort, Url: constants.BLMServiceUrlLogoCombine, RequireTimeout: time.Second * 15, }).PostJson(postMap, &resultBLM) @@ -409,6 +430,14 @@ type ( /* 图片裁剪 */ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) { + fmt.Println("算法请求轮训下标:", globalBLMServiceIndex) + var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex] + if len(l.BLMServicePorts) == globalBLMServiceIndex { + globalBLMServiceIndex = 0 + } else { + globalBLMServiceIndex = globalBLMServiceIndex + 1 + } + var ismaxProportion bool var imgColor []string var logoStandardMetaData LogoStandardMetaData @@ -453,7 +482,7 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR logc.Infof(ctx, "算法请求--去背景--开始时间:%v", time.Now().UTC()) err = curl.NewClient(ctx, &curl.Config{ - BaseUrl: *l.BLMServiceUrl, + BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort, Url: constants.BLMServiceUrlLogoRemovebg, }).PostJson(postMap, &resultBLM) logc.Infof(ctx, "算法请求--去背景--结束时间:%v", time.Now().UTC())