sync: 同步 v1.0.4 开源代码并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 14:59:32 +08:00
parent 14f4bb64e1
commit 3e5a7453b8
74 changed files with 3297 additions and 248 deletions
+57 -16
View File
@@ -3,14 +3,14 @@ package upstreamapi
import (
"context"
"database/sql"
"strings"
"sync"
"time"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/dao"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/model"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/model/entity"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/service"
"strings"
"sync"
"time"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
@@ -285,9 +285,11 @@ func (u *sUpstreamAPI) packChanKey(ctx context.Context, simKeys []*model.SimKey)
queryRedisIccids := make([]string, 0)
queryDbIccids := make([]string, 0)
chanKeyMap := make(map[string][]*model.SimKey)
simKeyMap := make(map[string][]*model.SimKey, len(simKeys))
// 检查通道id是都携带
for _, simKey := range simKeys {
if simKey.ChanKey == "" {
simKeyMap[simKey.ICCID] = append(simKeyMap[simKey.ICCID], simKey)
unknownChanKeyIccids = append(unknownChanKeyIccids, simKey.ICCID)
queryRedisIccids = append(queryRedisIccids, redisKey+simKey.ICCID)
} else {
@@ -319,10 +321,11 @@ func (u *sUpstreamAPI) packChanKey(ctx context.Context, simKeys []*model.SimKey)
continue
}
allIccid[iccid] = true
chanKeyMap[chanKeyStr] = append(chanKeyMap[chanKeyStr], &model.SimKey{
ChanKey: chanKeyStr,
ICCID: iccid,
})
for _, original := range simKeyMap[iccid] {
key := *original
key.ChanKey = chanKeyStr
chanKeyMap[chanKeyStr] = append(chanKeyMap[chanKeyStr], &key)
}
}
for iccid, found := range allIccid {
if !found {
@@ -347,18 +350,20 @@ func (u *sUpstreamAPI) packChanKey(ctx context.Context, simKeys []*model.SimKey)
for _, simCardInfo := range simCardInfos {
allIccid[simCardInfo.Iccid] = true
chanKeyMap[simCardInfo.ChanKey] = append(chanKeyMap[simCardInfo.ChanKey], &model.SimKey{
ChanKey: simCardInfo.ChanKey,
ICCID: simCardInfo.Iccid,
})
for _, original := range simKeyMap[simCardInfo.Iccid] {
key := *original
key.ChanKey = simCardInfo.ChanKey
chanKeyMap[simCardInfo.ChanKey] = append(chanKeyMap[simCardInfo.ChanKey], &key)
}
g.Redis().Set(ctx, redisKey+simCardInfo.Iccid, simCardInfo.ChanKey)
}
for iccid, found := range allIccid {
if !found {
chanKeyMap[""] = append(chanKeyMap[""], &model.SimKey{
ChanKey: "",
ICCID: iccid,
})
for _, original := range simKeyMap[iccid] {
key := *original
key.ChanKey = ""
chanKeyMap[""] = append(chanKeyMap[""], &key)
}
}
}
return chanKeyMap, nil
@@ -1273,7 +1278,19 @@ func (u *sUpstreamAPI) ChangeSimCardOperateApn(ctx context.Context, input *model
}
}
for chanKey, inputNew := range inputMap {
if inputNew.ReqData.RecoverOnly && inputNew.ReqData.QueryJobID == "" {
recovered, recoverErr := durableApnOperation(ctx, sqlApnOperationStore{}, chanKey, inputNew, nil)
if recoverErr != nil {
recovered = unknownApnOperation(inputNew, recoverErr.Error())
}
output = append(output, recovered...)
continue
}
if chanKey == "" {
if inputNew.ReqData.SubmitOnly || inputNew.ReqData.QueryJobID != "" {
output = append(output, unknownApnOperation(inputNew, "通道未配置,异步结果未确认")...)
continue
}
for _, simKey := range inputNew.SimKeys {
output = append(output, &model.SimBaseRes[model.SimCardOperateChangeApnItem]{
SimKey: simKey,
@@ -1285,6 +1302,10 @@ func (u *sUpstreamAPI) ChangeSimCardOperateApn(ctx context.Context, input *model
}
channel, ok := u.GetChan(chanKey)
if !ok || channel.Instance == nil {
if inputNew.ReqData.SubmitOnly || inputNew.ReqData.QueryJobID != "" {
output = append(output, unknownApnOperation(inputNew, "通道未实例化,异步结果未确认")...)
continue
}
for _, simKey := range inputNew.SimKeys {
output = append(output, &model.SimBaseRes[model.SimCardOperateChangeApnItem]{
SimKey: simKey,
@@ -1294,13 +1315,33 @@ func (u *sUpstreamAPI) ChangeSimCardOperateApn(ctx context.Context, input *model
}
continue
}
out, err := channel.Instance.ChangeSimApnFunction(ctx, inputNew)
var out model.SimCardOperateChangeApnOutput
var err error
if inputNew.ReqData.QueryJobID == "" && (inputNew.ReqData.RecoverOnly || inputNew.ReqData.SubmitOnly) {
out, err = durableApnOperation(ctx, sqlApnOperationStore{}, chanKey, inputNew, func(submitCtx context.Context) (model.SimCardOperateChangeApnOutput, error) {
return channel.Instance.ChangeSimApnFunction(submitCtx, inputNew)
})
} else if inputNew.ReqData.QueryJobID != "" {
querier, supported := channel.Instance.(interface {
QuerySimApnFunctionResult(context.Context, *model.SimCardOperateChangeApnInput) (model.SimCardOperateChangeApnOutput, error)
})
if !supported {
for _, key := range inputNew.SimKeys {
output = append(output, &model.SimBaseRes[model.SimCardOperateChangeApnItem]{SimKey: key, Code: consts.ApiStatusError, Message: "该通道不支持异步APN任务查询", ResData: model.SimCardOperateChangeApnItem{OrderNum: inputNew.ReqData.QueryJobID, Uncertain: true}})
}
continue
}
out, err = querier.QuerySimApnFunctionResult(ctx, inputNew)
} else {
out, err = channel.Instance.ChangeSimApnFunction(ctx, inputNew)
}
if err != nil {
for _, simKey := range inputNew.SimKeys {
output = append(output, &model.SimBaseRes[model.SimCardOperateChangeApnItem]{
SimKey: simKey,
Code: consts.ApiStatusError,
Message: err.Error(),
ResData: model.SimCardOperateChangeApnItem{OrderNum: inputNew.ReqData.QueryJobID, Uncertain: inputNew.ReqData.SubmitOnly || inputNew.ReqData.RecoverOnly || inputNew.ReqData.QueryJobID != ""},
})
}
} else {