Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
a5ea734eb0
|
@ -35,3 +35,6 @@ func (bm *FsProductTemplateBasemapModel) UpdateBaseMapWithTransaction(ctx contex
|
|||
Where("`status` = ? and `id` not in (?)", 1, notInIds).Update("status", 0).Error
|
||||
})
|
||||
}
|
||||
func (bm *FsProductTemplateBasemapModel) Create(ctx context.Context, data *FsProductTemplateBasemap) error {
|
||||
return bm.db.WithContext(ctx).Create(&data).Error
|
||||
}
|
||||
|
|
|
@ -37,3 +37,6 @@ func (t *FsProductTemplateV2Model) FindByParam(ctx context.Context, id int64, mo
|
|||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (t *FsProductTemplateV2Model) Update(ctx context.Context, id int64, data *FsProductTemplateV2) error {
|
||||
return t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Updates(&data).Error
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/logic"
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
"fusenapi/server/product-templatev2/internal/types"
|
||||
)
|
||||
|
||||
func AddBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AddBaseMapReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewAddBaseMapLogic(r.Context(), svcCtx)
|
||||
resp := l.AddBaseMap(&req, r)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/product-template/base-map-update",
|
||||
Handler: SaveBaseMapHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/product-template/base-map-add",
|
||||
Handler: AddBaseMapHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/product-template/update-template",
|
||||
Handler: UpdateTemplateHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/logic"
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
"fusenapi/server/product-templatev2/internal/types"
|
||||
)
|
||||
|
||||
func UpdateTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateTemplateReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUpdateTemplateLogic(r.Context(), svcCtx)
|
||||
resp := l.UpdateTemplate(&req, r)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
61
server/product-templatev2/internal/logic/addbasemaplogic.go
Normal file
61
server/product-templatev2/internal/logic/addbasemaplogic.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
"fusenapi/server/product-templatev2/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, 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")
|
||||
}
|
||||
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().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")
|
||||
}
|
102
server/product-templatev2/internal/logic/updatetemplatelogic.go
Normal file
102
server/product-templatev2/internal/logic/updatetemplatelogic.go
Normal file
|
@ -0,0 +1,102 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
"fusenapi/server/product-templatev2/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateTemplateLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateTemplateLogic {
|
||||
return &UpdateTemplateLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateTemplateLogic) UpdateTemplate(req *types.UpdateTemplateReq, 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")
|
||||
}
|
||||
if req.ModelId <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param modelId is required")
|
||||
}
|
||||
if req.TemplateData == nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param template data is required")
|
||||
}
|
||||
if req.TemplateData.Id <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param template data`id is required")
|
||||
}
|
||||
//验证模板数据真实性
|
||||
templatev2Info, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOne(l.ctx, req.TemplateData.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get v2 template info")
|
||||
}
|
||||
if *templatev2Info.ModelId != req.ModelId {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "the template`s model id is not match")
|
||||
}
|
||||
templateInfoBytes, err := json.Marshal(req.TemplateData)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to marshal template data")
|
||||
}
|
||||
templateInfoJson := string(templateInfoBytes)
|
||||
//保存模板宽高
|
||||
var logoWidth int64
|
||||
var logoHeight int64
|
||||
for _, v := range req.TemplateData.MaterialList {
|
||||
//logo面板需保存宽高
|
||||
if v["tag"] == "Logo" {
|
||||
logoWidth, _ = v["width"].(json.Number).Int64()
|
||||
logoHeight, _ = v["height"].(json.Number).Int64()
|
||||
break
|
||||
}
|
||||
}
|
||||
isPublic := int64(0)
|
||||
if req.TemplateData.IsPublic {
|
||||
isPublic = 1
|
||||
}
|
||||
updData := gmodel.FsProductTemplateV2{
|
||||
TemplateInfo: &templateInfoJson,
|
||||
MaterialImg: &req.TemplateData.Material,
|
||||
Name: &req.TemplateData.Name,
|
||||
LogoWidth: &logoWidth,
|
||||
LogoHeight: &logoHeight,
|
||||
IsPublic: &isPublic,
|
||||
}
|
||||
if err = l.svcCtx.AllModels.FsProductTemplateV2.Update(l.ctx, req.TemplateData.Id, &updData); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeSaveErr, "failed to update template")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.UpdateTemplateRsp{
|
||||
ModelId: req.ModelId,
|
||||
TemplateId: req.TemplateData.Id,
|
||||
})
|
||||
}
|
|
@ -31,6 +31,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
|
|
@ -42,20 +42,39 @@ type SaveBaseMapReq struct {
|
|||
Ctime string `json:"ctime"`
|
||||
}
|
||||
|
||||
type AddBaseMapReq struct {
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type UpdateTemplateReq struct {
|
||||
ModelId int64 `json:"modelId"`
|
||||
TemplateData *TemplateData `json:"templateData"`
|
||||
}
|
||||
|
||||
type TemplateData struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cover string `json:"cover"`
|
||||
IsPublic bool `json:"isPublic"`
|
||||
Material string `json:"material"`
|
||||
MaterialList []map[string]interface{} `json:"materialList"`
|
||||
}
|
||||
|
||||
type UpdateTemplateRsp struct {
|
||||
ModelId int64 `json:"modelId"`
|
||||
TemplateId int64 `json:"templateId"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ResponseJwt struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
AccessSecret string `json:"accessSecret"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
AccessSecret string `json:"accessSecret"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
|
|
|
@ -31,6 +31,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "产品模板"// TODO: add title
|
||||
title: "产品模板底图服务"// TODO: add title
|
||||
desc: // TODO: add description
|
||||
author: ""
|
||||
email: ""
|
||||
|
@ -16,10 +16,15 @@ service product-templatev2 {
|
|||
//获取底图列表
|
||||
@handler GetBaseMapListHandler
|
||||
get /product-template/base-map-list( ) returns (response);
|
||||
//保存底图列表信息
|
||||
//底图批量保存
|
||||
@handler SaveBaseMapHandler
|
||||
post /product-template/base-map-update ( ) returns (response);
|
||||
|
||||
//新增底图
|
||||
@handler AddBaseMapHandler
|
||||
post /product-template/base-map-add (AddBaseMapReq) returns (response);
|
||||
//更新模板
|
||||
@handler UpdateTemplateHandler
|
||||
post /product-template/update-template (UpdateTemplateReq) returns (response);
|
||||
}
|
||||
|
||||
//获取产品模板详情
|
||||
|
@ -57,4 +62,26 @@ type SaveBaseMapReq {
|
|||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
Ctime string `json:"ctime"`
|
||||
}
|
||||
//新增底图
|
||||
type AddBaseMapReq {
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
//更新模板
|
||||
type UpdateTemplateReq {
|
||||
ModelId int64 `json:"modelId"`
|
||||
TemplateData *TemplateData `json:"templateData"`
|
||||
}
|
||||
type TemplateData {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cover string `json:"cover"`
|
||||
IsPublic bool `json:"isPublic"`
|
||||
Material string `json:"material"`
|
||||
MaterialList []map[string]interface{} `json:"materialList"`
|
||||
}
|
||||
type UpdateTemplateRsp {
|
||||
ModelId int64 `json:"modelId"`
|
||||
TemplateId int64 `json:"templateId"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user