Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
bd092f44c8
|
@ -153,3 +153,17 @@ func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Co
|
|||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (t *FsProductTemplateV2Model) FindAllByProductIdsTemplateTag(ctx context.Context, productIds []int64, templateTag string, sort string, fields ...string) (resp []FsProductTemplateV2, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return
|
||||
}
|
||||
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ?", productIds, templateTag, 0, 1)
|
||||
if sort != "" {
|
||||
db = db.Order(sort)
|
||||
}
|
||||
if len(fields) != 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info")
|
||||
}
|
||||
//前台用的分类是1
|
||||
if *tagData.Category != 1 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "invalid tag")
|
||||
}
|
||||
|
@ -170,13 +171,20 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
}
|
||||
}
|
||||
//获取模板(只是获取产品product_id,id)
|
||||
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id")
|
||||
if req.TemplateTag != "" { //指定模板tag
|
||||
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "sort ASC", "product_id,id")
|
||||
} else { //没指定模板tag
|
||||
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id")
|
||||
}
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product templates")
|
||||
}
|
||||
//只存第一个
|
||||
for _, v := range productTemplatesV2 {
|
||||
if _, ok := mapProductTemplate[*v.ProductId]; ok {
|
||||
continue
|
||||
}
|
||||
mapProductTemplate[*v.ProductId] = v.Id
|
||||
}
|
||||
//获取产品尺寸数量
|
||||
|
|
|
@ -249,6 +249,7 @@ type GetRecommandProductListRsp struct {
|
|||
type GetTagProductListReq struct {
|
||||
Cid int64 `form:"cid,optional"` //分类id
|
||||
Size uint32 `form:"size,optional"` //尺寸
|
||||
TemplateTag string `form:"template_tag,optional"` //模板标签
|
||||
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/constants"
|
||||
"context"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/file"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/websocket/internal/svc"
|
||||
"fusenapi/server/websocket/internal/types"
|
||||
|
@ -77,34 +73,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
|||
logx.Error("渲染回调断言websocket连接失败")
|
||||
return true
|
||||
}
|
||||
//关闭标识
|
||||
if ws.isClose {
|
||||
return true
|
||||
}
|
||||
//查询有无该渲染任务
|
||||
renderId, ok := ws.renderProperty.renderImageTask[req.TaskId]
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderId,
|
||||
Image: uploadRes.ResourceUrl,
|
||||
//发送处理并删除任务
|
||||
ws.deleteRenderTask(renderImageControlChanItem{
|
||||
Option: 0, //0删除 1添加
|
||||
TaskId: req.TaskId,
|
||||
RenderNotifyImageUrl: uploadRes.ResourceUrl,
|
||||
})
|
||||
deleteTask := renderImageControlChanItem{
|
||||
Option: 0, //0删除 1添加
|
||||
TaskId: req.TaskId,
|
||||
RenderId: renderId,
|
||||
}
|
||||
select {
|
||||
case <-ws.closeChan: //关闭了
|
||||
return true
|
||||
case ws.renderProperty.renderImageTaskCtlChan <- deleteTask: //删除对应的需要渲染的图片map
|
||||
//发送数据到out chan
|
||||
ws.sendToOutChan(b)
|
||||
return true
|
||||
case <-time.After(time.Second * 3): //超时丢弃
|
||||
return true
|
||||
}
|
||||
return true
|
||||
})
|
||||
logx.Info("渲染回调成功######################")
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
|
|
|
@ -24,9 +24,10 @@ type renderProperty struct {
|
|||
|
||||
// 渲染任务新增移除的控制通道的数据
|
||||
type renderImageControlChanItem struct {
|
||||
Option int // 0删除 1添加
|
||||
TaskId string //map的key
|
||||
RenderId string // map的val
|
||||
Option int // 0删除 1添加
|
||||
TaskId string //map的key
|
||||
RenderId string // map的val(增加任务时候传)
|
||||
RenderNotifyImageUrl string //渲染回调数据(删除任务时候传)
|
||||
}
|
||||
|
||||
// 发送到渲染缓冲池
|
||||
|
@ -34,14 +35,14 @@ func (w *wsConnectItem) sendToRenderChan(data []byte) {
|
|||
select {
|
||||
case <-w.closeChan: //已经关闭
|
||||
return
|
||||
case w.renderProperty.renderChan <- data:
|
||||
case w.renderProperty.renderChan <- data: //发入到缓冲池
|
||||
return
|
||||
case <-time.After(time.Second * 3):
|
||||
case <-time.After(time.Second * 3): //三秒没进入缓冲池就丢弃
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染发送到组装数据组装数据
|
||||
// 渲染发送到组装数据组装数据(缓冲池)
|
||||
func (w *wsConnectItem) renderImage() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
|
@ -137,11 +138,11 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
|
|||
}
|
||||
//###########################################
|
||||
//把需要渲染的图片任务加进去
|
||||
w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
w.createRenderTask(renderImageControlChanItem{
|
||||
Option: 1, //0删除 1添加
|
||||
TaskId: taskId,
|
||||
RenderId: renderImageData.RenderId,
|
||||
}
|
||||
})
|
||||
//组装数据
|
||||
if err = w.assembleRenderData(taskId, renderImageData); err != nil {
|
||||
logx.Error("组装数据失败:", err)
|
||||
|
@ -292,7 +293,35 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
|
|||
return nil
|
||||
}
|
||||
|
||||
// 操作连接中渲染任务的增加/删除
|
||||
// 增加渲染任务
|
||||
func (w *wsConnectItem) createRenderTask(data renderImageControlChanItem) {
|
||||
//强制设为增加
|
||||
data.Option = 1
|
||||
select {
|
||||
case <-w.closeChan: //关闭
|
||||
return
|
||||
case w.renderProperty.renderImageTaskCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Second * 3):
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染回调处理并删除渲染任务
|
||||
func (w *wsConnectItem) deleteRenderTask(data renderImageControlChanItem) {
|
||||
//强制设为删除
|
||||
data.Option = 0
|
||||
select {
|
||||
case <-w.closeChan: //关闭
|
||||
return
|
||||
case w.renderProperty.renderImageTaskCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Second * 3):
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 操作连接中渲染任务的增加/删除(任务map不能读写并发,所以放在chan里面串行执行)
|
||||
func (w *wsConnectItem) operationRenderTask() {
|
||||
for {
|
||||
select {
|
||||
|
@ -300,7 +329,14 @@ func (w *wsConnectItem) operationRenderTask() {
|
|||
return
|
||||
case data := <-w.renderProperty.renderImageTaskCtlChan:
|
||||
switch data.Option {
|
||||
case 0: //删除任务
|
||||
case 0: //渲染结果回调,删除任务
|
||||
//存在任务,则发送渲染结果给前端
|
||||
if renderId, ok := w.renderProperty.renderImageTask[data.TaskId]; ok {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderId,
|
||||
Image: data.RenderNotifyImageUrl,
|
||||
}))
|
||||
}
|
||||
delete(w.renderProperty.renderImageTask, data.TaskId)
|
||||
case 1: //新增任务
|
||||
w.renderProperty.renderImageTask[data.TaskId] = data.RenderId
|
||||
|
|
|
@ -301,6 +301,7 @@ type GetRecommandProductListRsp {
|
|||
type GetTagProductListReq {
|
||||
Cid int64 `form:"cid,optional"` //分类id
|
||||
Size uint32 `form:"size,optional"` //尺寸
|
||||
TemplateTag string `form:"template_tag,optional"` //模板标签
|
||||
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
|
||||
}
|
||||
type GetTagProductListRsp {
|
||||
|
|
Loading…
Reference in New Issue
Block a user