fix
This commit is contained in:
81
server/map-library/internal/logic/getmaplibrarylistlogic.go
Normal file
81
server/map-library/internal/logic/getmaplibrarylistlogic.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/map-library/internal/svc"
|
||||
"fusenapi/server/map-library/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetMapLibraryListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMapLibraryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMapLibraryListLogic {
|
||||
return &GetMapLibraryListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
}
|
||||
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
||||
mapLibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get map library list")
|
||||
}
|
||||
if len(mapLibraryList) == 0 {
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
productTemplateTagIds := make([]int64, 0, len(mapLibraryList))
|
||||
for _, v := range mapLibraryList {
|
||||
productTemplateTagIds = append(productTemplateTagIds, *v.TagId)
|
||||
}
|
||||
//获取标签列表
|
||||
productTemplateTagsModel := gmodel.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn)
|
||||
templateTagList, err := productTemplateTagsModel.GetListByIds(l.ctx, productTemplateTagIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product template tags")
|
||||
}
|
||||
mapTag := make(map[int64]int)
|
||||
for k, v := range templateTagList {
|
||||
mapTag[v.Id] = k
|
||||
}
|
||||
list := make([]types.GetMapLibraryListRsp, 0, len(mapLibraryList))
|
||||
for _, v := range mapLibraryList {
|
||||
data := types.GetMapLibraryListRsp{
|
||||
Mid: v.Id,
|
||||
Ctime: time.Unix(*v.Ctime, 0).Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
//tag拼装
|
||||
if tagIndex, ok := mapTag[*v.TagId]; ok {
|
||||
data.Tag = types.MapLibraryListTag{
|
||||
Id: templateTagList[tagIndex].Id,
|
||||
Title: *templateTagList[tagIndex].Title,
|
||||
}
|
||||
}
|
||||
//解析info
|
||||
var info types.MapLibraryListInfo
|
||||
if err = json.Unmarshal([]byte(*v.Info), &info); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "json parse info err")
|
||||
}
|
||||
data.Info = info
|
||||
list = append(list, data)
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
||||
}
|
||||
Reference in New Issue
Block a user