fix
This commit is contained in:
parent
002ec9d292
commit
d876884397
|
@ -3,9 +3,10 @@ package gmodel
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) {
|
func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) {
|
||||||
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?)", ids).Find(&resp).Error
|
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?) and `status` = ?", ids, 1).Find(&resp).Error
|
||||||
if err != nil {
|
return resp, err
|
||||||
return nil, err
|
}
|
||||||
}
|
func (l *FsProductModel3dLightModel) GetAll(ctx context.Context) (resp []FsProductModel3dLight, err error) {
|
||||||
return
|
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`status` = ?", 1).Find(&resp).Error
|
||||||
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,3 +26,23 @@ func (d *FsProductModel3dModel) GetAllByIdsTag(ctx context.Context, ids []int64,
|
||||||
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ? and `tag` = ?", ids, 1, tag).Find(&resp).Error
|
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ? and `tag` = ?", ids, 1, tag).Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Get3dModelsByParamReq struct {
|
||||||
|
Tag int64
|
||||||
|
ProductId int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *FsProductModel3dModel) Get3dModelsByParam(ctx context.Context, req Get3dModelsByParamReq) (resp []FsProductModel3d, err error) {
|
||||||
|
if req.ProductId == 0 && req.Tag == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`status` = ?", 1)
|
||||||
|
if req.ProductId > 0 {
|
||||||
|
db = db.Where("`product_id` =? ", req.ProductId)
|
||||||
|
}
|
||||||
|
if req.Tag > 0 {
|
||||||
|
db = db.Where("`tag` =? ", req.Tag)
|
||||||
|
}
|
||||||
|
err = db.Find(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
|
@ -40,3 +40,13 @@ func (t *FsProductTemplateV2Model) FindByParam(ctx context.Context, id int64, mo
|
||||||
func (t *FsProductTemplateV2Model) Update(ctx context.Context, id int64, data *FsProductTemplateV2) error {
|
func (t *FsProductTemplateV2Model) Update(ctx context.Context, id int64, data *FsProductTemplateV2) error {
|
||||||
return t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Updates(&data).Error
|
return t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Updates(&data).Error
|
||||||
}
|
}
|
||||||
|
func (t *FsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelIds []int64) (resp []FsProductTemplateV2, err error) {
|
||||||
|
if len(modelIds) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `is_del` = ? and `status` = ?", modelIds, 0, 1).Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
8
server/product-model/etc/product-model.yaml
Normal file
8
server/product-model/etc/product-model.yaml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Name: product-model
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8897
|
||||||
|
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||||
|
Auth:
|
||||||
|
AccessSecret: fusen2023
|
||||||
|
AccessExpire: 60
|
||||||
|
RefreshAfter: 60
|
12
server/product-model/internal/config/config.go
Normal file
12
server/product-model/internal/config/config.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/server/product-model/internal/types"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
SourceMysql string
|
||||||
|
Auth types.Auth
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/product-model/internal/logic"
|
||||||
|
"fusenapi/server/product-model/internal/svc"
|
||||||
|
"fusenapi/server/product-model/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetModelDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetModelDetailReq
|
||||||
|
// 如果端点有请求结构体,则使用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.NewGetModelDetailLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.GetModelDetail(&req, r)
|
||||||
|
// 如果响应不为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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/product-model/internal/logic"
|
||||||
|
"fusenapi/server/product-model/internal/svc"
|
||||||
|
"fusenapi/server/product-model/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetModelOtherInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetModelOtherInfoReq
|
||||||
|
// 如果端点有请求结构体,则使用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.NewGetModelOtherInfoLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.GetModelOtherInfo(&req, r)
|
||||||
|
// 如果响应不为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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
server/product-model/internal/handler/routes.go
Normal file
27
server/product-model/internal/handler/routes.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"fusenapi/server/product-model/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-model/detail",
|
||||||
|
Handler: GetModelDetailHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/product-model/other-info",
|
||||||
|
Handler: GetModelOtherInfoHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
68
server/product-model/internal/logic/getmodeldetaillogic.go
Normal file
68
server/product-model/internal/logic/getmodeldetaillogic.go
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"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, r *http.Request) (resp *basic.Response) {
|
||||||
|
authKey := r.Header.Get("Auth-Key")
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
120
server/product-model/internal/logic/getmodelotherinfologic.go
Normal file
120
server/product-model/internal/logic/getmodelotherinfologic.go
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/product-model/internal/svc"
|
||||||
|
"fusenapi/server/product-model/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetModelOtherInfoLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetModelOtherInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetModelOtherInfoLogic {
|
||||||
|
return &GetModelOtherInfoLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetModelOtherInfoLogic) GetModelOtherInfo(req *types.GetModelOtherInfoReq, r *http.Request) (resp *basic.Response) {
|
||||||
|
authKey := r.Header.Get("Auth-Key")
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
//获取所有灯光列表
|
||||||
|
modelLightList, err := l.svcCtx.AllModels.FsProductModel3dLight.GetAll(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model light list")
|
||||||
|
}
|
||||||
|
//获取配件列表
|
||||||
|
Get3dModelsByParamReq := gmodel.Get3dModelsByParamReq{
|
||||||
|
Tag: constants.TAG_PARTS,
|
||||||
|
}
|
||||||
|
if req.ProductId > 0 {
|
||||||
|
Get3dModelsByParamReq.ProductId = req.ProductId
|
||||||
|
}
|
||||||
|
model3dList, err := l.svcCtx.AllModels.FsProductModel3d.Get3dModelsByParam(l.ctx, Get3dModelsByParamReq)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get 3d model list")
|
||||||
|
}
|
||||||
|
//组装灯光列表
|
||||||
|
lightListRsp := make([]types.LightListItem, 0, len(modelLightList))
|
||||||
|
for _, v := range modelLightList {
|
||||||
|
var info interface{}
|
||||||
|
if v.Info != nil && *v.Info != "" {
|
||||||
|
if err = json.Unmarshal([]byte(*v.Info), &info); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse light info")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lightListRsp = append(lightListRsp, types.LightListItem{
|
||||||
|
Id: v.Id,
|
||||||
|
Name: *v.Name,
|
||||||
|
Info: info,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
modelIds := make([]int64, 0, len(model3dList))
|
||||||
|
map3dModel := make(map[int64]int)
|
||||||
|
for k, v := range model3dList {
|
||||||
|
modelIds = append(modelIds, v.Id)
|
||||||
|
map3dModel[v.Id] = k
|
||||||
|
}
|
||||||
|
//根据模型ids获取产品模板
|
||||||
|
productTemplateV2List, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIds(l.ctx, modelIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product v2 template list")
|
||||||
|
}
|
||||||
|
mapProductTemplate := make(map[int64]int)
|
||||||
|
for k, v := range productTemplateV2List {
|
||||||
|
mapProductTemplate[v.Id] = k
|
||||||
|
}
|
||||||
|
//组装配件数据
|
||||||
|
partListRsp := make([]types.PartListItem, 0, len(model3dList))
|
||||||
|
for _, v := range model3dList {
|
||||||
|
materialImg := ""
|
||||||
|
if templateIndex, ok := mapProductTemplate[*v.OptionTemplate]; ok {
|
||||||
|
materialImg = *productTemplateV2List[templateIndex].MaterialImg
|
||||||
|
}
|
||||||
|
var info interface{}
|
||||||
|
if v.ModelInfo != nil && *v.ModelInfo != "" {
|
||||||
|
if err = json.Unmarshal([]byte(*v.ModelInfo), &info); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model info")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
partListRsp = append(partListRsp, types.PartListItem{
|
||||||
|
Id: v.Id,
|
||||||
|
Name: *v.Name,
|
||||||
|
MaterialImg: materialImg,
|
||||||
|
ModelInfo: info,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetModelOtherInfoRsp{
|
||||||
|
LightList: lightListRsp,
|
||||||
|
PartList: partListRsp,
|
||||||
|
})
|
||||||
|
}
|
60
server/product-model/internal/svc/servicecontext.go
Normal file
60
server/product-model/internal/svc/servicecontext.go
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"fusenapi/server/product-model/internal/config"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"fusenapi/initalize"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
|
||||||
|
MysqlConn *gorm.DB
|
||||||
|
AllModels *gmodel.AllModelsGen
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||||
|
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||||
|
AuthKey := r.Header.Get("Authorization")
|
||||||
|
if AuthKey == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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 []byte(svcCtx.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))
|
||||||
|
}
|
92
server/product-model/internal/types/types.go
Normal file
92
server/product-model/internal/types/types.go
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetModelDetailReq struct {
|
||||||
|
ModelId int64 `form:"model_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetModelDetailRsp struct {
|
||||||
|
Tag int64 `json:"tag"`
|
||||||
|
ProductModelInfo interface{} `json:"product_model_info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetModelOtherInfoReq struct {
|
||||||
|
ProductId int64 `form:"product_id,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetModelOtherInfoRsp struct {
|
||||||
|
LightList []LightListItem `json:"light_list"`
|
||||||
|
PartList []PartListItem `json:"part_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LightListItem struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info interface{} `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PartListItem struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
MaterialImg string `json:"material_img"`
|
||||||
|
ModelInfo interface{} `json:"model_info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"msg"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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-model/product-model.go
Normal file
49
server/product-model/product-model.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"fusenapi/server/product-model/internal/config"
|
||||||
|
"fusenapi/server/product-model/internal/handler"
|
||||||
|
"fusenapi/server/product-model/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/product-model.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-model.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
|
||||||
|
// }
|
48
server_api/product-model.api
Normal file
48
server_api/product-model.api
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
syntax = "v1"
|
||||||
|
|
||||||
|
info (
|
||||||
|
title: "产品3d模型服务"// TODO: add title
|
||||||
|
desc: // TODO: add description
|
||||||
|
author: ""
|
||||||
|
email: ""
|
||||||
|
)
|
||||||
|
|
||||||
|
import "basic.api"
|
||||||
|
|
||||||
|
service product-model {
|
||||||
|
//获取产品模型详情
|
||||||
|
@handler GetModelDetailHandler
|
||||||
|
get /product-model/detail(GetModelDetailReq) returns (response);
|
||||||
|
//获取产品模型其他信息
|
||||||
|
@handler GetModelOtherInfoHandler
|
||||||
|
get /product-model/other-info(GetModelOtherInfoReq) returns (response);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取产品模型详情
|
||||||
|
type GetModelDetailReq {
|
||||||
|
ModelId int64 `form:"model_id"`
|
||||||
|
}
|
||||||
|
type GetModelDetailRsp {
|
||||||
|
Tag int64 `json:"tag"`
|
||||||
|
ProductModelInfo interface{} `json:"product_model_info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取产品模型其他信息
|
||||||
|
type GetModelOtherInfoReq {
|
||||||
|
ProductId int64 `form:"product_id,optional"`
|
||||||
|
}
|
||||||
|
type GetModelOtherInfoRsp {
|
||||||
|
LightList []LightListItem `json:"light_list"`
|
||||||
|
PartList []PartListItem `json:"part_list"`
|
||||||
|
}
|
||||||
|
type LightListItem {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info interface{} `json:"info"`
|
||||||
|
}
|
||||||
|
type PartListItem {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
MaterialImg string `json:"material_img"`
|
||||||
|
ModelInfo interface{} `json:"model_info"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user