Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
@@ -87,6 +87,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/api/user/set_user_info",
|
||||
Handler: UserInfoSetHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/user/logo-set",
|
||||
Handler: UserLogoSetHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
35
server/home-user-auth/internal/handler/userlogosethandler.go
Normal file
35
server/home-user-auth/internal/handler/userlogosethandler.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/logic"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func UserLogoSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.UserLogoSetReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUserLogoSetLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.UserLogoSet(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -46,19 +47,76 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||
var userId int64
|
||||
var guestId int64
|
||||
|
||||
if userinfo.IsOnlooker() {
|
||||
// 如果是,返回未授权的错误码
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
// 用户信息
|
||||
NewFsUserInfoModel := gmodel.NewFsUserInfoModel(l.svcCtx.MysqlConn)
|
||||
userInfoGorm := NewFsUserInfoModel.BuilderDB(l.ctx, nil).Where("module = ?", "profile")
|
||||
userInfo := gmodel.FsUserInfo{}
|
||||
|
||||
// 检查用户是否是游客
|
||||
if userinfo.IsGuest() {
|
||||
// 如果是,使用游客ID和游客键名格式
|
||||
guestId = userinfo.GuestId
|
||||
userInfoGorm.Where("guest_id = ?", guestId)
|
||||
} else {
|
||||
// 否则,使用用户ID和用户键名格式
|
||||
userId = userinfo.UserId
|
||||
userInfoGorm.Where("user_id = ?", userId)
|
||||
}
|
||||
var merchantCategoryIds []int64
|
||||
var logoSelectedIdd int64
|
||||
var userMaterialInfo *gmodel.RelaFsUserMaterial
|
||||
userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
||||
resFirst := userInfoGorm.First(&userInfo)
|
||||
err := resFirst.Error
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "data not found")
|
||||
}
|
||||
}
|
||||
if userInfo.Id != 0 && userInfo.Metadata != nil {
|
||||
var metadata map[string]interface{}
|
||||
err = json.Unmarshal([]byte(*userInfo.Metadata), &metadata)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userInfo.Metadata Unmarshal err:%+v", err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
||||
}
|
||||
logoSelectedId, isEx := metadata["logo_selected_id"]
|
||||
if isEx {
|
||||
logoSelectedIdd = int64(logoSelectedId.(float64))
|
||||
userMaterialRSB1 := userMaterialModel.RowSelectBuilder(nil).Preload("ResourceInfo", func(dbPreload *gorm.DB) *gorm.DB {
|
||||
return dbPreload.Table(gmodel.NewFsResourceModel(l.svcCtx.MysqlConn).TableName())
|
||||
}).Where("module = ?", "logo").Where("id = ?", logoSelectedIdd)
|
||||
userMaterialInfo, err = userMaterialModel.FindOneData(l.ctx, userMaterialRSB1)
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
||||
}
|
||||
}
|
||||
var metadataMapuserMaterialInfo map[string]interface{}
|
||||
if userMaterialInfo.Metadata != nil {
|
||||
json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapuserMaterialInfo)
|
||||
merchantCategoryuserMaterialInfo, merchantCategoryEixuserMaterialInfo := metadataMapuserMaterialInfo["merchant_category"]
|
||||
if merchantCategoryEixuserMaterialInfo {
|
||||
merchantCategoryIduserMaterialInfo := int64(merchantCategoryuserMaterialInfo.(float64))
|
||||
merchantCategoryIds = append(merchantCategoryIds, merchantCategoryIduserMaterialInfo)
|
||||
}
|
||||
}
|
||||
userMaterialInfo.MetaDataMap = metadataMapuserMaterialInfo
|
||||
}
|
||||
}
|
||||
|
||||
userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
||||
// 历史列表
|
||||
|
||||
userMaterialRSB := userMaterialModel.RowSelectBuilder(nil).Preload("ResourceInfo", func(dbPreload *gorm.DB) *gorm.DB {
|
||||
return dbPreload.Table(gmodel.NewFsResourceModel(l.svcCtx.MysqlConn).TableName())
|
||||
}).Where("module = ?", "logo").Order("id desc").Limit(10)
|
||||
}).Where("module = ?", "logo").Order("id desc").Limit(5)
|
||||
if userId != 0 {
|
||||
userMaterialRSB.Where("user_id = ?", userId)
|
||||
} else {
|
||||
@@ -66,14 +124,13 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||
}
|
||||
list, err := userMaterialModel.FindList(l.ctx, userMaterialRSB, nil, "")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "data not found")
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
||||
}
|
||||
var isDefaul bool = false
|
||||
if len(list) > 0 {
|
||||
var merchantCategoryIds []int64
|
||||
for _, v := range list {
|
||||
var metadataMap map[string]interface{}
|
||||
if v.Metadata != nil {
|
||||
@@ -95,6 +152,10 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||
v.ResourceInfo.MetaDataMap = resourceMetadata
|
||||
}
|
||||
}
|
||||
|
||||
if logoSelectedIdd == v.Id {
|
||||
isDefaul = true
|
||||
}
|
||||
}
|
||||
if len(merchantCategoryIds) > 0 {
|
||||
newFsMerchantCategoryModel := gmodel.NewFsMerchantCategoryModel(l.svcCtx.MysqlConn)
|
||||
@@ -111,7 +172,10 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||
merchantCategoryData[v.Id] = v
|
||||
}
|
||||
}
|
||||
for _, v := range list {
|
||||
for k, v := range list {
|
||||
if !isDefaul && k == 4 && userMaterialInfo != nil {
|
||||
v = userMaterialInfo
|
||||
}
|
||||
if v.MetaDataMap != nil {
|
||||
merchantCategory1, merchantCategoryEix1 := v.MetaDataMap["merchant_category"]
|
||||
if merchantCategoryEix1 {
|
||||
@@ -121,6 +185,7 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||
v.MetaDataMap["merchant_category_info"] = nil
|
||||
}
|
||||
}
|
||||
list[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
188
server/home-user-auth/internal/logic/userlogosetlogic.go
Normal file
188
server/home-user-auth/internal/logic/userlogosetlogic.go
Normal file
@@ -0,0 +1,188 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/metadata"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserLogoSetLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserLogoSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogoSetLogic {
|
||||
return &UserLogoSetLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *UserLogoSetLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
// 更新用户信息
|
||||
if userinfo.IsOnlooker() {
|
||||
// 如果是,返回未授权的错误码
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
if req.LogoSelectedId == 0 {
|
||||
return resp.SetStatus(basic.CodeLogoSetCategory, "logo logo_selected_id not null")
|
||||
}
|
||||
if req.SetLogoCategory == 1 && req.CategoryId == 0 {
|
||||
return resp.SetStatus(basic.CodeLogoSetCategory, "logo category_id not null")
|
||||
}
|
||||
|
||||
var userId int64
|
||||
var guestId int64
|
||||
NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
||||
NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", req.LogoSelectedId)
|
||||
|
||||
if userinfo.IsGuest() {
|
||||
// 如果是,使用游客ID和游客键名格式
|
||||
guestId = userinfo.GuestId
|
||||
NewFsUserMaterialModelRow.Where("guest_id = ?", guestId)
|
||||
} else {
|
||||
// 否则,使用用户ID和用户键名格式
|
||||
userId = userinfo.UserId
|
||||
NewFsUserMaterialModelRow.Where("user_id = ?", userId)
|
||||
}
|
||||
|
||||
userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{}))
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err)
|
||||
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
|
||||
}
|
||||
|
||||
var nowTime = time.Now().UTC()
|
||||
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// 更新merchant_category
|
||||
if req.SetLogoCategory == 1 {
|
||||
|
||||
var metadataMapOldUserMaterial map[string]interface{}
|
||||
if userMaterialInfo.Metadata != nil {
|
||||
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
var metadataChildUserMaterial = make(map[string]interface{}, 1)
|
||||
metadataChildUserMaterial["merchant_category"] = req.CategoryId
|
||||
metadataMapUserMaterial, err := metadata.SetMetadata(metadataChildUserMaterial, metadataMapOldUserMaterial)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata SetMetadata err:%+v", err)
|
||||
return err
|
||||
}
|
||||
metadataBUserMaterial, err := json.Marshal(metadataMapUserMaterial)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata err:%+v", err)
|
||||
return err
|
||||
}
|
||||
userMaterialInfo.Metadata = &metadataBUserMaterial
|
||||
resUpdates := tx.Select("metadata").Where("id = ?", req.LogoSelectedId).Updates(&userMaterialInfo)
|
||||
err = resUpdates.Error
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
logc.Errorf(l.ctx, "userMaterialInfo Updates err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
var module = "profile"
|
||||
if req.SetLogoSelected == 1 {
|
||||
|
||||
var userInfo = &gmodel.FsUserInfo{}
|
||||
BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module)
|
||||
if userId > 0 {
|
||||
BuilderDB.Where("user_id=?", userId)
|
||||
} else {
|
||||
BuilderDB.Where("guest_id=?", guestId)
|
||||
}
|
||||
userInfoFirstRes := BuilderDB.First(userInfo)
|
||||
err = userInfoFirstRes.Error
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logc.Errorf(l.ctx, "userInfo First err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
var metadataMapOldUserInfo map[string]interface{}
|
||||
if userInfo.Metadata != nil {
|
||||
err = json.Unmarshal(*userInfo.Metadata, &metadataMapOldUserInfo)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userInfo Metadata Unmarshal err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var metadataChildUserInfo = make(map[string]interface{}, 1)
|
||||
metadataChildUserInfo["logo_selected_id"] = req.LogoSelectedId
|
||||
metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userInfo Metadata SetMetadata err:%+v", err)
|
||||
return err
|
||||
}
|
||||
metadataBUserInfo, err := json.Marshal(metadataMapUserInfo)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userInfo Metadata marshal err:%+v", err)
|
||||
return err
|
||||
}
|
||||
userInfo.Metadata = &metadataBUserInfo
|
||||
|
||||
if userInfo.Id == 0 {
|
||||
// 新增
|
||||
userInfo.Module = &module
|
||||
userInfo.Ctime = &nowTime
|
||||
userInfo.Utime = &nowTime
|
||||
userInfo.UserId = &userId
|
||||
userInfo.GuestId = &guestId
|
||||
resCreate := tx.Model(&userInfo).Create(&userInfo)
|
||||
err = resCreate.Error
|
||||
} else {
|
||||
// 更新
|
||||
userInfo.Utime = &nowTime
|
||||
resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo)
|
||||
err = resUpdates.Error
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
logc.Errorf(l.ctx, "FsUserInfo Updates err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, "set logo fail")
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *UserLogoSetLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
@@ -5,6 +5,13 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type UserLogoSetReq struct {
|
||||
SetLogoSelected int64 `form:"set_logo_selected"`
|
||||
LogoSelectedId int64 `form:"logo_selected_id"`
|
||||
SetLogoCategory int64 `form:"set_logo_category"`
|
||||
CategoryId int64 `form:"category_id"`
|
||||
}
|
||||
|
||||
type UserInfoSetReq struct {
|
||||
Module string `form:"module,options=[merchant_category,logo_merchant_category,profile]"` // json格式字符串
|
||||
Metadata string `form:"metadata"` // json格式字符串
|
||||
|
||||
@@ -193,7 +193,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||
Intro: *v.Intro,
|
||||
IsRecommend: isRecommend,
|
||||
MinPrice: minPrice,
|
||||
IsCustomization: *productInfo.IsCustomization,
|
||||
IsCustomization: *v.IsCustomization,
|
||||
}
|
||||
if _, ok := mapTagProp[productInfo.Id]; ok {
|
||||
item.CoverDefault = mapTagProp[productInfo.Id]
|
||||
|
||||
@@ -98,7 +98,7 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us
|
||||
hashKeyDataB, _ := json.Marshal(req)
|
||||
json.Unmarshal(hashKeyDataB, &hashKeyDataMap)
|
||||
var resourceId string = hash.JsonHashKey(hashKeyDataMap)
|
||||
fmt.Println(resourceId)
|
||||
//fmt.Println(resourceId)
|
||||
|
||||
// 上传文件
|
||||
var upload = file.Upload{
|
||||
@@ -107,6 +107,7 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us
|
||||
AwsSession: l.svcCtx.AwsSession,
|
||||
}
|
||||
uploadRes, err := upload.UploadFileByByte(&file.UploadBaseReq{
|
||||
Refresh: 1,
|
||||
FileHash: resourceId,
|
||||
FileByte: emptyBuff.Bytes(),
|
||||
UploadBucket: 1,
|
||||
|
||||
@@ -207,6 +207,7 @@ type UploadData struct {
|
||||
}
|
||||
|
||||
type UploadUrl struct {
|
||||
LogoId int64 `json:"logo_id"`
|
||||
Key string `json:"key"`
|
||||
Status int64 `json:"status"`
|
||||
ApiType int64 `json:"api_type"`
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/service/repositories"
|
||||
@@ -9,7 +8,6 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/file"
|
||||
"fusenapi/utils/hash"
|
||||
"fusenapi/utils/metadata"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -190,88 +188,23 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
|
||||
var module = "logo"
|
||||
var nowTime = time.Now().UTC()
|
||||
// 新增素材记录
|
||||
materialInfo := gmodel.FsUserMaterial{
|
||||
Module: &module,
|
||||
UserId: &userId,
|
||||
GuestId: &guestId,
|
||||
ResourceId: &uploadRes.ResourceId,
|
||||
ResourceUrl: &uploadRes.ResourceUrl,
|
||||
Metadata: &resultStrB,
|
||||
Ctime: &nowTime,
|
||||
}
|
||||
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// 新增素材记录
|
||||
materialInfo := gmodel.FsUserMaterial{
|
||||
Module: &module,
|
||||
UserId: &userId,
|
||||
GuestId: &guestId,
|
||||
ResourceId: &uploadRes.ResourceId,
|
||||
ResourceUrl: &uploadRes.ResourceUrl,
|
||||
Metadata: &resultStrB,
|
||||
Ctime: &nowTime,
|
||||
}
|
||||
resCreate := tx.Create(&materialInfo)
|
||||
err = resCreate.Error
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err)
|
||||
return err
|
||||
}
|
||||
// 更新用户信息
|
||||
var module = "profile"
|
||||
userInfoGorm := tx.Where("module = ?", module)
|
||||
userInfo := gmodel.FsUserInfo{}
|
||||
if userId > 0 {
|
||||
userInfoGorm.Where("user_id = ?", userId)
|
||||
userInfo.UserId = &userId
|
||||
} else {
|
||||
userInfoGorm.Where("guest_id = ?", guestId)
|
||||
userInfo.GuestId = &guestId
|
||||
}
|
||||
resFirst := userInfoGorm.First(&userInfo)
|
||||
err = resFirst.Error
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
var metadataMap map[string]interface{}
|
||||
var metadataMapOld map[string]interface{}
|
||||
if userInfo.Id > 0 {
|
||||
err = json.Unmarshal(*userInfo.Metadata, &metadataMapOld)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "userInfo.Metadata Unmarshal err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
var metadataChild = make(map[string]interface{}, 1)
|
||||
metadataChild["logo_selected_id"] = materialInfo.Id
|
||||
metadataMap, err = metadata.SetMetadata(metadataChild, metadataMapOld)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "metadata SetMetadata err:%+v", err)
|
||||
return err
|
||||
}
|
||||
metadataB, err := json.Marshal(metadataMap)
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "metadata marshal err:%+v", err)
|
||||
return err
|
||||
}
|
||||
userInfo.Metadata = &metadataB
|
||||
if userInfo.Id > 0 {
|
||||
userInfo.Utime = &nowTime
|
||||
resUpdates := tx.Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo)
|
||||
err = resUpdates.Error
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
logc.Errorf(l.ctx, "FsUserInfo Updates err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var nowTime = time.Now().UTC()
|
||||
userInfo.Module = &module
|
||||
userInfo.Ctime = &nowTime
|
||||
userInfo.Utime = &nowTime
|
||||
resCreate := tx.Create(&userInfo)
|
||||
err = resCreate.Error
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
logc.Errorf(l.ctx, "FsUserInfo Create err:%+v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -284,6 +217,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"upload_data": UploadUrl{
|
||||
Status: 1,
|
||||
LogoId: materialInfo.Id,
|
||||
ResourceId: uploadRes.ResourceId,
|
||||
ResourceUrl: uploadRes.ResourceUrl,
|
||||
},
|
||||
|
||||
@@ -195,6 +195,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||
renderImageTask: make(map[string]*renderTask),
|
||||
renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen),
|
||||
renderChan: make(chan []byte, renderChanLen),
|
||||
renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度
|
||||
},
|
||||
}
|
||||
//保存连接
|
||||
|
||||
@@ -35,6 +35,7 @@ type extendRenderProperty struct {
|
||||
renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId
|
||||
renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发)
|
||||
renderChan chan []byte //渲染消息入口的缓冲队列
|
||||
renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
|
||||
}
|
||||
|
||||
// 渲染任务新增移除的控制通道的数据
|
||||
@@ -74,15 +75,15 @@ func (w *wsConnectItem) consumeRenderImageData() {
|
||||
logx.Error("func renderImage err:", err)
|
||||
}
|
||||
}()
|
||||
tick := time.Tick(w.extendRenderProperty.renderConsumeTickTime)
|
||||
for {
|
||||
select {
|
||||
case <-w.closeChan: //已关闭
|
||||
return
|
||||
case data := <-w.extendRenderProperty.renderChan:
|
||||
w.renderImage(data)
|
||||
case <-tick: //消费数据
|
||||
w.renderImage(<-w.extendRenderProperty.renderChan)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 执行渲染任务
|
||||
@@ -94,8 +95,8 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||
logx.Error("invalid format of websocket render image message", err)
|
||||
return
|
||||
}
|
||||
//获取产品信息
|
||||
productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId)
|
||||
//获取产品信息(部分字段)
|
||||
productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
@@ -110,29 +111,21 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
}
|
||||
//获取上传最近的logo
|
||||
userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.ctx, w.userId, w.guestId)
|
||||
//获取用户需要渲染logo
|
||||
logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{
|
||||
UserId: w.userId,
|
||||
GuestId: w.guestId,
|
||||
})
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户上传logo素材失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
logx.Error("failed to get user logo")
|
||||
return
|
||||
}
|
||||
//使用默认logo(id=0)
|
||||
userMaterialDefault, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindOneById(w.logic.ctx, 0)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "默认logo不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
}
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取默认logo失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
logx.Error("default logo is not exists")
|
||||
return
|
||||
}
|
||||
renderImageData.RenderData.Logo = *userMaterialDefault.ResourceUrl
|
||||
} else {
|
||||
renderImageData.RenderData.Logo = *userMaterial.ResourceUrl
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户logo素材错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
if logoInfo == nil || logoInfo.LogoUrl == nil {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "用户logo素材url是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
}
|
||||
renderImageData.RenderData.Logo = *logoInfo.LogoUrl
|
||||
//用户id赋值
|
||||
renderImageData.RenderData.UserId = w.userId
|
||||
renderImageData.RenderData.GuestId = w.guestId
|
||||
|
||||
Reference in New Issue
Block a user