This commit is contained in:
laodaming 2023-08-16 14:09:03 +08:00
parent 37b5cc0f30
commit 7bdd1f00af
4 changed files with 28 additions and 28 deletions

View File

@ -18,4 +18,6 @@ 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"
Url: "http://18.119.109.254:8999/LogoCombine"
Unity:
Host: http://api.fusen.3718.cn:4050

View File

@ -25,4 +25,7 @@ type Config struct {
Url string
}
}
Unity struct {
Host string
}
}

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"fusenapi/constants"
"fusenapi/initalize"
"fusenapi/utils/auth"
"fusenapi/utils/id_generator"
"fusenapi/utils/websocket_data"
@ -67,19 +66,17 @@ var (
// 每个连接的连接基本属性
type wsConnectItem struct {
conn *websocket.Conn //websocket的连接
ctx context.Context
rabbitMq *initalize.RabbitMqHandle
svcCtx *svc.ServiceContext
closeChan chan struct{} //ws连接关闭chan
isClose bool //是否已经关闭
uniqueId string //ws连接唯一标识
inChan chan []byte //接受消息缓冲通道
outChan chan []byte //发送回客户端的消息
mutex sync.Mutex //互斥锁
userId int64 //用户id
guestId int64 //游客id
renderProperty renderProperty //扩展云渲染属性
conn *websocket.Conn //websocket的连接
logic *DataTransferLogic //logic
closeChan chan struct{} //ws连接关闭chan
isClose bool //是否已经关闭
uniqueId string //ws连接唯一标识
inChan chan []byte //接受消息缓冲通道
outChan chan []byte //发送回客户端的消息
mutex sync.Mutex //互斥锁
userId int64 //用户id
guestId int64 //游客id
renderProperty renderProperty //扩展云渲染属性
}
func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.ResponseWriter, r *http.Request) {
@ -135,9 +132,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
uniqueId := l.getUniqueId(userInfo)
ws := wsConnectItem{
conn: conn,
ctx: l.ctx,
rabbitMq: l.svcCtx.RabbitMq,
svcCtx: l.svcCtx,
logic: l,
uniqueId: uniqueId,
closeChan: make(chan struct{}, 1),
inChan: make(chan []byte, 1000),

View File

@ -12,7 +12,6 @@ import (
"fusenapi/utils/websocket_data"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
"os"
"strconv"
"time"
)
@ -55,7 +54,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
return
}
//获取上传最近的logo
userMaterial, err := w.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.ctx, w.userId, w.guestId)
userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.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"))
@ -63,7 +62,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
return
}
//使用默认logo(id=0)
userMaterialDefault, err := w.svcCtx.AllModels.FsUserMaterial.FindOneById(w.ctx, 0)
userMaterialDefault, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindOneById(w.logic.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"))
@ -84,7 +83,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
//生成任务id
taskId := hash.JsonHashKey(renderImageData.RenderData)
//查询有没有缓存的资源,有就返回######################
resource, err := w.svcCtx.AllModels.FsResource.FindOneById(w.ctx, taskId)
resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error("failed to find render resource:", err)
@ -119,7 +118,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
}
}()
//根据templateTag获取templateTagId(后续模板表的tag改成template_tag后可能就不需要这个步骤了)
templateTag, err := w.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(w.ctx, info.RenderData.TemplateTag)
templateTag, err := w.logic.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(w.logic.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)
@ -129,7 +128,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
return
}
//获取模板(模板标签下的对一个物料的的模板)
productTemplate, err := w.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.ctx, info.RenderData.ProductId, fmt.Sprintf("%d", templateTag.Id))
productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.logic.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")
@ -139,7 +138,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
return
}
//获取刀版图
res, err := w.svcCtx.Repositories.ImageHandle.LogoCombine(w.ctx, &repositories.LogoCombineReq{
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &repositories.LogoCombineReq{
UserId: info.RenderData.UserId,
GuestId: info.RenderData.GuestId,
TemplateId: productTemplate.Id,
@ -162,7 +161,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
}
logx.Info("合成刀版图成功:", *res.ResourceUrl)
//获取渲染设置信息
element, err := w.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.ctx, *productTemplate.ModelId)
element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ModelId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId)
@ -238,7 +237,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
"is_thousand_face": 0,
"folder": "", //todo 千人千面需要使用
}
// todo 请求unity接口 /api/render/queue/push
//请求unity接口
url := "http://api.fusen.3718.cn:4050/api/render/queue/push"
header := make(map[string]string)
header["content-type"] = "application/json"
@ -251,11 +250,12 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
"render_data": sendData,
}
p, _ := json.Marshal(postData)
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(p), time.Second*20)
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(p), time.Second*10)
if err != nil {
logx.Error("failed to send data to unity")
return
}
logx.Info("发送到unity成功################")
}
// 操作连接中渲染任务的增加/删除