fix
This commit is contained in:
parent
37b5cc0f30
commit
7bdd1f00af
|
@ -18,4 +18,6 @@ BLMService:
|
||||||
Url: "http://18.119.109.254:8999"
|
Url: "http://18.119.109.254:8999"
|
||||||
LogoCombine:
|
LogoCombine:
|
||||||
#Url: "http://192.168.1.7: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
|
|
@ -25,4 +25,7 @@ type Config struct {
|
||||||
Url string
|
Url string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Unity struct {
|
||||||
|
Host string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/initalize"
|
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/id_generator"
|
"fusenapi/utils/id_generator"
|
||||||
"fusenapi/utils/websocket_data"
|
"fusenapi/utils/websocket_data"
|
||||||
|
@ -67,19 +66,17 @@ var (
|
||||||
|
|
||||||
// 每个连接的连接基本属性
|
// 每个连接的连接基本属性
|
||||||
type wsConnectItem struct {
|
type wsConnectItem struct {
|
||||||
conn *websocket.Conn //websocket的连接
|
conn *websocket.Conn //websocket的连接
|
||||||
ctx context.Context
|
logic *DataTransferLogic //logic
|
||||||
rabbitMq *initalize.RabbitMqHandle
|
closeChan chan struct{} //ws连接关闭chan
|
||||||
svcCtx *svc.ServiceContext
|
isClose bool //是否已经关闭
|
||||||
closeChan chan struct{} //ws连接关闭chan
|
uniqueId string //ws连接唯一标识
|
||||||
isClose bool //是否已经关闭
|
inChan chan []byte //接受消息缓冲通道
|
||||||
uniqueId string //ws连接唯一标识
|
outChan chan []byte //发送回客户端的消息
|
||||||
inChan chan []byte //接受消息缓冲通道
|
mutex sync.Mutex //互斥锁
|
||||||
outChan chan []byte //发送回客户端的消息
|
userId int64 //用户id
|
||||||
mutex sync.Mutex //互斥锁
|
guestId int64 //游客id
|
||||||
userId int64 //用户id
|
renderProperty renderProperty //扩展云渲染属性
|
||||||
guestId int64 //游客id
|
|
||||||
renderProperty renderProperty //扩展云渲染属性
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.ResponseWriter, r *http.Request) {
|
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)
|
uniqueId := l.getUniqueId(userInfo)
|
||||||
ws := wsConnectItem{
|
ws := wsConnectItem{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
ctx: l.ctx,
|
logic: l,
|
||||||
rabbitMq: l.svcCtx.RabbitMq,
|
|
||||||
svcCtx: l.svcCtx,
|
|
||||||
uniqueId: uniqueId,
|
uniqueId: uniqueId,
|
||||||
closeChan: make(chan struct{}, 1),
|
closeChan: make(chan struct{}, 1),
|
||||||
inChan: make(chan []byte, 1000),
|
inChan: make(chan []byte, 1000),
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fusenapi/utils/websocket_data"
|
"fusenapi/utils/websocket_data"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -55,7 +54,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//获取上传最近的logo
|
//获取上传最近的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 err != nil {
|
||||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
w.sendToOutChan(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"))
|
||||||
|
@ -63,7 +62,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//使用默认logo(id=0)
|
//使用默认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 err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "default logo is not exists"))
|
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
|
//生成任务id
|
||||||
taskId := hash.JsonHashKey(renderImageData.RenderData)
|
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 err != nil {
|
||||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error("failed to find render resource:", err)
|
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获取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 err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error("can`t find template tag info by template tag:", info.RenderData.TemplateTag)
|
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
|
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 err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error("template info is not found")
|
logx.Error("template info is not found")
|
||||||
|
@ -139,7 +138,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
|
||||||
return
|
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,
|
UserId: info.RenderData.UserId,
|
||||||
GuestId: info.RenderData.GuestId,
|
GuestId: info.RenderData.GuestId,
|
||||||
TemplateId: productTemplate.Id,
|
TemplateId: productTemplate.Id,
|
||||||
|
@ -162,7 +161,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
|
||||||
}
|
}
|
||||||
logx.Info("合成刀版图成功:", *res.ResourceUrl)
|
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 err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId)
|
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,
|
"is_thousand_face": 0,
|
||||||
"folder": "", //todo 千人千面需要使用
|
"folder": "", //todo 千人千面需要使用
|
||||||
}
|
}
|
||||||
// todo 请求unity接口 /api/render/queue/push
|
//请求unity接口
|
||||||
url := "http://api.fusen.3718.cn:4050/api/render/queue/push"
|
url := "http://api.fusen.3718.cn:4050/api/render/queue/push"
|
||||||
header := make(map[string]string)
|
header := make(map[string]string)
|
||||||
header["content-type"] = "application/json"
|
header["content-type"] = "application/json"
|
||||||
|
@ -251,11 +250,12 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
|
||||||
"render_data": sendData,
|
"render_data": sendData,
|
||||||
}
|
}
|
||||||
p, _ := json.Marshal(postData)
|
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 {
|
if err != nil {
|
||||||
logx.Error("failed to send data to unity")
|
logx.Error("failed to send data to unity")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
logx.Info("发送到unity成功################")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 操作连接中渲染任务的增加/删除
|
// 操作连接中渲染任务的增加/删除
|
||||||
|
|
Loading…
Reference in New Issue
Block a user