This commit is contained in:
laodaming 2023-08-28 18:16:19 +08:00
parent 496c97eff1
commit 83b724d301
2 changed files with 48 additions and 44 deletions

View File

@ -27,8 +27,9 @@ type extendRenderProperty struct {
// 渲染任务新增移除的控制通道的数据
type renderImageControlChanItem struct {
option int // 0删除 1添加
taskId string //map的key
option int // 0删除 1添加 2修改耗时属性
taskId string //map的key(必须传)
combineImage string //刀版图地址(增加任务时候传)
renderId string // map的val(增加任务时候传)
renderNotifyImageUrl string //渲染回调数据(删除任务时候传)
taskProperty renderTask //渲染任务的属性
@ -152,8 +153,43 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
logx.Error("failed to get element list,", err)
return
}
//获取刀版图
combineReq := repositories.LogoCombineReq{
UserId: renderImageData.RenderData.UserId,
GuestId: renderImageData.RenderData.GuestId,
TemplateId: productTemplate.Id,
TemplateTag: renderImageData.RenderData.TemplateTag,
Website: renderImageData.RenderData.Website,
Slogan: renderImageData.RenderData.Slogan,
Address: renderImageData.RenderData.Address,
Phone: renderImageData.RenderData.Phone,
}
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
if err != nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to combine image:"+err.Error(), w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id)
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
return
}
combineImage := "" //刀版图
if res != nil && res.ResourceUrl != nil {
combineImage = *res.ResourceUrl
} else {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "combine image is empty", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id)
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
return
}
logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", renderImageData.RenderData.Logo, " 刀版图:", *res.ResourceUrl)
//获取唯一id
taskId := w.genRenderTaskId(renderImageData, model3dInfo, productTemplate, element)
//记录刀版图合成消耗时间跟上传刀版图时间
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
option: 2,
taskId: taskId,
taskProperty: renderTask{
combineTakesTime: res.DiffTimeLogoCombine,
uploadCombineImageTakesTime: res.DiffTimeUploadFile,
},
})
//查询有没有缓存的资源,有就返回######################
resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId)
if err != nil {
@ -181,12 +217,13 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
//###########################################
//把需要渲染的图片任务加进去
w.createRenderTask(renderImageControlChanItem{
option: 1, //0删除 1添加 2修改耗时属性
taskId: taskId,
renderId: renderImageData.RenderId,
option: 1, //0删除 1添加 2修改耗时属性
taskId: taskId,
renderId: renderImageData.RenderId,
combineImage: combineImage,
})
//组装数据
if err = w.assembleRenderData(taskId, renderImageData, productTemplate, model3dInfo, element, productFirstSize); err != nil {
if err = w.assembleRenderData(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productFirstSize); err != nil {
logx.Error("组装数据失败:", err)
return
}
@ -219,42 +256,7 @@ func (w *wsConnectItem) genRenderTaskId(renderImageData websocket_data.RenderIma
}
// 组装数据发送给unity
func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productFirstSize *gmodel.FsProductSize) error {
//获取刀版图
combineReq := 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,
}
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
if err != nil {
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "failed to combine image:"+err.Error(), w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id)
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
return err
}
combineImage := "" //刀版图
if res != nil && res.ResourceUrl != nil {
combineImage = *res.ResourceUrl
} else {
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "combine image is empty", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id)
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
return err
}
//记录刀版图合成消耗时间跟上传刀版图时间
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
option: 2,
taskId: taskId,
taskProperty: renderTask{
combineTakesTime: res.DiffTimeLogoCombine,
uploadCombineImageTakesTime: res.DiffTimeUploadFile,
},
})
logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl)
func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productFirstSize *gmodel.FsProductSize) (err error) {
//组装数据
refletion := -1
if element.Refletion != nil && *element.Refletion != "" {
@ -443,8 +445,9 @@ func (w *wsConnectItem) operationRenderTask() {
}
//发送到出口
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
RenderId: taskData.renderId,
Image: data.renderNotifyImageUrl,
RenderId: taskData.renderId,
Image: data.renderNotifyImageUrl,
CombineImage: data.combineImage,
RenderProcessTime: websocket_data.RenderProcessTime{
CombineTakesTime: CombineTakesTime,
UnityRenderTakesTime: UnityRenderTakesTime,

View File

@ -29,6 +29,7 @@ type RenderData struct {
type RenderImageRspMsg struct {
RenderId string `json:"render_id"` //渲染id
Image string `json:"image"` //渲染结果图片
CombineImage string `json:"combine_image"` //刀版图
RenderProcessTime RenderProcessTime `json:"render_process_time"` //流程耗时
}
type RenderProcessTime struct {