Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
75aacbcc65
|
@ -1,5 +1,6 @@
|
|||
package constants
|
||||
|
||||
const (
|
||||
BLMServiceUrlLogoCombine string = "/LogoCombine"
|
||||
BLMServiceUrlLogoCombine string = "/LogoCombine"
|
||||
BLMServiceUrlLogoRemovebg string = "/removebg"
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Name: resource
|
||||
Host: 0.0.0.0
|
||||
Port: 9916
|
||||
Timeout: 15000 #服务超时时间(毫秒)
|
||||
Timeout: 150000 #服务超时时间(毫秒)
|
||||
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/curl"
|
||||
|
@ -50,11 +51,12 @@ type (
|
|||
GuestId int64 `json:"guest_id"`
|
||||
TemplateId int64 `json:"template_id"`
|
||||
TemplateTag string `json:"template_tag"`
|
||||
Website string `json:"website"` // 合图参数
|
||||
Slogan string `json:"slogan"` // 合图参数
|
||||
Address string `json:"address"` // 合图参数
|
||||
Phone string `json:"phone"` // 合图参数
|
||||
Qrcode string `json:"qrcode"` // 合图参数
|
||||
Website string `json:"website"` // 合图参数
|
||||
Slogan string `json:"slogan"` // 合图参数
|
||||
Address string `json:"address"` // 合图参数
|
||||
Phone string `json:"phone"` // 合图参数
|
||||
Qrcode string `json:"qrcode"` // 合图参数
|
||||
LogoUrl string `json:"logo_url"` // 合图参数
|
||||
}
|
||||
LogoCombineRes struct {
|
||||
ResourceId string
|
||||
|
@ -64,10 +66,32 @@ type (
|
|||
)
|
||||
|
||||
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
|
||||
// 查询logo最新基础信息
|
||||
var metadata *string
|
||||
userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn)
|
||||
userMaterialInfo, err := userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
userMaterialInfoDefault, err := userMaterialModel.FindOneById(ctx, 0)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
metadata = userMaterialInfoDefault.Metadata
|
||||
} else {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
metadata = userMaterialInfo.Metadata
|
||||
}
|
||||
|
||||
// 根据hash 查询数据资源
|
||||
var hashKeyData = *in
|
||||
hashKeyData.GuestId = 0
|
||||
hashKeyData.UserId = 0
|
||||
hashKeyData.LogoUrl = *userMaterialInfo.ResourceUrl
|
||||
var resourceId string = hash.JsonHashKey(hashKeyData)
|
||||
|
||||
resourceModel := gmodel.NewFsResourceModel(l.MysqlConn)
|
||||
|
@ -114,27 +138,6 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
|||
moduleDataMap["groupOptions"] = groupOptions
|
||||
moduleDataMap["materialList"] = materialList
|
||||
|
||||
// 查询logo最新基础信息
|
||||
var metadata *string
|
||||
userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn)
|
||||
userMaterialInfo, err := userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
userMaterialInfoDefault, err := userMaterialModel.FindOneById(ctx, 0)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
metadata = userMaterialInfoDefault.Metadata
|
||||
} else {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
metadata = userMaterialInfo.Metadata
|
||||
}
|
||||
|
||||
var combineParam map[string]interface{}
|
||||
json.Unmarshal([]byte(*metadata), &combineParam)
|
||||
combineParam["template_tagid"] = in.TemplateTag
|
||||
|
@ -145,13 +148,14 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
|||
combineParam["qrcode"] = in.Qrcode
|
||||
|
||||
var postMap = make(map[string]interface{}, 2)
|
||||
fmt.Println(combineParam)
|
||||
postMap["module_data"] = moduleDataMap
|
||||
postMap["param_data"] = combineParam
|
||||
postMapB, _ := json.Marshal(postMap)
|
||||
|
||||
var headerData = make(map[string]string, 1)
|
||||
headerData["Content-Type"] = "application/json"
|
||||
result, err := curl.ApiCall(*l.BLMServiceUrl+constants.BLMServiceUrlLogoCombine, "POST", headerData, strings.NewReader(string(postMapB)), time.Second*20)
|
||||
result, err := curl.ApiCall(*l.BLMServiceUrl+constants.BLMServiceUrlLogoCombine, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
|
@ -236,11 +240,71 @@ type (
|
|||
Height string `json:"height"`
|
||||
Proportion int64 `json:"proportion"`
|
||||
}
|
||||
LogoStandardRes struct{}
|
||||
LogoStandardRes struct {
|
||||
ResourceId string
|
||||
ResourceUrl string
|
||||
IsmaxProportion bool
|
||||
ImgColor []string
|
||||
}
|
||||
)
|
||||
|
||||
/* 图片裁剪 */
|
||||
func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) {
|
||||
var postMap = make(map[string]interface{}, 2)
|
||||
postMap["is_remove_bg"] = in.IsRemoveBg
|
||||
postMap["logo_file"] = in.LogoFile
|
||||
postMap["width"] = in.Width
|
||||
postMap["height"] = in.Height
|
||||
postMap["proportion"] = in.Proportion
|
||||
postMapB, _ := json.Marshal(postMap)
|
||||
|
||||
var headerData = make(map[string]string, 1)
|
||||
headerData["Content-Type"] = "application/json"
|
||||
result, err := curl.ApiCall(*l.BLMServiceUrl+constants.BLMServiceUrlLogoRemovebg, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
defer result.Body.Close()
|
||||
b, err := io.ReadAll(result.Body)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
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{}
|
||||
err = json.Unmarshal([]byte(resultStr), &resultData)
|
||||
if err != nil || resultData == nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
//$removeBg ='{"nobg_url": "/test/dIE10gGfXM_scale.png", "thumbnail_url": "/test/dIE10gGfXM_thumbnail.png", "ismax_proportion": true, "img_color": ["#000000", "#EEF5FB", "#6AAFE6", "#9ECDF1", "#298EDC", "#0C7BD1"]}'
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user