Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
046ecb0ffb
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
type Repositories struct {
|
||||
ImageHandle repositories.ImageHandle
|
||||
NewResource repositories.Resource
|
||||
}
|
||||
|
||||
type NewAllRepositorieData struct {
|
||||
|
@ -20,5 +21,6 @@ type NewAllRepositorieData struct {
|
|||
func NewAllRepositories(newData *NewAllRepositorieData) *Repositories {
|
||||
return &Repositories{
|
||||
ImageHandle: repositories.NewImageHandle(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
|
||||
NewResource: repositories.NewResource(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,7 +3,9 @@ package logic
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/file"
|
||||
|
@ -96,6 +98,7 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us
|
|||
hashKeyDataB, _ := json.Marshal(req)
|
||||
json.Unmarshal(hashKeyDataB, &hashKeyDataMap)
|
||||
var resourceId string = hash.JsonHashKey(hashKeyDataMap)
|
||||
fmt.Println(resourceId)
|
||||
|
||||
// 上传文件
|
||||
var upload = file.Upload{
|
||||
|
@ -116,10 +119,28 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us
|
|||
logx.Errorf("upload UploadFileByByte err: %v", err)
|
||||
return resp.SetStatus(basic.CodeFileNoFoundErr)
|
||||
}
|
||||
metadataChild := make(map[string]interface{}, 1)
|
||||
metadataChildData := make(map[string]interface{}, 1)
|
||||
metadataChildKey := fmt.Sprintf("%d*%d", req.Width, req.Height)
|
||||
metadataChildData[metadataChildKey] = repositories.Cropping{
|
||||
ResourceId: uploadRes.ResourceId,
|
||||
ResourceUrl: uploadRes.ResourceUrl,
|
||||
Width: req.Width,
|
||||
Height: req.Height,
|
||||
}
|
||||
metadataChild["cropping"] = metadataChildData
|
||||
|
||||
// 原图metadata 更新
|
||||
_, err = l.svcCtx.Repositories.NewResource.UpdateMetadata(l.ctx, &repositories.UpdateMetadataReq{
|
||||
ResourceId: req.ResourceId,
|
||||
MetadataChild: metadataChild,
|
||||
})
|
||||
|
||||
// 返回成功的响应和上传URL
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeServiceErr, "原图metadata更新失败")
|
||||
}
|
||||
|
||||
// 返回成功的响应
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"resource_id": uploadRes.ResourceId,
|
||||
"resource_url": uploadRes.ResourceUrl,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -480,69 +485,72 @@ func (w *wsConnectItem) operationRenderTask() {
|
|||
case data := <-w.extendRenderProperty.renderImageTaskCtlChan:
|
||||
switch data.option {
|
||||
case 0: //渲染结果回调,删除任务
|
||||
//存在任务,则发送渲染结果给前端
|
||||
if taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]; ok {
|
||||
CombineTakesTime := "0ms"
|
||||
UnityRenderTakesTime := "0ms"
|
||||
uploadCombineImageTakesTime := "0ms"
|
||||
uploadUnityRenderImageTakesTime := "0ms"
|
||||
//合图时间
|
||||
if taskData.combineTakesTime > 0 {
|
||||
CombineTakesTime = fmt.Sprintf("%dms", taskData.combineTakesTime)
|
||||
}
|
||||
//上传刀版图时间
|
||||
if taskData.uploadCombineImageTakesTime > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", taskData.uploadCombineImageTakesTime)
|
||||
}
|
||||
//unity渲染时间
|
||||
if taskData.unityRenderBeginTime > 0 && taskData.unityRenderEndTime > 0 {
|
||||
UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.unityRenderEndTime-taskData.unityRenderBeginTime)
|
||||
}
|
||||
//上传unity渲染图耗时
|
||||
if taskData.uploadUnityRenderImageTakesTime > 0 {
|
||||
uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.uploadUnityRenderImageTakesTime)
|
||||
}
|
||||
//发送到出口
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: taskData.renderId,
|
||||
Image: data.renderNotifyImageUrl,
|
||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
||||
CombineTakesTime: CombineTakesTime,
|
||||
UnityRenderTakesTime: UnityRenderTakesTime,
|
||||
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
|
||||
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
|
||||
},
|
||||
}))
|
||||
taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
//存在任务,则发送渲染结果给前端
|
||||
CombineTakesTime := "0ms"
|
||||
UnityRenderTakesTime := "0ms"
|
||||
uploadCombineImageTakesTime := "0ms"
|
||||
uploadUnityRenderImageTakesTime := "0ms"
|
||||
//合图时间
|
||||
if taskData.combineTakesTime > 0 {
|
||||
CombineTakesTime = fmt.Sprintf("%dms", taskData.combineTakesTime)
|
||||
}
|
||||
//上传刀版图时间
|
||||
if taskData.uploadCombineImageTakesTime > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", taskData.uploadCombineImageTakesTime)
|
||||
}
|
||||
//unity渲染时间
|
||||
if taskData.unityRenderBeginTime > 0 && taskData.unityRenderEndTime > 0 {
|
||||
UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.unityRenderEndTime-taskData.unityRenderBeginTime)
|
||||
}
|
||||
//上传unity渲染图耗时
|
||||
if taskData.uploadUnityRenderImageTakesTime > 0 {
|
||||
uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.uploadUnityRenderImageTakesTime)
|
||||
}
|
||||
//发送到出口
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: taskData.renderId,
|
||||
Image: data.renderNotifyImageUrl,
|
||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
||||
CombineTakesTime: CombineTakesTime,
|
||||
UnityRenderTakesTime: UnityRenderTakesTime,
|
||||
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
|
||||
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
|
||||
},
|
||||
}))
|
||||
//删除任务
|
||||
delete(w.extendRenderProperty.renderImageTask, data.taskId)
|
||||
case 1: //新增任务
|
||||
w.extendRenderProperty.renderImageTask[data.taskId] = &renderTask{
|
||||
renderId: data.renderId,
|
||||
}
|
||||
|
||||
case 2: //修改任务属性
|
||||
if taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]; ok {
|
||||
//合图耗时
|
||||
if data.taskProperty.combineTakesTime != 0 {
|
||||
taskData.combineTakesTime = data.taskProperty.combineTakesTime
|
||||
}
|
||||
//上传合图耗时
|
||||
if data.taskProperty.uploadCombineImageTakesTime != 0 {
|
||||
taskData.uploadCombineImageTakesTime = data.taskProperty.uploadCombineImageTakesTime
|
||||
}
|
||||
//上传渲染结果图耗时
|
||||
if data.taskProperty.uploadUnityRenderImageTakesTime != 0 {
|
||||
taskData.uploadUnityRenderImageTakesTime = data.taskProperty.uploadUnityRenderImageTakesTime
|
||||
}
|
||||
//发送unity时间
|
||||
if data.taskProperty.unityRenderBeginTime != 0 {
|
||||
taskData.unityRenderBeginTime = data.taskProperty.unityRenderBeginTime
|
||||
}
|
||||
//收到unity返回的时间
|
||||
if data.taskProperty.unityRenderEndTime != 0 {
|
||||
taskData.unityRenderEndTime = data.taskProperty.unityRenderEndTime
|
||||
}
|
||||
taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
//合图耗时
|
||||
if data.taskProperty.combineTakesTime != 0 {
|
||||
taskData.combineTakesTime = data.taskProperty.combineTakesTime
|
||||
}
|
||||
//上传合图耗时
|
||||
if data.taskProperty.uploadCombineImageTakesTime != 0 {
|
||||
taskData.uploadCombineImageTakesTime = data.taskProperty.uploadCombineImageTakesTime
|
||||
}
|
||||
//上传渲染结果图耗时
|
||||
if data.taskProperty.uploadUnityRenderImageTakesTime != 0 {
|
||||
taskData.uploadUnityRenderImageTakesTime = data.taskProperty.uploadUnityRenderImageTakesTime
|
||||
}
|
||||
//发送unity时间
|
||||
if data.taskProperty.unityRenderBeginTime != 0 {
|
||||
taskData.unityRenderBeginTime = data.taskProperty.unityRenderBeginTime
|
||||
}
|
||||
//收到unity返回的时间
|
||||
if data.taskProperty.unityRenderEndTime != 0 {
|
||||
taskData.unityRenderEndTime = data.taskProperty.unityRenderEndTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,9 +193,17 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
|||
productTemplateV2Info, err := productTemplateV2Model.FindOne(ctx, in.TemplateId)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
logc.Errorf(ctx, "productTemplateV2Model.FindOne:%v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
productTemplateTagInfo, err := gmodel.NewFsProductTemplateTagsModel(l.MysqlConn).FindOneByTagName(ctx, in.TemplateTag, "groups")
|
||||
|
||||
if err != nil {
|
||||
logc.Errorf(ctx, "NewFsProductTemplateTagsModel.FindOneByTagName:%v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var groupOptions map[string]interface{}
|
||||
var materialList []interface{}
|
||||
if productTemplateV2Info.TemplateInfo != nil {
|
||||
|
@ -216,6 +224,13 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
|||
moduleDataMap["groupOptions"] = groupOptions
|
||||
moduleDataMap["materialList"] = materialList
|
||||
|
||||
var tagDataMap []interface{}
|
||||
err = json.Unmarshal([]byte(*productTemplateTagInfo.Groups), &tagDataMap)
|
||||
if err != nil {
|
||||
logc.Errorf(ctx, "Unmarshal tagDataMap:%v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var combineParam map[string]interface{}
|
||||
json.Unmarshal([]byte(*resLogoInfo.Metadata), &combineParam)
|
||||
combineParam["template_tagid"] = in.TemplateTag
|
||||
|
@ -227,6 +242,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
|||
|
||||
var postMap = make(map[string]interface{}, 2)
|
||||
postMap["module_data"] = moduleDataMap
|
||||
postMap["tag_data"] = tagDataMap
|
||||
postMap["param_data"] = combineParam
|
||||
|
||||
logc.Infof(ctx, "合图--算法请求--合图--开始时间:%v", time.Now().UTC())
|
||||
|
|
122
service/repositories/resource.go
Normal file
122
service/repositories/resource.go
Normal file
|
@ -0,0 +1,122 @@
|
|||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fusenapi/model/gmodel"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func NewResource(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session) Resource {
|
||||
return &defaultResource{
|
||||
MysqlConn: gormDB,
|
||||
BLMServiceUrl: bLMServiceUrl,
|
||||
AwsSession: awsSession,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
defaultResource struct {
|
||||
MysqlConn *gorm.DB
|
||||
BLMServiceUrl *string
|
||||
AwsSession *session.Session
|
||||
}
|
||||
Resource interface {
|
||||
// 更新metadata
|
||||
UpdateMetadata(ctx context.Context, in *UpdateMetadataReq) (*UpdateMetadataRes, error)
|
||||
}
|
||||
)
|
||||
|
||||
// 全局
|
||||
type (
|
||||
Cropping struct {
|
||||
ResourceId string `json:"resource_id"`
|
||||
ResourceUrl string `json:"resource_url"`
|
||||
Width int64 `json:"width"`
|
||||
Height int64 `json:"height"`
|
||||
}
|
||||
)
|
||||
|
||||
/* 更新metadata */
|
||||
type (
|
||||
UpdateMetadataReq struct {
|
||||
ResourceId string `json:"resource_id"`
|
||||
MetadataChild map[string]interface{} `json:"metadata_child"`
|
||||
}
|
||||
UpdateMetadataRes struct{}
|
||||
)
|
||||
|
||||
// 更新metadata
|
||||
func (d *defaultResource) UpdateMetadata(ctx context.Context, in *UpdateMetadataReq) (*UpdateMetadataRes, error) {
|
||||
// 事务处理
|
||||
err := d.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
var NewFsResourceModel = gmodel.NewFsResourceModel(tx)
|
||||
oldResourceWhere := tx.Where("resource_id = ?", in.ResourceId)
|
||||
oldResource, err := NewFsResourceModel.FindOneByQuery(ctx, oldResourceWhere, nil)
|
||||
if err != nil || oldResource.ResourceId == "" {
|
||||
logc.Errorf(ctx, "FindOneByQuery oldResource error: %v", err)
|
||||
return err
|
||||
}
|
||||
var newResourceMetadata string
|
||||
if oldResource.Metadata != nil && *oldResource.Metadata != "{}" {
|
||||
var oldResourceMetadata map[string]interface{}
|
||||
err = json.Unmarshal([]byte(*oldResource.Metadata), &oldResourceMetadata)
|
||||
if err != nil {
|
||||
logc.Errorf(ctx, "Unmarshal oldResourceMetadata error: %v", err)
|
||||
return err
|
||||
}
|
||||
for k, v := range in.MetadataChild {
|
||||
switch val := v.(type) {
|
||||
case map[string]interface{}:
|
||||
oldResourceMetadataData := oldResourceMetadata[k].(map[string]interface{})
|
||||
for key := range val {
|
||||
oldResourceMetadataData[key] = val
|
||||
}
|
||||
oldResourceMetadata[k] = oldResourceMetadataData
|
||||
}
|
||||
}
|
||||
oldResourceMetadataB, err := json.Marshal(oldResourceMetadata)
|
||||
if err != nil {
|
||||
logc.Errorf(ctx, "Marshal oldResourceMetadata error: %v", err)
|
||||
return err
|
||||
}
|
||||
newResourceMetadata = string(oldResourceMetadataB)
|
||||
} else {
|
||||
var resourceMetadata = make(map[string]interface{}, len(in.MetadataChild))
|
||||
for k, v := range in.MetadataChild {
|
||||
switch val := v.(type) {
|
||||
case map[string]interface{}:
|
||||
var resourceMetadataData = make(map[string]interface{}, len(val))
|
||||
for key := range val {
|
||||
resourceMetadataData[key] = val
|
||||
}
|
||||
resourceMetadata[k] = resourceMetadataData
|
||||
}
|
||||
}
|
||||
newResourceMetadataB, err := json.Marshal(resourceMetadata)
|
||||
if err != nil {
|
||||
logc.Errorf(ctx, "Marshal oldResourceMetadata error: %v", err)
|
||||
return err
|
||||
}
|
||||
newResourceMetadata = string(newResourceMetadataB)
|
||||
}
|
||||
oldResource.Metadata = &newResourceMetadata
|
||||
_, err = NewFsResourceModel.BuilderUpdate(ctx, tx, oldResource)
|
||||
if err != nil {
|
||||
logc.Errorf(ctx, "Transaction UpdateMetadata error: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
})
|
||||
if err != nil {
|
||||
logc.Errorf(ctx, "BuilderUpdate oldResource error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
/* 更新metadata */
|
Loading…
Reference in New Issue
Block a user