fix
This commit is contained in:
parent
55a879ada8
commit
7297a1ef02
|
@ -65,7 +65,6 @@ type wsConnectItem struct {
|
|||
inChan chan []byte //接受消息缓冲通道
|
||||
outChan chan []byte //发送回客户端的消息
|
||||
mutex sync.Mutex //互斥锁
|
||||
userId int64 //用户id
|
||||
renderProperty renderProperty //扩展云渲染属性
|
||||
}
|
||||
|
||||
|
@ -80,17 +79,17 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
|
|||
w.Header().Set("Connection", "Upgrade")
|
||||
rsp := types.DataTransferData{}
|
||||
//鉴权不成功10秒后断开
|
||||
/* isAuth, userInfo := l.checkAuth(svcCtx, r)
|
||||
if !isAuth {
|
||||
time.Sleep(time.Second) //兼容下火狐
|
||||
rsp.T = constants.WEBSOCKET_UNAUTH
|
||||
b, _ := json.Marshal(rsp)
|
||||
//先发一条正常信息
|
||||
_ = conn.WriteMessage(websocket.TextMessage, b)
|
||||
//发送关闭信息
|
||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||
return
|
||||
}*/
|
||||
/*isAuth, _ := l.checkAuth(svcCtx, r)
|
||||
if !isAuth {
|
||||
time.Sleep(time.Second) //兼容下火狐
|
||||
rsp.T = constants.WEBSOCKET_UNAUTH
|
||||
b, _ := json.Marshal(rsp)
|
||||
//先发一条正常信息
|
||||
_ = conn.WriteMessage(websocket.TextMessage, b)
|
||||
//发送关闭信息
|
||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||
return
|
||||
}*/
|
||||
//生成连接唯一标识
|
||||
flag := uuid.New().String() + "time=" + time.Now().Format("15-04-05")
|
||||
ws := wsConnectItem{
|
||||
|
@ -104,9 +103,6 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
|
|||
renderImageTaskCtlChan: make(chan renderImageControlChanItem, 100),
|
||||
},
|
||||
}
|
||||
/*if userInfo != nil {
|
||||
ws.userId = userInfo.UserId
|
||||
}*/
|
||||
//保存连接
|
||||
mapConnPool.Store(flag, ws)
|
||||
defer ws.close()
|
||||
|
@ -245,8 +241,8 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
|
|||
}
|
||||
|
||||
// 获取需要渲染图片的map key
|
||||
func (w *wsConnectItem) getRenderImageMapKey(productId, mapsSourceId, templateId, renderDesignId int64) string {
|
||||
return fmt.Sprintf("%d-%d-%d-%d", productId, mapsSourceId, templateId, renderDesignId)
|
||||
func (w *wsConnectItem) getRenderImageMapKey(productId, templateTagId int64) string {
|
||||
return fmt.Sprintf("%d-%d", productId, templateTagId)
|
||||
}
|
||||
|
||||
// 处理接受到的数据
|
||||
|
|
|
@ -50,7 +50,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi
|
|||
h.Write([]byte(fmt.Sprintf(constants.RENDER_NOTIFY_SIGN_KEY, string(notifyByte), req.Time)))
|
||||
signHex := h.Sum(nil)
|
||||
sign := hex.EncodeToString(signHex)
|
||||
//fmt.Println(sign)
|
||||
fmt.Println(sign)
|
||||
if req.Sign != sign {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign")
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi
|
|||
if !ok {
|
||||
return true
|
||||
}
|
||||
renderKey := ws.getRenderImageMapKey(req.Info.ProductId, req.Info.MapsSourceId, req.Info.TemplateId, req.Info.RenderDesignId)
|
||||
renderKey := ws.getRenderImageMapKey(req.Info.ProductId, req.Info.TemplateTagId)
|
||||
//查询有无该渲染任务
|
||||
_, ok = ws.renderProperty.renderImageTask[renderKey]
|
||||
if !ok {
|
||||
|
@ -70,10 +70,9 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi
|
|||
rspData := types.DataTransferData{
|
||||
T: constants.WEBSOCKET_RENDER_IMAGE,
|
||||
D: types.RenderImageRspMsg{
|
||||
ProductId: req.Info.ProductId,
|
||||
MapsSourceId: req.Info.MapsSourceId,
|
||||
TemplateId: req.Info.TemplateId,
|
||||
RenderResult: req.Info.RenderResult,
|
||||
ProductId: req.Info.ProductId,
|
||||
TemplateTagId: req.Info.TemplateTagId,
|
||||
Image: req.Info.Image,
|
||||
},
|
||||
}
|
||||
b, _ := json.Marshal(rspData)
|
||||
|
|
|
@ -20,28 +20,25 @@ type renderImageControlChanItem struct {
|
|||
|
||||
// 渲染请求数据处理发送云渲染服务处理
|
||||
func (w *wsConnectItem) SendToCloudRender(data []byte) {
|
||||
var renderImageData []types.RenderImageReqMsg
|
||||
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)
|
||||
//把需要渲染的图片任务加进去
|
||||
for _, v := range renderImageData {
|
||||
for _, productId := range v.ProductIds {
|
||||
select {
|
||||
case <-w.closeChan: //连接关闭了
|
||||
return
|
||||
default:
|
||||
//加入渲染任务
|
||||
key := w.getRenderImageMapKey(productId, v.MapsSourceId, v.TemplateId, v.RenderDesignId)
|
||||
w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 1, //0删除 1添加
|
||||
Key: key,
|
||||
}
|
||||
// TODO 数据发送给云渲染服务器
|
||||
v.UserId = w.userId //赋值
|
||||
for _, productId := range renderImageData.ProductIds {
|
||||
select {
|
||||
case <-w.closeChan: //连接关闭了
|
||||
return
|
||||
default:
|
||||
//加入渲染任务
|
||||
key := w.getRenderImageMapKey(productId, renderImageData.TemplateTagId)
|
||||
w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 1, //0删除 1添加
|
||||
Key: key,
|
||||
}
|
||||
// TODO 数据发送给云渲染服务器
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,19 +11,14 @@ type DataTransferData struct {
|
|||
}
|
||||
|
||||
type RenderImageReqMsg struct {
|
||||
ProductIds []int64 `json:"product_ids"` //产品 id
|
||||
MapsSourceId int64 `json:"maps_source_id"` //贴图数据id
|
||||
TemplateId int64 `json:"template_id"` //模板id
|
||||
UserId int64 `json:"user_id"` //用户id(这个前端不用传,后台获取)
|
||||
RenderDesignId int64 `json:"render_design_id"` //渲染设计id
|
||||
ProductIds []int64 `json:"product_ids"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
}
|
||||
|
||||
type RenderImageRspMsg struct {
|
||||
ProductId int64 `json:"product_id"` //产品 id
|
||||
MapsSourceId int64 `json:"maps_source_id"` //贴图数据id
|
||||
TemplateId int64 `json:"template_id"` //模板id
|
||||
RenderDesignId int64 `json:"render_design_id"` //渲染设计id
|
||||
RenderResult string `json:"render_result"` //渲染结果数据
|
||||
ProductId int64 `json:"product_id"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
Image string `json:"image"` //渲染后的图片
|
||||
}
|
||||
|
||||
type RenderNotifyReq struct {
|
||||
|
@ -33,11 +28,9 @@ type RenderNotifyReq struct {
|
|||
}
|
||||
|
||||
type NotifyInfo struct {
|
||||
ProductId int64 `json:"product_id"`
|
||||
MapsSourceId int64 `json:"maps_source_id"`
|
||||
TemplateId int64 `json:"template_id"`
|
||||
RenderDesignId int64 `json:"render_design_id"` //渲染设计id
|
||||
RenderResult string `json:"render_result"` //渲染结果数据
|
||||
ProductId int64 `json:"product_id"`
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
|
|
|
@ -23,18 +23,13 @@ type DataTransferData {
|
|||
D interface{} `json:"d"` //传递的消息
|
||||
}
|
||||
type RenderImageReqMsg { //websocket接受要云渲染处理的数据
|
||||
ProductIds []int64 `json:"product_ids"` //产品 id
|
||||
MapsSourceId int64 `json:"maps_source_id"` //贴图数据id
|
||||
TemplateId int64 `json:"template_id"` //模板id
|
||||
UserId int64 `json:"user_id"` //用户id(这个前端不用传,后台获取)
|
||||
RenderDesignId int64 `json:"render_design_id"` //渲染设计id
|
||||
ProductIds []int64 `json:"product_ids"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
}
|
||||
type RenderImageRspMsg { //websocket发送渲染完的数据
|
||||
ProductId int64 `json:"product_id"` //产品 id
|
||||
MapsSourceId int64 `json:"maps_source_id"` //贴图数据id
|
||||
TemplateId int64 `json:"template_id"` //模板id
|
||||
RenderDesignId int64 `json:"render_design_id"` //渲染设计id
|
||||
RenderResult string `json:"render_result"` //渲染结果数据
|
||||
ProductId int64 `json:"product_id"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
Image string `json:"image"` //渲染后的图片
|
||||
}
|
||||
//渲染完了通知接口
|
||||
type RenderNotifyReq {
|
||||
|
@ -43,9 +38,7 @@ type RenderNotifyReq {
|
|||
Info NotifyInfo `json:"info"`
|
||||
}
|
||||
type NotifyInfo {
|
||||
ProductId int64 `json:"product_id"`
|
||||
MapsSourceId int64 `json:"maps_source_id"`
|
||||
TemplateId int64 `json:"template_id"`
|
||||
RenderDesignId int64 `json:"render_design_id"` //渲染设计id
|
||||
RenderResult string `json:"render_result"` //渲染结果数据
|
||||
ProductId int64 `json:"product_id"`
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
Image string `json:"image"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user