From 2825f8ae54fe7890250085abc116d93ef32e5a01 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 15:20:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=80=E6=9C=89=E5=BA=8F=E5=88=97=E5=8C=96,?= =?UTF-8?q?=20=E9=83=BD=E5=8A=A0=E5=85=A5=20=20BeforeLogic=20AfterLogic?= =?UTF-8?q?=E6=96=B9=E6=B3=95.=20=E4=BE=BF=E4=BA=8E=E5=A4=84=E7=90=86=20w?= =?UTF-8?q?=20r=E7=9A=84=E4=BC=A0=E9=80=92=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fs_gen_api.sh | 4 +- goctl_template_backend/api/handler.tpl | 2 +- run_all_server.ps1 | 34 -------- server/assistant/internal/handler/routes.go | 2 +- server/assistant/internal/types/types.go | 2 +- .../handler/quotationdetailhandler.go | 47 +++-------- .../handler/getcanteendetailhandler.go | 14 ++++ .../handler/savecanteentypeproducthandler.go | 14 ++++ .../handler/getqrcodesetlisthandler.go | 22 ++++- .../handler/getstandardlogolisthandler.go | 22 ++++- .../internal/logic/getqrcodesetlistlogic.go | 2 +- .../logic/getstandardlogolistlogic.go | 3 +- .../internal/handler/acceptcookiehandler.go | 14 ++++ .../internal/handler/useraddaddresshandler.go | 14 ++++ .../handler/useraddresslisthandler.go | 14 ++++ .../internal/handler/userbasicinfohandler.go | 14 ++++ .../handler/usercontactservicehandler.go | 14 ++++ .../internal/handler/userfontshandler.go | 14 ++++ .../internal/handler/usergettypehandler.go | 14 ++++ .../handler/useroauth2loginhandler.go | 21 ----- .../internal/handler/useroderdeletehandler.go | 14 ++++ .../handler/userordercancelhandler.go | 14 ++++ .../internal/handler/userorderlisthandler.go | 14 ++++ .../handler/usersavebasicinfohandler.go | 14 ++++ .../handler/userstatusconfighandler.go | 14 ++++ .../internal/handler/getcloudlisthandler.go | 14 ++++ .../internal/handler/getpickuplisthandler.go | 14 ++++ .../internal/handler/supplementhandler.go | 14 ++++ .../inventory/internal/handler/takehandler.go | 14 ++++ .../handler/getmaplibrarylisthandler.go | 22 ++++- .../internal/handler/savemaplibraryhandler.go | 19 ++++- .../internal/logic/getmaplibrarylistlogic.go | 3 +- .../internal/logic/savemaplibrarylogic.go | 30 +++++-- .../internal/handler/getorderdetailhandler.go | 14 ++++ .../handler/getorderinvoicehandler.go | 14 ++++ .../internal/handler/getmodeldetailhandler.go | 47 +++-------- .../handler/getmodelotherinfohandler.go | 47 +++-------- .../handler/updateproductmodelhandler.go | 47 +++-------- .../internal/handler/addbasemaphandler.go | 47 +++-------- .../internal/handler/getbasemaplisthandler.go | 45 +++-------- .../handler/gettemplatevdetailhandler.go | 47 +++-------- .../internal/handler/savebasemaphandler.go | 45 +++-------- .../internal/handler/updatetemplatehandler.go | 47 +++-------- .../internal/logic/getbasemaplistlogic.go | 3 +- .../internal/logic/savebasemaplogic.go | 20 ++++- .../internal/handler/designgatherhandler.go | 16 +++- .../handler/getfittingbypidhandler.go | 14 ++++ .../handler/getlastproductdesignhandler.go | 14 ++++ .../internal/handler/getlightbypidhandler.go | 14 ++++ .../internal/handler/getmodelbypidhandler.go | 14 ++++ .../internal/handler/getpricebypidhandler.go | 14 ++++ .../handler/getproductdesignhandler.go | 14 ++++ .../internal/handler/getproductinfohandler.go | 14 ++++ .../internal/handler/getproductlisthandler.go | 14 ++++ .../handler/getrecommandproductlisthandler.go | 14 ++++ .../handler/getrenderdesignhandler.go | 14 ++++ .../handler/getrendersettingbypidhandler.go | 14 ++++ .../internal/handler/getsizebypidhandler.go | 14 ++++ .../handler/getsizebyproducthandler.go | 22 ++++- .../handler/getsuccessrecommandhandler.go | 14 ++++ .../handler/gettagproductlisthandler.go | 14 ++++ .../handler/gettemplatebypidhandler.go | 14 ++++ .../homepagerecommendproductlisthandler.go | 18 ++++- .../handler/otherproductlisthandler.go | 14 ++++ .../internal/handler/savedesignhandler.go | 14 ++++ .../internal/logic/designgatherlogic.go | 29 +++++-- .../internal/logic/getsizebyproductlogic.go | 2 +- server/render/etc/render.yaml | 8 ++ server/render/internal/config/config.go | 9 +++ .../internal/handler/readimageshandler.go | 35 ++++++++ server/render/internal/handler/routes.go | 27 +++++++ .../render/internal/handler/tounityhandler.go | 35 ++++++++ .../render/internal/logic/readimageslogic.go | 42 ++++++++++ server/render/internal/logic/tounitylogic.go | 42 ++++++++++ server/render/internal/svc/servicecontext.go | 61 ++++++++++++++ server/render/internal/types/types.go | 81 +++++++++++++++++++ server/render/render.go | 36 +++++++++ .../internal/handler/cartaddhandler.go | 14 ++++ .../internal/handler/cartdeletehandler.go | 14 ++++ .../internal/handler/cartlisthandler.go | 14 ++++ .../internal/handler/cartnumberhandler.go | 22 ++++- .../handler/cartorderdetailhandler.go | 14 ++++ .../handler/changeordermethodhandler.go | 14 ++++ .../internal/handler/createorderhandler.go | 14 ++++ .../internal/logic/cartnumberlogic.go | 3 +- .../handler/uploadfilebackendhandler.go | 56 ++++++++++++- .../handler/uploadfilefrontendhandler.go | 14 ++++ .../internal/handler/uploadqrcodehandler.go | 14 ++++ .../internal/handler/uploadupfilehandler.go | 14 ++++ .../internal/handler/websetsettinghandler.go | 16 +++- .../internal/logic/websetsettinglogic.go | 19 +++-- .../test/{wetset_test.go => webset_test.go} | 2 +- server_api/data-transfer.api | 4 +- server_api/product-template.api | 6 +- server_api/product.api | 12 +-- server_api/render.api | 4 +- server_api/upload.api | 2 +- server_api/webset.api | 2 +- stop_all_server.ps1 | 26 ------ utils/basic/request_parse.go | 42 ++++++++++ 100 files changed, 1499 insertions(+), 454 deletions(-) delete mode 100644 run_all_server.ps1 delete mode 100644 server/home-user-auth/internal/handler/useroauth2loginhandler.go create mode 100644 server/render/etc/render.yaml create mode 100644 server/render/internal/config/config.go create mode 100644 server/render/internal/handler/readimageshandler.go create mode 100644 server/render/internal/handler/routes.go create mode 100644 server/render/internal/handler/tounityhandler.go create mode 100644 server/render/internal/logic/readimageslogic.go create mode 100644 server/render/internal/logic/tounitylogic.go create mode 100644 server/render/internal/svc/servicecontext.go create mode 100644 server/render/internal/types/types.go create mode 100644 server/render/render.go rename server/webset/test/{wetset_test.go => webset_test.go} (98%) delete mode 100644 stop_all_server.ps1 diff --git a/fs_gen_api.sh b/fs_gen_api.sh index fedb12b8..d9ec9c69 100755 --- a/fs_gen_api.sh +++ b/fs_gen_api.sh @@ -13,8 +13,8 @@ done echo $name goctl api go -api server_api/$name.api -dir server/$name --home ./goctl_template/ -# List of API filenames without the '.api' extension -# api_names=("backend" "canteen" "home-user-auth" "map-library" "product" "product-template" "shopping-cart-confirmation" "webset" "data-transfer" "inventory" "orders" "product-model" "render" "upload") +# # List of API filenames without the '.api' extension +# api_names=("backend" "canteen" "home-user-auth" "map-library" "product" "product-template" "shopping-cart-confirmation" "webset" "data-transfer" "inventory" "orders" "product-model" "render" "upload" "assistant") # # Iterate over API filenames and generate Go code, excluding certain names # for api_name in "${api_names[@]}"; do diff --git a/goctl_template_backend/api/handler.tpl b/goctl_template_backend/api/handler.tpl index ca8330c6..4b289117 100644 --- a/goctl_template_backend/api/handler.tpl +++ b/goctl_template_backend/api/handler.tpl @@ -12,7 +12,7 @@ import ( func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { {{if .HasRequest}}var req types.{{.RequestType}} - userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) if err != nil { return } diff --git a/run_all_server.ps1 b/run_all_server.ps1 deleted file mode 100644 index d33cec58..00000000 --- a/run_all_server.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -Function Run-Server { - param ( - [Parameter(Mandatory=$true)] - [string] $server_name - ) - Write-Host "Running $server_name" - - # 导航到相应的目录 - Set-Location -Path "server/$server_name" - - # 使用 PowerShell Jobs 运行 go run .go - Start-Job -Name $server_name -ScriptBlock { go run $server_name.go } - - # 返回到上一级目录 - Set-Location -Path ".." -} - -# 列出所有服务器目录 -$server_dirs = "backend", "canteen", "data-transfer", "home-user-auth", "inventory", "map-library", "orders", "product", "product-model", "product-template", "shopping-cart-confirmation", "upload", "webset" - -# 在每个服务器目录下运行相应的 go 程序 -foreach ($server_dir in $server_dirs) { - Run-Server -server_name $server_dir -} - -# 定义目录和screen名称 -$dir_path = "./proxyserver" -$screen_name = "proxyserver" - -# 进入目录 -Set-Location -Path $dir_path - -# 启动新的 PowerShell Job 并运行 go 程序 -Start-Job -Name $screen_name -ScriptBlock { go run main.go } \ No newline at end of file diff --git a/server/assistant/internal/handler/routes.go b/server/assistant/internal/handler/routes.go index c15a409d..daeb8d44 100644 --- a/server/assistant/internal/handler/routes.go +++ b/server/assistant/internal/handler/routes.go @@ -13,7 +13,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ { - Method: http.MethodGet, + Method: http.MethodPost, Path: "/api/assistant/redirect", Handler: RedirectHandler(serverCtx), }, diff --git a/server/assistant/internal/types/types.go b/server/assistant/internal/types/types.go index f84b7394..bf4044b1 100644 --- a/server/assistant/internal/types/types.go +++ b/server/assistant/internal/types/types.go @@ -6,7 +6,7 @@ import ( ) type RequestRedirect struct { - Url string `query:"url"` + Url string `json:"url"` } type Request struct { diff --git a/server/backend/internal/handler/quotationdetailhandler.go b/server/backend/internal/handler/quotationdetailhandler.go index d84e0cda..ce9928ea 100644 --- a/server/backend/internal/handler/quotationdetailhandler.go +++ b/server/backend/internal/handler/quotationdetailhandler.go @@ -2,11 +2,8 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/backend/internal/logic" @@ -16,42 +13,22 @@ import ( func QuotationDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - var req types.RequestQuotationId + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewQuotationDetailLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.QuotationDetail(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/canteen/internal/handler/getcanteendetailhandler.go b/server/canteen/internal/handler/getcanteendetailhandler.go index d8834f08..24bfc2cb 100644 --- a/server/canteen/internal/handler/getcanteendetailhandler.go +++ b/server/canteen/internal/handler/getcanteendetailhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/canteen/internal/logic" "fusenapi/server/canteen/internal/svc" @@ -12,10 +15,21 @@ func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetCanteenDetailReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetCanteenDetailLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetCanteenDetail(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/canteen/internal/handler/savecanteentypeproducthandler.go b/server/canteen/internal/handler/savecanteentypeproducthandler.go index 47daa9d6..9cce2b29 100644 --- a/server/canteen/internal/handler/savecanteentypeproducthandler.go +++ b/server/canteen/internal/handler/savecanteentypeproducthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/canteen/internal/logic" "fusenapi/server/canteen/internal/svc" @@ -12,10 +15,21 @@ func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc return func(w http.ResponseWriter, r *http.Request) { var req types.SaveCanteenTypeProductReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.SaveCanteenTypeProduct(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/data-transfer/internal/handler/getqrcodesetlisthandler.go b/server/data-transfer/internal/handler/getqrcodesetlisthandler.go index 9c665dc4..a5dedcf2 100644 --- a/server/data-transfer/internal/handler/getqrcodesetlisthandler.go +++ b/server/data-transfer/internal/handler/getqrcodesetlisthandler.go @@ -2,16 +2,34 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/data-transfer/internal/logic" "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" ) func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := logic.NewGetQrCodeSetListLogic(r.Context(), svcCtx) - resp := l.GetQrCodeSetList(userinfo) + var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetQrCodeSetListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetQrCodeSetList(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/data-transfer/internal/handler/getstandardlogolisthandler.go b/server/data-transfer/internal/handler/getstandardlogolisthandler.go index 008deb56..48716664 100644 --- a/server/data-transfer/internal/handler/getstandardlogolisthandler.go +++ b/server/data-transfer/internal/handler/getstandardlogolisthandler.go @@ -2,16 +2,34 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/data-transfer/internal/logic" "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" ) func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := logic.NewGetStandardLogoListLogic(r.Context(), svcCtx) - resp := l.GetStandardLogoList(userinfo) + var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetStandardLogoListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetStandardLogoList(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/data-transfer/internal/logic/getqrcodesetlistlogic.go b/server/data-transfer/internal/logic/getqrcodesetlistlogic.go index 46ef0d22..3b9215d4 100644 --- a/server/data-transfer/internal/logic/getqrcodesetlistlogic.go +++ b/server/data-transfer/internal/logic/getqrcodesetlistlogic.go @@ -27,7 +27,7 @@ func NewGetQrCodeSetListLogic(ctx context.Context, svcCtx *svc.ServiceContext) * } // 获取二维码配置列表 -func (l *GetQrCodeSetListLogic) GetQrCodeSetList(userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *GetQrCodeSetListLogic) GetQrCodeSetList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { if userinfo.GetIdType() != auth.IDTYPE_User { return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first") } diff --git a/server/data-transfer/internal/logic/getstandardlogolistlogic.go b/server/data-transfer/internal/logic/getstandardlogolistlogic.go index 3deb42c5..4e946796 100644 --- a/server/data-transfer/internal/logic/getstandardlogolistlogic.go +++ b/server/data-transfer/internal/logic/getstandardlogolistlogic.go @@ -4,6 +4,7 @@ import ( "context" "fusenapi/model/gmodel" svc2 "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" types2 "fusenapi/server/data-transfer/internal/types" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -26,7 +27,7 @@ func NewGetStandardLogoListLogic(ctx context.Context, svcCtx *svc2.ServiceContex } // 获取标准logo列表 -func (l *GetStandardLogoListLogic) GetStandardLogoList(userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *GetStandardLogoListLogic) GetStandardLogoList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { if userinfo.GetIdType() != auth.IDTYPE_User { return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first") } diff --git a/server/home-user-auth/internal/handler/acceptcookiehandler.go b/server/home-user-auth/internal/handler/acceptcookiehandler.go index 99755317..ea24b81b 100644 --- a/server/home-user-auth/internal/handler/acceptcookiehandler.go +++ b/server/home-user-auth/internal/handler/acceptcookiehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func AcceptCookieHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewAcceptCookieLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.AcceptCookie(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/useraddaddresshandler.go b/server/home-user-auth/internal/handler/useraddaddresshandler.go index 70decaba..5b2c6c3d 100644 --- a/server/home-user-auth/internal/handler/useraddaddresshandler.go +++ b/server/home-user-auth/internal/handler/useraddaddresshandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserAddAddressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.RequestAddAddress + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserAddAddressLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserAddAddress(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/useraddresslisthandler.go b/server/home-user-auth/internal/handler/useraddresslisthandler.go index 93d1e571..f0e51bf7 100644 --- a/server/home-user-auth/internal/handler/useraddresslisthandler.go +++ b/server/home-user-auth/internal/handler/useraddresslisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserAddressListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserAddressListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserAddressList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/userbasicinfohandler.go b/server/home-user-auth/internal/handler/userbasicinfohandler.go index d9452400..070fc961 100644 --- a/server/home-user-auth/internal/handler/userbasicinfohandler.go +++ b/server/home-user-auth/internal/handler/userbasicinfohandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserBasicInfoLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserBasicInfo(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/usercontactservicehandler.go b/server/home-user-auth/internal/handler/usercontactservicehandler.go index a5570456..3e1129b5 100644 --- a/server/home-user-auth/internal/handler/usercontactservicehandler.go +++ b/server/home-user-auth/internal/handler/usercontactservicehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserContactServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.RequestContactService + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserContactServiceLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserContactService(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/userfontshandler.go b/server/home-user-auth/internal/handler/userfontshandler.go index afdc8f94..04ce08bf 100644 --- a/server/home-user-auth/internal/handler/userfontshandler.go +++ b/server/home-user-auth/internal/handler/userfontshandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserFontsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserFontsLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserFonts(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/usergettypehandler.go b/server/home-user-auth/internal/handler/usergettypehandler.go index 5d842075..c1b6fef4 100644 --- a/server/home-user-auth/internal/handler/usergettypehandler.go +++ b/server/home-user-auth/internal/handler/usergettypehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserGetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserGetTypeLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserGetType(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/useroauth2loginhandler.go b/server/home-user-auth/internal/handler/useroauth2loginhandler.go deleted file mode 100644 index c3038951..00000000 --- a/server/home-user-auth/internal/handler/useroauth2loginhandler.go +++ /dev/null @@ -1,21 +0,0 @@ -package handler - -import ( - "net/http" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserOAuth2LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - var req types.RequestOAuth - - // 创建一个业务逻辑层实例 - l := logic.NewUserOAuth2LoginLogic(r.Context(), svcCtx) - resp := l.UserOAuth2Login(&req, userinfo) - - } -} diff --git a/server/home-user-auth/internal/handler/useroderdeletehandler.go b/server/home-user-auth/internal/handler/useroderdeletehandler.go index c98ce43b..cd21c047 100644 --- a/server/home-user-auth/internal/handler/useroderdeletehandler.go +++ b/server/home-user-auth/internal/handler/useroderdeletehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserOderDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.RequestOrderId + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserOderDeleteLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserOderDelete(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/userordercancelhandler.go b/server/home-user-auth/internal/handler/userordercancelhandler.go index e1c2b563..f0065089 100644 --- a/server/home-user-auth/internal/handler/userordercancelhandler.go +++ b/server/home-user-auth/internal/handler/userordercancelhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserOrderCancelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.UserOrderCancelReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserOrderCancelLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserOrderCancel(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/userorderlisthandler.go b/server/home-user-auth/internal/handler/userorderlisthandler.go index 1fd6d4e5..e31f6ff8 100644 --- a/server/home-user-auth/internal/handler/userorderlisthandler.go +++ b/server/home-user-auth/internal/handler/userorderlisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserOrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.UserOrderListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserOrderListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserOrderList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go b/server/home-user-auth/internal/handler/usersavebasicinfohandler.go index 90cebbf8..362999fb 100644 --- a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go +++ b/server/home-user-auth/internal/handler/usersavebasicinfohandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.RequestBasicInfoForm + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserSaveBasicInfoLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserSaveBasicInfo(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/home-user-auth/internal/handler/userstatusconfighandler.go b/server/home-user-auth/internal/handler/userstatusconfighandler.go index 4d07e340..63447b0c 100644 --- a/server/home-user-auth/internal/handler/userstatusconfighandler.go +++ b/server/home-user-auth/internal/handler/userstatusconfighandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/home-user-auth/internal/logic" "fusenapi/server/home-user-auth/internal/svc" @@ -12,10 +15,21 @@ func UserStatusConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUserStatusConfigLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UserStatusConfig(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/inventory/internal/handler/getcloudlisthandler.go b/server/inventory/internal/handler/getcloudlisthandler.go index b8508640..436c1bca 100644 --- a/server/inventory/internal/handler/getcloudlisthandler.go +++ b/server/inventory/internal/handler/getcloudlisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/inventory/internal/logic" "fusenapi/server/inventory/internal/svc" @@ -12,10 +15,21 @@ func GetCloudListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetCloudListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetCloudListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetCloudList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/inventory/internal/handler/getpickuplisthandler.go b/server/inventory/internal/handler/getpickuplisthandler.go index fe5848f9..6d1c2ff4 100644 --- a/server/inventory/internal/handler/getpickuplisthandler.go +++ b/server/inventory/internal/handler/getpickuplisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/inventory/internal/logic" "fusenapi/server/inventory/internal/svc" @@ -12,10 +15,21 @@ func GetPickupListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetPickupListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetPickupListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetPickupList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/inventory/internal/handler/supplementhandler.go b/server/inventory/internal/handler/supplementhandler.go index c4f21bb4..0e5f08f4 100644 --- a/server/inventory/internal/handler/supplementhandler.go +++ b/server/inventory/internal/handler/supplementhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/inventory/internal/logic" "fusenapi/server/inventory/internal/svc" @@ -12,10 +15,21 @@ func SupplementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.SupplementReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewSupplementLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.Supplement(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/inventory/internal/handler/takehandler.go b/server/inventory/internal/handler/takehandler.go index 2bb89815..96007a4e 100644 --- a/server/inventory/internal/handler/takehandler.go +++ b/server/inventory/internal/handler/takehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/inventory/internal/logic" "fusenapi/server/inventory/internal/svc" @@ -12,10 +15,21 @@ func TakeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.TakeReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewTakeLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.Take(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/map-library/internal/handler/getmaplibrarylisthandler.go b/server/map-library/internal/handler/getmaplibrarylisthandler.go index 84b2f2c1..8c6c6364 100644 --- a/server/map-library/internal/handler/getmaplibrarylisthandler.go +++ b/server/map-library/internal/handler/getmaplibrarylisthandler.go @@ -2,16 +2,34 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/map-library/internal/logic" "fusenapi/server/map-library/internal/svc" + "fusenapi/server/map-library/internal/types" ) func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := logic.NewGetMapLibraryListLogic(r.Context(), svcCtx) - resp := l.GetMapLibraryList(userinfo) + var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetMapLibraryListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetMapLibraryList(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/map-library/internal/handler/savemaplibraryhandler.go b/server/map-library/internal/handler/savemaplibraryhandler.go index f09b1fd5..caee5c8c 100644 --- a/server/map-library/internal/handler/savemaplibraryhandler.go +++ b/server/map-library/internal/handler/savemaplibraryhandler.go @@ -2,17 +2,34 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/map-library/internal/logic" "fusenapi/server/map-library/internal/svc" + "fusenapi/server/map-library/internal/types" ) func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + // 创建一个业务逻辑层实例 l := logic.NewSaveMapLibraryLogic(r.Context(), svcCtx) - resp := l.SaveMapLibrary(userinfo, r) + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.SaveMapLibrary(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/map-library/internal/logic/getmaplibrarylistlogic.go b/server/map-library/internal/logic/getmaplibrarylistlogic.go index 696ea555..aa7ec7a8 100644 --- a/server/map-library/internal/logic/getmaplibrarylistlogic.go +++ b/server/map-library/internal/logic/getmaplibrarylistlogic.go @@ -10,6 +10,7 @@ import ( "time" "context" + "github.com/zeromicro/go-zero/core/logx" ) @@ -27,7 +28,7 @@ func NewGetMapLibraryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) } } -func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *GetMapLibraryListLogic) GetMapLibraryList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { if userinfo.GetIdType() != auth.IDTYPE_User { return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first") } diff --git a/server/map-library/internal/logic/savemaplibrarylogic.go b/server/map-library/internal/logic/savemaplibrarylogic.go index 48ae27ad..083609ce 100644 --- a/server/map-library/internal/logic/savemaplibrarylogic.go +++ b/server/map-library/internal/logic/savemaplibrarylogic.go @@ -19,8 +19,9 @@ import ( type SaveMapLibraryLogic struct { logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext + ctx context.Context + svcCtx *svc.ServiceContext + bodyData []byte } func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveMapLibraryLogic { @@ -31,14 +32,31 @@ func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sa } } -func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, r *http.Request) (resp *basic.Response) { +// 处理进入前逻辑w,r +func (l *SaveMapLibraryLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { + bodyData, err := ioutil.ReadAll(r.Body) + defer r.Body.Close() + if err != nil { + logx.Error(err) + return + } + + l.bodyData = bodyData +} + +func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { if userinfo.GetIdType() != auth.IDTYPE_User { return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first") } - bodyData, err := ioutil.ReadAll(r.Body) - defer r.Body.Close() + + if len(l.bodyData) == 0 { + return resp.SetStatus(basic.CodeApiErr, http.ErrBodyReadAfterClose.Error()) + } + + var err error + var postData []types.SaveMapLibraryData - if err = json.Unmarshal(bodyData, &postData); err != nil { + if err = json.Unmarshal(l.bodyData, &postData); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeSaveErr, "param err") } diff --git a/server/orders/internal/handler/getorderdetailhandler.go b/server/orders/internal/handler/getorderdetailhandler.go index 1223572d..b998c5e8 100644 --- a/server/orders/internal/handler/getorderdetailhandler.go +++ b/server/orders/internal/handler/getorderdetailhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/orders/internal/logic" "fusenapi/server/orders/internal/svc" @@ -12,10 +15,21 @@ func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetOrderDetailReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetOrderDetailLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetOrderDetail(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/orders/internal/handler/getorderinvoicehandler.go b/server/orders/internal/handler/getorderinvoicehandler.go index 4e74edb3..77f5ef61 100644 --- a/server/orders/internal/handler/getorderinvoicehandler.go +++ b/server/orders/internal/handler/getorderinvoicehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/orders/internal/logic" "fusenapi/server/orders/internal/svc" @@ -12,10 +15,21 @@ func GetOrderInvoiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetOrderInvoiceReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetOrderInvoiceLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetOrderInvoice(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-model/internal/handler/getmodeldetailhandler.go b/server/product-model/internal/handler/getmodeldetailhandler.go index 7d811902..7b2ea338 100644 --- a/server/product-model/internal/handler/getmodeldetailhandler.go +++ b/server/product-model/internal/handler/getmodeldetailhandler.go @@ -2,11 +2,8 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-model/internal/logic" @@ -16,42 +13,22 @@ import ( func GetModelDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - var req types.GetModelDetailReq + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetModelDetailLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetModelDetail(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-model/internal/handler/getmodelotherinfohandler.go b/server/product-model/internal/handler/getmodelotherinfohandler.go index b963705b..87e6d308 100644 --- a/server/product-model/internal/handler/getmodelotherinfohandler.go +++ b/server/product-model/internal/handler/getmodelotherinfohandler.go @@ -2,11 +2,8 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-model/internal/logic" @@ -16,42 +13,22 @@ import ( func GetModelOtherInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - var req types.GetModelOtherInfoReq + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetModelOtherInfoLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetModelOtherInfo(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-model/internal/handler/updateproductmodelhandler.go b/server/product-model/internal/handler/updateproductmodelhandler.go index 1f1212cb..cf105bda 100644 --- a/server/product-model/internal/handler/updateproductmodelhandler.go +++ b/server/product-model/internal/handler/updateproductmodelhandler.go @@ -2,11 +2,8 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-model/internal/logic" @@ -16,42 +13,22 @@ import ( func UpdateProductModelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - var req types.UpdateProductModelReq + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUpdateProductModelLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UpdateProductModel(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-template/internal/handler/addbasemaphandler.go b/server/product-template/internal/handler/addbasemaphandler.go index 049e2430..1e5942c9 100644 --- a/server/product-template/internal/handler/addbasemaphandler.go +++ b/server/product-template/internal/handler/addbasemaphandler.go @@ -2,11 +2,8 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-template/internal/logic" @@ -16,42 +13,22 @@ import ( func AddBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - var req types.AddBaseMapReq + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewAddBaseMapLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.AddBaseMap(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-template/internal/handler/getbasemaplisthandler.go b/server/product-template/internal/handler/getbasemaplisthandler.go index add18713..22c7296f 100644 --- a/server/product-template/internal/handler/getbasemaplisthandler.go +++ b/server/product-template/internal/handler/getbasemaplisthandler.go @@ -2,52 +2,33 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-template/internal/logic" "fusenapi/server/product-template/internal/svc" + "fusenapi/server/product-template/internal/types" ) func GetBaseMapListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + var req types.Request + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) return } + // 创建一个业务逻辑层实例 l := logic.NewGetBaseMapListLogic(r.Context(), svcCtx) - resp := l.GetBaseMapList(userinfo) + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetBaseMapList(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-template/internal/handler/gettemplatevdetailhandler.go b/server/product-template/internal/handler/gettemplatevdetailhandler.go index 7d843a3b..e7cef6dd 100644 --- a/server/product-template/internal/handler/gettemplatevdetailhandler.go +++ b/server/product-template/internal/handler/gettemplatevdetailhandler.go @@ -2,11 +2,8 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-template/internal/logic" @@ -16,42 +13,22 @@ import ( func GetTemplatevDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - var req types.GetTemplatevDetailReq + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetTemplatevDetailLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetTemplatevDetail(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-template/internal/handler/savebasemaphandler.go b/server/product-template/internal/handler/savebasemaphandler.go index 77a393d5..e3e41831 100644 --- a/server/product-template/internal/handler/savebasemaphandler.go +++ b/server/product-template/internal/handler/savebasemaphandler.go @@ -2,52 +2,33 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-template/internal/logic" "fusenapi/server/product-template/internal/svc" + "fusenapi/server/product-template/internal/types" ) func SaveBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + var req types.Request + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) return } + // 创建一个业务逻辑层实例 l := logic.NewSaveBaseMapLogic(r.Context(), svcCtx) - resp := l.SaveBaseMap(r, userinfo) + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.SaveBaseMap(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-template/internal/handler/updatetemplatehandler.go b/server/product-template/internal/handler/updatetemplatehandler.go index 9bb864da..3f4da440 100644 --- a/server/product-template/internal/handler/updatetemplatehandler.go +++ b/server/product-template/internal/handler/updatetemplatehandler.go @@ -2,11 +2,8 @@ package handler import ( "net/http" + "reflect" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/product-template/internal/logic" @@ -16,42 +13,22 @@ import ( func UpdateTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - - var ( - // 定义错误变量 - err error - // 定义用户信息变量 - userinfo *auth.BackendUserInfo - ) - // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 - if err != nil || claims == nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, // 返回401状态码,表示未授权 - Message: "unauthorized", // 返回未授权信息 - }) - logx.Info("unauthorized:", err.Error()) // 记录错误日志 - return - } - - // 从token中获取对应的用户信息 - userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - var req types.UpdateTemplateReq + userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUpdateTemplateLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UpdateTemplate(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product-template/internal/logic/getbasemaplistlogic.go b/server/product-template/internal/logic/getbasemaplistlogic.go index 1ba47e82..0ae6ac9a 100644 --- a/server/product-template/internal/logic/getbasemaplistlogic.go +++ b/server/product-template/internal/logic/getbasemaplistlogic.go @@ -9,6 +9,7 @@ import ( "context" "fusenapi/server/product-template/internal/svc" + "github.com/zeromicro/go-zero/core/logx" ) @@ -26,7 +27,7 @@ func NewGetBaseMapListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge } } -func (l *GetBaseMapListLogic) GetBaseMapList(userInfo *auth.BackendUserInfo) (resp *basic.Response) { +func (l *GetBaseMapListLogic) GetBaseMapList(req *types.Request, userinfo *auth.BackendUserInfo) (resp *basic.Response) { baseMapFields := "id,name,url,ctime" baseMapList, err := l.svcCtx.AllModels.FsProductTemplateBasemap.GetAllEnabledList(l.ctx, baseMapFields) if err != nil { diff --git a/server/product-template/internal/logic/savebasemaplogic.go b/server/product-template/internal/logic/savebasemaplogic.go index 8d908a8f..4931e15d 100644 --- a/server/product-template/internal/logic/savebasemaplogic.go +++ b/server/product-template/internal/logic/savebasemaplogic.go @@ -13,13 +13,15 @@ import ( "context" "fusenapi/server/product-template/internal/svc" + "github.com/zeromicro/go-zero/core/logx" ) type SaveBaseMapLogic struct { logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext + ctx context.Context + svcCtx *svc.ServiceContext + bodyBytes []byte } func NewSaveBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveBaseMapLogic { @@ -30,14 +32,24 @@ func NewSaveBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveB } } -func (l *SaveBaseMapLogic) SaveBaseMap(r *http.Request, userInfo *auth.BackendUserInfo) (resp *basic.Response) { +// 处理进入前逻辑w,r +func (l *SaveBaseMapLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { bodyBytes, err := ioutil.ReadAll(r.Body) defer r.Body.Close() + if err != nil { + logx.Error(err) + } + l.bodyBytes = bodyBytes +} + +func (l *SaveBaseMapLogic) SaveBaseMap(req *types.Request, userInfo *auth.BackendUserInfo) (resp *basic.Response) { + var err error var postData []types.SaveBaseMapReq - if err = json.Unmarshal(bodyBytes, &postData); err != nil { + if err = json.Unmarshal(l.bodyBytes, &postData); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid request param") } + //空数组 if len(postData) == 0 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param can`t be empty array") diff --git a/server/product/internal/handler/designgatherhandler.go b/server/product/internal/handler/designgatherhandler.go index fb24bb32..516fac2f 100644 --- a/server/product/internal/handler/designgatherhandler.go +++ b/server/product/internal/handler/designgatherhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func DesignGatherHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.DesignGatherReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewDesignGatherLogic(r.Context(), svcCtx) - resp := l.DesignGather(&req, userinfo, r) + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.DesignGather(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getfittingbypidhandler.go b/server/product/internal/handler/getfittingbypidhandler.go index c4b8c169..adbd78ff 100644 --- a/server/product/internal/handler/getfittingbypidhandler.go +++ b/server/product/internal/handler/getfittingbypidhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetFittingByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetFittingByPidReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetFittingByPidLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetFittingByPid(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getlastproductdesignhandler.go b/server/product/internal/handler/getlastproductdesignhandler.go index 3df924b5..79c32f1a 100644 --- a/server/product/internal/handler/getlastproductdesignhandler.go +++ b/server/product/internal/handler/getlastproductdesignhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetLastProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetLastProductDesignLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetLastProductDesign(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getlightbypidhandler.go b/server/product/internal/handler/getlightbypidhandler.go index d810afbf..9184c2ba 100644 --- a/server/product/internal/handler/getlightbypidhandler.go +++ b/server/product/internal/handler/getlightbypidhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetLightByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetLightByPidReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetLightByPidLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetLightByPid(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getmodelbypidhandler.go b/server/product/internal/handler/getmodelbypidhandler.go index 8a01c0ca..ab97af0f 100644 --- a/server/product/internal/handler/getmodelbypidhandler.go +++ b/server/product/internal/handler/getmodelbypidhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetModelByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetModelByPidReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetModelByPidLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetModelByPid(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getpricebypidhandler.go b/server/product/internal/handler/getpricebypidhandler.go index 42a607d8..f98054ac 100644 --- a/server/product/internal/handler/getpricebypidhandler.go +++ b/server/product/internal/handler/getpricebypidhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetPriceByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetPriceByPidReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetPriceByPidLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetPriceByPid(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getproductdesignhandler.go b/server/product/internal/handler/getproductdesignhandler.go index 4cd70b40..02fef73d 100644 --- a/server/product/internal/handler/getproductdesignhandler.go +++ b/server/product/internal/handler/getproductdesignhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetProductDesignReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetProductDesignLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetProductDesign(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getproductinfohandler.go b/server/product/internal/handler/getproductinfohandler.go index a8ac8ad5..7d01c0ee 100644 --- a/server/product/internal/handler/getproductinfohandler.go +++ b/server/product/internal/handler/getproductinfohandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetProductInfoReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetProductInfoLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetProductInfo(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getproductlisthandler.go b/server/product/internal/handler/getproductlisthandler.go index ba5f1fa4..a71fefc7 100644 --- a/server/product/internal/handler/getproductlisthandler.go +++ b/server/product/internal/handler/getproductlisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetProductListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetProductListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetProductList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getrecommandproductlisthandler.go b/server/product/internal/handler/getrecommandproductlisthandler.go index b6474541..00509d37 100644 --- a/server/product/internal/handler/getrecommandproductlisthandler.go +++ b/server/product/internal/handler/getrecommandproductlisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetRecommandProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc return func(w http.ResponseWriter, r *http.Request) { var req types.GetRecommandProductListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetRecommandProductListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetRecommandProductList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getrenderdesignhandler.go b/server/product/internal/handler/getrenderdesignhandler.go index 016a39fd..1a7d8ebd 100644 --- a/server/product/internal/handler/getrenderdesignhandler.go +++ b/server/product/internal/handler/getrenderdesignhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetRenderDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetRenderDesignReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetRenderDesignLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetRenderDesign(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getrendersettingbypidhandler.go b/server/product/internal/handler/getrendersettingbypidhandler.go index e46ba3f0..818f3d07 100644 --- a/server/product/internal/handler/getrendersettingbypidhandler.go +++ b/server/product/internal/handler/getrendersettingbypidhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetRenderSettingByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetRenderSettingByPidReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetRenderSettingByPidLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetRenderSettingByPid(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getsizebypidhandler.go b/server/product/internal/handler/getsizebypidhandler.go index edc29865..38b9c2d8 100644 --- a/server/product/internal/handler/getsizebypidhandler.go +++ b/server/product/internal/handler/getsizebypidhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetSizeByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetSizeByPidReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetSizeByPidLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetSizeByPid(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getsizebyproducthandler.go b/server/product/internal/handler/getsizebyproducthandler.go index 673433d3..9bc8db8b 100644 --- a/server/product/internal/handler/getsizebyproducthandler.go +++ b/server/product/internal/handler/getsizebyproducthandler.go @@ -2,16 +2,34 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" ) func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx) - resp := l.GetSizeByProduct(userinfo) + var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetSizeByProduct(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/getsuccessrecommandhandler.go b/server/product/internal/handler/getsuccessrecommandhandler.go index fb74bfb7..b6f5055b 100644 --- a/server/product/internal/handler/getsuccessrecommandhandler.go +++ b/server/product/internal/handler/getsuccessrecommandhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetSuccessRecommandReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetSuccessRecommand(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/gettagproductlisthandler.go b/server/product/internal/handler/gettagproductlisthandler.go index 88be7c20..02043645 100644 --- a/server/product/internal/handler/gettagproductlisthandler.go +++ b/server/product/internal/handler/gettagproductlisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetTagProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetTagProductListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetTagProductListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetTagProductList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/gettemplatebypidhandler.go b/server/product/internal/handler/gettemplatebypidhandler.go index 0f5ba9b1..94268c3c 100644 --- a/server/product/internal/handler/gettemplatebypidhandler.go +++ b/server/product/internal/handler/gettemplatebypidhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func GetTemplateByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetTemplateByPidReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewGetTemplateByPidLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.GetTemplateByPid(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/homepagerecommendproductlisthandler.go b/server/product/internal/handler/homepagerecommendproductlisthandler.go index d32dfb45..674580a3 100644 --- a/server/product/internal/handler/homepagerecommendproductlisthandler.go +++ b/server/product/internal/handler/homepagerecommendproductlisthandler.go @@ -1,21 +1,35 @@ package handler import ( - "fusenapi/server/product/internal/logic" - "fusenapi/server/product/internal/types" "net/http" + "reflect" + "fusenapi/utils/basic" + + "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" ) func HomePageRecommendProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.HomePageRecommendProductListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewHomePageRecommendProductListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.HomePageRecommendProductList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/otherproductlisthandler.go b/server/product/internal/handler/otherproductlisthandler.go index 13d827c1..43022089 100644 --- a/server/product/internal/handler/otherproductlisthandler.go +++ b/server/product/internal/handler/otherproductlisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func OtherProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.OtherProductListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewOtherProductListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.OtherProductList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/handler/savedesignhandler.go b/server/product/internal/handler/savedesignhandler.go index 78a1ea11..79e05c9a 100644 --- a/server/product/internal/handler/savedesignhandler.go +++ b/server/product/internal/handler/savedesignhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" @@ -12,10 +15,21 @@ func SaveDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.SaveDesignReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewSaveDesignLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.SaveDesign(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/product/internal/logic/designgatherlogic.go b/server/product/internal/logic/designgatherlogic.go index 38d075b5..5c7615a8 100644 --- a/server/product/internal/logic/designgatherlogic.go +++ b/server/product/internal/logic/designgatherlogic.go @@ -12,10 +12,11 @@ import ( "fusenapi/utils/encryption_decryption" "fusenapi/utils/id_generator" "fusenapi/utils/ip" - "gorm.io/gorm" "net/http" "time" + "gorm.io/gorm" + "github.com/zeromicro/go-zero/core/logx" ) @@ -23,6 +24,7 @@ type DesignGatherLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + ipAddr string } func NewDesignGatherLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DesignGatherLogic { @@ -33,7 +35,23 @@ func NewDesignGatherLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Desi } } -func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *auth.UserInfo, r *http.Request) (resp *basic.Response) { +// 处理进入前逻辑w,r +func (l *DesignGatherLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { + //获取ip地址 + ipAddr, err := ip.GetClientIP(r) + if err != nil { + logx.Error(err) + return + // return resp.SetStatusWithMessage(basic.CodeServiceErr, "client ip is not available") + } + l.ipAddr = ipAddr +} + +func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *auth.UserInfo) (resp *basic.Response) { + if l.ipAddr == "" { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "client ip is not available") + } + encryptWebsetting, err := l.svcCtx.AllModels.FsWebSet.FindValueByKey(l.ctx, "is_encrypt") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { @@ -60,13 +78,12 @@ func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *a return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json data,format may be invalid") } } - //获取ip地址 - ipAddr, err := ip.GetClientIP(r) + if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "client ip is not available") } - postInfo["client_ip"] = ipAddr + postInfo["client_ip"] = l.ipAddr var ( optionalId int64 sizeId int64 @@ -129,7 +146,7 @@ func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *a Cover: &cover, Info: &info, Utime: &now, - ClientIp: &ipAddr, + ClientIp: &l.ipAddr, ClientNo: &clientNo, }) if err != nil { diff --git a/server/product/internal/logic/getsizebyproductlogic.go b/server/product/internal/logic/getsizebyproductlogic.go index 3d111822..dea0a181 100644 --- a/server/product/internal/logic/getsizebyproductlogic.go +++ b/server/product/internal/logic/getsizebyproductlogic.go @@ -33,7 +33,7 @@ func NewGetSizeByProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) * } // 获取分类下的产品以及尺寸 -func (l *GetSizeByProductLogic) GetSizeByProduct(userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { if userinfo.GetIdType() != auth.IDTYPE_User { return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first") } diff --git a/server/render/etc/render.yaml b/server/render/etc/render.yaml new file mode 100644 index 00000000..2dba7dc7 --- /dev/null +++ b/server/render/etc/render.yaml @@ -0,0 +1,8 @@ +Name: render +Host: 0.0.0.0 +Port: 8888 +SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest +Auth: + AccessSecret: fusen2023 + AccessExpire: 2592000 + RefreshAfter: 1592000 \ No newline at end of file diff --git a/server/render/internal/config/config.go b/server/render/internal/config/config.go new file mode 100644 index 00000000..b24bb7d7 --- /dev/null +++ b/server/render/internal/config/config.go @@ -0,0 +1,9 @@ +package config + +import "github.com/zeromicro/go-zero/rest" + +type Config struct { + rest.RestConf + SourceMysql string + Auth types.Auth +} diff --git a/server/render/internal/handler/readimageshandler.go b/server/render/internal/handler/readimageshandler.go new file mode 100644 index 00000000..e387ea0f --- /dev/null +++ b/server/render/internal/handler/readimageshandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/render/internal/logic" + "fusenapi/server/render/internal/svc" + "fusenapi/server/render/internal/types" +) + +func ReadImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.RequestReadImages + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewReadImagesLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.ReadImages(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/render/internal/handler/routes.go b/server/render/internal/handler/routes.go new file mode 100644 index 00000000..46f97be9 --- /dev/null +++ b/server/render/internal/handler/routes.go @@ -0,0 +1,27 @@ +// Code generated by goctl. DO NOT EDIT. +package handler + +import ( + "net/http" + + "fusenapi/server/render/internal/svc" + + "github.com/zeromicro/go-zero/rest" +) + +func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/api/render/to-unity", + Handler: ToUnityHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/api/render/read-images", + Handler: ReadImagesHandler(serverCtx), + }, + }, + ) +} diff --git a/server/render/internal/handler/tounityhandler.go b/server/render/internal/handler/tounityhandler.go new file mode 100644 index 00000000..e3cb5d28 --- /dev/null +++ b/server/render/internal/handler/tounityhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/render/internal/logic" + "fusenapi/server/render/internal/svc" + "fusenapi/server/render/internal/types" +) + +func ToUnityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.RequestToUnity + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewToUnityLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.ToUnity(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/render/internal/logic/readimageslogic.go b/server/render/internal/logic/readimageslogic.go new file mode 100644 index 00000000..9ab23d58 --- /dev/null +++ b/server/render/internal/logic/readimageslogic.go @@ -0,0 +1,42 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/render/internal/svc" + "fusenapi/server/render/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ReadImagesLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewReadImagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReadImagesLogic { + return &ReadImagesLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *ReadImagesLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向 +// func (l *ReadImagesLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *ReadImagesLogic) ReadImages(req *types.RequestReadImages, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/render/internal/logic/tounitylogic.go b/server/render/internal/logic/tounitylogic.go new file mode 100644 index 00000000..f9ae5f29 --- /dev/null +++ b/server/render/internal/logic/tounitylogic.go @@ -0,0 +1,42 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/render/internal/svc" + "fusenapi/server/render/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ToUnityLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewToUnityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToUnityLogic { + return &ToUnityLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *ToUnityLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向 +// func (l *ToUnityLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *ToUnityLogic) ToUnity(req *types.RequestToUnity, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/render/internal/svc/servicecontext.go b/server/render/internal/svc/servicecontext.go new file mode 100644 index 00000000..bd083461 --- /dev/null +++ b/server/render/internal/svc/servicecontext.go @@ -0,0 +1,61 @@ +package svc + +import ( + "errors" + "fmt" + "fusenapi/server/render/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 + } + AuthKey = AuthKey[7:] + + 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/render/internal/types/types.go b/server/render/internal/types/types.go new file mode 100644 index 00000000..e2847118 --- /dev/null +++ b/server/render/internal/types/types.go @@ -0,0 +1,81 @@ +// Code generated by goctl. DO NOT EDIT. +package types + +import ( + "fusenapi/utils/basic" +) + +type RequestToUnity struct { +} + +type RequestReadImages struct { +} + +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"` +} + +type File struct { + Filename string `fsfile:"filename"` + Header map[string][]string `fsfile:"header"` + Size int64 `fsfile:"size"` + Data []byte `fsfile:"data"` +} + +type Meta struct { + TotalCount int64 `json:"totalCount"` + PageCount int64 `json:"pageCount"` + CurrentPage int `json:"currentPage"` + PerPage int `json:"perPage"` +} + +// 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/render/render.go b/server/render/render.go new file mode 100644 index 00000000..af3b93f1 --- /dev/null +++ b/server/render/render.go @@ -0,0 +1,36 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "time" + + "fusenapi/utils/auth" + + "fusenapi/server/render/internal/config" + "fusenapi/server/render/internal/handler" + "fusenapi/server/render/internal/svc" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/rest" +) + +var configFile = flag.String("f", "etc/render.yaml", "the config file") + +func main() { + flag.Parse() + + var c config.Config + conf.MustLoad(*configFile, &c) + c.Timeout = int64(time.Second * 15) + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { + })) + 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() +} diff --git a/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go b/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go index d07785f4..26c2c676 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/shopping-cart-confirmation/internal/logic" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -12,10 +15,21 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.CartAddReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewCartAddLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.CartAdd(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go b/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go index d5e578fb..c294d394 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/shopping-cart-confirmation/internal/logic" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -12,10 +15,21 @@ func CartDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.CartDeleteReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewCartDeleteLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.CartDelete(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go b/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go index 1e1eaa26..7632c87a 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/shopping-cart-confirmation/internal/logic" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -12,10 +15,21 @@ func CartListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.CartListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewCartListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.CartList(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go b/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go index 4f49ed1e..5aa85d0b 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go @@ -2,16 +2,34 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/shopping-cart-confirmation/internal/logic" "fusenapi/server/shopping-cart-confirmation/internal/svc" + "fusenapi/server/shopping-cart-confirmation/internal/types" ) func CartNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := logic.NewCartNumberLogic(r.Context(), svcCtx) - resp := l.CartNumber(userinfo) + var req types.Request + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + // 创建一个业务逻辑层实例 + l := logic.NewCartNumberLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.CartNumber(&req, userinfo) + + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go b/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go index 174f170c..a1bb344b 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/shopping-cart-confirmation/internal/logic" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -12,10 +15,21 @@ func CartOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.CartOrderDetailReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewCartOrderDetailLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.CartOrderDetail(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go b/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go index f52bf6f8..ce58d809 100644 --- a/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/shopping-cart-confirmation/internal/logic" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -12,10 +15,21 @@ func ChangeOrderMethodHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.ChangeOrderMethodReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewChangeOrderMethodLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.ChangeOrderMethod(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/shopping-cart-confirmation/internal/handler/createorderhandler.go b/server/shopping-cart-confirmation/internal/handler/createorderhandler.go index a0f4fc17..75083e14 100644 --- a/server/shopping-cart-confirmation/internal/handler/createorderhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/createorderhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/shopping-cart-confirmation/internal/logic" "fusenapi/server/shopping-cart-confirmation/internal/svc" @@ -12,10 +15,21 @@ func CreateOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.CreateOrderReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewCreateOrderLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.CreateOrder(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/shopping-cart-confirmation/internal/logic/cartnumberlogic.go b/server/shopping-cart-confirmation/internal/logic/cartnumberlogic.go index 44c35d32..327d1c9c 100644 --- a/server/shopping-cart-confirmation/internal/logic/cartnumberlogic.go +++ b/server/shopping-cart-confirmation/internal/logic/cartnumberlogic.go @@ -9,6 +9,7 @@ import ( "context" "fusenapi/server/shopping-cart-confirmation/internal/svc" + "github.com/zeromicro/go-zero/core/logx" ) @@ -26,7 +27,7 @@ func NewCartNumberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartNu } } -func (l *CartNumberLogic) CartNumber(userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *CartNumberLogic) CartNumber(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { if userinfo.GetIdType() != auth.IDTYPE_User { return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first") } diff --git a/server/upload/internal/handler/uploadfilebackendhandler.go b/server/upload/internal/handler/uploadfilebackendhandler.go index f68083ff..a3f72895 100644 --- a/server/upload/internal/handler/uploadfilebackendhandler.go +++ b/server/upload/internal/handler/uploadfilebackendhandler.go @@ -1,10 +1,13 @@ package handler import ( + "errors" "net/http" + "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/rest/httpx" + "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/server/upload/internal/logic" @@ -15,7 +18,51 @@ import ( func UploadFileBackendHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + var ( + // 定义错误变量 + err error + // 定义用户信息变量 + userinfo *auth.UserInfo + ) + // 解析JWT token,并对空用户进行判断 + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, // 返回401状态码,表示未授权 + Message: "unauthorized", // 返回未授权信息 + }) + logx.Info("unauthorized:", err.Error()) // 记录错误日志 + return + } + + if claims != nil { + // 从token中获取对应的用户信息 + userinfo, err = auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + } else { + // 如果claims为nil,则认为用户身份为白板用户 + userinfo = &auth.UserInfo{UserId: 0, GuestId: 0} + } + var req types.RequestUploadFileBackend + // 如果端点有请求结构体,则使用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 + } // 解析upload文件类型 err = basic.RequestFileParse(r, &req) @@ -30,6 +77,13 @@ func UploadFileBackendHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { // 创建一个业务逻辑层实例 l := logic.NewUploadFileBackendLogic(r.Context(), svcCtx) resp := l.UploadFileBackend(&req, userinfo) - + // 如果响应不为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/upload/internal/handler/uploadfilefrontendhandler.go b/server/upload/internal/handler/uploadfilefrontendhandler.go index bc6b2b54..6a0a4440 100644 --- a/server/upload/internal/handler/uploadfilefrontendhandler.go +++ b/server/upload/internal/handler/uploadfilefrontendhandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/upload/internal/logic" "fusenapi/server/upload/internal/svc" @@ -12,10 +15,21 @@ func UploadFileFrontendHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.RequestUploadFileFrontend + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUploadFileFrontendLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UploadFileFrontend(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/upload/internal/handler/uploadqrcodehandler.go b/server/upload/internal/handler/uploadqrcodehandler.go index 17c312b1..f5908197 100644 --- a/server/upload/internal/handler/uploadqrcodehandler.go +++ b/server/upload/internal/handler/uploadqrcodehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/upload/internal/logic" "fusenapi/server/upload/internal/svc" @@ -12,10 +15,21 @@ func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.UploadQrcodeReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUploadQrcodeLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UploadQrcode(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/upload/internal/handler/uploadupfilehandler.go b/server/upload/internal/handler/uploadupfilehandler.go index ae6fb6af..ae41d8b9 100644 --- a/server/upload/internal/handler/uploadupfilehandler.go +++ b/server/upload/internal/handler/uploadupfilehandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/upload/internal/logic" "fusenapi/server/upload/internal/svc" @@ -12,10 +15,21 @@ func UploadUpFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.RequestUpFile + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 l := logic.NewUploadUpFileLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.UploadUpFile(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/webset/internal/handler/websetsettinghandler.go b/server/webset/internal/handler/websetsettinghandler.go index 39624ba6..16f13892 100644 --- a/server/webset/internal/handler/websetsettinghandler.go +++ b/server/webset/internal/handler/websetsettinghandler.go @@ -2,6 +2,9 @@ package handler import ( "net/http" + "reflect" + + "fusenapi/utils/basic" "fusenapi/server/webset/internal/logic" "fusenapi/server/webset/internal/svc" @@ -12,10 +15,21 @@ func WebSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.RequestWebSet + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } // 创建一个业务逻辑层实例 - l := logic.NewWetSetSettingLogic(r.Context(), svcCtx) + l := logic.NewWebSetSettingLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + resp := l.WebSetSetting(&req, userinfo) + if !basic.AfterLogic(w, r, rl) { + basic.NormalAfterLogic(w, r, resp) + } } } diff --git a/server/webset/internal/logic/websetsettinglogic.go b/server/webset/internal/logic/websetsettinglogic.go index 956f5796..50da5798 100644 --- a/server/webset/internal/logic/websetsettinglogic.go +++ b/server/webset/internal/logic/websetsettinglogic.go @@ -15,24 +15,31 @@ import ( "gorm.io/gorm" ) -type WetSetSettingLogic struct { +type WebSetSettingLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewWetSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WetSetSettingLogic { - return &WetSetSettingLogic{ +func NewWebSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebSetSettingLogic { + return &WebSetSettingLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } -func (l *WetSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) { +// 处理进入前逻辑w,r +// func (l *WebSetSettingLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向 +// func (l *WebSetSettingLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *WebSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null - typeConf := constants.TypeWebSet(req.Type) //如果是这三个配置项 则读取缓存 @@ -52,4 +59,6 @@ func (l *WetSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *a } return resp.SetStatus(basic.CodeOK, result) + + return resp.SetStatus(basic.CodeOK) } diff --git a/server/webset/test/wetset_test.go b/server/webset/test/webset_test.go similarity index 98% rename from server/webset/test/wetset_test.go rename to server/webset/test/webset_test.go index f7a522f4..897f3e26 100644 --- a/server/webset/test/wetset_test.go +++ b/server/webset/test/webset_test.go @@ -10,7 +10,7 @@ import ( "github.com/tidwall/gjson" ) -func TestWetSetLogic(t *testing.T) { +func TestWebSetLogic(t *testing.T) { var err error var resp *requests.Response var result gjson.Result diff --git a/server_api/data-transfer.api b/server_api/data-transfer.api index 42a6acd9..6e1eec58 100644 --- a/server_api/data-transfer.api +++ b/server_api/data-transfer.api @@ -12,10 +12,10 @@ import "basic.api" service data-transfer { //获取标准logo列表 @handler GetStandardLogoListHandler - get /api/standard-logo/list returns (response); + get /api/standard-logo/list(request) returns (response); //获取二维码设置列表 @handler GetQrCodeSetListHandler - get /api/qrcode-set/list returns (response); + get /api/qrcode-set/list(request) returns (response); } //获取标准logo列表 diff --git a/server_api/product-template.api b/server_api/product-template.api index e101c805..dbe6f293 100644 --- a/server_api/product-template.api +++ b/server_api/product-template.api @@ -18,13 +18,13 @@ service product-template { get /api/product-template/base-map-list(request) returns (response); //底图批量保存 @handler SaveBaseMapHandler - post /api/product-template/base-map-update (request) returns (response); + post /api/product-template/base-map-update(request) returns (response); //新增底图 @handler AddBaseMapHandler - post /api/product-template/base-map-add (AddBaseMapReq) returns (response); + post /api/product-template/base-map-add(AddBaseMapReq) returns (response); //更新模板 @handler UpdateTemplateHandler - post /api/product-template/update-template (UpdateTemplateReq) returns (response); + post /api/product-template/update-template(UpdateTemplateReq) returns (response); } //获取产品模板详情 diff --git a/server_api/product.api b/server_api/product.api index 23929596..fadb0024 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -15,16 +15,16 @@ service product { get /api/product/list(GetProductListReq) returns (response); //获取支付成功后推荐产品 @handler GetSuccessRecommandHandler - get /api/product/success-recommand (GetSuccessRecommandReq) returns (response); + get /api/product/success-recommand(GetSuccessRecommandReq) returns (response); //获取分类下的产品以及尺寸 @handler GetSizeByProductHandler - get /api/product/get-size-by-product returns (response); + get /api/product/get-size-by-product(request) returns (response); //获取保存的设计信息 @handler GetProductDesignHandler get /api/product/design(GetProductDesignReq) returns (response); //产品设计数据采集 @handler DesignGatherHandler - post /api/product/design-gather (DesignGatherReq) returns (response); + post /api/product/design-gather(DesignGatherReq) returns (response); //获取产品信息 @handler GetProductInfoHandler get /api/product/info(GetProductInfoReq) returns (response); @@ -33,7 +33,7 @@ service product { post /api/product/save-design(SaveDesignReq) returns (response); //其他产品推荐列表 @handler OtherProductListHandler - get /api/product/other-list (OtherProductListReq) returns (response); + get /api/product/other-list(OtherProductListReq) returns (response); //获取分类产品列表 @handler GetTagProductListHandler get /api/product/tag_product_list(GetTagProductListReq) returns (response); @@ -67,10 +67,10 @@ service product { get /api/product/get_last_product_design(request) returns (response); //获取详情页推荐产品列表 @handler GetRecommandProductListHandler - get /api/product/recommand (GetRecommandProductListReq) returns (response); + get /api/product/recommand(GetRecommandProductListReq) returns (response); //获取列表页推荐产品列表 @handler HomePageRecommendProductListHandler - get /api/product/home_page_recommend (HomePageRecommendProductListReq) returns (response); + get /api/product/home_page_recommend(HomePageRecommendProductListReq) returns (response); //*********************产品详情分解接口结束*********************** //*********************推荐产品接口开始×××××××××××××××××××××××××× diff --git a/server_api/render.api b/server_api/render.api index 508dbd00..ba162b18 100644 --- a/server_api/render.api +++ b/server_api/render.api @@ -18,8 +18,8 @@ type RequestReadImages { service render { // 发送数据到unity渲染 @handler ToUnityHandler - get /api/render/to-unity (RequestToUnity) returns (response); + get /api/render/to-unity(RequestToUnity) returns (response); // 读图像 @handler ReadImagesHandler - get /api/render/read-images (RequestReadImages) returns (response); + get /api/render/read-images(RequestReadImages) returns (response); } \ No newline at end of file diff --git a/server_api/upload.api b/server_api/upload.api index 998e8522..91171381 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -20,7 +20,7 @@ service upload { post /api/upload/upload-file-backend(RequestUploadFileBackend) returns (response); //生成二维码 @handler UploadQrcodeHandler - post /api/upload/qrcode (UploadQrcodeReq) returns (response); + post /api/upload/qrcode(UploadQrcodeReq) returns (response); } type RequestUpFile { diff --git a/server_api/webset.api b/server_api/webset.api index 8eacc2ff..b6f4b92e 100644 --- a/server_api/webset.api +++ b/server_api/webset.api @@ -10,7 +10,7 @@ info ( import "basic.api" service webset { - @handler WetSetSettingHandler + @handler WebSetSettingHandler get /api/web-set/setting(RequestWebSet) returns (response); } diff --git a/stop_all_server.ps1 b/stop_all_server.ps1 deleted file mode 100644 index 13ca6734..00000000 --- a/stop_all_server.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -Function Stop-Server { - param ( - [Parameter(Mandatory=$true)] - [string] $server_name - ) - Write-Host "Stopping $server_name" - - # 如果存在具有相同名称的 PowerShell Job,将其终止 - $existing_job = Get-Job -Name $server_name -ErrorAction SilentlyContinue - if ($null -ne $existing_job) { - Write-Host "Terminating job for $server_name" - Stop-Job -Name $server_name - Remove-Job -Name $server_name - } - else { - Write-Host "No job found for $server_name" - } -} - -# 列出所有服务器目录 -$server_dirs = "backend", "canteen", "data-transfer", "home-user-auth", "inventory", "map-library", "orders", "product", "product-model", "product-template", "shopping-cart-confirmation", "upload", "webset" - -# 停止每个服务器的 PowerShell Job -foreach ($server_dir in $server_dirs) { - Stop-Server -server_name $server_dir -} \ No newline at end of file diff --git a/utils/basic/request_parse.go b/utils/basic/request_parse.go index cf88b23f..54504d6b 100644 --- a/utils/basic/request_parse.go +++ b/utils/basic/request_parse.go @@ -92,3 +92,45 @@ func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx IJWTParse, Logi return userinfo, err } + +func RequestParseBackend(w http.ResponseWriter, r *http.Request, svcCtx IJWTParse, LogicRequest any) (userinfo *auth.BackendUserInfo, err error) { + + // 解析JWT token,并对空用户进行判断 + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &Response{ + Code: 401, // 返回401状态码,表示未授权 + Message: "unauthorized", // 返回未授权信息 + }) + logx.Info("unauthorized:", err.Error()) // 记录错误日志 + return + } + + if claims != nil { + // 从token中获取对应的用户信息 + userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + } + + // var req types.RequestGoogleLogin + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err = httpx.Parse(r, LogicRequest); err != nil { + httpx.OkJsonCtx(r.Context(), w, &Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + + return userinfo, err +}