所有序列化, 都加入 BeforeLogic AfterLogic方法. 便于处理 w r的传递的参数
This commit is contained in:
parent
373d5dca45
commit
2825f8ae54
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 <server_name>.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 }
|
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
type RequestRedirect struct {
|
||||
Url string `query:"url"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
8
server/render/etc/render.yaml
Normal file
8
server/render/etc/render.yaml
Normal file
|
@ -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
|
9
server/render/internal/config/config.go
Normal file
9
server/render/internal/config/config.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
}
|
35
server/render/internal/handler/readimageshandler.go
Normal file
35
server/render/internal/handler/readimageshandler.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
27
server/render/internal/handler/routes.go
Normal file
27
server/render/internal/handler/routes.go
Normal file
|
@ -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),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
35
server/render/internal/handler/tounityhandler.go
Normal file
35
server/render/internal/handler/tounityhandler.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
42
server/render/internal/logic/readimageslogic.go
Normal file
42
server/render/internal/logic/readimageslogic.go
Normal file
|
@ -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)
|
||||
}
|
42
server/render/internal/logic/tounitylogic.go
Normal file
42
server/render/internal/logic/tounitylogic.go
Normal file
|
@ -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)
|
||||
}
|
61
server/render/internal/svc/servicecontext.go
Normal file
61
server/render/internal/svc/servicecontext.go
Normal file
|
@ -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))
|
||||
}
|
81
server/render/internal/types/types.go
Normal file
81
server/render/internal/types/types.go
Normal file
|
@ -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
|
||||
}
|
36
server/render/render.go
Normal file
36
server/render/render.go
Normal file
|
@ -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()
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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列表
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//获取产品模板详情
|
||||
|
|
|
@ -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);
|
||||
//*********************产品详情分解接口结束***********************
|
||||
//*********************推荐产品接口开始××××××××××××××××××××××××××
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -10,7 +10,7 @@ info (
|
|||
import "basic.api"
|
||||
|
||||
service webset {
|
||||
@handler WetSetSettingHandler
|
||||
@handler WebSetSettingHandler
|
||||
get /api/web-set/setting(RequestWebSet) returns (response);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user