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

This commit is contained in:
laodaming 2023-10-10 15:08:48 +08:00
commit 056fed40f1
6 changed files with 59 additions and 30 deletions

View File

@ -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),

View File

@ -21,9 +21,8 @@ type Config struct {
}
}
BLMService struct {
Url string
LogoCombine struct {
Url string
}
Version string
Url string
Ports []string
}
}

View File

@ -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,
}

View File

@ -22,10 +22,8 @@ type Config struct {
}
}
BLMService struct {
Version string
Url string
ImageProcess struct {
Url string
}
Version string
Url string
Ports []string
}
}

View File

@ -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)),
}),
}
}

View File

@ -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 + 1) {
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 + 1) {
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 + 1) {
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())