chore: 并入 iotlcm-upstream-chan 历史到 upstream-chan/(原提交 1e74497)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:02 +08:00
192 changed files with 33119 additions and 0 deletions
@@ -0,0 +1,179 @@
package upstreamimpl
import (
"context"
"strings"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/model"
"github.com/gogf/gf/v2/frame/g"
)
func convertDxSessionStatus(ctx context.Context, upstreamStatus string) string {
switch strings.TrimSpace(upstreamStatus) {
case "0":
return consts.CardSessionStatusOnline
case "1":
return consts.CardSessionStatusOffline
case "2", "":
return consts.CardSessionStatusUnknown
default:
g.Log().Warningf(ctx, "Unknown DX session status %s from upstream", upstreamStatus)
return consts.CardSessionStatusUnknown
}
}
func convertYdSessionStatus(ctx context.Context, upstreamStatus string) string {
switch strings.ToUpper(strings.TrimSpace(upstreamStatus)) {
case "01", "1", "0", "ONLINE":
return consts.CardSessionStatusOnline
case "00", "-1", "OFFLINE":
return consts.CardSessionStatusOffline
case "02", "2", "-2", "", "UNKNOWN":
return consts.CardSessionStatusUnknown
default:
g.Log().Warningf(ctx, "Unknown YD session status %s from upstream", upstreamStatus)
return consts.CardSessionStatusUnknown
}
}
func convertYdApnStatus(ctx context.Context, upstreamStatus string) string {
switch strings.TrimSpace(upstreamStatus) {
case consts.CardApnStatusPaused:
return consts.CardApnStatusPaused
case consts.CardApnStatusNormal:
return consts.CardApnStatusNormal
default:
g.Log().Warningf(ctx, "Unknown YD APN status %s from upstream", upstreamStatus)
return upstreamStatus
}
}
// convertDxApnOperType 把平台 APN 开停编码转换为电信 singleCutNet 的 action 取值,语义相反。
// 平台编码(全平台统一「开=0 / 停=1」,见 consts.CardApnOperType*):
//
// 0 = 开通数据(恢复联网)
// 1 = 停用数据(断网,含达量断网)
//
// 电信 singleCutNet(CTIOT_5GCMP_BA004)action:
//
// ADD = 单独断网(添加断网)
// DEL = 取消单独断网(恢复联网)
//
// 两者恰好相反:平台 0(开) -> 电信 DEL(取消断网),平台 1(停) -> 电信 ADD(断网)。禁止透传。
//
// 注意:singleCutNet 是整卡数据开停语义,电信侧没有「按 APN 定向」这一维度,
// 因此忽略调用方携带的 ApnName(预警自动断网、批量数据开停都会固定带 apnName="CMIOT")。
func convertDxApnOperType(ctx context.Context, operType string) (string, bool) {
switch strings.TrimSpace(operType) {
case consts.CardApnOperTypeOpen:
return "DEL", true
case consts.CardApnOperTypeStop:
return "ADD", true
default:
g.Log().Warningf(ctx, "Unknown APN operType %s for DX upstream", operType)
return "", false
}
}
// convertYdCommunicationBusinessType 把平台 APN 开停编码转换为移动 OneLink「通信业务开停-单卡」
// (7.2.1 CMIOT_API25M19,ec/manage/sim-communication-service)的 businessType。两者同向,无需翻转。
//
// 平台编码(全平台统一「开=0 / 停=1」,见 consts.CardApnOperType*):
//
// 0 = 开通数据(启用 APN)
// 1 = 停用数据(停用 APN,含达量断网)
//
// 移动 7.2.1 businessType:0:开 1:停(同向,直接透传)
func convertYdCommunicationBusinessType(ctx context.Context, operType string) (string, bool) {
switch strings.TrimSpace(operType) {
case consts.CardApnOperTypeOpen:
return "0", true
case consts.CardApnOperTypeStop:
return "1", true
default:
g.Log().Warningf(ctx, "Unknown APN operType %s for YD sim-communication-service", operType)
return "", false
}
}
// convertYdCommunicationOperType 把平台 APN 开停编码转换为移动 OneLink「通信功能开停-批量」
// (7.2.2 CMIOT_API23M09,ec/operate/sim-communication-function/batch)的 operType。语义相反,必须翻转。
//
// 平台编码(全平台统一「开=0 / 停=1」,见 consts.CardApnOperType*):
//
// 0 = 开通数据(启用 APN)
// 1 = 停用数据(停用 APN,含达量断网)
//
// 移动 7.2.2 operType:0:暂停(停) 1:恢复(开)(与平台相反)
//
// 平台 0(开) -> 移动 1(恢复),平台 1(停) -> 移动 0(暂停)。禁止透传。
func convertYdCommunicationOperType(ctx context.Context, operType string) (string, bool) {
switch strings.TrimSpace(operType) {
case consts.CardApnOperTypeOpen:
return "1", true
case consts.CardApnOperTypeStop:
return "0", true
default:
g.Log().Warningf(ctx, "Unknown APN operType %s for YD sim-communication-function", operType)
return "", false
}
}
func normalizeCardStatusChangeOperType(ctx context.Context, operType string) (string, bool) {
switch strings.TrimSpace(operType) {
case consts.CardStatusChangeOperTypeApplyStop:
return consts.CardStatusChangeOperTypeApplyStop, true
case consts.CardStatusChangeOperTypeApplyResume:
return consts.CardStatusChangeOperTypeApplyResume, true
default:
g.Log().Warningf(ctx, "Unknown card status change operType %s", operType)
return "", false
}
}
func convertDxCardStatusChangeOperType(ctx context.Context, operType string) (string, bool) {
switch strings.TrimSpace(operType) {
case consts.CardStatusChangeOperTypeApplyStop:
return "19", true
case consts.CardStatusChangeOperTypeApplyResume:
return "20", true
default:
g.Log().Warningf(ctx, "Unknown card status change operType %s for DX upstream", operType)
return "", false
}
}
func newInvalidCardStatusChangeOutput(simKeys []*model.SimKey) model.SimCardStatusChangeOutput {
items := make(model.SimCardStatusChangeOutput, 0, len(simKeys))
for _, simKey := range simKeys {
items = append(items, &model.SimBaseRes[model.SimCardStatusChangeItem]{
SimKey: simKey,
Code: consts.ApiStatusError,
Message: "unsupported operType, expected 0(stop) or 1(resume)",
ResData: model.SimCardStatusChangeItem{},
})
}
return items
}
// convertTibiotCardStatus 转换Tibiot卡状态码
// Tibiot: 1正常 2停机 3沉默期 5测试期 6停机保号
// 系统: 1待激活 2已激活 4停机 6可测试 7库存 8预销户 9已销户
func convertTibiotCardStatus(ctx context.Context, upstreamStatus int) int {
switch upstreamStatus {
case 1: // 正常
return 2 // 已激活
case 2: // 停机
return 4 // 停机
case 3: // 沉默期
return 1 // 待激活
case 5: // 测试期
return 6 // 可测试
case 6: // 停机保号
return 4 // 停机
default:
g.Log().Warningf(ctx, "Unknown Tibiot card status %d", upstreamStatus)
return 0 // 未知
}
}