60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"errors"
|
|
"fusenapi/model/gmodel"
|
|
"fusenapi/server/product-templatev2/internal/types"
|
|
"fusenapi/utils/basic"
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
"time"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/product-templatev2/internal/svc"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetBaseMapListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetBaseMapListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBaseMapListLogic {
|
|
return &GetBaseMapListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetBaseMapListLogic) GetBaseMapList(r *http.Request) (resp *basic.Response) {
|
|
authKey := r.Header.Get("Auth-Key")
|
|
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
|
_, err := genentModel.Find(l.ctx, authKey)
|
|
if err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
|
}
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
|
}
|
|
baseMapFields := "id,name,url,ctime"
|
|
baseMapList, err := l.svcCtx.AllModels.FsProductTemplateBasemap.GetAllEnabledList(l.ctx, baseMapFields)
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product base map list")
|
|
}
|
|
list := make([]types.GetBaseMapListRsp, 0, len(baseMapList))
|
|
for _, v := range baseMapList {
|
|
list = append(list, types.GetBaseMapListRsp{
|
|
Id: v.Id,
|
|
Name: *v.Name,
|
|
Url: *v.Url,
|
|
Ctime: time.Unix(*v.Ctime, 0).Format("2006-01-02 15:04:05"),
|
|
})
|
|
}
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
|
}
|