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

This commit is contained in:
eson 2023-08-25 15:37:58 +08:00
commit 7234b06745
11 changed files with 193 additions and 66 deletions

View File

@ -1,6 +1,7 @@
package logic package logic
import ( import (
"fmt"
"fusenapi/service/repositories" "fusenapi/service/repositories"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
@ -70,7 +71,7 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth
}) })
if err != nil { if err != nil {
return resp.SetStatus(basic.CodeServiceErr) return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err))
} }
// 返回成功的响应和上传URL // 返回成功的响应和上传URL

View File

@ -1,6 +1,7 @@
package logic package logic
import ( import (
"fmt"
"fusenapi/service/repositories" "fusenapi/service/repositories"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
@ -48,7 +49,7 @@ func (l *LogoRemovebgLogic) LogoRemovebg(req *types.LogoRemovebgReq, userinfo *a
}) })
if err != nil { if err != nil {
return resp.SetStatus(basic.CodeServiceErr) return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err))
} }
// 返回成功的响应和上传URL // 返回成功的响应和上传URL

View File

@ -1,6 +1,7 @@
package logic package logic
import ( import (
"fmt"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/service/repositories" "fusenapi/service/repositories"
"fusenapi/utils/auth" "fusenapi/utils/auth"
@ -135,7 +136,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
}) })
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatus(basic.CodeServiceErr) return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err))
} }
logoUrl = resLogoStandard.ResourceUrl logoUrl = resLogoStandard.ResourceUrl
} else { } else {
@ -178,7 +179,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatus(basic.CodeServiceErr) return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err))
} }
resultStr = resLogoStandard.Res resultStr = resLogoStandard.Res

View File

@ -5,6 +5,8 @@ import (
"fusenapi/constants" "fusenapi/constants"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"sync"
"time"
"fusenapi/server/websocket/internal/svc" "fusenapi/server/websocket/internal/svc"
"fusenapi/server/websocket/internal/types" "fusenapi/server/websocket/internal/types"
@ -26,6 +28,68 @@ func NewCommonNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Comm
} }
} }
// 定义公共回调未找到websocket连接时暂存数据缓冲队列
var commonConnectionNotFoundDataCacheChan = make(chan commonConnectionNotFoundDataCacheChanItem, 2000)
type commonConnectionNotFoundDataCacheChanItem struct {
retryTimes int //重回队列次数
data types.CommonNotifyReq //数据
}
// 放入缓冲队列
func (l *CommonNotifyLogic) pushCommonCache(data commonConnectionNotFoundDataCacheChanItem) {
select {
case commonConnectionNotFoundDataCacheChan <- data:
return
case <-time.After(time.Millisecond * 50): //超50ms就丢弃
return
}
}
// 取出元素
func (l *CommonNotifyLogic) popCommonCache() (data commonConnectionNotFoundDataCacheChanItem) {
return <-commonConnectionNotFoundDataCacheChan
}
// 保证处理消息就一个循环在执行
var consumeCommonCacheData sync.Once
// 消费公共通知未处理的消息
func (l *CommonNotifyLogic) consumeCommonCacheData() {
//单例
consumeCommonCacheData.Do(func() {
tick := time.Tick(time.Millisecond * 200)
for {
select {
case <-tick: //200毫秒触发一次
info := l.popCommonCache()
//查询websocket连接
value, ok := mapConnPool.Load(info.data.Wid)
//没有连接
if !ok {
info.retryTimes--
//大于0则放回队列
if info.retryTimes > 0 {
l.pushCommonCache(info)
continue
}
//否则直接丢弃消息
continue
}
//断言连接
ws, ok := value.(wsConnectItem)
if !ok {
logx.Error("渲染回调断言websocket连接失败")
continue
}
//发送
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_COMMON_NOTIFY, info.data.Data))
}
}
})
}
// 处理进入前逻辑w,r // 处理进入前逻辑w,r
// func (l *CommonNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // func (l *CommonNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// } // }
@ -35,10 +99,20 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a
if req.Wid == "" { if req.Wid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "websocket connect id is empty") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "websocket connect id is empty")
} }
//触发消费公共未处理的消息(该方法是单例)
go l.consumeCommonCacheData()
//查询websocket连接 //查询websocket连接
value, ok := mapConnPool.Load(req.Wid) value, ok := mapConnPool.Load(req.Wid)
if !ok { if !ok {
return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") //没找到连接就放到公共缓冲队列
go l.pushCommonCache(commonConnectionNotFoundDataCacheChanItem{
retryTimes: 20, //重试20次
data: types.CommonNotifyReq{
Wid: req.Wid,
Data: req.Data,
},
})
return resp.SetStatusWithMessage(basic.CodeOK, "success")
} }
//断言连接 //断言连接
ws, ok := value.(wsConnectItem) ws, ok := value.(wsConnectItem)

View File

@ -5,6 +5,7 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fusenapi/constants" "fusenapi/constants"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/encryption_decryption" "fusenapi/utils/encryption_decryption"
@ -138,8 +139,8 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
// 设置连接 // 设置连接
func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) { func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) {
//生成连接唯一标识 //生成连接唯一标识失败重试10次
uniqueId, err := l.getUniqueId(userInfo) uniqueId, err := l.getUniqueId(userInfo, 10)
if err != nil { if err != nil {
//发送获取唯一标识失败的消息 //发送获取唯一标识失败的消息
l.sendGetUniqueIdErrResponse(conn) l.sendGetUniqueIdErrResponse(conn)
@ -170,11 +171,15 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
} }
// 获取唯一id // 获取唯一id
func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo) (uniqueId string, err error) { func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo, retryTimes int) (uniqueId string, err error) {
if retryTimes < 0 {
return "", errors.New("failed to get unique id")
}
//后面拼接上用户id //后面拼接上用户id
uniqueId = hex.EncodeToString([]byte(uuid.New().String())) + getUserJoinPart(userInfo.UserId, userInfo.GuestId) uniqueId = hex.EncodeToString([]byte(uuid.New().String())) + getUserJoinPart(userInfo.UserId, userInfo.GuestId)
//存在则从新获取
if _, ok := mapConnPool.Load(uniqueId); ok { if _, ok := mapConnPool.Load(uniqueId); ok {
uniqueId, err = l.getUniqueId(userInfo) uniqueId, err = l.getUniqueId(userInfo, retryTimes-1)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -45,6 +45,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
logx.Error("渲染回调参数错误:渲染结果图片数据") logx.Error("渲染回调参数错误:渲染结果图片数据")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image")
} }
unityRenderEndTime := time.Now().UTC().UnixMilli()
//存base64打印测试 //存base64打印测试
/* f, _ := os.Create("b.txt") /* f, _ := os.Create("b.txt")
defer f.Close() defer f.Close()
@ -70,6 +71,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
logx.Error("渲染回调上传文件失败:", err) logx.Error("渲染回调上传文件失败:", err)
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image") return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
} }
uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime
//遍历websocket链接把数据传进去 //遍历websocket链接把数据传进去
mapConnPool.Range(func(key, value any) bool { mapConnPool.Range(func(key, value any) bool {
//断言连接 //断言连接
@ -78,12 +80,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
logx.Error("渲染回调断言websocket连接失败") logx.Error("渲染回调断言websocket连接失败")
return true return true
} }
//记录收到unity渲染结果时间 //记录收到unity渲染结果时间以及上传渲染图耗时时间
ws.modifyRenderTaskTimeConsuming(renderImageControlChanItem{ ws.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
Option: 2, Option: 2,
TaskId: req.TaskId, TaskId: req.TaskId,
TaskProperty: renderTask{ TaskProperty: renderTask{
UnityRenderEndTime: time.Now().UTC().Unix(), UnityRenderEndTime: unityRenderEndTime,
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
}, },
}) })
//发送处理并删除任务 //发送处理并删除任务

View File

@ -36,11 +36,12 @@ type renderImageControlChanItem struct {
// 渲染任务属性 // 渲染任务属性
type renderTask struct { type renderTask struct {
RenderId string //渲染id(前端传的) RenderId string //渲染id(前端传的)
CombineBeginTime int64 //合图开始时间 CombineTakesTime int64 //合刀版图耗时
CombineEndTime int64 //合图结束时间 UploadCombineImageTakesTime int64 //上传刀版图耗时
UnityRenderBeginTime int64 //发送给unity时间 UnityRenderBeginTime int64 //发送给unity时间
UnityRenderEndTime int64 //unity回调结果时间 UnityRenderEndTime int64 //unity回调结果时间
UploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间
} }
// 发送到渲染缓冲池 // 发送到渲染缓冲池
@ -164,10 +165,14 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
} else { } else {
//返回给客户端 //返回给客户端
b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
RenderId: renderImageData.RenderId, RenderId: renderImageData.RenderId,
Image: *resource.ResourceUrl, Image: *resource.ResourceUrl,
CombineTakesTime: "耗时0秒(缓存)", RenderProcessTime: websocket_data.RenderProcessTime{
UnityRenderTakesTime: "耗时0秒(缓存)", CombineTakesTime: "cache",
UnityRenderTakesTime: "cache",
UploadCombineImageTakesTime: "cache",
UploadUnityRenderImageTakesTime: "cache",
},
}) })
//发送数据到out chan //发送数据到out chan
w.sendToOutChan(b) w.sendToOutChan(b)
@ -214,15 +219,6 @@ func (w *wsConnectItem) genRenderTaskId(renderImageData websocket_data.RenderIma
// 组装数据发送给unity // 组装数据发送给unity
func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productFirstSize *gmodel.FsProductSize) error { func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productFirstSize *gmodel.FsProductSize) error {
//记录刀版图合成开始时间
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
Option: 2,
TaskId: taskId,
TaskProperty: renderTask{
CombineBeginTime: time.Now().UTC().Unix(),
},
})
//获取刀版图 //获取刀版图
combineReq := repositories.LogoCombineReq{ combineReq := repositories.LogoCombineReq{
UserId: info.RenderData.UserId, UserId: info.RenderData.UserId,
@ -236,7 +232,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
} }
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
if err != nil { if err != nil {
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "failed to combine image", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id) 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) logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
return err return err
} }
@ -248,12 +244,13 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err) logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
return err return err
} }
//记录刀版图合成结束时间 //记录刀版图合成消耗时间跟上传刀版图时间
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{ w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
Option: 2, Option: 2,
TaskId: taskId, TaskId: taskId,
TaskProperty: renderTask{ TaskProperty: renderTask{
CombineEndTime: time.Now().UTC().Unix(), CombineTakesTime: res.DiffTimeLogoCombine,
UploadCombineImageTakesTime: res.DiffTimeUploadFile,
}, },
}) })
logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl) logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl)
@ -334,15 +331,15 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
url := w.logic.svcCtx.Config.Unity.Host + "/api/render/queue/push" url := w.logic.svcCtx.Config.Unity.Host + "/api/render/queue/push"
header := make(map[string]string) header := make(map[string]string)
header["content-type"] = "application/json" header["content-type"] = "application/json"
t := time.Now().UTC()
postData := map[string]interface{}{ postData := map[string]interface{}{
"group": "unity3d", "group": "unity3d",
"source": "home page", "source": "home page",
"priority": 1, "priority": 1,
"create_at": t, "create_at": time.Now().UTC(),
"render_data": sendData, "render_data": sendData,
} }
postDataBytes, _ := json.Marshal(postData) postDataBytes, _ := json.Marshal(postData)
unityRenderBeginTime := time.Now().UTC().UnixMilli()
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10) _, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
if err != nil { 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) w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id)
@ -354,7 +351,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
Option: 2, Option: 2,
TaskId: taskId, TaskId: taskId,
TaskProperty: renderTask{ TaskProperty: renderTask{
UnityRenderBeginTime: time.Now().UTC().Unix(), UnityRenderBeginTime: unityRenderBeginTime,
}, },
}) })
logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes)) logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes))
@ -423,20 +420,36 @@ func (w *wsConnectItem) operationRenderTask() {
case 0: //渲染结果回调,删除任务 case 0: //渲染结果回调,删除任务
//存在任务,则发送渲染结果给前端 //存在任务,则发送渲染结果给前端
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok { if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
CombineTakesTime := "" CombineTakesTime := "0ms"
UnityRenderTakesTime := "" UnityRenderTakesTime := "0ms"
if taskData.CombineBeginTime > 0 && taskData.CombineEndTime > 0 { uploadCombineImageTakesTime := "0ms"
CombineTakesTime = fmt.Sprintf("耗时%d秒", taskData.CombineEndTime-taskData.CombineBeginTime) 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 { if taskData.UnityRenderBeginTime > 0 && taskData.UnityRenderEndTime > 0 {
UnityRenderTakesTime = fmt.Sprintf("耗时%d秒", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime) 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{ w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
RenderId: taskData.RenderId, RenderId: taskData.RenderId,
Image: data.RenderNotifyImageUrl, Image: data.RenderNotifyImageUrl,
CombineTakesTime: CombineTakesTime, RenderProcessTime: websocket_data.RenderProcessTime{
UnityRenderTakesTime: UnityRenderTakesTime, CombineTakesTime: CombineTakesTime,
UnityRenderTakesTime: UnityRenderTakesTime,
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
},
})) }))
} }
//删除任务 //删除任务
@ -447,15 +460,23 @@ func (w *wsConnectItem) operationRenderTask() {
} }
case 2: //修改(耗时)属性 case 2: //修改(耗时)属性
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok { if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
if data.TaskProperty.CombineBeginTime != 0 { //合图耗时
taskData.CombineBeginTime = data.TaskProperty.CombineBeginTime if data.TaskProperty.CombineTakesTime != 0 {
taskData.CombineTakesTime = data.TaskProperty.CombineTakesTime
} }
if data.TaskProperty.CombineEndTime != 0 { //上传合图耗时
taskData.CombineEndTime = data.TaskProperty.CombineEndTime 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 { if data.TaskProperty.UnityRenderBeginTime != 0 {
taskData.UnityRenderBeginTime = data.TaskProperty.UnityRenderBeginTime taskData.UnityRenderBeginTime = data.TaskProperty.UnityRenderBeginTime
} }
//收到unity返回的时间
if data.TaskProperty.UnityRenderEndTime != 0 { if data.TaskProperty.UnityRenderEndTime != 0 {
taskData.UnityRenderEndTime = data.TaskProperty.UnityRenderEndTime taskData.UnityRenderEndTime = data.TaskProperty.UnityRenderEndTime
} }

View File

@ -53,6 +53,7 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) {
} }
//重新绑定 //重新绑定
w.uniqueId = wid w.uniqueId = wid
mapConnPool.Store(wid, *w)
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid)
w.sendToOutChan(rsp) w.sendToOutChan(rsp)
return return

View File

@ -96,9 +96,11 @@ type (
LogoUrl string `json:"logo_url"` // 合图参数 LogoUrl string `json:"logo_url"` // 合图参数
} }
LogoCombineRes struct { LogoCombineRes struct {
ResourceId string ResourceId string
ResourceUrl *string ResourceUrl *string
Metadata *string Metadata *string
DiffTimeLogoCombine int64
DiffTimeUploadFile int64
} }
) )
@ -194,14 +196,19 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
postMap["module_data"] = moduleDataMap postMap["module_data"] = moduleDataMap
postMap["param_data"] = combineParam postMap["param_data"] = combineParam
logc.Infof(ctx, "算法请求--合图--开始时间:%v", time.Now().UTC()) logc.Infof(ctx, "合图--算法请求--合图--开始时间:%v", time.Now().UTC())
var startTimeLogoCombine = time.Now().UnixMilli() //合图--处理--开始时间
var resultBLM constants.BLMServiceUrlResult var resultBLM constants.BLMServiceUrlResult
err = curl.NewClient(ctx, &curl.Config{ err = curl.NewClient(ctx, &curl.Config{
BaseUrl: *l.BLMServiceUrl, BaseUrl: *l.BLMServiceUrl,
Url: constants.BLMServiceUrlLogoCombine, Url: constants.BLMServiceUrlLogoCombine,
}).PostJson(postMap, &resultBLM) }).PostJson(postMap, &resultBLM)
logc.Infof(ctx, "算法请求--合图--结束时间:%v", time.Now().UTC())
logc.Infof(ctx, "合图--算法请求--合图--结束时间:%v", time.Now().UTC())
endTimeLogoCombine := time.Now().UnixMilli() //合图--处理--开始时间
diffTimeLogoCombine := endTimeLogoCombine - startTimeLogoCombine //合图--处理--中间差
logc.Infof(ctx, "合图--算法请求--合图--业务耗时:%d", diffTimeLogoCombine)
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return nil, err return nil, err
@ -229,6 +236,10 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
MysqlConn: l.MysqlConn, MysqlConn: l.MysqlConn,
AwsSession: l.AwsSession, AwsSession: l.AwsSession,
} }
logc.Infof(ctx, "合图--上传文件--开始时间:%v", time.Now().UTC())
var startTimeUploadFile = time.Now().UnixMilli() //合图--上传--开始时间
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
Source: "combine-image", Source: "combine-image",
FileHash: resourceId, FileHash: resourceId,
@ -238,13 +249,21 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
UserId: in.UserId, UserId: in.UserId,
GuestId: in.GuestId, GuestId: in.GuestId,
}) })
logc.Infof(ctx, "合图--上传文件--结束时间:%v", time.Now().UTC())
endTimeUploadFile := time.Now().UnixMilli() //合图--处理--开始时间
diffTimeUploadFile := endTimeUploadFile - startTimeUploadFile //合图--处理--中间差
logc.Infof(ctx, "合图--上传文件--业务耗时:%d", diffTimeUploadFile)
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return nil, err return nil, err
} }
return &LogoCombineRes{ return &LogoCombineRes{
ResourceId: uploadRes.ResourceId, ResourceId: uploadRes.ResourceId,
ResourceUrl: &uploadRes.ResourceUrl, ResourceUrl: &uploadRes.ResourceUrl,
DiffTimeLogoCombine: diffTimeLogoCombine,
DiffTimeUploadFile: diffTimeUploadFile,
}, nil }, nil
} }

View File

@ -3,7 +3,7 @@ package curl
import ( import (
"bytes" "bytes"
"context" "context"
"errors" "fmt"
"time" "time"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -87,7 +87,7 @@ func (c *defaultClient) PostJson(jsonData interface{}, res interface{}) error {
//logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm res result:%+v", res) //logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm res result:%+v", res)
if resp.StatusCode() != 200 { if resp.StatusCode() != 200 {
err = errors.New("服务端失败") err = fmt.Errorf("服务端失败,返回结果:%+v", resp.RawResponse.Status)
logx.Errorf("客户端 请求失败 Client PostForm Server error:%+v", err) logx.Errorf("客户端 请求失败 Client PostForm Server error:%+v", err)
} }
return err return err
@ -111,7 +111,7 @@ func (c *defaultClient) PostForm(formData map[string]string, res interface{}) (i
logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm RawResponse result:%+v,%+V", resp.RawResponse.Status, resp.RawResponse.StatusCode) logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm RawResponse result:%+v,%+V", resp.RawResponse.Status, resp.RawResponse.StatusCode)
logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm res result:%+v", res) logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm res result:%+v", res)
if resp.StatusCode() != 200 { if resp.StatusCode() != 200 {
err = errors.New("服务端失败") err = fmt.Errorf("服务端失败,返回结果:%+v", resp.RawResponse.Status)
logx.Errorf("客户端 请求失败 Client PostForm Server error:%+v", err) logx.Errorf("客户端 请求失败 Client PostForm Server error:%+v", err)
} }
return res, err return res, err
@ -137,7 +137,7 @@ func (c *defaultClient) PostFile(fileParam string, fileName string, res interfac
logc.Infof(c.ctx, "客户端 请求返回结果 Client PostFile RawResponse result:%+v,%+V", resp.RawResponse.Status, resp.RawResponse.StatusCode) logc.Infof(c.ctx, "客户端 请求返回结果 Client PostFile RawResponse result:%+v,%+V", resp.RawResponse.Status, resp.RawResponse.StatusCode)
logc.Infof(c.ctx, "客户端 请求返回结果 Client PostFile res result:%+v", res) logc.Infof(c.ctx, "客户端 请求返回结果 Client PostFile res result:%+v", res)
if resp.StatusCode() != 200 { if resp.StatusCode() != 200 {
err = errors.New("服务端失败") err = fmt.Errorf("服务端失败,返回结果:%+v", resp.RawResponse.Status)
logx.Errorf("客户端 请求失败 Client PostFile Server error:%+v", err) logx.Errorf("客户端 请求失败 Client PostFile Server error:%+v", err)
} }
return res, err return res, err

View File

@ -27,12 +27,13 @@ type RenderData struct {
// websocket发送渲染完的数据 // websocket发送渲染完的数据
type RenderImageRspMsg struct { type RenderImageRspMsg struct {
RenderId string `json:"render_id"` //渲染id RenderId string `json:"render_id"` //渲染id
Image string `json:"image"` //渲染结果图片 Image string `json:"image"` //渲染结果图片
CombineTakesTime string `json:"combine_takes_time"` //合图需要时间 RenderProcessTime RenderProcessTime `json:"render_process_time"` //流程耗时
UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时
} }
type ThirdPartyLoginRspMsg struct { type RenderProcessTime struct {
//websocket三方登录的通知数据 CombineTakesTime string `json:"combine_takes_time"` //合图需要时间
Token string `json:"token"` UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时
UploadCombineImageTakesTime string `json:"upload_combine_image_takes_time"` //上传刀版图耗时
UploadUnityRenderImageTakesTime string `json:"upload_unity_render_image_takes_time"` //上传unity渲染结果图时间
} }