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

This commit is contained in:
eson 2023-06-25 18:30:58 +08:00
commit 1a0156c686
35 changed files with 641 additions and 58 deletions

View File

@ -7,7 +7,6 @@ import (
"time"
)
// SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
// 初始化mysql
func InitMysql(sourceMysql string) *gorm.DB {
dsn := sourceMysql + "?charset=utf8mb4&parseTime=true"

View File

@ -3,9 +3,10 @@ package gmodel
import "context"
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
if err != nil {
return nil, err
}
return
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?) and `status` = ?", ids, 1).Find(&resp).Error
return resp, err
}
func (l *FsProductModel3dLightModel) GetAll(ctx context.Context) (resp []FsProductModel3dLight, err error) {
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`status` = ?", 1).Find(&resp).Error
return resp, err
}

View File

@ -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
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
}

View File

@ -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 {
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
}

View File

@ -5,9 +5,6 @@ import (
"fusenapi/utils/basic"
)
type Request struct {
}
type RequestBasicInfoForm struct {
FirstName string `json:"first_name"` // FirstName
LastName string `json:"last_name"` // LastName
@ -111,20 +108,15 @@ type DataAddressList struct {
IsDefault int64 `json:"is_default"` // 1默认地址0非默认地址
}
type Request struct {
}
type Response struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
}
type ResponseJwt struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
}
type Auth struct {
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`

View File

@ -31,12 +31,12 @@ func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sa
}
}
func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, req *http.Request) (resp *basic.Response) {
func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, r *http.Request) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
}
bodyData, err := ioutil.ReadAll(req.Body)
defer req.Body.Close()
bodyData, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
var postData []types.SaveMapLibraryData
if err = json.Unmarshal(bodyData, &postData); err != nil {
logx.Error(err)

View 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

View File

@ -1,7 +1,7 @@
package config
import (
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-model/internal/types"
"github.com/zeromicro/go-zero/rest"
)

View File

@ -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)
}
}
}

View File

@ -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)
}
}
}

View 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),
},
},
)
}

View 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,
})
}

View 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,
})
}

View File

@ -3,7 +3,7 @@ package svc
import (
"errors"
"fmt"
"fusenapi/server/product-templatev2/internal/config"
"fusenapi/server/product-model/internal/config"
"net/http"
"fusenapi/initalize"
@ -34,6 +34,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
if AuthKey == "" {
return nil, nil
}
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
}

View 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
}

View 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
// }

View File

@ -1,4 +1,4 @@
Name: product-templatev2
Name: product-template
Host: 0.0.0.0
Port: 8896
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest

View File

@ -0,0 +1,12 @@
package config
import (
"fusenapi/server/product-template/internal/types"
"github.com/zeromicro/go-zero/rest"
)
type Config struct {
rest.RestConf
SourceMysql string
Auth types.Auth
}

View File

@ -9,9 +9,9 @@ import (
"fusenapi/utils/basic"
"fusenapi/server/product-templatev2/internal/logic"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/logic"
"fusenapi/server/product-template/internal/svc"
"fusenapi/server/product-template/internal/types"
)
func AddBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {

View File

@ -7,8 +7,8 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"fusenapi/server/product-templatev2/internal/logic"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-template/internal/logic"
"fusenapi/server/product-template/internal/svc"
)
func GetBaseMapListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {

View File

@ -9,9 +9,9 @@ import (
"fusenapi/utils/basic"
"fusenapi/server/product-templatev2/internal/logic"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/logic"
"fusenapi/server/product-template/internal/svc"
"fusenapi/server/product-template/internal/types"
)
func GetTemplatevDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {

View File

@ -4,7 +4,7 @@ package handler
import (
"net/http"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-template/internal/svc"
"github.com/zeromicro/go-zero/rest"
)

View File

@ -7,8 +7,8 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"fusenapi/server/product-templatev2/internal/logic"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-template/internal/logic"
"fusenapi/server/product-template/internal/svc"
)
func SaveBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {

View File

@ -8,9 +8,9 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"fusenapi/server/product-templatev2/internal/logic"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/logic"
"fusenapi/server/product-template/internal/svc"
"fusenapi/server/product-template/internal/types"
)
func UpdateTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {

View File

@ -11,8 +11,8 @@ import (
"context"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/svc"
"fusenapi/server/product-template/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@ -3,7 +3,7 @@ package logic
import (
"errors"
"fusenapi/model/gmodel"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/types"
"fusenapi/utils/basic"
"gorm.io/gorm"
"net/http"
@ -11,7 +11,7 @@ import (
"context"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-template/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@ -13,8 +13,8 @@ import (
"context"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/svc"
"fusenapi/server/product-template/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fusenapi/model/gmodel"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/types"
"fusenapi/utils/basic"
"gorm.io/gorm"
"io/ioutil"
@ -13,7 +13,7 @@ import (
"context"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-template/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@ -10,8 +10,8 @@ import (
"context"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-templatev2/internal/types"
"fusenapi/server/product-template/internal/svc"
"fusenapi/server/product-template/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@ -0,0 +1,59 @@
package svc
import (
"errors"
"fmt"
"fusenapi/server/product-template/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))
}

View File

@ -4,15 +4,15 @@ import (
"flag"
"fmt"
"fusenapi/server/product-templatev2/internal/config"
"fusenapi/server/product-templatev2/internal/handler"
"fusenapi/server/product-templatev2/internal/svc"
"fusenapi/server/product-template/internal/config"
"fusenapi/server/product-template/internal/handler"
"fusenapi/server/product-template/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/product-templatev2.yaml", "the config file")
var configFile = flag.String("f", "etc/product-template.yaml", "the config file")
func main() {
flag.Parse()

View File

@ -9,11 +9,6 @@ info (
import "basic.api"
type request {
// TODO: add members here and delete this comment
// Name string `form:"name"` // parameters are auto validated
}
service home-user-auth {
@handler UserLoginHandler
post /user/login(RequestUserLogin) returns (response);
@ -44,7 +39,7 @@ service home-user-auth {
// @handler UserOderListHandler
// get /user/order-list(RequestOrderId) returns (response);
@handler UserOderDeleteHandler
post /user/order-delete(RequestOrderId) returns (response);
}

View 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"`
}

View File

@ -9,7 +9,7 @@ info (
import "basic.api"
service product-templatev2 {
service product-template {
//获取产品模板详情
@handler GetTemplatevDetailHandler
get /product-template/detail(GetTemplatevDetailReq) returns (response);