Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-09-18 18:44:40 +08:00
commit 3ff55f671e
4 changed files with 92 additions and 43 deletions

View File

@ -36,8 +36,19 @@ func NewGetProductTemplateTagsLogic(ctx context.Context, svcCtx *svc.ServiceCont
// func (l *GetProductTemplateTagsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }
type logoSelect struct {
LogoSelected struct {
LogoSelectedId int `json:"logo_selected_id"`
TemplateTagSelected struct {
TemplateTag string `json:"template_tag"`
Color [][]string `json:"color"`
SelectedIndex int `json:"selected_index"`
} `json:"template_tag_selected"`
} `json:"logo_selected"`
}
func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProductTemplateTagsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
userinfo.UserId = 127
if req.Limit <= 0 || req.Limit > 100 {
req.Limit = 5
}
@ -54,34 +65,44 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
logx.Error(err)
return
}
var colors interface{}
if logoInfo.Metadata == nil || *logoInfo.Metadata == "" {
// 返回固定模板A1a
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 1, "`id` DESC")
if err != nil {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "logo info`s metadata is not set")
}
//解析元数据
var metaData map[string]interface{}
if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
}
var mapTemplateTag map[string][][]string
b, _ := json.Marshal(metaData["template_tag"])
if err = json.Unmarshal(b, &mapTemplateTag); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag")
}
//获取选中的颜色数据
mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引
if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" {
var logoSelectInfo logoSelect
if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user info metadata")
}
} else {
//解析元数据
var metaData map[string]interface{}
if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
}
colors = metaData["colors"]
var templateTagNameList []string
b, _ := json.Marshal(metaData["template_tagid"])
if err = json.Unmarshal(b, &templateTagNameList); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid")
}
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
//设置选中
key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag
if _, ok := mapTemplateTag[key]; ok {
mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex
}
}
var templateTagNameList []string
for templateTag, _ := range mapTemplateTag {
templateTagNameList = append(templateTagNameList, templateTag)
}
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
}
//资源id集合
resourceIds := make([]string, 0, 5)
for _, v := range productTemplateTags {
@ -102,12 +123,25 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
mapResourceMetadata[*v.ResourceUrl] = metadata
}
list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
for _, v := range productTemplateTags {
for _, templateInfo := range productTemplateTags {
colors := make([]types.ColorsItem, 0, 10)
for index, v := range mapTemplateTag[*templateInfo.TemplateTag] {
selected := false
if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok {
if index == selectIndex {
selected = true
}
}
colors = append(colors, types.ColorsItem{
Color: v,
Selected: selected,
})
}
list = append(list, types.GetProductTemplateTagsRsp{
Id: v.Id,
TemplateTag: *v.TemplateTag,
Cover: *v.Cover,
CoverMetadata: mapResourceMetadata[*v.Cover],
Id: templateInfo.Id,
TemplateTag: *templateInfo.TemplateTag,
Cover: *templateInfo.Cover,
CoverMetadata: mapResourceMetadata[*templateInfo.Cover],
Colors: colors,
})
}

View File

@ -10,11 +10,16 @@ type GetProductTemplateTagsReq struct {
}
type GetProductTemplateTagsRsp struct {
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors interface{} `json:"colors"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors []ColorsItem `json:"colors"`
}
type ColorsItem struct {
Color []string `json:"color"`
Selected bool `json:"selected"`
}
type Request struct {

View File

@ -20,9 +20,13 @@ type GetProductTemplateTagsReq {
Limit int `form:"limit"`
}
type GetProductTemplateTagsRsp {
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors interface{} `json:"colors"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors []ColorsItem `json:"colors"`
}
type ColorsItem {
Color []string `json:"color"`
Selected bool `json:"selected"`
}

View File

@ -54,15 +54,16 @@ type (
GuestId int64 `json:"guest_id"`
}
LogoInfoRes struct {
Metadata *string `json:"metadata"`
LogoUrl *string `json:"logo_url"`
Metadata *string `json:"metadata"`
LogoUrl *string `json:"logo_url"`
UserInfoMetadata *string `json:"user_info_metadata"`
}
)
func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*LogoInfoRes, error) {
var metadata *string
var logoUrl *string
var userInfoMetadata *string
// 更新用户信息
var module = "profile"
userInfoGorm := l.MysqlConn.Where("module = ?", module)
@ -82,6 +83,10 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo
return nil, err
}
}
if userInfo.Id != 0 {
tmp := string(*userInfo.Metadata)
userInfoMetadata = &tmp
}
var userMaterialInfo gmodel.FsUserMaterial
userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn)
@ -134,8 +139,9 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo
logoUrl = userMaterialInfo.ResourceUrl
}
return &LogoInfoRes{
Metadata: metadata,
LogoUrl: logoUrl,
Metadata: metadata,
LogoUrl: logoUrl,
UserInfoMetadata: userInfoMetadata,
}, nil
}