2023-07-26 06:35:29 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-07-26 08:47:53 +00:00
|
|
|
"fmt"
|
2023-07-26 06:35:29 +00:00
|
|
|
"fusenapi/server/websocket/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 渲染请求数据处理发送云渲染服务处理
|
|
|
|
func (w *wsConnectItem) SendToCloudRender(data []byte) {
|
2023-07-26 08:47:53 +00:00
|
|
|
fmt.Println(string(data))
|
2023-07-26 06:35:29 +00:00
|
|
|
var renderImageData []types.RenderImageReqMsg
|
|
|
|
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
|
|
|
logx.Error("invalid format of websocket render image message", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logx.Info("收到请求云渲染图片数据:", renderImageData)
|
2023-07-26 07:05:53 +00:00
|
|
|
//把需要渲染的图片任务加进去
|
2023-07-26 06:35:29 +00:00
|
|
|
for _, v := range renderImageData {
|
2023-07-26 08:23:38 +00:00
|
|
|
select {
|
|
|
|
case <-w.closeChan: //连接关闭了
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
//加入渲染任务
|
|
|
|
key := w.getRenderImageMapKey(v.ProductId, v.SizeId, v.TemplateId)
|
|
|
|
w.renderImageTaskCtlChan <- renderImageControlChanItem{
|
|
|
|
Option: 1,
|
|
|
|
Key: key,
|
|
|
|
}
|
|
|
|
// TODO 数据发送给云渲染服务器
|
2023-07-26 07:01:59 +00:00
|
|
|
}
|
2023-07-26 06:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-26 07:15:37 +00:00
|
|
|
|
|
|
|
// 操作连接中渲染任务的增加/删除
|
|
|
|
func (w *wsConnectItem) operationRenderTask() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-w.closeChan:
|
|
|
|
return
|
|
|
|
case data := <-w.renderImageTaskCtlChan:
|
|
|
|
switch data.Option {
|
|
|
|
case 0: //删除任务
|
|
|
|
delete(w.renderImageTask, data.Key)
|
|
|
|
case 1: //新增任务
|
|
|
|
w.renderImageTask[data.Key] = struct{}{}
|
|
|
|
default:
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|