Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-08-29 10:22:04 +08:00
commit 368ce4a604
2 changed files with 30 additions and 21 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

@ -29,7 +29,6 @@ type extendRenderProperty struct {
type renderImageControlChanItem struct {
option int // 0删除 1添加 2修改耗时属性
taskId string //map的key(必须传)
combineImage string //刀版图地址(增加任务时候传)
renderId string // map的val(增加任务时候传)
renderNotifyImageUrl string //渲染回调数据(删除任务时候传)
taskProperty renderTask //渲染任务的属性
@ -37,7 +36,8 @@ type renderImageControlChanItem struct {
// 渲染任务属性
type renderTask struct {
renderId string //渲染id(前端传的)
renderId string //渲染id(新增任务传)
combineImage string //刀版图(新增任务传)
combineTakesTime int64 //合刀版图耗时
uploadCombineImageTakesTime int64 //上传刀版图耗时
unityRenderBeginTime int64 //发送给unity时间
@ -59,6 +59,11 @@ func (w *wsConnectItem) sendToRenderChan(data []byte) {
// 渲染发送到组装数据组装数据(缓冲队列)
func (w *wsConnectItem) renderImage() {
defer func() {
if err := recover(); err != nil {
logx.Error("func renderImage err:", err)
}
}()
for {
select {
case <-w.closeChan: //已关闭
@ -133,23 +138,23 @@ func (w *wsConnectItem) consumeRenderCache(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", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product template is not exists", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("template info is not found")
return
}
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product template", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product template", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("failed to get template info:", err)
return
}
//获取渲染设置信息
element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ElementModelId)
element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ModelId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "render element is not exists", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
logx.Error("element info is not found,element_model_id = ", *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "render element is not exists", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("element info is not found,element_model_id = ", 0)
return
}
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get render element", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get render element", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("failed to get element ,", err)
return
}
@ -166,7 +171,7 @@ func (w *wsConnectItem) consumeRenderCache(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(), w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to combine image:"+err.Error(), w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
return
}
@ -174,7 +179,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
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, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "combine image is empty", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
return
}
@ -194,7 +199,7 @@ func (w *wsConnectItem) consumeRenderCache(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", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, taskId, "failed to get render cache", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("failed to find render resource:", err)
return
}
@ -218,10 +223,12 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
//###########################################
//把需要渲染的图片任务加进去
w.createRenderTask(renderImageControlChanItem{
option: 1, //0删除 1添加 2修改耗时属性
taskId: taskId,
renderId: renderImageData.RenderId,
combineImage: combineImage,
option: 1, //0删除 1添加 2修改耗时属性
taskId: taskId,
renderId: renderImageData.RenderId,
taskProperty: renderTask{
combineImage: combineImage,
},
})
//组装数据
if err = w.assembleRenderData(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productFirstSize); err != nil {
@ -264,7 +271,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, i
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", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Refletion from string to number err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
return err
}
}
@ -273,7 +280,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, i
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", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Mode err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
return err
}
}
@ -346,7 +353,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, i
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", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId)
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0)
logx.Error("failed to send data to unity")
return err
}
@ -448,7 +455,7 @@ func (w *wsConnectItem) operationRenderTask() {
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
RenderId: taskData.renderId,
Image: data.renderNotifyImageUrl,
CombineImage: data.combineImage,
CombineImage: data.taskProperty.combineImage,
RenderProcessTime: websocket_data.RenderProcessTime{
CombineTakesTime: CombineTakesTime,
UnityRenderTakesTime: UnityRenderTakesTime,
@ -461,8 +468,10 @@ func (w *wsConnectItem) operationRenderTask() {
delete(w.extendRenderProperty.renderImageTask, data.taskId)
case 1: //新增任务
w.extendRenderProperty.renderImageTask[data.taskId] = &renderTask{
renderId: data.renderId,
renderId: data.renderId,
combineImage: data.taskProperty.combineImage,
}
case 2: //修改(耗时)属性
if taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]; ok {
//合图耗时