Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
c870ab773a
|
@ -3,7 +3,7 @@ package gmodel
|
|||
import "context"
|
||||
|
||||
func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields string) (resp []FsMapLibrary, err error) {
|
||||
db := ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 0)
|
||||
db := ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 1)
|
||||
if fields != "" {
|
||||
db = db.Select(fields)
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields strin
|
|||
return
|
||||
}
|
||||
func (ml *FsMapLibraryModel) Create(ctx context.Context, data *FsMapLibrary) error {
|
||||
return ml.db.WithContext(ctx).Create(data).Error
|
||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Create(data).Error
|
||||
}
|
||||
func (ml *FsMapLibraryModel) Update(ctx context.Context, id int64, data *FsMapLibrary) error {
|
||||
return ml.db.WithContext(ctx).Where("`id` = ? ", id).Updates(data).Error
|
||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`id` = ? ", id).Updates(data).Error
|
||||
}
|
||||
func (ml *FsMapLibraryModel) ChangeStatusByIds(ctx context.Context, ids []int64, status int64) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
return ml.db.WithContext(ctx).Where("`id` in (?) ", ids).Update("status", 0).Error
|
||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`id` in (?) ", ids).Update("status", 0).Error
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
"fusenapi/server/map-library/internal/logic"
|
||||
"fusenapi/server/map-library/internal/svc"
|
||||
"fusenapi/server/map-library/internal/types"
|
||||
)
|
||||
|
||||
func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
@ -52,20 +51,9 @@ func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
// 如果claims为nil,则认为用户身份为白板用户
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
var req types.SaveMapLibraryReq
|
||||
// 如果端点有请求结构体,则使用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.NewSaveMapLibraryLogic(r.Context(), svcCtx)
|
||||
resp := l.SaveMapLibrary(&req, userinfo)
|
||||
resp := l.SaveMapLibrary(userinfo, r)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
|
|
@ -69,7 +69,7 @@ func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (res
|
|||
}
|
||||
}
|
||||
//解析info
|
||||
var info types.Info
|
||||
var info interface{}
|
||||
if err = json.Unmarshal([]byte(*v.Info), &info); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "json parse info err")
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -30,10 +32,17 @@ func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sa
|
|||
}
|
||||
}
|
||||
|
||||
func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, req *http.Request) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
}
|
||||
bodyData, err := ioutil.ReadAll(req.Body)
|
||||
defer req.Body.Close()
|
||||
var postData []types.SaveMapLibraryData
|
||||
if err = json.Unmarshal(bodyData, &postData); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeSaveErr, "param err")
|
||||
}
|
||||
//获取所有贴图数据[获取id]
|
||||
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
||||
maplibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "`id`")
|
||||
|
@ -45,11 +54,11 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, useri
|
|||
sort := int64(0)
|
||||
status := int64(1)
|
||||
now := time.Now().Unix()
|
||||
needDeleteMid := make([]int64, 0, len(req.Data))
|
||||
needDeleteMid := make([]int64, 0, len(postData))
|
||||
mapPostMid := make(map[int64]struct{})
|
||||
//开启事务
|
||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
for _, v := range req.Data {
|
||||
for _, v := range postData {
|
||||
infoByte, _ := json.Marshal(v.Info)
|
||||
infoJsonStr := string(infoByte)
|
||||
switch v.Mid {
|
||||
|
@ -72,9 +81,10 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, useri
|
|||
}
|
||||
mapPostMid[midInt] = struct{}{}
|
||||
err = mapLibraryModel.Update(l.ctx, midInt, &gmodel.FsMapLibrary{
|
||||
Title: &v.Info.Title,
|
||||
Info: &infoJsonStr,
|
||||
TagId: &v.Tag.Id,
|
||||
Title: &v.Info.Title,
|
||||
Info: &infoJsonStr,
|
||||
TagId: &v.Tag.Id,
|
||||
Status: &status,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -9,7 +9,7 @@ type GetMapLibraryListRsp struct {
|
|||
Mid int64 `json:"mid"`
|
||||
Ctime string `json:"ctime"`
|
||||
Tag MapLibraryListTag `json:"tag"`
|
||||
Info Info `json:"info"`
|
||||
Info interface{} `json:"info"`
|
||||
}
|
||||
|
||||
type MapLibraryListTag struct {
|
||||
|
@ -17,78 +17,74 @@ type MapLibraryListTag struct {
|
|||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type SaveMapLibraryReq struct {
|
||||
Data []SaveMapLibraryData `json:"-"`
|
||||
}
|
||||
|
||||
type SaveMapLibraryData struct {
|
||||
Mid string `json:"mid"`
|
||||
Tid string `json:"tid"`
|
||||
Ctime string `json:"ctime"`
|
||||
Tag Tag `json:"tag"`
|
||||
Info Info `json:"info"`
|
||||
Tag Tag `json:"tag,optional"`
|
||||
Info Info `json:"info,optional"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Id int64 `json:"id,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
Id string `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Fill string `json:"fill"`
|
||||
FontSize int64 `json:"fontSize"`
|
||||
FontFamily string `json:"fontFamily"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
IfGroup bool `json:"ifGroup"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Rotation int64 `json:"rotation"`
|
||||
Align string `json:"align"`
|
||||
VerticalAlign string `json:"verticalAlign"`
|
||||
Material string `json:"material"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"Y"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
||||
ZIndex int64 `json:"zIndex"`
|
||||
SvgPath string `json:"svgPath"`
|
||||
Follow Follow `json:"follow"`
|
||||
Group []Group `json:"group"`
|
||||
CameraStand CameraStand `json:"cameraStand"`
|
||||
Id string `json:"id,optional"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
Type string `json:"type,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Fill string `json:"fill,optional"`
|
||||
FontSize int64 `json:"fontSize,optional"`
|
||||
FontFamily string `json:"fontFamily,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
IfGroup bool `json:"ifGroup,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
Rotation int64 `json:"rotation,optional"`
|
||||
Align string `json:"align,optional"`
|
||||
VerticalAlign string `json:"verticalAlign,optional"`
|
||||
Material string `json:"material,optional"`
|
||||
Width float64 `json:"width,optional"`
|
||||
Height float64 `json:"height,optional"`
|
||||
X float64 `json:"x,optional"`
|
||||
Y float64 `json:"Y,optional"`
|
||||
Opacity float64 `json:"opacity,optional"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor,optional"`
|
||||
ZIndex int64 `json:"zIndex,optional"`
|
||||
SvgPath string `json:"svgPath,optional"`
|
||||
Follow Follow `json:"follow,optional"`
|
||||
Group []Group `json:"group,optional"`
|
||||
CameraStand CameraStand `json:"cameraStand,optional"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
Tag string `json:"tag"`
|
||||
Text string `json:"text"`
|
||||
Title string `json:"title"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
}
|
||||
|
||||
type OptionalColor struct {
|
||||
OptionalColor string `json:"color"`
|
||||
Name string `json:"name"`
|
||||
Default bool `json:"default"`
|
||||
OptionalColor string `json:"color,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Default bool `json:"default,optional"`
|
||||
}
|
||||
|
||||
type Follow struct {
|
||||
Fill string `json:"fill"`
|
||||
IfShow string `json:"ifShow"`
|
||||
Content string `json:"content"`
|
||||
Fill string `json:"fill,optional"`
|
||||
IfShow string `json:"ifShow,optional"`
|
||||
Content string `json:"content,optional"`
|
||||
}
|
||||
|
||||
type CameraStand struct {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
X int64 `json:"x,optional"`
|
||||
Y int64 `json:"y,optional"`
|
||||
Z int64 `json:"z,optional"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
|
|
8
server/product-templatev2/etc/product-templatev2.yaml
Normal file
8
server/product-templatev2/etc/product-templatev2.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
Name: product-templatev2
|
||||
Host: 0.0.0.0
|
||||
Port: 8895
|
||||
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
AccessExpire: 60
|
||||
RefreshAfter: 60
|
12
server/product-templatev2/internal/config/config.go
Normal file
12
server/product-templatev2/internal/config/config.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fusenapi/server/product-templatev2/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/logic"
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
"fusenapi/server/product-templatev2/internal/types"
|
||||
)
|
||||
|
||||
func GetTemplatevDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var (
|
||||
// 定义错误变量
|
||||
err error
|
||||
// 定义用户信息变量
|
||||
userinfo *auth.UserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
if claims != nil {
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 如果claims为nil,则认为用户身份为白板用户
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
var req types.GetTemplatevDetailReq
|
||||
// 如果端点有请求结构体,则使用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.NewGetTemplatevDetailLogic(r.Context(), svcCtx)
|
||||
resp := l.GetTemplatevDetail(&req, userinfo)
|
||||
// 如果响应不为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)
|
||||
}
|
||||
}
|
||||
}
|
22
server/product-templatev2/internal/handler/routes.go
Normal file
22
server/product-templatev2/internal/handler/routes.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/product-template/detail",
|
||||
Handler: GetTemplatevDetailHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
"fusenapi/server/product-templatev2/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetTemplatevDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetTemplatevDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTemplatevDetailLogic {
|
||||
return &GetTemplatevDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
50
server/product-templatev2/internal/svc/servicecontext.go
Normal file
50
server/product-templatev2/internal/svc/servicecontext.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package svc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/product-templatev2/internal/config"
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
|
||||
MysqlConn *gorm.DB
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
}
|
||||
|
||||
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
|
||||
// 检查签名方法是否为 HS256
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
}
|
||||
|
||||
// 验证成功返回
|
||||
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
||||
}
|
241
server/product-templatev2/internal/types/types.go
Normal file
241
server/product-templatev2/internal/types/types.go
Normal file
|
@ -0,0 +1,241 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
import (
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type GetTemplatevDetailReq struct {
|
||||
ModelId int64 `form:"model_id"`
|
||||
TemplateId int64 `form:"template_id"`
|
||||
}
|
||||
|
||||
type GetTemplatevDetailRsp struct {
|
||||
ProductModelInfo ProductModelInfo `json:"product_model_info"`
|
||||
ProductTemplate ProductTemplate `json:"product_template"`
|
||||
LightList []Light `json:"light_list"`
|
||||
OptionModelInfo []interface{} `json:"option_model_info"`
|
||||
Tag int64 `json:"tag"`
|
||||
}
|
||||
|
||||
type ProductModelInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
KnifeTerritory string `json:"knifeTerritory"`
|
||||
Cover string `json:"cover"`
|
||||
CameraData CameraData `json:"cameraData"`
|
||||
ControlsData ControlsData `json:"controlsData"`
|
||||
Material ModelMaterial `json:"material"`
|
||||
ModelData ModelData `json:"modelData"`
|
||||
LightData int64 `json:"lightData"`
|
||||
LightList []int64 `json:"lightList"`
|
||||
Parts string `json:"parts"`
|
||||
PartsList []int64 `json:"partsList"`
|
||||
Tag int64 `json:"tag"`
|
||||
}
|
||||
|
||||
type CameraData struct {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
}
|
||||
|
||||
type ControlsData struct {
|
||||
MinDistance int64 `json:"minDistance"`
|
||||
MaxDistance int64 `json:"maxDistance"`
|
||||
MaxPolarAngle float64 `json:"maxPolarAngle"`
|
||||
MinPolarAngle float64 `json:"minPolarAngle"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type TemplateInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cover string `json:"cover"`
|
||||
IsPublic bool `json:"isPublic"`
|
||||
Material string `json:"material"`
|
||||
MaterialList TemplateMateria `json:"materialList"`
|
||||
}
|
||||
|
||||
type ProductTemplate struct {
|
||||
CoverImg string `json:"cover_img"`
|
||||
Id int64 `json:"id"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
LogoHeight int64 `json:"logo_height"`
|
||||
LogoWidth int64 `json:"logo_width"`
|
||||
MaterialImg string `json:"material_img"`
|
||||
ModelId int64 `json:"model_id"`
|
||||
Name string `json:"name"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
Sort int64 `json:"sort"`
|
||||
Tag Tag `json:"tag"`
|
||||
TemplateInfo TemplateInfo `json:"template_info"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type Light struct {
|
||||
Id int64 `json:"id"`
|
||||
Info LightInfo `json:"info"`
|
||||
}
|
||||
|
||||
type ModelMaterial struct {
|
||||
AoMap string `json:"aoMap"`
|
||||
AoMapint64ensity int64 `json:"aoMapint64ensity"`
|
||||
NormalMap string `json:"normalMap"`
|
||||
NormalScale []int64 `json:"normalScale"`
|
||||
SpecularMap string `json:"specularMap"`
|
||||
Roughness int64 `json:"roughness"`
|
||||
MetalnessMap string `json:"metalnessMap"`
|
||||
Metalness int64 `json:"metalness"`
|
||||
}
|
||||
|
||||
type ModelData struct {
|
||||
Path string `json:"path"`
|
||||
Shadow string `json:"shadow"`
|
||||
}
|
||||
|
||||
type TemplateMateria struct {
|
||||
Id string `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Fill string `json:"fill"`
|
||||
FontSize int64 `json:"fontSize"`
|
||||
FontFamily string `json:"fontFamily"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
IfGroup bool `json:"ifGroup"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Rotation int64 `json:"rotation"`
|
||||
LineHeight int64 `json:"lineHeight"`
|
||||
Align string `json:"align"`
|
||||
VerticalAlign string `json:"verticalAlign"`
|
||||
Material string `json:"material"`
|
||||
MaterialTime string `json:"materialTime"`
|
||||
MaterialName string `json:"materialName"`
|
||||
QRcodeType string `json:"QRcodeType"`
|
||||
Width int64 `json:"width"`
|
||||
Height int64 `json:"height"`
|
||||
Proportion int64 `json:"proportion"`
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Opacity int64 `json:"opacity"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
||||
ZIndex int64 `json:"zIndex"`
|
||||
SvgPath string `json:"svgPath"`
|
||||
Follow Follow `json:"follow"`
|
||||
Group []interface{} `json:"group"`
|
||||
CameraStand CameraStand `json:"cameraStand"`
|
||||
}
|
||||
|
||||
type LightInfo struct {
|
||||
Name string `json:"name"`
|
||||
Hdr Hdr `json:"hdr"`
|
||||
LightData []LightDataItem `json:"lightData"`
|
||||
}
|
||||
|
||||
type LightDataItem struct {
|
||||
Color string `json:"color"`
|
||||
Id string `json:"id"`
|
||||
Intensity float64 `json:"intensity"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
X float64 `json:"x,omitempty"`
|
||||
Y int64 `json:"y,omitempty"`
|
||||
Z float64 `json:"z,omitempty"`
|
||||
ShowHelper bool `json:"showHelper,omitempty"`
|
||||
Width int64 `json:"width,omitempty"`
|
||||
Height int64 `json:"height,omitempty"`
|
||||
Rx int64 `json:"rx,omitempty"`
|
||||
Ry int64 `json:"ry,omitempty"`
|
||||
Rz int64 `json:"rz,omitempty"`
|
||||
}
|
||||
|
||||
type Hdr struct {
|
||||
IfBg bool `json:"ifBg"`
|
||||
ToneMappingExposure float64 `json:"toneMappingExposure"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type OptionalColor struct {
|
||||
Color string `json:"color"`
|
||||
Name string `json:"name"`
|
||||
Default bool `json:"default"`
|
||||
}
|
||||
|
||||
type Follow struct {
|
||||
Fill string `json:"fill"`
|
||||
IfShow string `json:"ifShow"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type CameraStand struct {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
}
|
||||
|
||||
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"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
func (resp *Response) Set(Code int, Message string) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
}
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
Data: Data,
|
||||
}
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: msg,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
49
server/product-templatev2/product-templatev2.go
Normal file
49
server/product-templatev2/product-templatev2.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"fusenapi/server/product-templatev2/internal/config"
|
||||
"fusenapi/server/product-templatev2/internal/handler"
|
||||
"fusenapi/server/product-templatev2/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/product-templatev2.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
|
||||
// var testConfigFile = flag.String("f", "../etc/product-templatev2.yaml", "the config file")
|
||||
// var cnf config.Config
|
||||
|
||||
// func GetTestServer() *rest.Server {
|
||||
// flag.Parse()
|
||||
|
||||
// conf.MustLoad(*testConfigFile, &cnf)
|
||||
|
||||
// server := rest.MustNewServer(cnf.RestConf)
|
||||
// defer server.Stop()
|
||||
|
||||
// ctx := svc.NewServiceContext(cnf)
|
||||
// handler.RegisterHandlers(server, ctx)
|
||||
|
||||
// fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
|
||||
// return server
|
||||
// }
|
|
@ -14,7 +14,7 @@ service map-library {
|
|||
get /map-library/list ( ) returns (response);
|
||||
//保存贴图信息
|
||||
@handler SaveMapLibraryHandler
|
||||
post /map-library/save (SaveMapLibraryReq) returns (response);
|
||||
post /map-library/save () returns (response);
|
||||
}
|
||||
|
||||
//获取贴图库列表
|
||||
|
@ -22,7 +22,7 @@ type GetMapLibraryListRsp {
|
|||
Mid int64 `json:"mid"`
|
||||
Ctime string `json:"ctime"`
|
||||
Tag MapLibraryListTag `json:"tag"`
|
||||
Info Info `json:"info"`
|
||||
Info interface{} `json:"info"`
|
||||
}
|
||||
type MapLibraryListTag {
|
||||
Id int64 `json:"id"`
|
||||
|
@ -30,70 +30,67 @@ type MapLibraryListTag {
|
|||
}
|
||||
|
||||
//保存贴图信息
|
||||
type SaveMapLibraryReq {
|
||||
Data []SaveMapLibraryData `json:"-"`
|
||||
}
|
||||
type SaveMapLibraryData {
|
||||
Mid string `json:"mid"`
|
||||
Tid string `json:"tid"`
|
||||
Ctime string `json:"ctime"`
|
||||
Tag Tag `json:"tag"`
|
||||
Info Info `json:"info"`
|
||||
Tag Tag `json:"tag,optional"`
|
||||
Info Info `json:"info,optional"`
|
||||
}
|
||||
|
||||
type Tag {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Id int64 `json:"id,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
}
|
||||
type Info {
|
||||
Id string `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Fill string `json:"fill"`
|
||||
FontSize int64 `json:"fontSize"`
|
||||
FontFamily string `json:"fontFamily"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
IfGroup bool `json:"ifGroup"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Rotation int64 `json:"rotation"`
|
||||
Align string `json:"align"`
|
||||
VerticalAlign string `json:"verticalAlign"`
|
||||
Material string `json:"material"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"Y"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
||||
ZIndex int64 `json:"zIndex"`
|
||||
SvgPath string `json:"svgPath"`
|
||||
Follow Follow `json:"follow"`
|
||||
Group []Group `json:"group"`
|
||||
CameraStand CameraStand `json:"cameraStand"`
|
||||
Id string `json:"id,optional"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
Type string `json:"type,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Fill string `json:"fill,optional"`
|
||||
FontSize int64 `json:"fontSize,optional"`
|
||||
FontFamily string `json:"fontFamily,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
IfGroup bool `json:"ifGroup,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
Rotation int64 `json:"rotation,optional"`
|
||||
Align string `json:"align,optional"`
|
||||
VerticalAlign string `json:"verticalAlign,optional"`
|
||||
Material string `json:"material,optional"`
|
||||
Width float64 `json:"width,optional"`
|
||||
Height float64 `json:"height,optional"`
|
||||
X float64 `json:"x,optional"`
|
||||
Y float64 `json:"Y,optional"`
|
||||
Opacity float64 `json:"opacity,optional"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor,optional"`
|
||||
ZIndex int64 `json:"zIndex,optional"`
|
||||
SvgPath string `json:"svgPath,optional"`
|
||||
Follow Follow `json:"follow,optional"`
|
||||
Group []Group `json:"group,optional"`
|
||||
CameraStand CameraStand `json:"cameraStand,optional"`
|
||||
}
|
||||
type Group {
|
||||
Tag string `json:"tag"`
|
||||
Text string `json:"text"`
|
||||
Title string `json:"title"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
}
|
||||
type OptionalColor {
|
||||
OptionalColor string `json:"color"`
|
||||
Name string `json:"name"`
|
||||
Default bool `json:"default"`
|
||||
OptionalColor string `json:"color,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Default bool `json:"default,optional"`
|
||||
}
|
||||
type Follow {
|
||||
Fill string `json:"fill"`
|
||||
IfShow string `json:"ifShow"`
|
||||
Content string `json:"content"`
|
||||
Fill string `json:"fill,optional"`
|
||||
IfShow string `json:"ifShow,optional"`
|
||||
Content string `json:"content,optional"`
|
||||
}
|
||||
type CameraStand {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
X int64 `json:"x,optional"`
|
||||
Y int64 `json:"y,optional"`
|
||||
Z int64 `json:"z,optional"`
|
||||
}
|
176
server_api/product-templatev2.api
Normal file
176
server_api/product-templatev2.api
Normal file
|
@ -0,0 +1,176 @@
|
|||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "产品模板"// TODO: add title
|
||||
desc: // TODO: add description
|
||||
author: ""
|
||||
email: ""
|
||||
)
|
||||
import "basic.api"
|
||||
service product-templatev2 {
|
||||
//获取产品模板详情
|
||||
@handler GetTemplatevDetailHandler
|
||||
get /product-template/detail(GetTemplatevDetailReq) returns (response);
|
||||
}
|
||||
|
||||
//获取产品模板详情
|
||||
type GetTemplatevDetailReq {
|
||||
ModelId int64 `form:"model_id"`
|
||||
TemplateId int64 `form:"template_id"`
|
||||
}
|
||||
type GetTemplatevDetailRsp {
|
||||
ProductModelInfo ProductModelInfo `json:"product_model_info"`
|
||||
ProductTemplate ProductTemplate `json:"product_template"`
|
||||
LightList []Light `json:"light_list"`
|
||||
OptionModelInfo []interface{} `json:"option_model_info"`
|
||||
Tag int64 `json:"tag"`
|
||||
}
|
||||
|
||||
type ProductModelInfo {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
KnifeTerritory string `json:"knifeTerritory"`
|
||||
Cover string `json:"cover"`
|
||||
CameraData CameraData `json:"cameraData"`
|
||||
ControlsData ControlsData `json:"controlsData"`
|
||||
Material ModelMaterial `json:"material"`
|
||||
ModelData ModelData `json:"modelData"`
|
||||
LightData int64 `json:"lightData"`
|
||||
LightList []int64 `json:"lightList"`
|
||||
Parts string `json:"parts"`
|
||||
PartsList []int64 `json:"partsList"`
|
||||
Tag int64 `json:"tag"`
|
||||
}
|
||||
|
||||
type CameraData {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
}
|
||||
type ControlsData {
|
||||
MinDistance int64 `json:"minDistance"`
|
||||
MaxDistance int64 `json:"maxDistance"`
|
||||
MaxPolarAngle float64 `json:"maxPolarAngle"`
|
||||
MinPolarAngle float64 `json:"minPolarAngle"`
|
||||
}
|
||||
type Tag {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
type TemplateInfo {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cover string `json:"cover"`
|
||||
IsPublic bool `json:"isPublic"`
|
||||
Material string `json:"material"`
|
||||
MaterialList TemplateMateria `json:"materialList"`
|
||||
}
|
||||
type ProductTemplate {
|
||||
CoverImg string `json:"cover_img"`
|
||||
Id int64 `json:"id"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
LogoHeight int64 `json:"logo_height"`
|
||||
LogoWidth int64 `json:"logo_width"`
|
||||
MaterialImg string `json:"material_img"`
|
||||
ModelId int64 `json:"model_id"`
|
||||
Name string `json:"name"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
Sort int64 `json:"sort"`
|
||||
Tag Tag `json:"tag"`
|
||||
TemplateInfo TemplateInfo `json:"template_info"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
type Light {
|
||||
Id int64 `json:"id"`
|
||||
Info LightInfo `json:"info"`
|
||||
}
|
||||
|
||||
type ModelMaterial {
|
||||
AoMap string `json:"aoMap"`
|
||||
AoMapint64ensity int64 `json:"aoMapint64ensity"`
|
||||
NormalMap string `json:"normalMap"`
|
||||
NormalScale []int64 `json:"normalScale"`
|
||||
SpecularMap string `json:"specularMap"`
|
||||
Roughness int64 `json:"roughness"`
|
||||
MetalnessMap string `json:"metalnessMap"`
|
||||
Metalness int64 `json:"metalness"`
|
||||
}
|
||||
type ModelData {
|
||||
Path string `json:"path"`
|
||||
Shadow string `json:"shadow"`
|
||||
}
|
||||
type TemplateMateria {
|
||||
Id string `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Fill string `json:"fill"`
|
||||
FontSize int64 `json:"fontSize"`
|
||||
FontFamily string `json:"fontFamily"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
IfGroup bool `json:"ifGroup"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Rotation int64 `json:"rotation"`
|
||||
LineHeight int64 `json:"lineHeight"`
|
||||
Align string `json:"align"`
|
||||
VerticalAlign string `json:"verticalAlign"`
|
||||
Material string `json:"material"`
|
||||
MaterialTime string `json:"materialTime"`
|
||||
MaterialName string `json:"materialName"`
|
||||
QRcodeType string `json:"QRcodeType"`
|
||||
Width int64 `json:"width"`
|
||||
Height int64 `json:"height"`
|
||||
Proportion int64 `json:"proportion"`
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Opacity int64 `json:"opacity"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
||||
ZIndex int64 `json:"zIndex"`
|
||||
SvgPath string `json:"svgPath"`
|
||||
Follow Follow `json:"follow"`
|
||||
Group []interface{} `json:"group"`
|
||||
CameraStand CameraStand `json:"cameraStand"`
|
||||
}
|
||||
type LightInfo {
|
||||
Name string `json:"name"`
|
||||
Hdr Hdr `json:"hdr"`
|
||||
LightData []LightDataItem `json:"lightData"`
|
||||
}
|
||||
type LightDataItem {
|
||||
Color string `json:"color"`
|
||||
Id string `json:"id"`
|
||||
Intensity float64 `json:"intensity"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
X float64 `json:"x,omitempty"`
|
||||
Y int64 `json:"y,omitempty"`
|
||||
Z float64 `json:"z,omitempty"`
|
||||
ShowHelper bool `json:"showHelper,omitempty"`
|
||||
Width int64 `json:"width,omitempty"`
|
||||
Height int64 `json:"height,omitempty"`
|
||||
Rx int64 `json:"rx,omitempty"`
|
||||
Ry int64 `json:"ry,omitempty"`
|
||||
Rz int64 `json:"rz,omitempty"`
|
||||
}
|
||||
type Hdr {
|
||||
IfBg bool `json:"ifBg"`
|
||||
ToneMappingExposure float64 `json:"toneMappingExposure"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
type OptionalColor {
|
||||
Color string `json:"color"`
|
||||
Name string `json:"name"`
|
||||
Default bool `json:"default"`
|
||||
}
|
||||
type Follow {
|
||||
Fill string `json:"fill"`
|
||||
IfShow string `json:"ifShow"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
type CameraStand {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user