Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
056fed40f1
@ -16,15 +16,16 @@ type Repositories struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type NewAllRepositorieData struct {
|
type NewAllRepositorieData struct {
|
||||||
GormDB *gorm.DB
|
GormDB *gorm.DB
|
||||||
BLMServiceUrl *string
|
BLMServiceUrl *string
|
||||||
AwsSession *session.Session
|
BLMServicePorts []string
|
||||||
DelayQueue *queue.DelayMessage
|
AwsSession *session.Session
|
||||||
|
DelayQueue *queue.DelayMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAllRepositories(newData *NewAllRepositorieData) *Repositories {
|
func NewAllRepositories(newData *NewAllRepositorieData) *Repositories {
|
||||||
return &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),
|
NewShoppingCart: repositories.NewShoppingCart(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
|
||||||
NewResource: repositories.NewResource(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),
|
NewOrder: repositories.NewOrder(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession, newData.DelayQueue),
|
||||||
|
@ -21,9 +21,8 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BLMService struct {
|
BLMService struct {
|
||||||
Url string
|
Version string
|
||||||
LogoCombine struct {
|
Url string
|
||||||
Url string
|
Ports []string
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,9 +42,10 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
||||||
AwsSession: session.Must(session.NewSession(&config)),
|
AwsSession: session.Must(session.NewSession(&config)),
|
||||||
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
||||||
GormDB: initalize.InitMysql(c.SourceMysql),
|
GormDB: initalize.InitMysql(c.SourceMysql),
|
||||||
BLMServiceUrl: &c.BLMService.Url,
|
BLMServiceUrl: &c.BLMService.Url,
|
||||||
AwsSession: session.Must(session.NewSession(&config)),
|
BLMServicePorts: c.BLMService.Ports,
|
||||||
|
AwsSession: session.Must(session.NewSession(&config)),
|
||||||
}),
|
}),
|
||||||
Tracing: middleware.NewTracingMiddleware().Handle,
|
Tracing: middleware.NewTracingMiddleware().Handle,
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,8 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BLMService struct {
|
BLMService struct {
|
||||||
Version string
|
Version string
|
||||||
Url string
|
Url string
|
||||||
ImageProcess struct {
|
Ports []string
|
||||||
Url string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,10 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||||
AwsSession: session.Must(session.NewSession(&config)),
|
AwsSession: session.Must(session.NewSession(&config)),
|
||||||
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
||||||
GormDB: initalize.InitMysql(c.SourceMysql),
|
GormDB: initalize.InitMysql(c.SourceMysql),
|
||||||
BLMServiceUrl: &c.BLMService.Url,
|
BLMServiceUrl: &c.BLMService.Url,
|
||||||
AwsSession: session.Must(session.NewSession(&config)),
|
BLMServicePorts: c.BLMService.Ports,
|
||||||
|
AwsSession: session.Must(session.NewSession(&config)),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/curl"
|
"fusenapi/utils/curl"
|
||||||
@ -18,19 +19,23 @@ import (
|
|||||||
"gorm.io/gorm"
|
"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{
|
return &defaultImageHandle{
|
||||||
MysqlConn: gormDB,
|
MysqlConn: gormDB,
|
||||||
BLMServiceUrl: bLMServiceUrl,
|
BLMServiceUrl: bLMServiceUrl,
|
||||||
AwsSession: awsSession,
|
BLMServicePorts: bLMServicePorts,
|
||||||
|
AwsSession: awsSession,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
defaultImageHandle struct {
|
defaultImageHandle struct {
|
||||||
MysqlConn *gorm.DB
|
MysqlConn *gorm.DB
|
||||||
BLMServiceUrl *string
|
BLMServiceUrl *string
|
||||||
AwsSession *session.Session
|
BLMServicePorts []string
|
||||||
|
AwsSession *session.Session
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageHandle = interface {
|
ImageHandle = interface {
|
||||||
@ -168,6 +173,14 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) {
|
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
|
var resultBLM constants.BLMServiceUrlResult
|
||||||
postMap := make(map[string]string, 2)
|
postMap := make(map[string]string, 2)
|
||||||
postMap["logo_url"] = in.LogoUrl
|
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())
|
logc.Infof(ctx, "算法请求--LOGO基础信息--开始时间:%v", time.Now().UTC())
|
||||||
err := curl.NewClient(ctx, &curl.Config{
|
err := curl.NewClient(ctx, &curl.Config{
|
||||||
BaseUrl: *l.BLMServiceUrl,
|
BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort,
|
||||||
Url: constants.BLMServiceUrlLogoFeatureExtraction,
|
Url: constants.BLMServiceUrlLogoFeatureExtraction,
|
||||||
}).PostJson(postMap, &resultBLM)
|
}).PostJson(postMap, &resultBLM)
|
||||||
logc.Infof(ctx, "算法请求--LOGO基础信息--结束时间:%v", time.Now().UTC())
|
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) {
|
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)
|
logoResourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(in.LogoUrl)
|
||||||
if logoResourceId == "" {
|
if logoResourceId == "" {
|
||||||
return nil, errors.New("invalid logo url")
|
return nil, errors.New("invalid logo url")
|
||||||
@ -319,7 +340,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
|||||||
|
|
||||||
var resultBLM constants.BLMServiceUrlResult
|
var resultBLM constants.BLMServiceUrlResult
|
||||||
err = curl.NewClient(ctx, &curl.Config{
|
err = curl.NewClient(ctx, &curl.Config{
|
||||||
BaseUrl: *l.BLMServiceUrl,
|
BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort,
|
||||||
Url: constants.BLMServiceUrlLogoCombine,
|
Url: constants.BLMServiceUrlLogoCombine,
|
||||||
RequireTimeout: time.Second * 15,
|
RequireTimeout: time.Second * 15,
|
||||||
}).PostJson(postMap, &resultBLM)
|
}).PostJson(postMap, &resultBLM)
|
||||||
@ -409,6 +430,14 @@ type (
|
|||||||
|
|
||||||
/* 图片裁剪 */
|
/* 图片裁剪 */
|
||||||
func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) {
|
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 ismaxProportion bool
|
||||||
var imgColor []string
|
var imgColor []string
|
||||||
var logoStandardMetaData LogoStandardMetaData
|
var logoStandardMetaData LogoStandardMetaData
|
||||||
@ -453,7 +482,7 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR
|
|||||||
|
|
||||||
logc.Infof(ctx, "算法请求--去背景--开始时间:%v", time.Now().UTC())
|
logc.Infof(ctx, "算法请求--去背景--开始时间:%v", time.Now().UTC())
|
||||||
err = curl.NewClient(ctx, &curl.Config{
|
err = curl.NewClient(ctx, &curl.Config{
|
||||||
BaseUrl: *l.BLMServiceUrl,
|
BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort,
|
||||||
Url: constants.BLMServiceUrlLogoRemovebg,
|
Url: constants.BLMServiceUrlLogoRemovebg,
|
||||||
}).PostJson(postMap, &resultBLM)
|
}).PostJson(postMap, &resultBLM)
|
||||||
logc.Infof(ctx, "算法请求--去背景--结束时间:%v", time.Now().UTC())
|
logc.Infof(ctx, "算法请求--去背景--结束时间:%v", time.Now().UTC())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user