fix:裁剪业务逻辑调整
This commit is contained in:
parent
c942855683
commit
89d8a8963c
|
@ -80,6 +80,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
||||||
Source: req.Source,
|
Source: req.Source,
|
||||||
Refresh: req.Refresh,
|
Refresh: req.Refresh,
|
||||||
Metadata: req.Metadata,
|
Metadata: req.Metadata,
|
||||||
|
ResourceId: req.ResourceId,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/service/repositories"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/curl"
|
|
||||||
"fusenapi/utils/file"
|
"fusenapi/utils/file"
|
||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
@ -126,13 +122,25 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||||
Source: "upload-logo",
|
Source: "upload-logo",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var logoUrl string
|
||||||
|
|
||||||
// 是否去背景
|
// 是否去背景
|
||||||
if req.IsRemoveBg == 1 {
|
if req.IsRemoveBg == 1 {
|
||||||
// res, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{})
|
resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoStandard(l.ctx, &repositories.LogoStandardReq{
|
||||||
|
LogoFile: uploadRes.ResourceUrl,
|
||||||
|
IsRemoveBg: "true",
|
||||||
|
Width: "0",
|
||||||
|
Height: "0",
|
||||||
|
Proportion: "100",
|
||||||
|
})
|
||||||
|
logoUrl = resLogoStandard.ResourceUrl
|
||||||
|
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return resp.SetStatus(basic.CodeServiceErr)
|
logx.Error(err)
|
||||||
// }
|
return resp.SetStatus(basic.CodeServiceErr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logoUrl = uploadRes.ResourceUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -140,8 +148,6 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||||
return resp.SetStatus(basic.CodeFileUploadErr, "upload file failed")
|
return resp.SetStatus(basic.CodeFileUploadErr, "upload file failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
logx.Infof("上传logo请求算法--开始时间:%v", time.Now())
|
|
||||||
|
|
||||||
var logoWidth int64
|
var logoWidth int64
|
||||||
var logoHeight int64
|
var logoHeight int64
|
||||||
// 查看sku是否存在
|
// 查看sku是否存在
|
||||||
|
@ -165,52 +171,17 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||||
var resultStr string
|
var resultStr string
|
||||||
|
|
||||||
var postMap = make(map[string]string, 1)
|
var postMap = make(map[string]string, 1)
|
||||||
postMap["logo_url"] = uploadRes.ResourceUrl
|
postMap["logo_url"] = logoUrl
|
||||||
postMapB, _ := json.Marshal(postMap)
|
|
||||||
fmt.Println(string(postMapB))
|
|
||||||
|
|
||||||
var headerData = make(map[string]string, 1)
|
resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{
|
||||||
headerData["Content-Type"] = "application/json"
|
LogoUrl: logoUrl,
|
||||||
result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5)
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 01")
|
return resp.SetStatus(basic.CodeServiceErr)
|
||||||
}
|
|
||||||
defer result.Body.Close()
|
|
||||||
b, err := io.ReadAll(result.Body)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 02")
|
|
||||||
}
|
|
||||||
|
|
||||||
logx.Infof("上传logo请求算法--结束时间:%v", time.Now())
|
|
||||||
logx.Infof("上传logo请求算法--返回结果:%v", string(b))
|
|
||||||
|
|
||||||
if string(b) == "Internal Server Error" {
|
|
||||||
err = errors.New("BLMService fail Internal Server Error")
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 03")
|
|
||||||
} else {
|
|
||||||
var resData map[string]interface{}
|
|
||||||
err = json.Unmarshal(b, &resData)
|
|
||||||
if err != nil || resData == nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 04")
|
|
||||||
}
|
|
||||||
|
|
||||||
if resData != nil {
|
|
||||||
if resData["code"].(string) == "200" {
|
|
||||||
resultStr = resData["data"].(string)
|
|
||||||
} else {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail 05")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 06")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
resultStr = resLogoStandard.Res
|
||||||
|
|
||||||
var module = "logo"
|
var module = "logo"
|
||||||
var nowTime = time.Now().Unix()
|
var nowTime = time.Now().Unix()
|
||||||
|
|
|
@ -23,6 +23,7 @@ type UploadFileBaseReq struct {
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
Source string `form:"source"` // 上传来源
|
Source string `form:"source"` // 上传来源
|
||||||
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
||||||
|
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadLogoReq struct {
|
type UploadLogoReq struct {
|
||||||
|
|
|
@ -68,6 +68,7 @@ type (
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
Source string `form:"source"` // 上传来源
|
Source string `form:"source"` // 上传来源
|
||||||
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
||||||
|
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,11 @@ 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"
|
||||||
"fusenapi/utils/file"
|
"fusenapi/utils/file"
|
||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
"io"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -51,7 +47,9 @@ type (
|
||||||
LogoInfoSetReq struct {
|
LogoInfoSetReq struct {
|
||||||
LogoUrl string `json:"logo_url"`
|
LogoUrl string `json:"logo_url"`
|
||||||
}
|
}
|
||||||
LogoInfoSetRes struct{}
|
LogoInfoSetRes struct {
|
||||||
|
Res string `json:"res"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) {
|
func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) {
|
||||||
|
@ -59,14 +57,19 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq
|
||||||
postMap := make(map[string]string, 1)
|
postMap := make(map[string]string, 1)
|
||||||
postMap["logo_url"] = in.LogoUrl
|
postMap["logo_url"] = in.LogoUrl
|
||||||
|
|
||||||
_, err := curl.NewClient(ctx, &curl.Config{
|
err := curl.NewClient(ctx, &curl.Config{
|
||||||
BaseUrl: *l.BLMServiceUrl,
|
BaseUrl: *l.BLMServiceUrl,
|
||||||
Url: constants.BLMServiceUrlLogoCombine,
|
Url: constants.BLMServiceUrlLogoCombine,
|
||||||
}).PostForm(postMap, &resultBLM)
|
}).PostJson(postMap, &resultBLM)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if resultBLM.Code != "200" {
|
||||||
|
err = errors.New(resultBLM.Msg)
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,9 +169,6 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
||||||
groupOptions = templateInfo["groupOptions"].(map[string]interface{})
|
groupOptions = templateInfo["groupOptions"].(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("合图开始时间:", time.Now())
|
|
||||||
logx.Infof("合图请求算法--开始时间:%v", time.Now())
|
|
||||||
|
|
||||||
var moduleDataMap = make(map[string]interface{}, 4)
|
var moduleDataMap = make(map[string]interface{}, 4)
|
||||||
moduleDataMap["id"] = productTemplateV2Info.Id
|
moduleDataMap["id"] = productTemplateV2Info.Id
|
||||||
moduleDataMap["material"] = productTemplateV2Info.MaterialImg
|
moduleDataMap["material"] = productTemplateV2Info.MaterialImg
|
||||||
|
@ -185,54 +185,27 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
||||||
combineParam["qrcode"] = in.Qrcode
|
combineParam["qrcode"] = in.Qrcode
|
||||||
|
|
||||||
var postMap = make(map[string]interface{}, 2)
|
var postMap = make(map[string]interface{}, 2)
|
||||||
fmt.Println(combineParam)
|
|
||||||
postMap["module_data"] = moduleDataMap
|
postMap["module_data"] = moduleDataMap
|
||||||
postMap["param_data"] = combineParam
|
postMap["param_data"] = combineParam
|
||||||
postMapB, _ := json.Marshal(postMap)
|
|
||||||
|
|
||||||
var headerData = make(map[string]string, 1)
|
var resultBLM constants.BLMServiceUrlResult
|
||||||
headerData["Content-Type"] = "application/json"
|
err = curl.NewClient(ctx, &curl.Config{
|
||||||
result, err := curl.ApiCall(*l.BLMServiceUrl+constants.BLMServiceUrlLogoCombine, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5)
|
BaseUrl: *l.BLMServiceUrl,
|
||||||
|
Url: constants.BLMServiceUrlLogoCombine,
|
||||||
|
}).PostJson(postMap, &resultBLM)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer result.Body.Close()
|
|
||||||
b, err := io.ReadAll(result.Body)
|
if resultBLM.Code != "200" {
|
||||||
if err != nil {
|
err = errors.New(resultBLM.Msg)
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
logx.Infof("合图请求算法--结束时间:%v", time.Now())
|
var resultStr string = resultBLM.Data.(string)
|
||||||
|
|
||||||
var resultStr string
|
|
||||||
if string(b) == "Internal Server Error" {
|
|
||||||
err = errors.New("BLMService fail Internal Server Error")
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
var resData map[string]interface{}
|
|
||||||
err = json.Unmarshal(b, &resData)
|
|
||||||
if err != nil || resData == nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resData != nil {
|
|
||||||
if resData["code"].(string) == "200" {
|
|
||||||
resultStr = resData["data"].(string)
|
|
||||||
} else {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var resultData map[string]interface{}
|
var resultData map[string]interface{}
|
||||||
err = json.Unmarshal([]byte(resultStr), &resultData)
|
err = json.Unmarshal([]byte(resultStr), &resultData)
|
||||||
if err != nil || resultData == nil {
|
if err != nil || resultData == nil {
|
||||||
|
@ -240,12 +213,6 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("合图结束时间:", time.Now())
|
|
||||||
// {
|
|
||||||
// id: "",
|
|
||||||
// logo_url:"https://s3.amazon.com/xxxx",
|
|
||||||
// result: "$saa541afaldjaldjasldjsadjsapsaasda"
|
|
||||||
// }
|
|
||||||
var fileBase = resultData["result"].(string)
|
var fileBase = resultData["result"].(string)
|
||||||
|
|
||||||
// 上传文件
|
// 上传文件
|
||||||
|
@ -347,6 +314,13 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resultBLM.Code != "200" {
|
||||||
|
err = errors.New(resultBLM.Msg)
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var resultStr string = resultBLM.Data.(string)
|
var resultStr string = resultBLM.Data.(string)
|
||||||
var resultData map[string]interface{}
|
var resultData map[string]interface{}
|
||||||
err = json.Unmarshal([]byte(resultStr), &resultData)
|
err = json.Unmarshal([]byte(resultStr), &resultData)
|
||||||
|
|
|
@ -22,6 +22,7 @@ type Upload struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadBaseReq struct {
|
type UploadBaseReq struct {
|
||||||
|
ResourceId string
|
||||||
Refresh int64
|
Refresh int64
|
||||||
Source string
|
Source string
|
||||||
FileHash string
|
FileHash string
|
||||||
|
@ -71,15 +72,16 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
|
||||||
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) {
|
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) {
|
||||||
var resourceInfo *gmodel.FsResource
|
var resourceInfo *gmodel.FsResource
|
||||||
|
|
||||||
if req.Refresh == 0 {
|
if req.ResourceId == "" {
|
||||||
err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
|
err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Refresh == 0 && err == nil && resourceInfo.ResourceId != "" {
|
if req.ResourceId == "" && err == nil && resourceInfo.ResourceId != "" {
|
||||||
uploadBaseRes.Status = 1
|
uploadBaseRes.Status = 1
|
||||||
uploadBaseRes.ResourceId = resourceId
|
uploadBaseRes.ResourceId = resourceId
|
||||||
uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl
|
uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl
|
||||||
} else {
|
} else {
|
||||||
|
resourceId = req.ResourceId
|
||||||
dist, contentType, err := FileBase64ToByte(req.FileData)
|
dist, contentType, err := FileBase64ToByte(req.FileData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user