57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fusenapi/utils/auth"
|
|
"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,
|
|
}
|
|
}
|
|
|
|
func (l *GetModelDetailLogic) GetModelDetail(req *types.GetModelDetailReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
|
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,
|
|
})
|
|
}
|