Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
ba0d6b2525
|
@ -50,7 +50,29 @@ func (m *FsUserInfoModel) MergeMetadata(userId int64, meta any) error {
|
||||||
return fssql.MetadataModulePATCH(m.db, "profile", FsUserInfo{}, meta, "user_id = ?", userId)
|
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
|
var baseinfo map[string]any
|
||||||
tname := fssql.GetGormTableName(m.db, FsUserInfo{})
|
tname := fssql.GetGormTableName(m.db, FsUserInfo{})
|
||||||
|
@ -61,15 +83,22 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
|
||||||
pkey = "." + pkey
|
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)
|
var condUser string
|
||||||
err := m.db.WithContext(ctx).Raw(rawsql, userId).Take(&baseinfo).Error
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
v, ok := baseinfo["query"].(string)
|
v, ok := baseinfo["query"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil
|
return m.getDefaultProfile(ctx, tname)
|
||||||
}
|
}
|
||||||
|
|
||||||
var info map[string]any
|
var info map[string]any
|
||||||
|
@ -77,8 +106,19 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(info) == 0 {
|
||||||
|
return m.getDefaultProfile(ctx, tname)
|
||||||
|
}
|
||||||
|
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *FsUserInfoModel) GetDefaultProfile(ctx context.Context) (map[string]any, error) {
|
||||||
|
tname := fssql.GetGormTableName(m.db, FsUserInfo{})
|
||||||
|
return m.getDefaultProfile(ctx, tname)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int64, module string) (resp *FsUserInfo, err error) {
|
func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int64, module string) (resp *FsUserInfo, err error) {
|
||||||
if userId > 0 {
|
if userId > 0 {
|
||||||
err = m.db.WithContext(ctx).Model(&FsUserInfo{}).Where("user_id = ? and module = ?", userId, module).Take(&resp).Error
|
err = m.db.WithContext(ctx).Model(&FsUserInfo{}).Where("user_id = ? and module = ?", userId, module).Take(&resp).Error
|
||||||
|
@ -87,32 +127,3 @@ func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int
|
||||||
}
|
}
|
||||||
return resp, err
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -72,6 +72,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/user/logo-templatetag-set",
|
Path: "/api/user/logo-templatetag-set",
|
||||||
Handler: UserLogoTemplateTagSetHandler(serverCtx),
|
Handler: UserLogoTemplateTagSetHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/user/logo-data-set",
|
||||||
|
Handler: UserLogoDataSetHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 UserLogoDataSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.UserLogoDataSetReq
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewUserLogoDataSetLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.UserLogoDataSet(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
130
server/home-user-auth/internal/logic/userlogodatasetlogic.go
Normal file
130
server/home-user-auth/internal/logic/userlogodatasetlogic.go
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/service/repositories"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
|
"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 UserLogoDataSetLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserLogoDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogoDataSetLogic {
|
||||||
|
return &UserLogoDataSetLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *UserLogoDataSetLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *UserLogoDataSetLogic) UserLogoDataSet(req *types.UserLogoDataSetReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
if userinfo.IsOnlooker() {
|
||||||
|
// 如果是,返回未授权的错误码
|
||||||
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
|
}
|
||||||
|
var userId int64
|
||||||
|
var guestId int64
|
||||||
|
|
||||||
|
// 检查用户是否是游客
|
||||||
|
if userinfo.IsGuest() {
|
||||||
|
// 如果是,使用游客ID和游客键名格式
|
||||||
|
guestId = userinfo.GuestId
|
||||||
|
} else {
|
||||||
|
// 否则,使用用户ID和用户键名格式
|
||||||
|
userId = userinfo.UserId
|
||||||
|
}
|
||||||
|
var logoData = gmodel.FsPreprocessLogo{}
|
||||||
|
result := l.svcCtx.MysqlConn.Model(&gmodel.FsPreprocessLogo{}).Where("id = ?", req.LogoDataId).Take(&logoData)
|
||||||
|
err := result.Error
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
logc.Errorf(l.ctx, "UserLogoDataSet logoData find err:%+v", err)
|
||||||
|
basic.CodeApiErr.Message = "logo data not find"
|
||||||
|
return resp.SetStatus(basic.CodeApiErr)
|
||||||
|
}
|
||||||
|
return resp.SetStatus(basic.CodeApiErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
var userMaterialMetadata []byte
|
||||||
|
if logoData.Metadata == nil {
|
||||||
|
var resultStr string
|
||||||
|
resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{
|
||||||
|
LogoUrl: *logoData.ResourceUrl,
|
||||||
|
Version: l.svcCtx.Config.BLMService.Version,
|
||||||
|
Debug: userinfo.Debug,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
basic.CodeServiceErr.Message = fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err)
|
||||||
|
return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err))
|
||||||
|
}
|
||||||
|
resultStr = resLogoStandard.Res
|
||||||
|
userMaterialMetadata = []byte(resultStr)
|
||||||
|
} else {
|
||||||
|
userMaterialMetadata = *logoData.Metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增素材
|
||||||
|
var module = "logo"
|
||||||
|
var nowTime = time.Now().UTC()
|
||||||
|
var resourceId = s3url_to_s3id.GetS3ResourceIdFormUrl(*logoData.ResourceUrl)
|
||||||
|
// 新增素材记录
|
||||||
|
materialInfo := gmodel.FsUserMaterial{
|
||||||
|
Module: &module,
|
||||||
|
UserId: &userId,
|
||||||
|
GuestId: &guestId,
|
||||||
|
ResourceId: &resourceId,
|
||||||
|
ResourceUrl: logoData.ResourceUrl,
|
||||||
|
Metadata: &userMaterialMetadata,
|
||||||
|
Ctime: &nowTime,
|
||||||
|
}
|
||||||
|
resCreate := l.svcCtx.MysqlConn.Create(&materialInfo)
|
||||||
|
err = resCreate.Error
|
||||||
|
if err != nil {
|
||||||
|
logc.Errorf(l.ctx, "UserLogoDataSet logoData find err:%+v", err)
|
||||||
|
return resp.SetStatus(basic.CodeApiErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回成功的响应和上传URL
|
||||||
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||||
|
"id": materialInfo.Id,
|
||||||
|
"module": materialInfo.Module,
|
||||||
|
"user_id": materialInfo.UserId,
|
||||||
|
"guest_id": materialInfo.GuestId,
|
||||||
|
"resource_id": materialInfo.ResourceId,
|
||||||
|
"resource_url": materialInfo.ResourceUrl,
|
||||||
|
"metadata": materialInfo.Metadata,
|
||||||
|
"ctime": materialInfo.Ctime,
|
||||||
|
"resource_info": nil,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *UserLogoDataSetLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
|
@ -106,6 +106,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var logoCategoryId int64
|
||||||
// 更新merchant_category
|
// 更新merchant_category
|
||||||
if req.SetLogoCategory == 1 {
|
if req.SetLogoCategory == 1 {
|
||||||
var metadataChildUserMaterial = make(map[string]interface{}, 1)
|
var metadataChildUserMaterial = make(map[string]interface{}, 1)
|
||||||
|
@ -121,7 +122,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
userMaterialInfo.Metadata = &metadataBUserMaterial
|
userMaterialInfo.Metadata = &metadataBUserMaterial
|
||||||
resUpdates := tx.Select("metadata").Where("id = ?", req.LogoSelectedId).Updates(&userMaterialInfo)
|
resUpdates := tx.Model(&gmodel.FsUserMaterial{}).Select("metadata", "utime").Where("id = ?", req.LogoSelectedId).Updates(&userMaterialInfo)
|
||||||
err = resUpdates.Error
|
err = resUpdates.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != gorm.ErrRecordNotFound {
|
if err != gorm.ErrRecordNotFound {
|
||||||
|
@ -129,7 +130,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logoCategoryId = req.CategoryId
|
||||||
}
|
}
|
||||||
var module = "profile"
|
var module = "profile"
|
||||||
if req.SetLogoSelected == 1 {
|
if req.SetLogoSelected == 1 {
|
||||||
|
@ -182,11 +183,16 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
|
||||||
templateTagSelected["template_tag"] = userMaterialTemplateIdTagId
|
templateTagSelected["template_tag"] = userMaterialTemplateIdTagId
|
||||||
templateTagSelected["selected_index"] = 0
|
templateTagSelected["selected_index"] = 0
|
||||||
|
|
||||||
metadataChildUserInfo["logo_selected"] = map[string]interface{}{
|
var logoSelectedMap = map[string]interface{}{
|
||||||
"logo_selected_id": req.LogoSelectedId,
|
"logo_selected_id": req.LogoSelectedId,
|
||||||
"logo_url": userMaterialInfo.ResourceUrl,
|
"logo_url": userMaterialInfo.ResourceUrl,
|
||||||
"template_tag_selected": templateTagSelected,
|
"template_tag_selected": templateTagSelected,
|
||||||
}
|
}
|
||||||
|
if logoCategoryId != 0 {
|
||||||
|
logoSelectedMap["merchant_category"] = logoCategoryId
|
||||||
|
}
|
||||||
|
|
||||||
|
metadataChildUserInfo["logo_selected"] = logoSelectedMap
|
||||||
|
|
||||||
metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo)
|
metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -212,7 +218,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
|
||||||
} else {
|
} else {
|
||||||
// 更新
|
// 更新
|
||||||
userInfo.Utime = &nowTime
|
userInfo.Utime = &nowTime
|
||||||
resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo)
|
resUpdates := tx.Model(&gmodel.FsUserInfo{}).Select("metadata", "utime").Where("id = ?", userInfo.Id).Updates(&userInfo)
|
||||||
err = resUpdates.Error
|
err = resUpdates.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,10 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type UserLogoDataSetReq struct {
|
||||||
|
LogoDataId int64 `form:"logo_data_id"`
|
||||||
|
}
|
||||||
|
|
||||||
type UserLogoTemplateTagSetReq struct {
|
type UserLogoTemplateTagSetReq struct {
|
||||||
TemplateTag string `form:"template_tag"`
|
TemplateTag string `form:"template_tag"`
|
||||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||||
|
|
|
@ -22,6 +22,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/info/user/profile",
|
Path: "/api/info/user/profile",
|
||||||
Handler: UserGetProfileHandler(serverCtx),
|
Handler: UserGetProfileHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/info/user/profile/default",
|
||||||
|
Handler: UserGetDefaultProfileHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/info/user/profile/base/update",
|
Path: "/api/info/user/profile/base/update",
|
||||||
|
|
35
server/info/internal/handler/usergetdefaultprofilehandler.go
Normal file
35
server/info/internal/handler/usergetdefaultprofilehandler.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/logic"
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UserGetDefaultProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.Request
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewUserGetDefaultProfileLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.UserGetDefaultProfile(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
server/info/internal/logic/usergetdefaultprofilelogic.go
Normal file
47
server/info/internal/logic/usergetdefaultprofilelogic.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserGetDefaultProfileLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserGetDefaultProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserGetDefaultProfileLogic {
|
||||||
|
return &UserGetDefaultProfileLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *UserGetDefaultProfileLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *UserGetDefaultProfileLogic) UserGetDefaultProfile(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
defaultProfile, err := l.svcCtx.AllModels.FsUserInfo.GetDefaultProfile(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK, defaultProfile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *UserGetDefaultProfileLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
|
@ -34,7 +34,7 @@ func (l *UserGetProfileLogic) UserGetProfile(req *types.QueryProfileRequest, use
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
// userinfo 传入值时, 一定不为null
|
// userinfo 传入值时, 一定不为null
|
||||||
|
|
||||||
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 {
|
if err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ type UploadFileBaseReq struct {
|
||||||
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
||||||
UserId int64 `form:"user_id,optional"` // 上传文件额外信息
|
UserId int64 `form:"user_id,optional"` // 上传文件额外信息
|
||||||
GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息
|
GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
Source string `form:"source"` // 上传来源
|
Source string `form:"source"` // 上传来源
|
||||||
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
||||||
ResourceId string `form:"resource_id,optional"` // 资源ID
|
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||||
|
@ -35,7 +35,7 @@ type UploadLogoReq struct {
|
||||||
|
|
||||||
type UploadFileBackendReq struct {
|
type UploadFileBackendReq struct {
|
||||||
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
FileKey string `form:"file_key"` // 上传唯一标识信息
|
FileKey string `form:"file_key"` // 上传唯一标识信息
|
||||||
FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息
|
FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息
|
||||||
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
||||||
|
@ -46,7 +46,7 @@ type UploadFileBackendReq struct {
|
||||||
|
|
||||||
type UploadFilesReq struct {
|
type UploadFilesReq struct {
|
||||||
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
UploadInfo string `form:"upload_info"` // 上传信息 json
|
UploadInfo string `form:"upload_info"` // 上传信息 json
|
||||||
Source string `form:"source"` // 上传来源
|
Source string `form:"source"` // 上传来源
|
||||||
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
||||||
|
@ -54,7 +54,7 @@ type UploadFilesReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadCallbackReq struct {
|
type UploadCallbackReq struct {
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
ResourceId string `form:"resource_id"` // 资源ID
|
ResourceId string `form:"resource_id"` // 资源ID
|
||||||
ResourceType string `form:"resource_type"` // 资源类型
|
ResourceType string `form:"resource_type"` // 资源类型
|
||||||
ResourceUrl string `form:"resource_url"` // 资源URL
|
ResourceUrl string `form:"resource_url"` // 资源URL
|
||||||
|
@ -114,10 +114,10 @@ type File struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
TotalCount int64 `json:"totalCount"`
|
TotalCount int64 `json:"total_count"`
|
||||||
PageCount int64 `json:"pageCount"`
|
PageCount int64 `json:"page_count"`
|
||||||
CurrentPage int `json:"currentPage"`
|
CurrentPage int `json:"current_page"`
|
||||||
PerPage int `json:"perPage"`
|
PerPage int `json:"per_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set 设置Response的Code和Message值
|
// Set 设置Response的Code和Message值
|
||||||
|
|
|
@ -62,8 +62,18 @@ service home-user-auth {
|
||||||
// 用户logo模版信息
|
// 用户logo模版信息
|
||||||
@handler UserLogoTemplateTagSetHandler
|
@handler UserLogoTemplateTagSetHandler
|
||||||
post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response);
|
post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response);
|
||||||
|
|
||||||
|
// 用户logo数据设置用户logo素材
|
||||||
|
@handler UserLogoDataSetHandler
|
||||||
|
post /api/user/logo-data-set (UserLogoDataSetReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
UserLogoDataSetReq {
|
||||||
|
LogoDataId int64 `form:"logo_data_id"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
UserLogoTemplateTagSetReq {
|
UserLogoTemplateTagSetReq {
|
||||||
TemplateTag string `form:"template_tag"`
|
TemplateTag string `form:"template_tag"`
|
||||||
|
|
|
@ -16,6 +16,9 @@ service info {
|
||||||
@handler UserGetProfileHandler
|
@handler UserGetProfileHandler
|
||||||
post /api/info/user/profile(QueryProfileRequest) returns (response);
|
post /api/info/user/profile(QueryProfileRequest) returns (response);
|
||||||
|
|
||||||
|
@handler UserGetDefaultProfileHandler
|
||||||
|
get /api/info/user/profile/default(request) returns (response);
|
||||||
|
|
||||||
@handler UpdateProfileBaseHandler
|
@handler UpdateProfileBaseHandler
|
||||||
post /api/info/user/profile/base/update(ProfileRequest) returns (response);
|
post /api/info/user/profile/base/update(ProfileRequest) returns (response);
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ type (
|
||||||
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
||||||
UserId int64 `form:"user_id,optional"` // 上传文件额外信息
|
UserId int64 `form:"user_id,optional"` // 上传文件额外信息
|
||||||
GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息
|
GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
Source string `form:"source"` // 上传来源
|
Source string `form:"source"` // 上传来源
|
||||||
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
||||||
ResourceId string `form:"resource_id,optional"` // 资源ID
|
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||||
|
@ -84,7 +84,7 @@ type (
|
||||||
type (
|
type (
|
||||||
UploadFileBackendReq {
|
UploadFileBackendReq {
|
||||||
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
FileKey string `form:"file_key"` // 上传唯一标识信息
|
FileKey string `form:"file_key"` // 上传唯一标识信息
|
||||||
FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息
|
FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息
|
||||||
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
||||||
|
@ -95,14 +95,14 @@ type (
|
||||||
|
|
||||||
UploadFilesReq {
|
UploadFilesReq {
|
||||||
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
UploadInfo string `form:"upload_info"` // 上传信息 json
|
UploadInfo string `form:"upload_info"` // 上传信息 json
|
||||||
Source string `form:"source"` // 上传来源
|
Source string `form:"source"` // 上传来源
|
||||||
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
||||||
ResourceId string `form:"resource_id,optional"` // 资源ID
|
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||||
}
|
}
|
||||||
UploadCallbackReq {
|
UploadCallbackReq {
|
||||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
UploadBucket int64 `form:"upload_bucket,options=[1,2,3],default=1"` // 上传桶名:1=缓存,2=持久
|
||||||
ResourceId string `form:"resource_id"` // 资源ID
|
ResourceId string `form:"resource_id"` // 资源ID
|
||||||
ResourceType string `form:"resource_type"` // 资源类型
|
ResourceType string `form:"resource_type"` // 资源类型
|
||||||
ResourceUrl string `form:"resource_url"` // 资源URL
|
ResourceUrl string `form:"resource_url"` // 资源URL
|
||||||
|
|
|
@ -11,10 +11,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// 全局的BucketName
|
// 全局的BucketName
|
||||||
var StorageBucketName = aws.String("storage.fusenpack.com")
|
var StorageBucketName = aws.String("fusenstorage")
|
||||||
|
|
||||||
// 全局的BucketName 缓存使用
|
// 全局的BucketName 缓存使用
|
||||||
var TempfileBucketName = aws.String("tempfile.fusenpack.com")
|
var TempfileBucketName = aws.String("fusentempfile")
|
||||||
|
|
||||||
|
var FusenLogoDbBucketName = aws.String("fusenstorage")
|
||||||
|
|
||||||
const UploadFileLimitSize = 200 << 20
|
const UploadFileLimitSize = 200 << 20
|
||||||
|
|
||||||
|
|
|
@ -57,12 +57,13 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
|
||||||
switch req.UploadBucket {
|
switch req.UploadBucket {
|
||||||
case 2:
|
case 2:
|
||||||
bucketName = basic.TempfileBucketName
|
bucketName = basic.TempfileBucketName
|
||||||
|
case 3:
|
||||||
|
bucketName = basic.StorageBucketName
|
||||||
default:
|
default:
|
||||||
bucketName = basic.StorageBucketName
|
bucketName = basic.StorageBucketName
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置AWS会话的区域
|
// 设置AWS会话的区域
|
||||||
upload.AwsSession.Config.Region = aws.String("us-west-1")
|
upload.AwsSession.Config.Region = aws.String("us-east-2")
|
||||||
|
|
||||||
// 创建新的S3服务实例
|
// 创建新的S3服务实例
|
||||||
svc := s3.New(upload.AwsSession)
|
svc := s3.New(upload.AwsSession)
|
||||||
|
@ -108,7 +109,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
|
||||||
&s3.PutObjectInput{
|
&s3.PutObjectInput{
|
||||||
Bucket: bucketName,
|
Bucket: bucketName,
|
||||||
Key: &resourceId,
|
Key: &resourceId,
|
||||||
CacheControl: aws.String("no-cache, must-revalidate"),
|
CacheControl: aws.String("no-cache"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -192,12 +193,13 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
|
||||||
switch req.UploadBucket {
|
switch req.UploadBucket {
|
||||||
case 2:
|
case 2:
|
||||||
bucketName = basic.TempfileBucketName
|
bucketName = basic.TempfileBucketName
|
||||||
|
case 3:
|
||||||
|
bucketName = basic.StorageBucketName
|
||||||
default:
|
default:
|
||||||
bucketName = basic.StorageBucketName
|
bucketName = basic.StorageBucketName
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置AWS会话的区域
|
// 设置AWS会话的区域
|
||||||
upload.AwsSession.Config.Region = aws.String("us-west-1")
|
upload.AwsSession.Config.Region = aws.String("us-east-2")
|
||||||
|
|
||||||
// 创建新的S3服务实例
|
// 创建新的S3服务实例
|
||||||
svc := s3.New(upload.AwsSession)
|
svc := s3.New(upload.AwsSession)
|
||||||
|
@ -237,7 +239,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
|
||||||
&s3.PutObjectInput{
|
&s3.PutObjectInput{
|
||||||
Bucket: bucketName,
|
Bucket: bucketName,
|
||||||
Key: &resourceId,
|
Key: &resourceId,
|
||||||
CacheControl: aws.String("no-cache, must-revalidate"),
|
CacheControl: aws.String("no-cache"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user