This commit is contained in:
laodaming 2023-08-31 11:50:55 +08:00
parent e2d6182f62
commit 0cabd3d284
2 changed files with 23 additions and 18 deletions

View File

@ -117,7 +117,7 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co
func (t *FsProductTemplateV2Model) FindFirstOneCloudRenderByProductIdModelIdTemplateTag(ctx context.Context, productId, modelId int64, templateTag string) (resp *FsProductTemplateV2, err error) {
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
Where("product_id = ? and model_id = ? and template_tag = ? ", productId, modelId, templateTag).
Where("status = ? and is_del = ? and element_model_id != ?", 1, 0, 0).
Where("status = ? and is_del = ?", 1, 0).
Order("sort ASC").
Take(&resp).Error
return resp, err

View File

@ -92,7 +92,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
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.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get user logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户上传logo素材失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error("failed to get user logo")
return
}
@ -100,10 +100,10 @@ func (w *wsConnectItem) renderImage(data []byte) {
userMaterialDefault, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindOneById(w.logic.ctx, 0)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "default logo is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "默认logo不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return
}
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get default logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取默认logo失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error("default logo is not exists")
return
}
@ -123,11 +123,11 @@ func (w *wsConnectItem) renderImage(data []byte) {
}
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product first size is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到产品的第一个尺寸", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
logx.Error("product size is not found")
return
}
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product first size", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品的第一个尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
logx.Error("failed to get product size:", err)
return
}
@ -135,11 +135,11 @@ func (w *wsConnectItem) renderImage(data []byte) {
model3dInfo, err := w.logic.svcCtx.AllModels.FsProductModel3d.GetOneBySizeIdTag(w.logic.ctx, productSize.Id, constants.TAG_MODEL, "id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product model is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "产品第一个尺寸对应的模型不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0)
logx.Error("product model is not found")
return
}
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product model", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品第一个尺寸对应的模型失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0)
logx.Error("failed to get product model:", err)
return
}
@ -147,23 +147,28 @@ func (w *wsConnectItem) renderImage(data []byte) {
productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindFirstOneCloudRenderByProductIdModelIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, model3dInfo.Id, renderImageData.RenderData.TemplateTag)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product template is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3dInfo.Id, productSize.Id, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3dInfo.Id, productSize.Id, 0)
logx.Error("template info is not found")
return
}
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product template", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3dInfo.Id, productSize.Id, 0)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3dInfo.Id, productSize.Id, 0)
logx.Error("failed to get template info:", err)
return
}
//如果未开启云渲染
if *productTemplate.ElementModelId <= 0 {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "模板未开启云渲染", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
return
}
//获取渲染设置信息
element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ElementModelId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "render element is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "云渲染设置不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
logx.Error("element info is not found,element_model_id = ", 0)
return
}
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get render element", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取云渲染设置失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
logx.Error("failed to get element ,", err)
return
}
@ -182,7 +187,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
}
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(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "合成刀版图失败:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
return
}
@ -190,7 +195,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
if res != nil && res.ResourceUrl != nil {
combineImage = *res.ResourceUrl
} else {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "combine image is empty", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "合成的刀版图是空的地址", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
return
}
@ -207,7 +212,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, taskId, "failed to get render cache", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, taskId, "获取unity云渲染缓存失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
logx.Error("failed to find render resource:", err)
return
}
@ -258,7 +263,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
refletion, err = strconv.Atoi(*element.Refletion)
if err != nil {
logx.Error("err refletion:set default -1")
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Refletion from string to number err", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "解析云渲染设置把Refletion字段值从字符串转数字失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
return err
}
}
@ -267,7 +272,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
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)
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Mode err", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "解析云渲染设置字段 mode 为map对象失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
return err
}
}
@ -342,7 +347,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
unityRenderBeginTime := time.Now().UTC().UnixMilli()
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
if err != nil {
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "请求unity接口失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
logx.Error("failed to send data to unity")
return err
}