This commit is contained in:
laodaming 2023-08-09 12:28:06 +08:00
parent b1abc92b16
commit e185ae7458
6 changed files with 38 additions and 32 deletions

View File

@ -8,6 +8,7 @@ import (
type FsCloudRenderLog struct { type FsCloudRenderLog struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID
UserId *int64 `gorm:"default:0;" json:"user_id"` // 用户id UserId *int64 `gorm:"default:0;" json:"user_id"` // 用户id
GuestId *int64 `gorm:"default:0;" json:"guest_id"` // 游客id
PostData *string `gorm:"default:'';" json:"post_data"` // PostData *string `gorm:"default:'';" json:"post_data"` //
PostUrl *string `gorm:"default:'';" json:"post_url"` // PostUrl *string `gorm:"default:'';" json:"post_url"` //
Title *string `gorm:"index;default:'';" json:"title"` // Title *string `gorm:"index;default:'';" json:"title"` //

View File

@ -17,7 +17,7 @@ type FsResource struct {
Metadata *string `gorm:"default:'';" json:"metadata"` // 元数据,json格式,存储图像分率 Metadata *string `gorm:"default:'';" json:"metadata"` // 元数据,json格式,存储图像分率
MetaKey1 *string `gorm:"index;default:'';" json:"meta_key1"` // 需要关键信息查询的自定义属性1,可以动态增加 MetaKey1 *string `gorm:"index;default:'';" json:"meta_key1"` // 需要关键信息查询的自定义属性1,可以动态增加
ApiType *int64 `gorm:"default:1;" json:"api_type"` // 调用类型1=对外2=对内 ApiType *int64 `gorm:"default:1;" json:"api_type"` // 调用类型1=对外2=对内
BucketName *string `gorm:"default:'';" json:"bucket_name"` // 存储桶名 BucketName *string `gorm:"default:'';" json:"bucket_name"` // 存储桶名: 1=持久 2=缓存
} }
type FsResourceModel struct { type FsResourceModel struct {
db *gorm.DB db *gorm.DB

View File

@ -65,6 +65,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
//云渲染日志 //云渲染日志
err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{ err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{
UserId: &parseInfo.RenderData.UserId, UserId: &parseInfo.RenderData.UserId,
GuestId: &parseInfo.RenderData.GuestId,
Title: &title, Title: &title,
Time: &renderLogTime, Time: &renderLogTime,
Tag: &parseInfo.RenderId, Tag: &parseInfo.RenderId,
@ -117,6 +118,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
pyRequestTime := time.Now().UnixMilli() - pyapiBeginTime pyRequestTime := time.Now().UnixMilli() - pyapiBeginTime
err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{ err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{
UserId: &parseInfo.RenderData.UserId, UserId: &parseInfo.RenderData.UserId,
GuestId: &parseInfo.RenderData.GuestId,
Title: &title, Title: &title,
Time: &pyRequestTime, Time: &pyRequestTime,
Tag: &parseInfo.RenderId, Tag: &parseInfo.RenderId,
@ -138,6 +140,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
pyRspStr := string(pyRspBytes) pyRspStr := string(pyRspBytes)
err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{ err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{
UserId: &parseInfo.RenderData.UserId, UserId: &parseInfo.RenderData.UserId,
GuestId: &parseInfo.RenderData.GuestId,
PostUrl: &url, PostUrl: &url,
PostData: &postData, PostData: &postData,
Result: &pyRspStr, Result: &pyRspStr,
@ -226,6 +229,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
now = time.Now().Unix() now = time.Now().Unix()
err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{ err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{
UserId: &parseInfo.RenderData.UserId, UserId: &parseInfo.RenderData.UserId,
GuestId: &parseInfo.RenderData.GuestId,
Title: &title, Title: &title,
Time: &timePinjie, Time: &timePinjie,
Tag: &parseInfo.RenderId, Tag: &parseInfo.RenderId,

View File

@ -71,7 +71,8 @@ type wsConnectItem struct {
inChan chan []byte //接受消息缓冲通道 inChan chan []byte //接受消息缓冲通道
outChan chan []byte //发送回客户端的消息 outChan chan []byte //发送回客户端的消息
mutex sync.Mutex //互斥锁 mutex sync.Mutex //互斥锁
userId int64 userId int64 //用户id
guestId int64 //游客id
renderProperty renderProperty //扩展云渲染属性 renderProperty renderProperty //扩展云渲染属性
} }
@ -84,7 +85,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
} }
defer conn.Close() defer conn.Close()
//鉴权不成功10秒后断开 //鉴权不成功10秒后断开
/*var ( var (
userInfo *auth.UserInfo userInfo *auth.UserInfo
isAuth bool isAuth bool
) )
@ -101,10 +102,10 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
//发送关闭信息 //发送关闭信息
_ = conn.WriteMessage(websocket.CloseMessage, nil) _ = conn.WriteMessage(websocket.CloseMessage, nil)
return return
}*/ }
//测试的目前写死 39 //测试的目前写死 39
var userInfo auth.UserInfo /*var userInfo auth.UserInfo
userInfo.UserId = 39 userInfo.UserId = 39*/
//生成连接唯一标识 //生成连接唯一标识
uniqueId := websocketIdGenerator.Get() uniqueId := websocketIdGenerator.Get()
ws := wsConnectItem{ ws := wsConnectItem{
@ -114,16 +115,13 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
closeChan: make(chan struct{}, 1), closeChan: make(chan struct{}, 1),
inChan: make(chan []byte, 1000), inChan: make(chan []byte, 1000),
outChan: make(chan []byte, 1000), outChan: make(chan []byte, 1000),
userId: userInfo.UserId,
guestId: userInfo.GuestId,
renderProperty: renderProperty{ renderProperty: renderProperty{
renderImageTask: make(map[string]string), renderImageTask: make(map[string]string),
renderImageTaskCtlChan: make(chan renderImageControlChanItem, 100), renderImageTaskCtlChan: make(chan renderImageControlChanItem, 100),
}, },
} }
if userInfo.UserId > 0 {
ws.userId = userInfo.UserId
} else {
ws.userId = userInfo.GuestId
}
//保存连接 //保存连接
mapConnPool.Store(uniqueId, ws) mapConnPool.Store(uniqueId, ws)
defer ws.close() defer ws.close()

View File

@ -30,7 +30,9 @@ func (w *wsConnectItem) renderImage(data []byte) {
return return
} }
logx.Info("收到请求云渲染图片数据:", renderImageData) logx.Info("收到请求云渲染图片数据:", renderImageData)
//用户id赋值
renderImageData.RenderData.UserId = w.userId renderImageData.RenderData.UserId = w.userId
renderImageData.RenderData.GuestId = w.guestId
//把需要渲染的图片任务加进去 //把需要渲染的图片任务加进去
taskId := hash.JsonHashKey(renderImageData.RenderData) taskId := hash.JsonHashKey(renderImageData.RenderData)
w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{ w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{

View File

@ -16,6 +16,7 @@ type RenderData struct {
ProductId int64 `json:"product_id"` //产品id ProductId int64 `json:"product_id"` //产品id
Data interface{} `json:"data"` //面片数据 Data interface{} `json:"data"` //面片数据
UserId int64 `json:"user_id"` //用户id UserId int64 `json:"user_id"` //用户id
GuestId int64 `json:"guest_id"` //游客id
} }
// websocket发送渲染完的数据 // websocket发送渲染完的数据