fix
This commit is contained in:
parent
d4d11db732
commit
313e8a9457
|
@ -1,2 +1,10 @@
|
|||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (g *FsGerentModel) Find(ctx context.Context, authKey string) (resp FsGerent, err error) {
|
||||
err = g.db.WithContext(ctx).Model(&FsGerent{}).Where("`auth_key` = ?", authKey).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -82,22 +53,6 @@ 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"`
|
||||
|
|
|
@ -19,40 +19,13 @@ type GetTemplatevDetailReq {
|
|||
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"`
|
||||
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 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"`
|
||||
|
@ -85,20 +58,6 @@ type Light {
|
|||
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"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user