From 002ec9d292b587d5679e36f48e0e1bceebcb1716 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 25 Jun 2023 14:11:47 +0800 Subject: [PATCH 1/5] fix --- .../etc/product-template.yaml} | 2 +- .../internal/config/config.go | 2 +- .../internal/handler/addbasemaphandler.go | 6 +++--- .../internal/handler/getbasemaplisthandler.go | 4 ++-- .../internal/handler/gettemplatevdetailhandler.go | 6 +++--- .../internal/handler/routes.go | 2 +- .../internal/handler/savebasemaphandler.go | 4 ++-- .../internal/handler/updatetemplatehandler.go | 6 +++--- .../internal/logic/addbasemaplogic.go | 4 ++-- .../internal/logic/getbasemaplistlogic.go | 4 ++-- .../internal/logic/gettemplatevdetaillogic.go | 4 ++-- .../internal/logic/savebasemaplogic.go | 4 ++-- .../internal/logic/updatetemplatelogic.go | 4 ++-- .../internal/svc/servicecontext.go | 2 +- .../internal/types/types.go | 0 .../product-template.go} | 8 ++++---- .../{product-templatev2.api => product-template.api} | 2 +- 17 files changed, 32 insertions(+), 32 deletions(-) rename server/{product-templatev2/etc/product-templatev2.yaml => product-template/etc/product-template.yaml} (87%) rename server/{product-templatev2 => product-template}/internal/config/config.go (73%) rename server/{product-templatev2 => product-template}/internal/handler/addbasemaphandler.go (86%) rename server/{product-templatev2 => product-template}/internal/handler/getbasemaplisthandler.go (85%) rename server/{product-templatev2 => product-template}/internal/handler/gettemplatevdetailhandler.go (86%) rename server/{product-templatev2 => product-template}/internal/handler/routes.go (94%) rename server/{product-templatev2 => product-template}/internal/handler/savebasemaphandler.go (86%) rename server/{product-templatev2 => product-template}/internal/handler/updatetemplatehandler.go (86%) rename server/{product-templatev2 => product-template}/internal/logic/addbasemaplogic.go (93%) rename server/{product-templatev2 => product-template}/internal/logic/getbasemaplistlogic.go (93%) rename server/{product-templatev2 => product-template}/internal/logic/gettemplatevdetaillogic.go (98%) rename server/{product-templatev2 => product-template}/internal/logic/savebasemaplogic.go (95%) rename server/{product-templatev2 => product-template}/internal/logic/updatetemplatelogic.go (96%) rename server/{product-templatev2 => product-template}/internal/svc/servicecontext.go (96%) rename server/{product-templatev2 => product-template}/internal/types/types.go (100%) rename server/{product-templatev2/product-templatev2.go => product-template/product-template.go} (78%) rename server_api/{product-templatev2.api => product-template.api} (98%) diff --git a/server/product-templatev2/etc/product-templatev2.yaml b/server/product-template/etc/product-template.yaml similarity index 87% rename from server/product-templatev2/etc/product-templatev2.yaml rename to server/product-template/etc/product-template.yaml index 16a15785..a5a69f1c 100644 --- a/server/product-templatev2/etc/product-templatev2.yaml +++ b/server/product-template/etc/product-template.yaml @@ -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 diff --git a/server/product-templatev2/internal/config/config.go b/server/product-template/internal/config/config.go similarity index 73% rename from server/product-templatev2/internal/config/config.go rename to server/product-template/internal/config/config.go index ccc7c293..cfb76dd9 100644 --- a/server/product-templatev2/internal/config/config.go +++ b/server/product-template/internal/config/config.go @@ -1,7 +1,7 @@ package config import ( - "fusenapi/server/product-templatev2/internal/types" + "fusenapi/server/product-template/internal/types" "github.com/zeromicro/go-zero/rest" ) diff --git a/server/product-templatev2/internal/handler/addbasemaphandler.go b/server/product-template/internal/handler/addbasemaphandler.go similarity index 86% rename from server/product-templatev2/internal/handler/addbasemaphandler.go rename to server/product-template/internal/handler/addbasemaphandler.go index 314c6e2e..74c4b06e 100644 --- a/server/product-templatev2/internal/handler/addbasemaphandler.go +++ b/server/product-template/internal/handler/addbasemaphandler.go @@ -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 { diff --git a/server/product-templatev2/internal/handler/getbasemaplisthandler.go b/server/product-template/internal/handler/getbasemaplisthandler.go similarity index 85% rename from server/product-templatev2/internal/handler/getbasemaplisthandler.go rename to server/product-template/internal/handler/getbasemaplisthandler.go index 1e23d005..4f57cef4 100644 --- a/server/product-templatev2/internal/handler/getbasemaplisthandler.go +++ b/server/product-template/internal/handler/getbasemaplisthandler.go @@ -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 { diff --git a/server/product-templatev2/internal/handler/gettemplatevdetailhandler.go b/server/product-template/internal/handler/gettemplatevdetailhandler.go similarity index 86% rename from server/product-templatev2/internal/handler/gettemplatevdetailhandler.go rename to server/product-template/internal/handler/gettemplatevdetailhandler.go index cc4b07c0..716523a0 100644 --- a/server/product-templatev2/internal/handler/gettemplatevdetailhandler.go +++ b/server/product-template/internal/handler/gettemplatevdetailhandler.go @@ -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 { diff --git a/server/product-templatev2/internal/handler/routes.go b/server/product-template/internal/handler/routes.go similarity index 94% rename from server/product-templatev2/internal/handler/routes.go rename to server/product-template/internal/handler/routes.go index a91d7c77..95802ac0 100644 --- a/server/product-templatev2/internal/handler/routes.go +++ b/server/product-template/internal/handler/routes.go @@ -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" ) diff --git a/server/product-templatev2/internal/handler/savebasemaphandler.go b/server/product-template/internal/handler/savebasemaphandler.go similarity index 86% rename from server/product-templatev2/internal/handler/savebasemaphandler.go rename to server/product-template/internal/handler/savebasemaphandler.go index 69f85393..1dc72d92 100644 --- a/server/product-templatev2/internal/handler/savebasemaphandler.go +++ b/server/product-template/internal/handler/savebasemaphandler.go @@ -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 { diff --git a/server/product-templatev2/internal/handler/updatetemplatehandler.go b/server/product-template/internal/handler/updatetemplatehandler.go similarity index 86% rename from server/product-templatev2/internal/handler/updatetemplatehandler.go rename to server/product-template/internal/handler/updatetemplatehandler.go index 2f868d9b..a95689d5 100644 --- a/server/product-templatev2/internal/handler/updatetemplatehandler.go +++ b/server/product-template/internal/handler/updatetemplatehandler.go @@ -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 { diff --git a/server/product-templatev2/internal/logic/addbasemaplogic.go b/server/product-template/internal/logic/addbasemaplogic.go similarity index 93% rename from server/product-templatev2/internal/logic/addbasemaplogic.go rename to server/product-template/internal/logic/addbasemaplogic.go index cd73c66c..5d1620a2 100644 --- a/server/product-templatev2/internal/logic/addbasemaplogic.go +++ b/server/product-template/internal/logic/addbasemaplogic.go @@ -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" ) diff --git a/server/product-templatev2/internal/logic/getbasemaplistlogic.go b/server/product-template/internal/logic/getbasemaplistlogic.go similarity index 93% rename from server/product-templatev2/internal/logic/getbasemaplistlogic.go rename to server/product-template/internal/logic/getbasemaplistlogic.go index d1da6ba9..781ee56c 100644 --- a/server/product-templatev2/internal/logic/getbasemaplistlogic.go +++ b/server/product-template/internal/logic/getbasemaplistlogic.go @@ -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" ) diff --git a/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go b/server/product-template/internal/logic/gettemplatevdetaillogic.go similarity index 98% rename from server/product-templatev2/internal/logic/gettemplatevdetaillogic.go rename to server/product-template/internal/logic/gettemplatevdetaillogic.go index 3beb2e37..5f02eb31 100644 --- a/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go +++ b/server/product-template/internal/logic/gettemplatevdetaillogic.go @@ -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" ) diff --git a/server/product-templatev2/internal/logic/savebasemaplogic.go b/server/product-template/internal/logic/savebasemaplogic.go similarity index 95% rename from server/product-templatev2/internal/logic/savebasemaplogic.go rename to server/product-template/internal/logic/savebasemaplogic.go index 9c597641..39d7ddcc 100644 --- a/server/product-templatev2/internal/logic/savebasemaplogic.go +++ b/server/product-template/internal/logic/savebasemaplogic.go @@ -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" ) diff --git a/server/product-templatev2/internal/logic/updatetemplatelogic.go b/server/product-template/internal/logic/updatetemplatelogic.go similarity index 96% rename from server/product-templatev2/internal/logic/updatetemplatelogic.go rename to server/product-template/internal/logic/updatetemplatelogic.go index fd1e27ab..e268e6e2 100644 --- a/server/product-templatev2/internal/logic/updatetemplatelogic.go +++ b/server/product-template/internal/logic/updatetemplatelogic.go @@ -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" ) diff --git a/server/product-templatev2/internal/svc/servicecontext.go b/server/product-template/internal/svc/servicecontext.go similarity index 96% rename from server/product-templatev2/internal/svc/servicecontext.go rename to server/product-template/internal/svc/servicecontext.go index 635b8dce..b2001218 100644 --- a/server/product-templatev2/internal/svc/servicecontext.go +++ b/server/product-template/internal/svc/servicecontext.go @@ -3,7 +3,7 @@ package svc import ( "errors" "fmt" - "fusenapi/server/product-templatev2/internal/config" + "fusenapi/server/product-template/internal/config" "net/http" "fusenapi/initalize" diff --git a/server/product-templatev2/internal/types/types.go b/server/product-template/internal/types/types.go similarity index 100% rename from server/product-templatev2/internal/types/types.go rename to server/product-template/internal/types/types.go diff --git a/server/product-templatev2/product-templatev2.go b/server/product-template/product-template.go similarity index 78% rename from server/product-templatev2/product-templatev2.go rename to server/product-template/product-template.go index 52faa7ac..1be70a8a 100644 --- a/server/product-templatev2/product-templatev2.go +++ b/server/product-template/product-template.go @@ -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() diff --git a/server_api/product-templatev2.api b/server_api/product-template.api similarity index 98% rename from server_api/product-templatev2.api rename to server_api/product-template.api index 430c7348..071ecaa4 100644 --- a/server_api/product-templatev2.api +++ b/server_api/product-template.api @@ -9,7 +9,7 @@ info ( import "basic.api" -service product-templatev2 { +service product-template { //获取产品模板详情 @handler GetTemplatevDetailHandler get /product-template/detail(GetTemplatevDetailReq) returns (response); From d8768843972d5d796cc043ce6a5933bd36b3edba Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 25 Jun 2023 17:11:42 +0800 Subject: [PATCH 2/5] fix --- .../gmodel/fs_product_model3d_light_logic.go | 11 +- model/gmodel/fs_product_model3d_logic.go | 20 +++ model/gmodel/fs_product_template_v2_logic.go | 10 ++ server/product-model/etc/product-model.yaml | 8 ++ .../product-model/internal/config/config.go | 12 ++ .../internal/handler/getmodeldetailhandler.go | 41 ++++++ .../handler/getmodelotherinfohandler.go | 41 ++++++ .../product-model/internal/handler/routes.go | 27 ++++ .../internal/logic/getmodeldetaillogic.go | 68 ++++++++++ .../internal/logic/getmodelotherinfologic.go | 120 ++++++++++++++++++ .../internal/svc/servicecontext.go | 60 +++++++++ server/product-model/internal/types/types.go | 92 ++++++++++++++ server/product-model/product-model.go | 49 +++++++ server_api/product-model.api | 48 +++++++ 14 files changed, 602 insertions(+), 5 deletions(-) create mode 100644 server/product-model/etc/product-model.yaml create mode 100644 server/product-model/internal/config/config.go create mode 100644 server/product-model/internal/handler/getmodeldetailhandler.go create mode 100644 server/product-model/internal/handler/getmodelotherinfohandler.go create mode 100644 server/product-model/internal/handler/routes.go create mode 100644 server/product-model/internal/logic/getmodeldetaillogic.go create mode 100644 server/product-model/internal/logic/getmodelotherinfologic.go create mode 100644 server/product-model/internal/svc/servicecontext.go create mode 100644 server/product-model/internal/types/types.go create mode 100644 server/product-model/product-model.go create mode 100644 server_api/product-model.api diff --git a/model/gmodel/fs_product_model3d_light_logic.go b/model/gmodel/fs_product_model3d_light_logic.go index 919e6e9c..4b60c0ee 100755 --- a/model/gmodel/fs_product_model3d_light_logic.go +++ b/model/gmodel/fs_product_model3d_light_logic.go @@ -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 } diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index c216c086..5f3f01cf 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -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 +} diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index bc0d5670..92289072 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -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 +} diff --git a/server/product-model/etc/product-model.yaml b/server/product-model/etc/product-model.yaml new file mode 100644 index 00000000..ebf5393c --- /dev/null +++ b/server/product-model/etc/product-model.yaml @@ -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 \ No newline at end of file diff --git a/server/product-model/internal/config/config.go b/server/product-model/internal/config/config.go new file mode 100644 index 00000000..0904b683 --- /dev/null +++ b/server/product-model/internal/config/config.go @@ -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 +} diff --git a/server/product-model/internal/handler/getmodeldetailhandler.go b/server/product-model/internal/handler/getmodeldetailhandler.go new file mode 100644 index 00000000..4c9ec6fe --- /dev/null +++ b/server/product-model/internal/handler/getmodeldetailhandler.go @@ -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) + } + } +} diff --git a/server/product-model/internal/handler/getmodelotherinfohandler.go b/server/product-model/internal/handler/getmodelotherinfohandler.go new file mode 100644 index 00000000..15bd2554 --- /dev/null +++ b/server/product-model/internal/handler/getmodelotherinfohandler.go @@ -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) + } + } +} diff --git a/server/product-model/internal/handler/routes.go b/server/product-model/internal/handler/routes.go new file mode 100644 index 00000000..f363144a --- /dev/null +++ b/server/product-model/internal/handler/routes.go @@ -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), + }, + }, + ) +} diff --git a/server/product-model/internal/logic/getmodeldetaillogic.go b/server/product-model/internal/logic/getmodeldetaillogic.go new file mode 100644 index 00000000..c0a6760a --- /dev/null +++ b/server/product-model/internal/logic/getmodeldetaillogic.go @@ -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, + }) +} diff --git a/server/product-model/internal/logic/getmodelotherinfologic.go b/server/product-model/internal/logic/getmodelotherinfologic.go new file mode 100644 index 00000000..679d5705 --- /dev/null +++ b/server/product-model/internal/logic/getmodelotherinfologic.go @@ -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, + }) +} diff --git a/server/product-model/internal/svc/servicecontext.go b/server/product-model/internal/svc/servicecontext.go new file mode 100644 index 00000000..4fe39c6a --- /dev/null +++ b/server/product-model/internal/svc/servicecontext.go @@ -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)) +} diff --git a/server/product-model/internal/types/types.go b/server/product-model/internal/types/types.go new file mode 100644 index 00000000..a160f0ef --- /dev/null +++ b/server/product-model/internal/types/types.go @@ -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 +} diff --git a/server/product-model/product-model.go b/server/product-model/product-model.go new file mode 100644 index 00000000..67e2a1a0 --- /dev/null +++ b/server/product-model/product-model.go @@ -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 +// } diff --git a/server_api/product-model.api b/server_api/product-model.api new file mode 100644 index 00000000..145e6cdb --- /dev/null +++ b/server_api/product-model.api @@ -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"` +} \ No newline at end of file From 15eb99d9750cb9efe0d40a7ac0d1f2efb5ab3ee3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 25 Jun 2023 17:51:37 +0800 Subject: [PATCH 3/5] fix --- server/home-user-auth/internal/types/types.go | 14 +++----------- server_api/home-user-auth.api | 7 +------ 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index b5e34494..903b376d 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -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"` diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 8dfd9d96..c8820ad6 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -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); } From 5116b06f2f9067b5499c187063ed37b35d755438 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 25 Jun 2023 18:05:29 +0800 Subject: [PATCH 4/5] fix --- server/map-library/internal/logic/savemaplibrarylogic.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/map-library/internal/logic/savemaplibrarylogic.go b/server/map-library/internal/logic/savemaplibrarylogic.go index 819e3ac1..48ae27ad 100644 --- a/server/map-library/internal/logic/savemaplibrarylogic.go +++ b/server/map-library/internal/logic/savemaplibrarylogic.go @@ -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) From edda375a538c8ffdcd04ea6686a46b6f508ead59 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Sun, 25 Jun 2023 18:08:30 +0800 Subject: [PATCH 5/5] fix --- initalize/mysql.go | 1 - 1 file changed, 1 deletion(-) diff --git a/initalize/mysql.go b/initalize/mysql.go index 4ffc7ce5..b41fe319 100644 --- a/initalize/mysql.go +++ b/initalize/mysql.go @@ -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"