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