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

This commit is contained in:
eson 2023-08-16 10:43:33 +08:00
commit 6fe706e9e7
63 changed files with 367 additions and 238 deletions

View File

@ -9,11 +9,9 @@ const (
//ws连接成功
WEBSOCKET_CONNECT_SUCCESS = "WEBSOCKET_CONNECT_SUCCESS"
//请求恢复为上次连接的标识
WEBSOCKET_REQUEST_RESUME_LAST_CONNECT = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT"
WEBSOCKET_REQUEST_REUSE_LAST_CONNECT = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT"
//请求恢复为上次连接的标识错误
WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR"
//请求恢复为上次连接的标识成功
WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_SUCCESS = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_SUCCESS"
//渲染前数据组装
WEBSOCKET_RENDER_IMAGE_ASSEMBLE = "WEBSOCKET_RENDER_IMAGE_ASSEMBLE"
//图片渲染

View File

@ -7,7 +7,7 @@ import (
// fs_product_template_tags 模板标签表
type FsProductTemplateTags struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID
Title *string `gorm:"default:'';" json:"title"` // 标题
Title *string `gorm:"unique_key;default:'';" json:"title"` // 标题
Cover *string `gorm:"default:'';" json:"cover"` // 封面图
Status *int64 `gorm:"default:0;" json:"status"` // 状态 1可用
CreateAt *int64 `gorm:"default:0;" json:"create_at"` // 创建时间

View File

@ -32,14 +32,18 @@ func (pt *FsProductTemplateTagsModel) GetList(ctx context.Context, page, limit i
err = db.Offset(offset).Limit(limit).Find(&resp).Error
return resp, err
}
func (pt *FsProductTemplateTagsModel) GetListByTitles(ctx context.Context, titles []string, limit int, orderBy string) (resp []FsProductTemplateTags, err error) {
if len(titles) == 0 {
func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tagNames []string, limit int, orderBy string) (resp []FsProductTemplateTags, err error) {
if len(tagNames) == 0 {
return nil, nil
}
db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`title` in (?) and `status` = ?", titles, 1)
db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`title` in (?) and `status` = ?", tagNames, 1)
if orderBy != "" {
db = db.Order(orderBy)
}
err = db.Limit(limit).Find(&resp).Error
return resp, err
}
func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string) (resp *FsProductTemplateTags, err error) {
err = pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`title` = ? and `status` = ?", tagName, 1).Take(&resp).Error
return resp, err
}

View File

@ -24,7 +24,7 @@ type FsProductTemplateV2 struct {
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除
SwitchInfo *string `gorm:"default:'';" json:"switch_info"` //
GroupOptions *string `gorm:"default:'';" json:"group_options"` //
Version *int64 `gorm:"default:0;" json:"version"` //
Version *int64 `gorm:"index;default:0;" json:"version"` // 默认1
}
type FsProductTemplateV2Model struct {
db *gorm.DB

View File

@ -111,11 +111,11 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co
}
// 获取第一个尺寸下的模板
func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx context.Context, productId int64, tagId string) (resp *FsProductTemplateV2, err error) {
func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx context.Context, productId int64, templateTag string) (resp *FsProductTemplateV2, err error) {
err = t.db.WithContext(ctx).Table(t.name+" as t").
Joins("left join fs_product_size as s on t.product_id = s.product_id").
Select("t.*").
Where("t.product_id = ? and t.tag = ? ", productId, tagId).
Where("t.product_id = ? and t.tag = ? ", productId, templateTag).
Where("t.status = ? and t.is_del = ?", 1, 0).
Where("s.status = ?", 1).
Order("s.sort ASC").

View File

@ -0,0 +1,9 @@
Name: assistant
Host: 0.0.0.0
Port: 9950
Timeout: 15000 #服务超时时间
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000
RefreshAfter: 1592000

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/utils/auth"
@ -23,7 +22,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/backend/internal/config"
"fusenapi/server/backend/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,6 +1,7 @@
Name: backend
Host: localhost
Port: 9901
Timeout: 15000 #服务超时时间
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen_backend_2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/utils/auth"
@ -23,7 +22,7 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/canteen/internal/config"
"fusenapi/server/canteen/internal/handler"
@ -23,8 +22,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: canteen
Host: localhost
Port: 9902
<<<<<<< HEAD
ReplicaId: 15
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -8,7 +8,6 @@ import (
svc2 "fusenapi/server/data-transfer/internal/svc"
"fusenapi/utils/auth"
"net/http"
"time"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -21,7 +20,6 @@ func main() {
var c config2.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: data-transfer
Host: localhost
Port: 9903
<<<<<<< HEAD
ReplicaId: 20
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -1,7 +1,11 @@
Name: home-user-auth
Host: localhost
Port: 9904
<<<<<<< HEAD
ReplicaId: 25
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
MainAddress: "http://localhost:9900"
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/home-user-auth/internal/config"
"fusenapi/server/home-user-auth/internal/handler"
@ -23,7 +22,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: inventory
Host: localhost
Port: 9905
<<<<<<< HEAD
ReplicaId: 30
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/inventory/internal/config"
"fusenapi/server/inventory/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: map-library
Host: localhost
Port: 9906
<<<<<<< HEAD
ReplicaId: 35
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/map-library/internal/config"
"fusenapi/server/map-library/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: orders
Host: localhost
Port: 9907
<<<<<<< HEAD
ReplicaId: 40
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/orders/internal/config"
"fusenapi/server/orders/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: pay
Host: 0.0.0.0
Port: 9915
<<<<<<< HEAD
ReplicaId: 45
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/utils/auth"
@ -23,7 +22,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/product-model/internal/config"
"fusenapi/server/product-model/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -2,6 +2,7 @@ Name: product-template-tag
Host: 0.0.0.0
ReplicaId: 10
Port: 9917
Timeout: 15000 #服务超时时间
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -1,6 +1,7 @@
package logic
import (
"context"
"encoding/json"
"errors"
"fusenapi/model/gmodel"
@ -8,8 +9,6 @@ import (
"fusenapi/utils/basic"
"gorm.io/gorm"
"context"
"fusenapi/server/product-template-tag/internal/svc"
"fusenapi/server/product-template-tag/internal/types"
@ -67,11 +66,13 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
}
templateTagNameList, ok := metaData["template_tagid"].([]string)
if !ok {
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`template_tagid")
var templateTagNameList []string
b, _ := json.Marshal(metaData["template_tagid"])
if err = json.Unmarshal(b, &templateTagNameList); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid")
}
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTitles(l.ctx, templateTagNameList, req.Limit, "id DESC")
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, "id DESC")
}
}
if err != nil {
@ -81,9 +82,9 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
for _, v := range productTemplateTags {
list = append(list, types.GetProductTemplateTagsRsp{
Id: v.Id,
Tag: *v.Title,
Cover: *v.Cover,
Id: v.Id,
TemplateTag: *v.Title,
Cover: *v.Cover,
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)

View File

@ -10,9 +10,9 @@ type GetProductTemplateTagsReq struct {
}
type GetProductTemplateTagsRsp struct {
Id int64 `json:"id"`
Tag string `json:"tag"`
Cover string `json:"cover"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
}
type Request struct {

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/utils/auth"
@ -23,7 +22,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -1,6 +1,7 @@
Name: product-template
Host: localhost
Port: 9910
Timeout: 15000 #服务超时时间
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/product-template/internal/config"
"fusenapi/server/product-template/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: product
Host: localhost
Port: 9908
<<<<<<< HEAD
ReplicaId: 50
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -36,7 +36,7 @@ func NewGetRecommandProductListLogic(ctx context.Context, svcCtx *svc.ServiceCon
func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRecommandProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Num = 4 //写死4个
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
req.Size = int32(image.GetCurrentSize(uint32(req.Size)))
}
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Sn)
if err != nil {

View File

@ -228,7 +228,7 @@ type OtherProductListRsp struct {
}
type GetRecommandProductListReq struct {
Size uint32 `form:"size,optional"`
Size int32 `form:"size,optional"`
Num int64 `form:"num,optional"`
Sn string `form:"sn"`
}

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/product/internal/config"
"fusenapi/server/product/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -9,12 +9,10 @@ import (
"fusenapi/initalize"
"fusenapi/server/render/internal/svc"
"fusenapi/service/repositories"
"fusenapi/utils/hash"
"fusenapi/utils/websocket_data"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
"strconv"
"time"
)
// 这里请求的py接口返回数据
@ -51,8 +49,18 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
return nil //不返回错误就删除消息
}
rabbitmq := initalize.RabbitMqHandle{}
//根据templateTag获取templateTagId(后续模板表的tag改成template_tag后可能就不需要这个步骤了)
templateTag, err := svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(ctx, parseInfo.RenderData.TemplateTag)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error("can`t find template tag info by template tag:", parseInfo.RenderData.TemplateTag)
return nil
}
logx.Error("failed to get template tag info")
return nil
}
//获取模板(模板标签下的对一个物料的的模板)
productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId))
productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", templateTag.Id))
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error("template info is not found")
@ -61,33 +69,17 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
logx.Error("failed to get template info:", err)
return nil //不返回错误就删除消息
}
time.Now().UTC()
resourceKey := hash.JsonHashKey(parseInfo)
combineParam := map[string]interface{}{
"logo_url": parseInfo.RenderData.Logo,
"website": "",
"slogan": "",
"address": "",
"phone": "",
"colors": []string{},
"template_tagid": "b1a",
"is_crop": false,
"shape": "rectangle",
"ratio": 0,
"line": "",
"other": "",
"other1": "",
}
combineParamBytes, _ := json.Marshal(combineParam)
//获取刀版图
res, err := svcCtx.Repositories.ImageHandle.LogoCombine(ctx, &repositories.LogoCombineReq{
ResourceKey: resourceKey,
TemplateId: productTemplate.Id,
CombineParam: string(combineParamBytes),
UserId: parseInfo.RenderData.UserId,
GuestId: parseInfo.RenderData.GuestId,
UserId: parseInfo.RenderData.UserId,
GuestId: parseInfo.RenderData.GuestId,
TemplateId: productTemplate.Id,
TemplateTag: parseInfo.RenderData.TemplateTag,
Website: parseInfo.RenderData.Website,
Slogan: parseInfo.RenderData.Slogan,
Address: parseInfo.RenderData.Address,
Phone: parseInfo.RenderData.Phone,
})
if err != nil {
logx.Error("合成刀版图失败:", err)
return nil
@ -99,7 +91,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
return nil
}
logx.Info("合成刀版图成功")
logx.Info("合成刀版图成功:", *res.ResourceUrl)
//获取渲染设置信息
element, err := svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(ctx, *productTemplate.ModelId)
if err != nil {

View File

@ -1,7 +1,11 @@
Name: render
Host: 0.0.0.0
Port: 9919
<<<<<<< HEAD
ReplicaId: 55
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -39,30 +39,15 @@ func NewRenderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Rend
// }
func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
/*if time.Now().Unix()-120 > req.Time || req.Time > time.Now().Unix() {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param time")
}*/
if req.Info.TaskId == "" {
if req.TaskId == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id")
}
if req.Info.Image == "" {
if req.Image == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image")
}
if req.Info.UserId == 0 && req.Info.GuestId == 0 {
if req.UserId == 0 && req.GuestId == 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid user_id or guest_id")
}
/* if req.Sign == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param sign")
}*/
//验证签名 sha256
/*notifyByte, _ := json.Marshal(req.Info)
h := sha256.New()
h.Write([]byte(fmt.Sprintf(constants.RENDER_NOTIFY_SIGN_KEY, string(notifyByte), req.Time)))
signHex := h.Sum(nil)
sign := hex.EncodeToString(signHex)
if req.Sign != sign {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign")
}*/
// 上传文件
var upload = file.Upload{
Ctx: l.ctx,
@ -70,12 +55,12 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
AwsSession: l.svcCtx.AwsSession,
}
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
FileHash: req.Info.TaskId,
FileData: req.Info.Image,
FileHash: req.TaskId,
FileData: req.Image,
UploadBucket: 1,
ApiType: 2,
UserId: req.Info.UserId,
GuestId: req.Info.GuestId,
UserId: req.UserId,
GuestId: req.GuestId,
})
if err != nil {
logx.Error(err)
@ -83,13 +68,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
}
//发送消息到对应的rabbitmq
data := websocket_data.RenderImageNotify{
TaskId: req.Info.TaskId,
TaskId: req.TaskId,
Image: uploadRes.ResourceUrl,
}
d, _ := json.Marshal(data)
if err = l.svcCtx.RabbitMq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeServiceErr, "failed to send data")
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to send data")
}
return resp.SetStatus(basic.CodeOK)
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}

View File

@ -12,12 +12,6 @@ type RequestReadImages struct {
}
type RenderNotifyReq struct {
Sign string `json:"sign"`
Time int64 `json:"time"`
Info NotifyInfo `json:"info"`
}
type NotifyInfo struct {
TaskId string `json:"task_id"` //任务id
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`

View File

@ -7,7 +7,6 @@ import (
"fusenapi/constants"
"fusenapi/server/render/consumer"
"net/http"
"time"
"fusenapi/utils/auth"
@ -26,7 +25,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -17,6 +17,7 @@ AWS:
Token:
BLMService:
Url: "http://18.119.109.254:8999"
# Url: "http://192.168.1.7:8999"
LogoCombine:
#Url: "http://192.168.1.7:8999/LogoCombine"
Url: "http://18.119.109.254:8999/LogoCombine"

View File

@ -57,11 +57,15 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth
userId = userinfo.UserId
}
res, err := l.svcCtx.Repositories.ImageHandle.LogoCombine(l.ctx, &repositories.LogoCombineReq{
ResourceKey: req.ResourceKey,
TemplateId: req.TemplateId,
CombineParam: req.CombineParam,
UserId: userId,
GuestId: guestId,
UserId: userId,
GuestId: guestId,
TemplateId: req.TemplateId,
TemplateTag: req.TemplateTag,
Website: req.Website,
Slogan: req.Slogan,
Phone: req.Phone,
Address: req.Address,
Qrcode: req.Qrcode,
})
if err != nil {

View File

@ -11,9 +11,13 @@ type ResourceInfoReq struct {
}
type LogoCombineReq struct {
ResourceKey string `form:"resource_key"` // 资源唯一标识
CombineParam string `form:"combine_param"` // 合图参数
TemplateId int64 `form:"template_id"` // 合图参数
TemplateId int64 `form:"template_id"` // 合图参数
TemplateTag string `form:"template_tag"` // 合图参数
Website string `form:"website,optional"` // 合图参数
Slogan string `form:"slogan,optional"` // 合图参数
Address string `form:"address,optional"` // 合图参数
Phone string `form:"phone,optional"` // 合图参数
Qrcode string `form:"qrcode,optional"` // 合图参数
}
type Request struct {

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/utils/auth"
@ -23,7 +22,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -1,7 +1,11 @@
Name: shopping-cart-confirmation
Host: localhost
Port: 9911
<<<<<<< HEAD
ReplicaId: 65
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
AccessSecret: fusen2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/shopping-cart-confirmation/internal/config"
"fusenapi/server/shopping-cart-confirmation/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -1,7 +1,11 @@
Name: upload
Host: localhost
Port: 9912
<<<<<<< HEAD
ReplicaId: 70
=======
Timeout: 15000 #服务超时时间
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest"
Env: "test"
Auth:
@ -16,5 +20,5 @@ AWS:
Token:
BLMService:
ImageProcess:
#Url: "http://192.168.1.7:45678/FeatureExtraction"
# Url: "http://192.168.1.7:8999/FeatureExtraction"
Url: "http://18.119.109.254:8999/FeatureExtraction"

View File

@ -1,6 +1,7 @@
package logic
import (
"fmt"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/file"
@ -44,28 +45,25 @@ func NewUploadFileBackendLogic(r *http.Request, svcCtx *svc.ServiceContext) *Upl
func (l *UploadFileBackendLogic) UploadFileBackend(req *types.UploadFileBackendReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if userinfo.IsOnlooker() {
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
// 定义用户ID和S3键名格式
var userId int64
var guestId int64
var userId int64 = 0
var guestId int64 = 0
// 检查用户是否是游客
if userinfo.IsGuest() {
// 如果是使用游客ID和游客键名格式
guestId = userinfo.GuestId
} else {
// 否则使用用户ID和用户键名格式
userId = userinfo.UserId
if userinfo != nil {
if userinfo.IsGuest() {
// 如果是使用游客ID和游客键名格式
guestId = userinfo.GuestId
} else {
// 否则使用用户ID和用户键名格式
userId = userinfo.UserId
}
}
//设置内存大小
l.r.ParseMultipartForm(32 << 20)
fileObject, _, err := l.r.FormFile("file")
fmt.Printf("%#v", fileObject)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files")

View File

@ -2,6 +2,7 @@ package logic
import (
"encoding/json"
"errors"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@ -69,11 +70,29 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
//设置内存大小
l.r.ParseMultipartForm(32 << 20)
fileObject, _, err := l.r.FormFile("file")
fileObject, fileHeader, err := l.r.FormFile("file")
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files")
}
defer fileObject.Close()
// 获取文件的MIME类型
fileType := fileHeader.Header.Get("Content-Type")
var imageTypes = make(map[string]struct{}, 7)
imageTypes["image/jpg"] = struct{}{}
imageTypes["image/jpeg"] = struct{}{}
imageTypes["image/png"] = struct{}{}
imageTypes["image/gif"] = struct{}{}
imageTypes["image/bmp"] = struct{}{}
imageTypes["image/tiff"] = struct{}{}
imageTypes["image/webp"] = struct{}{}
imageTypes["image/svg+xml"] = struct{}{}
// 判断文件类型是否为图片
_, ok := imageTypes[fileType]
if !ok {
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,file is not image")
}
// 读取数据流
ioData, err := io.ReadAll(fileObject)
@ -143,10 +162,30 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
logx.Error(err)
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail")
}
resultStr = string(b)
if resultStr == "Internal Server Error" {
return resp.SetStatus(basic.CodeFileUploadLogoErr, resultStr)
if string(b) == "Internal Server Error" {
err = errors.New("BLMService fail Internal Server Error")
logx.Error(err)
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail")
} 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")
}
if resData != nil {
if resData["code"].(string) == "200" {
resultStr = resData["data"].(string)
} else {
logx.Error(err)
return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail")
}
} else {
logx.Error(err)
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail")
}
}
var module = "logo"

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/upload/internal/config"
"fusenapi/server/upload/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -2,6 +2,7 @@ Name: webset
Host: localhost
Port: 9913
ReplicaId: 75
Timeout: 15000 #服务超时时间
SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest"
Auth:
AccessSecret: fusen2023

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"net/http"
"time"
"fusenapi/server/webset/internal/config"
"fusenapi/server/webset/internal/handler"
@ -22,7 +21,6 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -3,6 +3,7 @@ package logic
import (
"bytes"
"encoding/json"
"fmt"
"fusenapi/constants"
"fusenapi/initalize"
"fusenapi/model/gmodel"
@ -99,7 +100,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
)
isAuth, userInfo = l.checkAuth(svcCtx, r)
if !isAuth {
time.Sleep(time.Second * 2) //兼容下火狐
time.Sleep(time.Second * 1) //兼容下火狐
rsp := websocket_data.DataTransferData{
T: constants.WEBSOCKET_UNAUTH,
D: nil,
@ -134,7 +135,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
publicMutex.Lock()
defer publicMutex.Unlock()
//生成连接唯一标识
uniqueId := l.getUniqueId()
uniqueId := l.getUniqueId(userInfo)
ws := wsConnectItem{
conn: conn,
ctx: l.ctx,
@ -155,22 +156,27 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
mapConnPool.Store(uniqueId, ws)
go func() {
//把连接成功消息发回去
time.Sleep(time.Second * 2) //兼容下火狐
b := ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId)
_ = conn.WriteMessage(websocket.TextMessage, b)
time.Sleep(time.Second * 1) //兼容下火狐
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId))
}()
return ws
}
// 获取唯一id
func (l *DataTransferLogic) getUniqueId() string {
uniqueId := uuid.New().String() + time.Now().Format("20060102150405")
func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo) string {
//后面拼接上用户id
uniqueId := uuid.New().String() + getUserPart(userInfo.UserId, userInfo.GuestId)
if _, ok := mapConnPool.Load(uniqueId); ok {
uniqueId = l.getUniqueId()
uniqueId = l.getUniqueId(userInfo)
}
return uniqueId
}
// 获取用户拼接部分
func getUserPart(userId, guestId int64) string {
return fmt.Sprintf("_%d_%d", userId, guestId)
}
// 鉴权
func (l *DataTransferLogic) checkAuth(svcCtx *svc.ServiceContext, r *http.Request) (isAuth bool, userInfo *auth.UserInfo) {
// 解析JWT token,并对空用户进行判断
@ -286,7 +292,9 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
case <-w.closeChan:
return
case w.outChan <- data:
logx.Info("notify send render result to out chan")
return
case <-time.After(time.Second * 3): //阻塞超过3秒丢弃
return
}
}
@ -304,8 +312,8 @@ func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []by
func (w *wsConnectItem) dealwithReciveData(data []byte) {
var parseInfo websocket_data.DataTransferData
if err := json.Unmarshal(data, &parseInfo); err != nil {
logx.Error("invalid format of websocket message")
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data))
logx.Error("invalid format of websocket message:", err)
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data)))
return
}
d, _ := json.Marshal(parseInfo.D)
@ -315,8 +323,8 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) {
case constants.WEBSOCKET_RENDER_IMAGE:
w.renderImage(d)
//刷新重连请求恢复上次连接的标识
case constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT:
w.resumeLateConnect(d)
case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT:
w.reuseLastConnect(d)
default:
}

View File

@ -28,39 +28,48 @@ type renderImageControlChanItem struct {
func (w *wsConnectItem) renderImage(data []byte) {
var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data)))
logx.Error("invalid format of websocket render image message", err)
return
}
logx.Info("收到请求云渲染图片数据:", renderImageData)
if renderImageData.RenderId == "" {
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:render_id is empty")
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:render_id is empty"))
logx.Error("invalid format of websocket render image message:render_id is empty")
return
}
if renderImageData.RenderData.ProductId <= 0 {
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:product_id ")
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:product_id "))
logx.Error("invalid format of websocket render image message:product_id")
return
}
if renderImageData.RenderData.TemplateTagId <= 0 {
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:template_tag_id ")
logx.Error("invalid format of websocket render image message:template_tag_id")
if renderImageData.RenderData.TemplateTag == "" {
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:template_tag "))
logx.Error("invalid format of websocket render image message:template_tag")
return
}
//获取上传最近的logo
userMaterial, err := w.allModels.FsUserMaterial.FindLatestOne(w.ctx, w.userId, w.guestId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get user logo")
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get user logo"))
logx.Error("failed to get user logo")
return
}
//使用默认logo(写死一个默认)
renderImageData.RenderData.Logo = "https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/f5ccd11365099fa47a6316b1cd639f6dd6064dcd2d37c8d2fcd0a322160b33cc"
//使用默认logo(id=0)
userMaterialDefault, err := w.allModels.FsUserMaterial.FindOneById(w.ctx, 0)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "default logo is not exists"))
return
}
logx.Error("default logo is not exists")
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get default logo"))
return
}
renderImageData.RenderData.Logo = *userMaterialDefault.ResourceUrl
} else {
renderImageData.RenderData.Logo = *userMaterial.ResourceUrl
renderImageData.RenderData.UserMaterialId = userMaterial.Id
}
//用户id赋值
renderImageData.RenderData.UserId = w.userId
@ -99,7 +108,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
}
d, _ := json.Marshal(tmpData)
//发送给对应的流水线组装数据
if err := w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, d); err != nil {
if err = w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, d); err != nil {
logx.Error("发送渲染任务数据到MQ失败:", string(d), "err:", err)
return
}

View File

@ -1,27 +0,0 @@
package logic
import "fusenapi/constants"
// 刷新重连请求恢复上次连接的标识
func (w *wsConnectItem) resumeLateConnect(data []byte) {
clientId := string(data)
//id长度不对
if len(clientId) != 50 {
rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "request id is invalid")
w.sendToOutChan(rsp)
return
}
publicMutex.Lock()
defer publicMutex.Unlock()
//存在是不能给他申请重新绑定
if _, ok := mapConnPool.Load(clientId); ok {
rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "id has bound by other connect ")
w.sendToOutChan(rsp)
return
}
//重新绑定
w.uniqueId = clientId
rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_SUCCESS, clientId)
w.sendToOutChan(rsp)
return
}

View File

@ -0,0 +1,49 @@
package logic
import (
"encoding/json"
"fusenapi/constants"
"github.com/zeromicro/go-zero/core/logx"
)
// 刷新重连请求恢复上次连接的标识
func (w *wsConnectItem) reuseLastConnect(data []byte) {
logx.Info("收到请求恢复上次连接标识数据:", string(data))
var clientId string
if err := json.Unmarshal(data, &clientId); err != nil {
logx.Error(" invalid format of client id :", clientId)
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "invalid format of client id"))
return
}
lenClientId := len(clientId)
//id长度不对
if lenClientId > 100 {
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "length of client id is to long"))
return
}
//合成client后缀,不是同个后缀的不能复用
userPart := getUserPart(w.userId, w.guestId)
lenUserPart := len(userPart)
if lenClientId <= lenUserPart {
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "length of client id is to short"))
return
}
//尾部不同不能复用
if clientId[lenClientId-lenUserPart:] != userPart {
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "the client id is not belong you before"))
return
}
publicMutex.Lock()
defer publicMutex.Unlock()
//存在是不能给他申请重新绑定
if _, ok := mapConnPool.Load(clientId); ok {
rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "id has bound by other connect ")
w.sendToOutChan(rsp)
return
}
//重新绑定
w.uniqueId = clientId
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId)
w.sendToOutChan(rsp)
return
}

View File

@ -20,7 +20,7 @@ type GetProductTemplateTagsReq {
Limit int `form:"limit"`
}
type GetProductTemplateTagsRsp {
Id int64 `json:"id"`
Tag string `json:"tag"`
Cover string `json:"cover"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
}

View File

@ -281,7 +281,7 @@ type OtherProductListRsp {
}
//获取详情页推荐产品列表
type GetRecommandProductListReq {
Size uint32 `form:"size,optional"`
Size int32 `form:"size,optional"`
Num int64 `form:"num,optional"`
Sn string `form:"sn"`
}

View File

@ -26,11 +26,6 @@ service render {
//渲染完了通知接口
type RenderNotifyReq {
Sign string `json:"sign"`
Time int64 `json:"time"`
Info NotifyInfo `json:"info"`
}
type NotifyInfo {
TaskId string `json:"task_id"` //任务id
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`

View File

@ -26,8 +26,12 @@ type (
type (
LogoCombineReq {
ResourceKey string `form:"resource_key"` // 资源唯一标识
CombineParam string `form:"combine_param"` // 合图参数
TemplateId int64 `form:"template_id"` // 合图参数
TemplateId int64 `form:"template_id"` // 合图参数
TemplateTag string `form:"template_tag"` // 合图参数
Website string `form:"website,optional"` // 合图参数
Slogan string `form:"slogan,optional"` // 合图参数
Address string `form:"address,optional"` // 合图参数
Phone string `form:"phone,optional"` // 合图参数
Qrcode string `form:"qrcode,optional"` // 合图参数
}
)

View File

@ -43,11 +43,15 @@ type (
/* logo合图 */
type (
LogoCombineReq struct {
ResourceKey string `json:"resource_key"`
TemplateId int64 `json:"template_id"`
CombineParam string `json:"combine_param"`
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`
TemplateId int64 `json:"template_id"`
TemplateTag string `json:"resource_key"`
Website string `json:"website"` // 合图参数
Slogan string `json:"slogan"` // 合图参数
Address string `json:"address"` // 合图参数
Phone string `json:"phone"` // 合图参数
Qrcode string `json:"qrcode"` // 合图参数
}
LogoCombineRes struct {
ResourceId string
@ -58,7 +62,8 @@ type (
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
// 根据hash 查询数据资源
var resourceId string = hash.JsonHashKey(in.ResourceKey)
var resourceId string = hash.JsonHashKey(in)
resourceModel := gmodel.NewFsResourceModel(l.MysqlConn)
resourceInfo, err := resourceModel.FindOneById(ctx, resourceId)
if err == nil && resourceInfo.ResourceId != "" {
@ -111,8 +116,36 @@ 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(in.CombineParam), &combineParam)
json.Unmarshal([]byte(*metadata), &combineParam)
combineParam["template_tagid"] = in.TemplateTag
combineParam["website"] = in.Website
combineParam["slogan"] = in.Slogan
combineParam["phone"] = in.Phone
combineParam["address"] = in.Address
combineParam["qrcode"] = in.Qrcode
var postMap = make(map[string]interface{}, 2)
postMap["module_data"] = moduleDataMap
postMap["param_data"] = combineParam
@ -132,16 +165,35 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
logx.Error(err)
return nil, err
}
ress := string(b)
if ress == "Internal Server Error" {
logx.Error(errors.New("BLMService fail Internal Server Error"))
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(b, &resultData)
if err != nil {
err = json.Unmarshal([]byte(resultStr), &resultData)
if err != nil || resultData == nil {
logx.Error(err)
return nil, err
}

View File

@ -87,9 +87,10 @@ var (
CodeSharedStateErr = &StatusResponse{5201, "shared state server err"} // 状态机错误
CodeEmailConfirmationErr = &StatusResponse{5202, "email confirmation err"} // email 验证错误
CodeFileUploadErr = &StatusResponse{5110, "file upload err"} // 文件上传失败
CodeFileUploadLogoErr = &StatusResponse{5111, "logo upload err"} // 用户上传LOGO失败
CodeFileLogoCombineErr = &StatusResponse{5112, "logo upload err"} // 用户合图失败
CodeFileUploadErr = &StatusResponse{5110, "file upload err"} // 文件上传失败
CodeFileUploadLogoErr = &StatusResponse{5111, "logo upload err"} // 用户上传LOGO失败
CodeFileUploadLogoErrType = &StatusResponse{5111, "logo upload err file is not image"} // 用户上位LOGO失败"}
CodeFileLogoCombineErr = &StatusResponse{5112, "logo upload err"} // 用户合图失败
)
type Response struct {

View File

@ -12,16 +12,15 @@ type RenderImageReqMsg struct {
RenderData RenderData `json:"render_data"`
}
type RenderData struct {
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
ProductId int64 `json:"product_id"` //产品id
UserMaterialId int64 `json:"user_material_id"` //用户素材id
Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值)
/*Website string `json:"website"` //网站
Slogan string `json:"slogan"` //slogan
Address string `json:"address"` //地址
Phone string `json:"phone"` //电话*/
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
TemplateTag string `json:"template_tag"` //模板标签(必须)
ProductId int64 `json:"product_id"` //产品id(必须)
Website string `json:"website"` //网站(可选)
Slogan string `json:"slogan"` //slogan(可选)
Address string `json:"address"` //地址(可选)
Phone string `json:"phone"` //电话(可选)
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值)
}
// websocket发送渲染完的数据