fusenapi/server/product-model/internal/logic/getmodeldetaillogic.go

57 lines
1.7 KiB
Go
Raw Normal View History

2023-06-25 09:11:42 +00:00
package logic
import (
2023-06-26 10:32:28 +00:00
"context"
2023-06-25 09:11:42 +00:00
"encoding/json"
"errors"
2023-06-26 10:32:28 +00:00
"fusenapi/utils/auth"
2023-06-25 09:11:42 +00:00
"fusenapi/utils/basic"
"gorm.io/gorm"
"fusenapi/server/product-model/internal/svc"
"fusenapi/server/product-model/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetModelDetailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetModelDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetModelDetailLogic {
return &GetModelDetailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
2023-06-26 10:32:28 +00:00
func (l *GetModelDetailLogic) GetModelDetail(req *types.GetModelDetailReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
2023-06-25 09:11:42 +00:00
if req.ModelId <= 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param model_id is required")
}
//获取产品模型信息
productModel3dInfo, err := l.svcCtx.AllModels.FsProductModel3d.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.CodeDbSqlErr, "failed to get product model info")
}
//解析模型json数据
var modelInfoRsp interface{}
if productModel3dInfo.ModelInfo != nil && *productModel3dInfo.ModelInfo != "" {
if err = json.Unmarshal([]byte(*productModel3dInfo.ModelInfo), &modelInfoRsp); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model info")
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetModelDetailRsp{
Tag: *productModel3dInfo.Tag,
ProductModelInfo: modelInfoRsp,
})
}