fix
This commit is contained in:
parent
b11e768550
commit
a022e5a8d9
|
@ -4,17 +4,16 @@ type RABBIT_MQ string
|
|||
|
||||
// 消息队列队列名
|
||||
const (
|
||||
//组装渲染数据队列
|
||||
RABBIT_MQ_ASSEMBLE_RENDER_DATA RABBIT_MQ = "RABBIT_MQ_ASSEMBLE_RENDER_DATA"
|
||||
//渲染结果数据队列
|
||||
RABBIT_MQ_RENDER_RESULT_DATA RABBIT_MQ = "RABBIT_MQ_RENDER_RESULT_DATA"
|
||||
//原来发送到unity渲染的队列
|
||||
RABBIT_MQ_TO_UNITY RABBIT_MQ = "newTaskQueue"
|
||||
//组装渲染数据队列
|
||||
/*RABBIT_MQ_ASSEMBLE_RENDER_DATA RABBIT_MQ = "RABBIT_MQ_ASSEMBLE_RENDER_DATA"
|
||||
//渲染结果数据队列
|
||||
RABBIT_MQ_RENDER_RESULT_DATA RABBIT_MQ = "RABBIT_MQ_RENDER_RESULT_DATA"*/
|
||||
)
|
||||
|
||||
// 队列列表
|
||||
var MqQueueArr = []RABBIT_MQ{
|
||||
RABBIT_MQ_ASSEMBLE_RENDER_DATA,
|
||||
RABBIT_MQ_RENDER_RESULT_DATA,
|
||||
RABBIT_MQ_TO_UNITY,
|
||||
/*
|
||||
RABBIT_MQ_ASSEMBLE_RENDER_DATA,
|
||||
RABBIT_MQ_RENDER_RESULT_DATA,
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -1,186 +0,0 @@
|
|||
package consumer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/render/internal/svc"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// 这里请求的py接口返回数据
|
||||
type pythonApiRsp struct {
|
||||
Id string `json:"id"` //物料模板的id
|
||||
LogoUrl string `json:"logo_url"` //logo地址
|
||||
Result string `json:"result"` //图片base64
|
||||
}
|
||||
|
||||
// 消费渲染需要组装的数据
|
||||
type MqConsumerRenderAssemble struct {
|
||||
}
|
||||
|
||||
func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("MqConsumerRenderAssemble panic:", err)
|
||||
}
|
||||
}()
|
||||
logx.Info("收到需要组装的消息:", string(data))
|
||||
var parseInfo websocket_data.AssembleRenderData
|
||||
if err := json.Unmarshal(data, &parseInfo); err != nil {
|
||||
logx.Error("MqConsumerRenderAssemble数据格式错误:", err)
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
val := ctx.Value("svcctx")
|
||||
if val == nil {
|
||||
logx.Error("svcctx is nil")
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
svcCtx, ok := val.(*svc.ServiceContext)
|
||||
if !ok {
|
||||
logx.Error("svcctx is nil!!")
|
||||
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", templateTag.Id))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("template info is not found")
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
logx.Error("failed to get template info:", err)
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
//获取刀版图
|
||||
res, err := svcCtx.Repositories.ImageHandle.LogoCombine(ctx, &repositories.LogoCombineReq{
|
||||
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
|
||||
}
|
||||
combineImage := "" //刀版图
|
||||
if res != nil && res.ResourceUrl != nil {
|
||||
combineImage = *res.ResourceUrl
|
||||
} else {
|
||||
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
|
||||
return nil
|
||||
}
|
||||
logx.Info("合成刀版图成功:", *res.ResourceUrl)
|
||||
//获取渲染设置信息
|
||||
element, err := svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(ctx, *productTemplate.ModelId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId)
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
logx.Error("failed to get element list,", err)
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
//组装数据
|
||||
refletion := -1
|
||||
if element.Refletion != nil && *element.Refletion != "" {
|
||||
refletion, err = strconv.Atoi(*element.Refletion)
|
||||
}
|
||||
//组装data数据
|
||||
var mode map[string]interface{}
|
||||
if element.Mode != nil && *element.Mode != "" {
|
||||
if err = json.Unmarshal([]byte(*element.Mode), &mode); err != nil {
|
||||
logx.Error("faile to parse element mode json:", err)
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
}
|
||||
tempData := make([]map[string]interface{}, 0, 3)
|
||||
if element.Base != nil && *element.Base != "" {
|
||||
tempData = append(tempData, map[string]interface{}{
|
||||
"name": "model",
|
||||
"data": "0," + combineImage + "," + *element.Base,
|
||||
"type": "other",
|
||||
"layer": "0",
|
||||
"is_update": 1,
|
||||
"mode": mode["model"],
|
||||
})
|
||||
}
|
||||
if element.Shadow != nil && *element.Shadow != "" {
|
||||
tempData = append(tempData, map[string]interface{}{
|
||||
"name": "shadow",
|
||||
"data": *element.Shadow,
|
||||
"type": "other",
|
||||
"layer": "0",
|
||||
"is_update": 0,
|
||||
"mode": mode["shadow"],
|
||||
})
|
||||
}
|
||||
if element.ModelP != nil && *element.ModelP != "" {
|
||||
tempData = append(tempData, map[string]interface{}{
|
||||
"name": "model_P",
|
||||
"data": "0," + *element.ModelP,
|
||||
"type": "other",
|
||||
"layer": "0",
|
||||
"is_update": 0,
|
||||
"mode": mode["model_P"],
|
||||
})
|
||||
}
|
||||
result := []interface{}{
|
||||
map[string]interface{}{
|
||||
"light": *element.Light,
|
||||
"refletion": refletion,
|
||||
"scale": *element.Scale,
|
||||
"sku_id": parseInfo.RenderData.ProductId,
|
||||
"tid": *element.Title,
|
||||
"rotation": *element.Rotation,
|
||||
"filePath": "", //todo 文件路径,针对千人千面
|
||||
"data": tempData,
|
||||
},
|
||||
}
|
||||
sendData := map[string]interface{}{
|
||||
"id": parseInfo.TaskId,
|
||||
"order_id": 0,
|
||||
"user_id": parseInfo.RenderData.UserId,
|
||||
"guest_id": parseInfo.RenderData.GuestId,
|
||||
"sku_ids": []int64{parseInfo.RenderData.ProductId},
|
||||
"tids": []string{*element.Title},
|
||||
"data": result,
|
||||
"is_thousand_face": 0,
|
||||
"folder": "", //todo 千人千面需要使用
|
||||
}
|
||||
b, _ := json.Marshal(sendData)
|
||||
if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil {
|
||||
logx.Error("发送渲染组装数据到rabbitmq失败:", err)
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
logx.Info("发送渲染组装数据到unity成功")
|
||||
//模拟发送回去(unity部署后要去掉)
|
||||
h := websocket_data.RenderImageNotify{
|
||||
TaskId: parseInfo.TaskId,
|
||||
Image: "https://fusenh5.kayue.cn:8011/storage/test/final_k8TgMUxauc_temp.png",
|
||||
}
|
||||
d, _ := json.Marshal(h)
|
||||
_ = rabbitmq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d)
|
||||
return nil
|
||||
}
|
|
@ -12,11 +12,6 @@ import (
|
|||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/render/render_notify",
|
||||
Handler: RenderNotifyHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/render/get_face_slice",
|
||||
|
|
|
@ -5,19 +5,6 @@ import (
|
|||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type RequestToUnity struct {
|
||||
}
|
||||
|
||||
type RequestReadImages struct {
|
||||
}
|
||||
|
||||
type RenderNotifyReq struct {
|
||||
TaskId string `json:"task_id"` //任务id
|
||||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/server/render/consumer"
|
||||
"net/http"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
|
@ -30,12 +27,6 @@ func main() {
|
|||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
//消费渲染前组装数据队列
|
||||
ctx1 := context.Background()
|
||||
ctx2, cancel := context.WithCancel(ctx1)
|
||||
ctx2 = context.WithValue(ctx2, "svcctx", ctx)
|
||||
defer cancel()
|
||||
go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, &consumer.MqConsumerRenderAssemble{})
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
|
|
|
@ -7,4 +7,15 @@ Auth:
|
|||
AccessSecret: fusen2023
|
||||
AccessExpire: 2592000
|
||||
RefreshAfter: 1592000
|
||||
SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672
|
||||
SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672
|
||||
AWS:
|
||||
S3:
|
||||
Credentials:
|
||||
AccessKeyID: AKIAZB2JKUXDPNRP4YT2
|
||||
Secret: sjCEv0JxATnPCxno2KNLm0X8oDc7srUR+4vkYhvm
|
||||
Token:
|
||||
BLMService:
|
||||
Url: "http://18.119.109.254:8999"
|
||||
LogoCombine:
|
||||
#Url: "http://192.168.1.7:8999/LogoCombine"
|
||||
Url: "http://18.119.109.254:8999/LogoCombine"
|
|
@ -10,4 +10,19 @@ type Config struct {
|
|||
SourceMysql string
|
||||
Auth types.Auth
|
||||
SourceRabbitMq string
|
||||
AWS struct {
|
||||
S3 struct {
|
||||
Credentials struct {
|
||||
AccessKeyID string
|
||||
Secret string
|
||||
Token string
|
||||
}
|
||||
}
|
||||
}
|
||||
BLMService struct {
|
||||
Url string
|
||||
LogoCombine struct {
|
||||
Url string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/render/internal/logic"
|
||||
"fusenapi/server/render/internal/svc"
|
||||
"fusenapi/server/render/internal/types"
|
||||
"fusenapi/server/websocket/internal/logic"
|
||||
"fusenapi/server/websocket/internal/svc"
|
||||
"fusenapi/server/websocket/internal/types"
|
||||
)
|
||||
|
||||
func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/websocket/data_transfer",
|
||||
Handler: DataTransferHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/websocket/render_notify",
|
||||
Handler: RenderNotifyHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/id_generator"
|
||||
"fusenapi/utils/websocket_data"
|
||||
|
@ -71,7 +70,7 @@ type wsConnectItem struct {
|
|||
conn *websocket.Conn //websocket的连接
|
||||
ctx context.Context
|
||||
rabbitMq *initalize.RabbitMqHandle
|
||||
allModels *gmodel.AllModelsGen
|
||||
svcCtx *svc.ServiceContext
|
||||
closeChan chan struct{} //ws连接关闭chan
|
||||
isClose bool //是否已经关闭
|
||||
uniqueId string //ws连接唯一标识
|
||||
|
@ -138,7 +137,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
|
|||
conn: conn,
|
||||
ctx: l.ctx,
|
||||
rabbitMq: l.svcCtx.RabbitMq,
|
||||
allModels: l.svcCtx.AllModels,
|
||||
svcCtx: l.svcCtx,
|
||||
uniqueId: uniqueId,
|
||||
closeChan: make(chan struct{}, 1),
|
||||
inChan: make(chan []byte, 1000),
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// 消费渲染结果数据
|
||||
type MqConsumerRenderResult struct {
|
||||
}
|
||||
|
||||
func (m *MqConsumerRenderResult) Run(ctx context.Context, data []byte) error {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("MqConsumerRenderResult panic:", err)
|
||||
}
|
||||
}()
|
||||
logx.Info("接收到MqConsumerRenderResult数据:", string(data))
|
||||
var parseInfo websocket_data.RenderImageNotify
|
||||
if err := json.Unmarshal(data, &parseInfo); err != nil {
|
||||
logx.Error("MqConsumerRenderResult data format err:", err)
|
||||
return nil //不返回错误则就删掉该消息
|
||||
}
|
||||
//遍历websocket链接把数据传进去
|
||||
mapConnPool.Range(func(key, value any) bool {
|
||||
//断言连接
|
||||
ws, ok := value.(wsConnectItem)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
//关闭标识
|
||||
if ws.isClose {
|
||||
return true
|
||||
}
|
||||
//查询有无该渲染任务
|
||||
renderId, ok := ws.renderProperty.renderImageTask[parseInfo.TaskId]
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderId,
|
||||
Image: parseInfo.Image,
|
||||
})
|
||||
//删除对应的需要渲染的图片map
|
||||
ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 0, //0删除 1添加
|
||||
TaskId: parseInfo.TaskId,
|
||||
RenderId: renderId,
|
||||
}
|
||||
//发送数据到out chan
|
||||
ws.sendToOutChan(b)
|
||||
return true
|
||||
})
|
||||
return nil
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/file"
|
||||
"fusenapi/utils/websocket_data"
|
||||
|
||||
"fusenapi/server/render/internal/svc"
|
||||
"fusenapi/server/render/internal/types"
|
||||
"context"
|
||||
|
||||
"fusenapi/server/websocket/internal/svc"
|
||||
"fusenapi/server/websocket/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
@ -66,15 +66,35 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
|
||||
}
|
||||
//发送消息到对应的rabbitmq
|
||||
data := websocket_data.RenderImageNotify{
|
||||
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.SetStatusWithMessage(basic.CodeServiceErr, "failed to send data")
|
||||
}
|
||||
//遍历websocket链接把数据传进去
|
||||
mapConnPool.Range(func(key, value any) bool {
|
||||
//断言连接
|
||||
ws, ok := value.(wsConnectItem)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
//关闭标识
|
||||
if ws.isClose {
|
||||
return true
|
||||
}
|
||||
//查询有无该渲染任务
|
||||
renderId, ok := ws.renderProperty.renderImageTask[req.TaskId]
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderId,
|
||||
Image: uploadRes.ResourceUrl,
|
||||
})
|
||||
//删除对应的需要渲染的图片map
|
||||
ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 0, //0删除 1添加
|
||||
TaskId: req.TaskId,
|
||||
RenderId: renderId,
|
||||
}
|
||||
//发送数据到out chan
|
||||
ws.sendToOutChan(b)
|
||||
return true
|
||||
})
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
}
|
|
@ -3,11 +3,14 @@ package logic
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/hash"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// 云渲染属性
|
||||
|
@ -48,7 +51,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
return
|
||||
}
|
||||
//获取上传最近的logo
|
||||
userMaterial, err := w.allModels.FsUserMaterial.FindLatestOne(w.ctx, w.userId, w.guestId)
|
||||
userMaterial, err := w.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.ctx, w.userId, w.guestId)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get user logo"))
|
||||
|
@ -56,7 +59,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
return
|
||||
}
|
||||
//使用默认logo(id=0)
|
||||
userMaterialDefault, err := w.allModels.FsUserMaterial.FindOneById(w.ctx, 0)
|
||||
userMaterialDefault, err := w.svcCtx.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"))
|
||||
|
@ -77,7 +80,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
//生成任务id
|
||||
taskId := hash.JsonHashKey(renderImageData.RenderData)
|
||||
//查询有没有缓存的资源,有就返回######################
|
||||
resource, err := w.allModels.FsResource.FindOneById(w.ctx, taskId)
|
||||
resource, err := w.svcCtx.AllModels.FsResource.FindOneById(w.ctx, taskId)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("failed to find render resource:", err)
|
||||
|
@ -100,18 +103,151 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
TaskId: taskId,
|
||||
RenderId: renderImageData.RenderId,
|
||||
}
|
||||
tmpData := websocket_data.AssembleRenderData{
|
||||
TaskId: taskId,
|
||||
RenderId: renderImageData.RenderId,
|
||||
RenderData: renderImageData.RenderData,
|
||||
}
|
||||
d, _ := json.Marshal(tmpData)
|
||||
//发送给对应的流水线组装数据
|
||||
if err = w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, d); err != nil {
|
||||
logx.Error("发送渲染任务数据到MQ失败:", string(d), "err:", err)
|
||||
//组装数据
|
||||
go w.assembleRenderData(taskId, renderImageData)
|
||||
}
|
||||
|
||||
// 组装数据发送给unity
|
||||
func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("MqConsumerRenderAssemble panic:", err)
|
||||
}
|
||||
}()
|
||||
//根据templateTag获取templateTagId(后续模板表的tag改成template_tag后可能就不需要这个步骤了)
|
||||
templateTag, err := w.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(w.ctx, info.RenderData.TemplateTag)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("can`t find template tag info by template tag:", info.RenderData.TemplateTag)
|
||||
return
|
||||
}
|
||||
logx.Error("failed to get template tag info")
|
||||
return
|
||||
}
|
||||
logx.Info("发送渲染数据到rabbitmq成功:", string(d))
|
||||
//获取模板(模板标签下的对一个物料的的模板)
|
||||
productTemplate, err := w.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.ctx, info.RenderData.ProductId, fmt.Sprintf("%d", templateTag.Id))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("template info is not found")
|
||||
return
|
||||
}
|
||||
logx.Error("failed to get template info:", err)
|
||||
return
|
||||
}
|
||||
//获取刀版图
|
||||
res, err := w.svcCtx.Repositories.ImageHandle.LogoCombine(w.ctx, &repositories.LogoCombineReq{
|
||||
UserId: info.RenderData.UserId,
|
||||
GuestId: info.RenderData.GuestId,
|
||||
TemplateId: productTemplate.Id,
|
||||
TemplateTag: info.RenderData.TemplateTag,
|
||||
Website: info.RenderData.Website,
|
||||
Slogan: info.RenderData.Slogan,
|
||||
Address: info.RenderData.Address,
|
||||
Phone: info.RenderData.Phone,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error("合成刀版图失败:", err)
|
||||
return
|
||||
}
|
||||
combineImage := "" //刀版图
|
||||
if res != nil && res.ResourceUrl != nil {
|
||||
combineImage = *res.ResourceUrl
|
||||
} else {
|
||||
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
|
||||
return
|
||||
}
|
||||
logx.Info("合成刀版图成功:", *res.ResourceUrl)
|
||||
//获取渲染设置信息
|
||||
element, err := w.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.ctx, *productTemplate.ModelId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId)
|
||||
return
|
||||
}
|
||||
logx.Error("failed to get element list,", err)
|
||||
return
|
||||
}
|
||||
//组装数据
|
||||
refletion := -1
|
||||
if element.Refletion != nil && *element.Refletion != "" {
|
||||
refletion, err = strconv.Atoi(*element.Refletion)
|
||||
}
|
||||
//组装data数据
|
||||
var mode map[string]interface{}
|
||||
if element.Mode != nil && *element.Mode != "" {
|
||||
if err = json.Unmarshal([]byte(*element.Mode), &mode); err != nil {
|
||||
logx.Error("faile to parse element mode json:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
tempData := make([]map[string]interface{}, 0, 3)
|
||||
if element.Base != nil && *element.Base != "" {
|
||||
tempData = append(tempData, map[string]interface{}{
|
||||
"name": "model",
|
||||
"data": "0," + combineImage + "," + *element.Base,
|
||||
"type": "other",
|
||||
"layer": "0",
|
||||
"is_update": 1,
|
||||
"mode": mode["model"],
|
||||
})
|
||||
}
|
||||
if element.Shadow != nil && *element.Shadow != "" {
|
||||
tempData = append(tempData, map[string]interface{}{
|
||||
"name": "shadow",
|
||||
"data": *element.Shadow,
|
||||
"type": "other",
|
||||
"layer": "0",
|
||||
"is_update": 0,
|
||||
"mode": mode["shadow"],
|
||||
})
|
||||
}
|
||||
if element.ModelP != nil && *element.ModelP != "" {
|
||||
tempData = append(tempData, map[string]interface{}{
|
||||
"name": "model_P",
|
||||
"data": "0," + *element.ModelP,
|
||||
"type": "other",
|
||||
"layer": "0",
|
||||
"is_update": 0,
|
||||
"mode": mode["model_P"],
|
||||
})
|
||||
}
|
||||
result := []interface{}{
|
||||
map[string]interface{}{
|
||||
"light": *element.Light,
|
||||
"refletion": refletion,
|
||||
"scale": *element.Scale,
|
||||
"sku_id": info.RenderData.ProductId,
|
||||
"tid": *element.Title,
|
||||
"rotation": *element.Rotation,
|
||||
"filePath": "", //todo 文件路径,针对千人千面
|
||||
"data": tempData,
|
||||
},
|
||||
}
|
||||
sendData := map[string]interface{}{
|
||||
"id": taskId,
|
||||
"order_id": 0,
|
||||
"user_id": info.RenderData.UserId,
|
||||
"guest_id": info.RenderData.GuestId,
|
||||
"sku_ids": []int64{info.RenderData.ProductId},
|
||||
"tids": []string{*element.Title},
|
||||
"data": result,
|
||||
"is_thousand_face": 0,
|
||||
"folder": "", //todo 千人千面需要使用
|
||||
}
|
||||
/*b, _ := json.Marshal(sendData)
|
||||
if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil {
|
||||
logx.Error("发送渲染组装数据到rabbitmq失败:", err)
|
||||
return nil
|
||||
}
|
||||
logx.Info("发送渲染组装数据到unity成功")*/
|
||||
// todo 请求unity接口 /api/render/queue/push
|
||||
logx.Info(sendData["id"])
|
||||
//模拟发送回去(unity部署后要去掉)
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: info.RenderId,
|
||||
Image: "https://fusenh5.kayue.cn:8011/storage/test/final_k8TgMUxauc_temp.png",
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
// 操作连接中渲染任务的增加/删除
|
||||
|
|
|
@ -4,6 +4,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/server/websocket/internal/config"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"net/http"
|
||||
|
||||
"fusenapi/initalize"
|
||||
|
@ -16,17 +19,28 @@ import (
|
|||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
|
||||
MysqlConn *gorm.DB
|
||||
AllModels *gmodel.AllModelsGen
|
||||
RabbitMq *initalize.RabbitMqHandle
|
||||
MysqlConn *gorm.DB
|
||||
AllModels *gmodel.AllModelsGen
|
||||
RabbitMq *initalize.RabbitMqHandle
|
||||
AwsSession *session.Session
|
||||
Repositories *initalize.Repositories
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
config := aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token),
|
||||
}
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
||||
Config: c,
|
||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||
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)),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,13 @@ import (
|
|||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type RenderNotifyReq struct {
|
||||
TaskId string `json:"task_id"` //任务id
|
||||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/server/websocket/internal/logic"
|
||||
"net/http"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
|
@ -30,12 +27,6 @@ func main() {
|
|||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
//消费渲染结果队列
|
||||
ctx1 := context.Background()
|
||||
ctx2, cancel := context.WithCancel(ctx1)
|
||||
ctx2 = context.WithValue(ctx2, "allmodels", ctx.AllModels)
|
||||
defer cancel()
|
||||
go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_RENDER_RESULT_DATA, &logic.MqConsumerRenderResult{})
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
|
|
|
@ -8,26 +8,8 @@ info (
|
|||
)
|
||||
|
||||
import "basic.api"
|
||||
|
||||
type RequestToUnity {
|
||||
}
|
||||
|
||||
type RequestReadImages {
|
||||
}
|
||||
|
||||
service render {
|
||||
//云渲染完了通知接口
|
||||
@handler RenderNotifyHandler
|
||||
post /api/render/render_notify(RenderNotifyReq) returns (response);
|
||||
//获取面片信息
|
||||
@handler GetFaceSliceHandler
|
||||
post /api/render/get_face_slice(request) returns (response);
|
||||
}
|
||||
|
||||
//渲染完了通知接口
|
||||
type RenderNotifyReq {
|
||||
TaskId string `json:"task_id"` //任务id
|
||||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
Image string `json:"image"`
|
||||
}
|
|
@ -12,4 +12,15 @@ service websocket {
|
|||
//websocket数据交互
|
||||
@handler DataTransferHandler
|
||||
get /api/websocket/data_transfer(request) returns (response);
|
||||
//云渲染完了通知接口
|
||||
@handler RenderNotifyHandler
|
||||
post /api/websocket/render_notify(RenderNotifyReq) returns (response);
|
||||
}
|
||||
|
||||
//渲染完了通知接口
|
||||
type RenderNotifyReq {
|
||||
TaskId string `json:"task_id"` //任务id
|
||||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
Image string `json:"image"`
|
||||
}
|
|
@ -28,20 +28,7 @@ type RenderImageRspMsg struct {
|
|||
RenderId string `json:"render_id"` //渲染id
|
||||
Image string `json:"image"` //渲染结果图片
|
||||
}
|
||||
|
||||
// 渲染服务器回调数据
|
||||
type RenderImageNotify struct {
|
||||
TaskId string `json:"task_id"`
|
||||
Image string `json:"image"`
|
||||
}
|
||||
type ThirdPartyLoginRspMsg struct {
|
||||
//websocket三方登录的通知数据
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// 发送到渲染组装的mq数据
|
||||
type AssembleRenderData struct {
|
||||
TaskId string `json:"task_id"`
|
||||
RenderId string `json:"render_id"`
|
||||
RenderData RenderData `json:"render_data"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user