This commit is contained in:
laodaming 2023-08-09 15:29:27 +08:00
parent 2d0d410c40
commit fcf7c909a3
3 changed files with 28 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package gmodel
import ( import (
"context" "context"
"errors"
"fusenapi/utils/handlers" "fusenapi/utils/handlers"
"gorm.io/gorm" "gorm.io/gorm"
@ -10,16 +9,9 @@ import (
// TODO: 使用model的属性做你想做的 // TODO: 使用model的属性做你想做的
func (p *FsResourceModel) FindOneById(ctx context.Context, resourceId string) (*FsResource, error) { func (p *FsResourceModel) FindOneById(ctx context.Context, resourceId string) (resp *FsResource, err error) {
var resp FsResource err = p.db.Table(p.name).WithContext(ctx).Where("resource_id =?", resourceId).Take(&resp).Error
result := p.db.Table(p.name).WithContext(ctx).Where("resource_id =?", resourceId).Take(&resp) return resp, err
if result.Error != nil {
// 检查 ErrRecordNotFound 错误
if !errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, result.Error
}
}
return &resp, nil
} }
func (p *FsResourceModel) Create(ctx context.Context, req *FsResource) (resp *FsResource, err error) { func (p *FsResourceModel) Create(ctx context.Context, req *FsResource) (resp *FsResource, err error) {

View File

@ -48,6 +48,27 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
if !ok { if !ok {
return errors.New("allmodels is nil!!") return errors.New("allmodels is nil!!")
} }
rabbitmq := initalize.RabbitMqHandle{}
//查询有没有缓存的资源
resource, err := allmodels.FsResource.FindOneById(ctx, parseInfo.TaskId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error("failed to find render resource:", err)
return err
}
} else {
//有数据则直接返回
cacheData := websocket_data.RenderImageNotify{
TaskId: parseInfo.TaskId,
Image: *resource.ResourceUrl,
}
d, _ := json.Marshal(cacheData)
if err = rabbitmq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil {
logx.Error("failed to send cache render resource to queue:RABBIT_MQ_RENDER_RESULT_DATA")
return err
}
return nil
}
timeSearchBegin := time.Now().UnixMilli() timeSearchBegin := time.Now().UnixMilli()
//获取模板 //获取模板
templateInfo, err := allmodels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId)) templateInfo, err := allmodels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId))
@ -250,7 +271,6 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
"folder": "", //todo 千人千面需要使用 "folder": "", //todo 千人千面需要使用
} }
b, _ := json.Marshal(sendData) b, _ := json.Marshal(sendData)
rabbitmq := initalize.RabbitMqHandle{}
if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil { if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil {
logx.Error("发送渲染组装数据到rabbitmq失败", err) logx.Error("发送渲染组装数据到rabbitmq失败", err)
return err return err

View File

@ -85,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
) )
@ -102,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{