fix
This commit is contained in:
parent
d5b829c212
commit
58d02d0d50
78
server/inventory/internal/handler/getpickuplisthandler.go
Normal file
78
server/inventory/internal/handler/getpickuplisthandler.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
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/inventory/internal/logic"
|
||||
"fusenapi/server/inventory/internal/svc"
|
||||
"fusenapi/server/inventory/internal/types"
|
||||
)
|
||||
|
||||
func GetPickupListHandler(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.GetPickupListReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetPickupListLogic(r.Context(), svcCtx)
|
||||
resp := l.GetPickupList(&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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/inventory/supplement",
|
||||
Handler: SupplementHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/inventory/pick-up-list",
|
||||
Handler: GetPickupListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
34
server/inventory/internal/logic/getpickuplistlogic.go
Normal file
34
server/inventory/internal/logic/getpickuplistlogic.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/inventory/internal/svc"
|
||||
"fusenapi/server/inventory/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPickupListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetPickupListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPickupListLogic {
|
||||
return &GetPickupListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPickupListLogic) GetPickupList(req *types.GetPickupListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
|
@ -16,8 +16,8 @@ type TakeForm struct {
|
|||
}
|
||||
|
||||
type GetCloudListReq struct {
|
||||
Page int64 `form:"page"`
|
||||
PageSize int64 `form:"page_size"`
|
||||
Page int `form:"page"`
|
||||
PageSize int `form:"page_size"`
|
||||
Size int64 `form:"size"`
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,13 @@ type SupplementRsp struct {
|
|||
Sn string `json:"sn"`
|
||||
}
|
||||
|
||||
type GetPickupListReq struct {
|
||||
Status int64 `form:"status,options=0|1|2|3|4"`
|
||||
Page int `form:"page"`
|
||||
PageSize int `form:"page_size"`
|
||||
Size int `form:"size"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
@ -81,8 +88,8 @@ type Auth struct {
|
|||
type Pagnation struct {
|
||||
TotalCount int64 `json:"total_count"`
|
||||
TotalPage int64 `json:"total_page"`
|
||||
CurPage int64 `json:"cur_page"`
|
||||
PageSize int64 `json:"page_size"`
|
||||
CurPage int `json:"cur_page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
|
|
|
@ -29,7 +29,7 @@ type Auth {
|
|||
type Pagnation{
|
||||
TotalCount int64 `json:"total_count"`
|
||||
TotalPage int64 `json:"total_page"`
|
||||
CurPage int64 `json:"cur_page"`
|
||||
PageSize int64 `json:"page_size"`
|
||||
CurPage int `json:"cur_page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ service inventory {
|
|||
//云仓补货
|
||||
@handler SupplementHandler
|
||||
post /inventory/supplement(SupplementReq) returns (response);
|
||||
//提货列表
|
||||
@handler GetPickupListHandler
|
||||
get /inventory/pick-up-list(GetPickupListReq) returns (response);
|
||||
}
|
||||
|
||||
//提取云仓货物
|
||||
|
@ -31,8 +34,8 @@ type TakeForm {
|
|||
}
|
||||
//获取云仓库存列表
|
||||
type GetCloudListReq {
|
||||
Page int64 `form:"page"`
|
||||
PageSize int64 `form:"page_size"`
|
||||
Page int `form:"page"`
|
||||
PageSize int `form:"page_size"`
|
||||
Size int64 `form:"size"`
|
||||
}
|
||||
type GetCloudListRsp {
|
||||
|
@ -73,4 +76,12 @@ type SupplementReq {
|
|||
}
|
||||
type SupplementRsp {
|
||||
Sn string `json:"sn"`
|
||||
}
|
||||
|
||||
//提货列表
|
||||
type GetPickupListReq {
|
||||
Status int64 `form:"status,options=0|1|2|3|4"`
|
||||
Page int `form:"page"`
|
||||
PageSize int `form:"page_size"`
|
||||
Size int `form:"size"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user