开放接口,修复上游同步不对的问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m55s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m55s
This commit is contained in:
32
internal/gateway/card_status.go
Normal file
32
internal/gateway/card_status.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// ParseCardNetworkStatus 将 Gateway 卡状态转换为系统网络状态。
|
||||
// 只有网关明确返回“正常”才视为开机;“准备”或“待激活”不能按正常卡展示。
|
||||
func ParseCardNetworkStatus(cardStatus, extend string) (int, bool) {
|
||||
status := strings.TrimSpace(cardStatus)
|
||||
ext := strings.TrimSpace(extend)
|
||||
|
||||
switch status {
|
||||
case constants.GatewayCardStatusNormal:
|
||||
return constants.NetworkStatusOnline, true
|
||||
case constants.GatewayCardStatusStopped, constants.GatewayCardStatusReady:
|
||||
return constants.NetworkStatusOffline, true
|
||||
}
|
||||
|
||||
if ext == constants.GatewayCardExtendPendingActivation {
|
||||
return constants.NetworkStatusOffline, true
|
||||
}
|
||||
|
||||
return constants.NetworkStatusOffline, false
|
||||
}
|
||||
|
||||
// IsGatewayCardStopped 判断 Gateway 是否明确返回停机状态。
|
||||
func IsGatewayCardStopped(cardStatus string) bool {
|
||||
return strings.TrimSpace(cardStatus) == constants.GatewayCardStatusStopped
|
||||
}
|
||||
@@ -46,6 +46,37 @@ func (i *FlexInt) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FlexFloat 灵活浮点类型
|
||||
// Gateway 部分流量字段会在 number / string 之间漂移,此类型统一解析为 float64。
|
||||
type FlexFloat float64
|
||||
|
||||
// UnmarshalJSON 实现 json.Unmarshaler 接口
|
||||
// 支持:0.00, "0.00", null
|
||||
func (f *FlexFloat) UnmarshalJSON(data []byte) error {
|
||||
raw := strings.TrimSpace(string(data))
|
||||
if raw == "" || raw == "null" {
|
||||
*f = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(raw, "\"") && strings.HasSuffix(raw, "\"") {
|
||||
unquoted, err := strconv.Unquote(raw)
|
||||
if err != nil {
|
||||
*f = 0
|
||||
return nil
|
||||
}
|
||||
raw = strings.TrimSpace(unquoted)
|
||||
}
|
||||
|
||||
n, err := strconv.ParseFloat(raw, 64)
|
||||
if err != nil {
|
||||
*f = 0
|
||||
return nil
|
||||
}
|
||||
*f = FlexFloat(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
// FlexString 灵活字符串类型
|
||||
// Gateway 部分字段会在 string / number / bool 之间漂移,此类型统一转为字符串避免解析失败。
|
||||
type FlexString string
|
||||
@@ -91,7 +122,7 @@ type CardStatusReq struct {
|
||||
// CardStatusResp 是查询流量卡状态的响应
|
||||
type CardStatusResp struct {
|
||||
ICCID string `json:"iccid" description:"ICCID"`
|
||||
CardStatus string `json:"cardStatus" description:"卡状态(准备、正常、停机)"`
|
||||
CardStatus string `json:"cardStatus" description:"卡状态(准备、正常、停机;仅正常表示开机)"`
|
||||
Extend string `json:"extend,omitempty" description:"扩展字段(广电国网特殊参数)"`
|
||||
}
|
||||
|
||||
@@ -102,9 +133,9 @@ type FlowQueryReq struct {
|
||||
|
||||
// FlowUsageResp 是查询流量使用的响应
|
||||
type FlowUsageResp struct {
|
||||
ICCID string `json:"iccid" description:"ICCID"`
|
||||
Used float64 `json:"used" description:"当月已用流量(MB)"`
|
||||
Unit string `json:"unit" description:"流量单位(MB)"`
|
||||
ICCID string `json:"iccid" description:"ICCID"`
|
||||
Used FlexFloat `json:"used" description:"当月已用流量(MB,兼容数字或字符串)"`
|
||||
Unit string `json:"unit" description:"流量单位(MB)"`
|
||||
}
|
||||
|
||||
// CardOperationReq 是停机/复机请求
|
||||
|
||||
Reference in New Issue
Block a user