所有序列化, 都加入 BeforeLogic AfterLogic方法. 便于处理 w r的传递的参数

This commit is contained in:
eson
2023-07-21 15:20:18 +08:00
parent 373d5dca45
commit 2825f8ae54
100 changed files with 1499 additions and 454 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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