fix
This commit is contained in:
@@ -7,16 +7,14 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/map_library/internal/logic"
|
||||
"fusenapi/server/map_library/internal/svc"
|
||||
"fusenapi/utils/auth"
|
||||
)
|
||||
|
||||
func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// 解析jwtToken
|
||||
/*// 解析jwtToken
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
@@ -38,10 +36,10 @@ func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
}*/
|
||||
|
||||
l := logic.NewGetMapLibraryListLogic(r.Context(), svcCtx)
|
||||
resp := l.GetMapLibraryList(userinfo)
|
||||
resp := l.GetMapLibraryList(&auth.UserInfo{86})
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||
if resp != nil {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/map_library/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -25,5 +29,51 @@ func NewGetMapLibraryListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
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.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package svc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/map_library/internal/config"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -19,7 +20,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MysqlConn: initalize.InitMysql(c.DataSource),
|
||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user