Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
893e21fd4d
|
@ -88,9 +88,10 @@ func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (r
|
|||
Where("`is_del` =? and `is_shelf` = ?", 0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (p *FsProductModel) GetIgnoreRandomProductList(ctx context.Context, limit int, notInProductIds []int64) (resp []FsProduct, err error) {
|
||||
func (p *FsProductModel) GetIgnoreRandomProductList(ctx context.Context, notEqType int64, limit int, notInProductIds []int64) (resp []FsProduct, err error) {
|
||||
db := p.db.WithContext(ctx).Model(&FsProduct{}).
|
||||
Where("`is_del` =? and `is_shelf` = ? ", 0, 1)
|
||||
//过滤报价单产品
|
||||
Where("`is_del` =? and `is_shelf` = ? and `type` != ?", 0, 1, notEqType)
|
||||
if len(notInProductIds) > 0 {
|
||||
db = db.Where("`id` not in(?)", notInProductIds)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,29 @@ func (m *FsUserInfoModel) MergeMetadata(userId int64, meta any) error {
|
|||
return fssql.MetadataModulePATCH(m.db, "profile", FsUserInfo{}, meta, "user_id = ?", userId)
|
||||
}
|
||||
|
||||
func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId int64) (map[string]any, error) {
|
||||
func (m *FsUserInfoModel) GetDefaultProfile(ctx context.Context, tname string) (map[string]any, error) {
|
||||
var baseinfo map[string]any
|
||||
condUser := "user_id = 0 and guest_id = 0"
|
||||
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$') as query from %s where %s and module = 'profile' order by ctime DESC limit 1", tname, condUser)
|
||||
err := m.db.WithContext(ctx).Raw(rawsql).Take(&baseinfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v, ok := baseinfo["query"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("default userinfo profile is not exists")
|
||||
}
|
||||
|
||||
var info map[string]any
|
||||
err = json.Unmarshal([]byte(v), &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId int64, guestId int64) (map[string]any, error) {
|
||||
|
||||
var baseinfo map[string]any
|
||||
tname := fssql.GetGormTableName(m.db, FsUserInfo{})
|
||||
|
@ -61,15 +83,22 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
|
|||
pkey = "." + pkey
|
||||
}
|
||||
|
||||
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname)
|
||||
err := m.db.WithContext(ctx).Raw(rawsql, userId).Take(&baseinfo).Error
|
||||
var condUser string
|
||||
if userId == 0 {
|
||||
condUser = fmt.Sprintf("user_id = 0 and guest_id = %d", guestId)
|
||||
} else {
|
||||
condUser = fmt.Sprintf("user_id = %d", userId)
|
||||
}
|
||||
|
||||
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where %s and module = 'profile' order by ctime DESC limit 1", pkey, tname, condUser)
|
||||
err := m.db.WithContext(ctx).Raw(rawsql).Take(&baseinfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v, ok := baseinfo["query"].(string)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
return m.GetDefaultProfile(ctx, tname)
|
||||
}
|
||||
|
||||
var info map[string]any
|
||||
|
@ -77,6 +106,11 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(info) == 0 {
|
||||
return m.GetDefaultProfile(ctx, tname)
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int64, module string) (resp *FsUserInfo, err error) {
|
||||
|
@ -87,32 +121,3 @@ func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int
|
|||
}
|
||||
return resp, err
|
||||
}
|
||||
func (m *FsUserInfoModel) GetProfileByUserIdGuestId(ctx context.Context, pkey string, userId, guestId int64) (map[string]any, error) {
|
||||
|
||||
var baseinfo map[string]any
|
||||
tname := fssql.GetGormTableName(m.db, FsUserInfo{})
|
||||
|
||||
if pkey == "." {
|
||||
pkey = ""
|
||||
} else {
|
||||
pkey = "." + pkey
|
||||
}
|
||||
|
||||
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and guest_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname)
|
||||
err := m.db.WithContext(ctx).Raw(rawsql, userId, guestId).Take(&baseinfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v, ok := baseinfo["query"].(string)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var info map[string]any
|
||||
err = json.Unmarshal([]byte(v), &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
|
|
@ -34,11 +34,7 @@ func (l *UserGetProfileLogic) UserGetProfile(req *types.QueryProfileRequest, use
|
|||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
profileBase, err := l.svcCtx.AllModels.FsUserInfo.GetProfile(l.ctx, req.TopKey, userinfo.UserId)
|
||||
profileBase, err := l.svcCtx.AllModels.FsUserInfo.GetProfile(l.ctx, req.TopKey, userinfo.UserId, userinfo.GuestId)
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||
}
|
||||
|
|
|
@ -84,7 +84,8 @@ func (l *GetRecommendProductListLogic) GetRecommendProductList(req *types.GetRec
|
|||
lenRecommendProduct := len(recommendProductList)
|
||||
if lenRecommendProduct < int(req.Num) {
|
||||
appendNum := int(req.Num) - lenRecommendProduct
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetIgnoreRandomProductList(l.ctx, appendNum, ignoreProductIds)
|
||||
//不要查报价单的
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetIgnoreRandomProductList(l.ctx, 39, appendNum, ignoreProductIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list")
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/curl"
|
||||
|
@ -297,6 +298,7 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.
|
|||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "获取对应开启云渲染模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return nil, nil, nil, errors.New("获取对应开启云渲染模板失败")
|
||||
}
|
||||
//判断设计信息是否为空
|
||||
if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "模板设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, 0, 0, 0)
|
||||
return nil, nil, nil, errors.New("模板设计信息是空的")
|
||||
|
@ -312,6 +314,7 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.
|
|||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "获取对应模型失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, 0, 0, 0)
|
||||
return nil, nil, nil, errors.New("获取对应模型失败")
|
||||
}
|
||||
//判断设计信息是否为空
|
||||
if model3d.ModelInfo == nil || *model3d.ModelInfo == "" {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "模型设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, 0, 0)
|
||||
return nil, nil, nil, errors.New("模型设计信息是空的")
|
||||
|
@ -428,12 +431,14 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
|
|||
"render_data": sendData,
|
||||
}
|
||||
postDataBytes, _ := json.Marshal(postData)
|
||||
beginPostTime := time.Now().UTC().UnixMilli()
|
||||
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
|
||||
if err != nil {
|
||||
w.renderErrResponse(info.RenderId, info.RequestId, info.RenderData.TemplateTag, taskId, "请求unity接口失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
|
||||
logx.Error("failed to send data to unity")
|
||||
return err
|
||||
}
|
||||
logx.Info(fmt.Sprintf("发送unity post数据耗时:%dms", time.Now().UTC().UnixMilli()-beginPostTime))
|
||||
//发送运行阶段消息
|
||||
w.sendRenderDataToUnityStepResponseMessage(info.RenderId, info.RequestId)
|
||||
logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/)
|
||||
|
|
Loading…
Reference in New Issue
Block a user