|
|
|
|
@@ -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成功################")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 操作连接中渲染任务的增加/删除
|
|
|
|
|
|