50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"fusenapi/model/gmodel"
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/basic"
|
|
"strings"
|
|
"time"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/product-template/internal/svc"
|
|
"fusenapi/server/product-template/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AddBaseMapLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewAddBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddBaseMapLogic {
|
|
return &AddBaseMapLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *AddBaseMapLogic) AddBaseMap(req *types.AddBaseMapReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
|
req.Name = strings.Trim(req.Name, " ")
|
|
req.Url = strings.Trim(req.Url, " ")
|
|
if req.Name == "" || req.Url == "" {
|
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param is empty")
|
|
}
|
|
now := time.Now().UTC().Unix()
|
|
err := l.svcCtx.AllModels.FsProductTemplateBasemap.Create(l.ctx, &gmodel.FsProductTemplateBasemap{
|
|
Name: &req.Name,
|
|
Url: &req.Url,
|
|
Ctime: &now,
|
|
})
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeSaveErr, "failed to add base map")
|
|
}
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
|
}
|