Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/check"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
@@ -82,6 +83,26 @@ func (mquery *ModuleQuery) EncodeEmpty() map[string]any {
|
||||
return qstr
|
||||
}
|
||||
|
||||
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {
|
||||
|
||||
qname := strings.Split(moduleQuery, ".")
|
||||
queryAsName := qname[len(qname)-1]
|
||||
sqlstr := fmt.Sprintf(
|
||||
"select JSON_EXTRACT(metadata,'$.%s') as %s from %s where module = '%s' and user_id = 0 and guest_id = 0 order by ctime DESC limit 1",
|
||||
moduleQuery, // logo_selected
|
||||
queryAsName, // logo_selected
|
||||
tname, // fs_user_info
|
||||
module, // profile
|
||||
)
|
||||
raw := conn.Raw(sqlstr)
|
||||
var info map[string]any
|
||||
err := raw.Scan(&info).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
logx.Error(err)
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
@@ -178,6 +199,29 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
||||
}
|
||||
}
|
||||
|
||||
// 隐含白板用户逻辑
|
||||
if v, ok := metadict["userinfo.profile"]; ok {
|
||||
|
||||
if v == nil {
|
||||
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
|
||||
log.Println(info)
|
||||
metadict["userinfo.profile"] = info
|
||||
// log.Println(metadict)
|
||||
} else {
|
||||
profileDict := v.(map[string]any)
|
||||
if _, ok := profileDict["logo_selected"]; !ok {
|
||||
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
|
||||
profileDict["logo_selected"] = info["logo_selected"]
|
||||
}
|
||||
}
|
||||
|
||||
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
|
||||
if v == nil {
|
||||
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
|
||||
metadict["userinfo.profile.logo_selected"] = info
|
||||
}
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, metadict)
|
||||
}
|
||||
|
||||
|
||||
@@ -115,9 +115,7 @@ func TestMain(t *testing.T) {
|
||||
if v, ok := metadict["userinfo.profile"]; ok {
|
||||
|
||||
if v == nil {
|
||||
|
||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||
log.Println(info)
|
||||
metadict["userinfo.profile"] = info
|
||||
// log.Println(metadict)
|
||||
} else {
|
||||
@@ -126,19 +124,15 @@ func TestMain(t *testing.T) {
|
||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||
profileDict["logo_selected"] = info["logo_selected"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
|
||||
if v == nil {
|
||||
|
||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||
metadict["userinfo.profile.logo_selected"] = info
|
||||
}
|
||||
}
|
||||
|
||||
log.Println(metadict)
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/file"
|
||||
"fusenapi/utils/hash"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
@@ -51,6 +53,31 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
||||
if cartCount >= 100 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "sorry,the count of your carts can`t greater than 100")
|
||||
}
|
||||
if req.RenderImage != "" {
|
||||
//上传base64文件
|
||||
// 上传文件
|
||||
var upload = file.Upload{
|
||||
Ctx: l.ctx,
|
||||
MysqlConn: l.svcCtx.MysqlConn,
|
||||
AwsSession: l.svcCtx.AwsSession,
|
||||
}
|
||||
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
|
||||
Source: "webGl render image",
|
||||
FileHash: hash.JsonHashKey(req.RenderImage),
|
||||
FileData: req.RenderImage,
|
||||
Metadata: "",
|
||||
UploadBucket: 1,
|
||||
ApiType: 2,
|
||||
UserId: userinfo.UserId,
|
||||
GuestId: userinfo.GuestId,
|
||||
FileByte: nil,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload webGl render image")
|
||||
}
|
||||
req.RenderImage = uploadRes.ResourceUrl
|
||||
}
|
||||
//获取产品是否存在
|
||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOne(l.ctx, req.ProductId)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,6 +16,7 @@ type ServiceContext struct {
|
||||
AllModels *gmodel.AllModelsGen
|
||||
RabbitMq *initalize.RabbitMqHandle
|
||||
Repositories *initalize.Repositories
|
||||
AwsSession *session.Session
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
@@ -24,10 +25,11 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token),
|
||||
}
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MysqlConn: conn,
|
||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
||||
Config: c,
|
||||
MysqlConn: conn,
|
||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
||||
AwsSession: session.Must(session.NewSession(&config)),
|
||||
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
||||
GormDB: conn,
|
||||
BLMServiceUrl: &c.BLMService.Url,
|
||||
|
||||
@@ -67,9 +67,9 @@ var (
|
||||
//websocket连接存储
|
||||
mapConnPool = sync.Map{}
|
||||
//每个websocket连接入口缓冲队列长度默认值
|
||||
websocketInChanLen = 500
|
||||
websocketInChanLen = 1000
|
||||
//每个websocket连接出口缓冲队列长度默认值
|
||||
websocketOutChanLen = 500
|
||||
websocketOutChanLen = 1000
|
||||
//是否开启debug
|
||||
openDebug = true
|
||||
//允许跨域的origin
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
var (
|
||||
//每个websocket渲染任务缓冲队列长度默认值
|
||||
renderChanLen = 500
|
||||
//每个websocket渲染并发数
|
||||
renderChanConcurrency = 100
|
||||
)
|
||||
|
||||
// 渲染处理器
|
||||
@@ -30,9 +32,7 @@ type renderProcessor struct {
|
||||
|
||||
// 云渲染属性
|
||||
type extendRenderProperty struct {
|
||||
renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列
|
||||
colorSelectedIndex int //选择颜色索引
|
||||
templateTag string //模板标签
|
||||
renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列
|
||||
}
|
||||
|
||||
// 处理分发到这里的数据
|
||||
@@ -48,8 +48,6 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||
case <-w.closeChan: //已经关闭
|
||||
return
|
||||
case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列
|
||||
w.extendRenderProperty.colorSelectedIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
|
||||
w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -58,36 +56,35 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||
func (w *wsConnectItem) consumeRenderImageData() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("func renderImage err:", err)
|
||||
logx.Error("func consumeRenderImageData err:", err)
|
||||
}
|
||||
}()
|
||||
//限制并发
|
||||
limitChan := make(chan struct{}, renderChanConcurrency)
|
||||
defer close(limitChan)
|
||||
for {
|
||||
select {
|
||||
case <-w.closeChan: //已关闭
|
||||
return
|
||||
case data := <-w.extendRenderProperty.renderChan: //消费数据
|
||||
//属性不同则不发送渲染
|
||||
if data.RenderData.TemplateTag != w.extendRenderProperty.templateTag {
|
||||
continue
|
||||
}
|
||||
//属性不同则不发送渲染
|
||||
if data.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.colorSelectedIndex {
|
||||
continue
|
||||
}
|
||||
w.renderImage(data)
|
||||
limitChan <- struct{}{}
|
||||
go func(d websocket_data.RenderImageReqMsg) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("func renderImage err:", err)
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
<-limitChan
|
||||
}()
|
||||
w.renderImage(d)
|
||||
}(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行渲染任务
|
||||
func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageReqMsg) {
|
||||
//logx.Info("消费渲染数据:", string(data))
|
||||
/*var renderImageData websocket_data.RenderImageReqMsg
|
||||
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
logx.Error("invalid format of websocket render image message", err)
|
||||
return
|
||||
}*/
|
||||
if renderImageData.RenderData.Logo == "" {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user