This commit is contained in:
@@ -3,7 +3,6 @@ package admin
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
iotCardService "github.com/break/junhong_cmp_fiber/internal/service/iot_card"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
@@ -13,14 +12,12 @@ import (
|
||||
)
|
||||
|
||||
type IotCardHandler struct {
|
||||
service *iotCardService.Service
|
||||
gatewayClient *gateway.Client
|
||||
service *iotCardService.Service
|
||||
}
|
||||
|
||||
func NewIotCardHandler(service *iotCardService.Service, gatewayClient *gateway.Client) *IotCardHandler {
|
||||
func NewIotCardHandler(service *iotCardService.Service) *IotCardHandler {
|
||||
return &IotCardHandler{
|
||||
service: service,
|
||||
gatewayClient: gatewayClient,
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,16 +133,7 @@ func (h *IotCardHandler) GetGatewayStatus(c *fiber.Ctx) error {
|
||||
return errors.New(errors.CodeInvalidParam, "ICCID不能为空")
|
||||
}
|
||||
|
||||
// 验证权限:查询数据库确认卡存在且用户有权限访问
|
||||
_, err := h.service.GetByICCID(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeNotFound, "卡不存在或无权限访问")
|
||||
}
|
||||
|
||||
// 调用 Gateway
|
||||
resp, err := h.gatewayClient.QueryCardStatus(c.UserContext(), &gateway.CardStatusReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
resp, err := h.service.GatewayQueryCardStatus(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -160,16 +148,7 @@ func (h *IotCardHandler) GetGatewayFlow(c *fiber.Ctx) error {
|
||||
return errors.New(errors.CodeInvalidParam, "ICCID不能为空")
|
||||
}
|
||||
|
||||
// 验证权限:查询数据库确认卡存在且用户有权限访问
|
||||
_, err := h.service.GetByICCID(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeNotFound, "卡不存在或无权限访问")
|
||||
}
|
||||
|
||||
// 调用 Gateway
|
||||
resp, err := h.gatewayClient.QueryFlow(c.UserContext(), &gateway.FlowQueryReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
resp, err := h.service.GatewayQueryFlow(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -184,16 +163,7 @@ func (h *IotCardHandler) GetGatewayRealname(c *fiber.Ctx) error {
|
||||
return errors.New(errors.CodeInvalidParam, "ICCID不能为空")
|
||||
}
|
||||
|
||||
// 验证权限:查询数据库确认卡存在且用户有权限访问
|
||||
_, err := h.service.GetByICCID(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeNotFound, "卡不存在或无权限访问")
|
||||
}
|
||||
|
||||
// 调用 Gateway
|
||||
resp, err := h.gatewayClient.QueryRealnameStatus(c.UserContext(), &gateway.CardStatusReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
resp, err := h.service.GatewayQueryRealnameStatus(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -208,16 +178,7 @@ func (h *IotCardHandler) GetRealnameLink(c *fiber.Ctx) error {
|
||||
return errors.New(errors.CodeInvalidParam, "ICCID不能为空")
|
||||
}
|
||||
|
||||
// 验证权限:查询数据库确认卡存在且用户有权限访问
|
||||
_, err := h.service.GetByICCID(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeNotFound, "卡不存在或无权限访问")
|
||||
}
|
||||
|
||||
// 调用 Gateway
|
||||
link, err := h.gatewayClient.GetRealnameLink(c.UserContext(), &gateway.CardStatusReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
link, err := h.service.GatewayGetRealnameLink(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -232,17 +193,7 @@ func (h *IotCardHandler) StopCard(c *fiber.Ctx) error {
|
||||
return errors.New(errors.CodeInvalidParam, "ICCID不能为空")
|
||||
}
|
||||
|
||||
// 验证权限:查询数据库确认卡存在且用户有权限访问
|
||||
_, err := h.service.GetByICCID(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeNotFound, "卡不存在或无权限访问")
|
||||
}
|
||||
|
||||
// 调用 Gateway
|
||||
err = h.gatewayClient.StopCard(c.UserContext(), &gateway.CardOperationReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
if err != nil {
|
||||
if err := h.service.GatewayStopCard(c.UserContext(), iccid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -256,17 +207,7 @@ func (h *IotCardHandler) StartCard(c *fiber.Ctx) error {
|
||||
return errors.New(errors.CodeInvalidParam, "ICCID不能为空")
|
||||
}
|
||||
|
||||
// 验证权限:查询数据库确认卡存在且用户有权限访问
|
||||
_, err := h.service.GetByICCID(c.UserContext(), iccid)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeNotFound, "卡不存在或无权限访问")
|
||||
}
|
||||
|
||||
// 调用 Gateway
|
||||
err = h.gatewayClient.StartCard(c.UserContext(), &gateway.CardOperationReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
if err != nil {
|
||||
if err := h.service.GatewayStartCard(c.UserContext(), iccid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user