Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson
2023-06-20 19:37:08 +08:00
22 changed files with 406 additions and 485 deletions

View File

@@ -7,7 +7,6 @@ import (
"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"
@@ -17,42 +16,6 @@ import (
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 {
@@ -65,7 +28,7 @@ func GetTemplatevDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
// 创建一个业务逻辑层实例
l := logic.NewGetTemplatevDetailLogic(r.Context(), svcCtx)
resp := l.GetTemplatevDetail(&req, userinfo)
resp := l.GetTemplatevDetail(&req, r)
// 如果响应不为nil则使用httpx.OkJsonCtx方法返回JSON响应;
if resp != nil {
httpx.OkJsonCtx(r.Context(), w, resp)

View File

@@ -1,10 +1,9 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/utils/basic"
"net/http"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-templatev2/internal/types"
@@ -26,9 +25,41 @@ func NewGetTemplatevDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, r *http.Request) (resp *basic.Response) {
/*authKey := r.Header.Get("Auth-Key")
if authKey == "" {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
}
if req.TemplateId <= 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param template_id")
}
if req.ModelId <= 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param model_id")
}
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")
}
//查询产品模型并肩测数据完整性
productModel3dModel := gmodel.NewFsProductModel3dModel(l.svcCtx.MysqlConn)
model3dInfo, err := productModel3dModel.FindOne(l.ctx, req.ModelId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product model info is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product model info")
}
//配件ids
partIds, err := format.StrSlicToIntSlice(strings.Split(*model3dInfo.PartList, ","))
//产品模型数据解析model_info
if model3dInfo.ModelInfo != nil && *model3dInfo.ModelInfo != "" {
}*/
return resp.SetStatus(basic.CodeOK)
}

View File

@@ -11,40 +11,11 @@ type GetTemplatevDetailReq struct {
}
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"`
ProductModelInfo interface{} `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 Tag struct {
@@ -53,28 +24,28 @@ type Tag struct {
}
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"`
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"`
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 {
@@ -82,55 +53,39 @@ type Light struct {
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"`
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 {