chore: 并入 iotlcm-openapi 历史到 openapi/(原提交 3b05d5a)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model/entity"
|
||||
)
|
||||
|
||||
type (
|
||||
ICommon interface {
|
||||
BuildBatchNo(ctx context.Context, prefix string) (string, error)
|
||||
BuildRenewBatchNo(ctx context.Context) (string, error)
|
||||
SaveBatchMain(ctx context.Context, tx gdb.TX, batch *entity.BatchMain, executionMode int) error
|
||||
SaveBatchDetail(ctx context.Context, tx gdb.TX, detail *entity.BatchDetail) error
|
||||
SaveBatchDetails(ctx context.Context, tx gdb.TX, details []*entity.BatchDetail) error
|
||||
Publish(ctx context.Context, queue string, data any) error
|
||||
SubmitRenew(ctx context.Context, in *model.CommonRenewParam) (*model.CommonRenewRes, error)
|
||||
SubmitSingleRenew(ctx context.Context, card model.CommonRenewCard, appID, packageID, remark string, validity int) (*model.CommonSingleRenewRes, error)
|
||||
SubmitBatchRenew(ctx context.Context, appID string, cards []model.CommonRenewCard, iccids []string, packageID, remark string, validity int) (*model.CommonRenewRes, error)
|
||||
SubmitTrafficCutoffConfig(ctx context.Context, in *model.CommonTrafficCutoffConfigParam) (*model.CommonTrafficCutoffConfigRes, error)
|
||||
SubmitSingleTrafficCutoffConfig(ctx context.Context, in *model.CommonTrafficCutoffSingleParam) (*model.CommonSingleTrafficCutoffRes, error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localCommon ICommon
|
||||
)
|
||||
|
||||
func Common() ICommon {
|
||||
if localCommon == nil {
|
||||
panic("implement not found for interface ICommon, forgot register?")
|
||||
}
|
||||
return localCommon
|
||||
}
|
||||
|
||||
func RegisterCommon(i ICommon) {
|
||||
localCommon = i
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/library/xgorm/handler"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
)
|
||||
|
||||
type (
|
||||
IIotTSimCardInfo interface {
|
||||
Model(ctx context.Context, option ...*handler.Option) *gdb.Model
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localIotTSimCardInfo IIotTSimCardInfo
|
||||
)
|
||||
|
||||
func IotTSimCardInfo() IIotTSimCardInfo {
|
||||
if localIotTSimCardInfo == nil {
|
||||
panic("implement not found for interface IIotTSimCardInfo, forgot register?")
|
||||
}
|
||||
return localIotTSimCardInfo
|
||||
}
|
||||
|
||||
func RegisterIotTSimCardInfo(i IIotTSimCardInfo) {
|
||||
localIotTSimCardInfo = i
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type (
|
||||
IMiddleware interface {
|
||||
ResponseHandler(r *ghttp.Request)
|
||||
ApiCtx(r *ghttp.Request)
|
||||
ApiAuth(r *ghttp.Request)
|
||||
OldResponseHandler(r *ghttp.Request)
|
||||
OldCtx(r *ghttp.Request)
|
||||
OldAuth(r *ghttp.Request)
|
||||
IsExceptLogin(ctx context.Context, path string) bool
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localMiddleware IMiddleware
|
||||
)
|
||||
|
||||
func Middleware() IMiddleware {
|
||||
if localMiddleware == nil {
|
||||
panic("implement not found for interface IMiddleware, forgot register?")
|
||||
}
|
||||
return localMiddleware
|
||||
}
|
||||
|
||||
func RegisterMiddleware(i IMiddleware) {
|
||||
localMiddleware = i
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// ================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// You can delete these comments if you wish manually maintain this interface file.
|
||||
// ================================================================================
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model/entity"
|
||||
)
|
||||
|
||||
type (
|
||||
IOldApiQuery interface {
|
||||
StatusConversion(simCardInfo entity.TSimCardInfo) int
|
||||
QuerySimCard(ctx context.Context, input *model.SimCardInfoInput) (output *model.SimCardInfoOutput, err error)
|
||||
QuerySimDataUsage(ctx context.Context, input *model.SimDataUsageOldInput) (output *model.SimDataUsageOldOutput, err error)
|
||||
QuerySimDataUsageMonthly(ctx context.Context, input *model.SimDataUsageMonthlyOldInput) (output *model.SimDataUsageMonthlyOldOutput, err error)
|
||||
QuerySimStatus(ctx context.Context, input *model.SimStatusOldInput) (output *model.SimStatusOldOutput, err error)
|
||||
QuerySimSession(ctx context.Context, input *model.SimStatusOnlineOldInput) (output *model.SimStatusOnlineOldOutput, err error)
|
||||
QueryCardInfoList(ctx context.Context, input *model.QueryCardInfoListInput) (output []model.QueryCardInfoListOutput, err error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localOldApiQuery IOldApiQuery
|
||||
)
|
||||
|
||||
func OldApiQuery() IOldApiQuery {
|
||||
if localOldApiQuery == nil {
|
||||
panic("implement not found for interface IOldApiQuery, forgot register?")
|
||||
}
|
||||
return localOldApiQuery
|
||||
}
|
||||
|
||||
func RegisterOldApiQuery(i IOldApiQuery) {
|
||||
localOldApiQuery = i
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model"
|
||||
)
|
||||
|
||||
type (
|
||||
IQuerySim interface {
|
||||
QuerySimInfo(ctx context.Context, input *model.QuerySimInput) (output *model.QuerySimInfoOutput, err error)
|
||||
QuerySimLimit(ctx context.Context, input *model.QuerySimInput) (output *model.QuerySimLimitOutput, err error)
|
||||
QuerySimImei(ctx context.Context, input *model.QuerySimInput) (output *model.QuerySimImeiOutput, err error)
|
||||
QuerySimUsage(ctx context.Context, input *model.QuerySimInput) (output *model.QuerySimUsageOutput, err error)
|
||||
QuerySimStatus(ctx context.Context, input *model.QuerySimInput) (output *model.QuerySimCardStatusOutput, err error)
|
||||
QueryTrafficCutoffConfig(ctx context.Context, in *model.QueryTrafficCutoffConfigParam) (*model.QueryTrafficCutoffConfigOutput, error)
|
||||
QueryBatchStatus(ctx context.Context, in *model.QueryBatchStatusParam) (*model.QueryBatchStatusOutput, error)
|
||||
QuerySimStatusBatch(ctx context.Context, in *model.QuerySimStatusBatchParam) (*model.QuerySimStatusBatchOutput, error)
|
||||
QuerySimUsageBatch(ctx context.Context, in *model.QuerySimUsageBatchParam) (*model.QuerySimUsageBatchOutput, error)
|
||||
QuerySimImeiBatch(ctx context.Context, in *model.QuerySimImeiBatchParam) (*model.QuerySimImeiBatchOutput, error)
|
||||
}
|
||||
|
||||
IQueryToken interface {
|
||||
Token(ctx context.Context, input model.TokenInputApi) (res model.TokenOutputApi, err error)
|
||||
OperatorToken(ctx context.Context, input model.OperatorTokenInput) (res model.OperatorTokenOutput, err error)
|
||||
OperatorTokenWithAuth(ctx context.Context, input model.OperatorTokenInput) (res model.OperatorTokenOutput, err error)
|
||||
GenerateToken(ctx context.Context, customer *model.CustomClaimsApi) (claims *model.CustomClaimsApi, shortToken string, err error)
|
||||
GenerateShortToken(ctx context.Context, tokenUuid string) (token string, err error)
|
||||
ParseToken(ctx context.Context, token string) (claims *model.CustomClaimsApi, err error)
|
||||
DeleteToken(ctx context.Context, token string) (err error)
|
||||
GetAccessToken(ctx context.Context) (token string, err error)
|
||||
GetCurrentCustomer(ctx context.Context) (claims *model.CustomClaimsApi, err error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localQuerySim IQuerySim
|
||||
localQueryToken IQueryToken
|
||||
)
|
||||
|
||||
func QuerySim() IQuerySim {
|
||||
if localQuerySim == nil {
|
||||
panic("implement not found for interface IQuerySim, forgot register?")
|
||||
}
|
||||
return localQuerySim
|
||||
}
|
||||
|
||||
func RegisterQuerySim(i IQuerySim) {
|
||||
localQuerySim = i
|
||||
}
|
||||
|
||||
func QueryToken() IQueryToken {
|
||||
if localQueryToken == nil {
|
||||
panic("implement not found for interface IQueryToken, forgot register?")
|
||||
}
|
||||
return localQueryToken
|
||||
}
|
||||
|
||||
func RegisterQueryToken(i IQueryToken) {
|
||||
localQueryToken = i
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// ================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// You can delete these comments if you wish manually maintain this interface file.
|
||||
// ================================================================================
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model"
|
||||
)
|
||||
|
||||
type (
|
||||
IUpstreamChan interface {
|
||||
GetUpstreamChanConfig(ctx context.Context) (output model.UpstreamChanConfig, err error)
|
||||
GetSharedToken(ctx context.Context, chanKey string) (*model.SharedTokenResult, error)
|
||||
// 获取卡基本信息
|
||||
QuerySimBasicInfo(ctx context.Context, input *model.SimBasicInfoInput) ([]model.SimBaseRes[model.SimBasicInfoItem], error)
|
||||
// 查询会话信息
|
||||
QuerySimSession(ctx context.Context, input *model.SimSessionInput) ([]model.SimBaseRes[model.SimSessionItem], error)
|
||||
// 查询状态
|
||||
QuerySimCardStatus(ctx context.Context, input *model.SimCardStatusInput) ([]model.SimBaseRes[model.SimCardStatusItem], error)
|
||||
// 查询IMEI
|
||||
QuerySimImei(ctx context.Context, input *model.SimImeiInput) ([]model.SimBaseRes[model.SimImeiItem], error)
|
||||
// 查询流量
|
||||
QuerySimDatausage(ctx context.Context, input *model.SimDataUsageInput) ([]model.SimBaseRes[model.SimDataUsageItem], error)
|
||||
// 查询月流量
|
||||
QuerySimDatausageMonthly(ctx context.Context, input *model.SimDataUsageMonthlyInput) ([]model.SimBaseRes[model.SimDataUsageMonthlyOutputItem], error)
|
||||
// 查询日流量
|
||||
QuerySimDatausageDaily(ctx context.Context, input *model.SimDataUsageDailyInput) ([]model.SimBaseRes[model.SimDataUsageDailyOutputItem], error)
|
||||
// 查询已开通APN信息
|
||||
QuerySimApnInfo(ctx context.Context, input *model.SimApnInfoInput) ([]model.SimBaseRes[model.SimApnInfoItemList], error)
|
||||
// 卡状态变更
|
||||
ChangeSimStatus(ctx context.Context, input *model.SimCardStatusChangeInput) ([]model.SimBaseRes[model.SimCardStatusChangeItem], error)
|
||||
// 卡APN功能开停
|
||||
ChangeSimApnFunction(ctx context.Context, input *model.SimCardOperateChangeApnInput) ([]model.SimBaseRes[model.SimCardOperateChangeApnItem], error)
|
||||
// 查询机卡绑定状态
|
||||
QuerySimCardBindStatus(ctx context.Context, input *model.SimCardBindStatusInput) ([]model.SimBaseRes[model.SimCardBindStatusItem], error)
|
||||
// 查询设备状态
|
||||
QuerySimDeviceStatus(ctx context.Context, input *model.SimDeviceStatusInput) ([]model.SimBaseRes[model.SimDeviceStatusItem], error)
|
||||
// 查询地域限制状态
|
||||
QuerySimRegionLimitStatus(ctx context.Context, input *model.SimRegionLimitStatusInput) ([]model.SimBaseRes[model.SimRegionLimitStatusItem], error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localUpstreamChan IUpstreamChan
|
||||
)
|
||||
|
||||
func UpstreamChan() IUpstreamChan {
|
||||
if localUpstreamChan == nil {
|
||||
panic("implement not found for interface IUpstreamChan, forgot register?")
|
||||
}
|
||||
return localUpstreamChan
|
||||
}
|
||||
|
||||
func RegisterUpstreamChan(i IUpstreamChan) {
|
||||
localUpstreamChan = i
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package workerdiagnostic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model"
|
||||
)
|
||||
|
||||
type Publisher func(ctx context.Context, queue string, data any) error
|
||||
|
||||
type Service struct {
|
||||
publisher Publisher
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
TraceID string
|
||||
Queue string
|
||||
SentAt int64
|
||||
}
|
||||
|
||||
func New(publisher Publisher) *Service {
|
||||
return &Service{publisher: publisher}
|
||||
}
|
||||
|
||||
func (s *Service) Publish(ctx context.Context, message string) (*Result, error) {
|
||||
var (
|
||||
traceID = fmt.Sprintf("worker-test-%s", guid.S())
|
||||
sentAt = gtime.TimestampMilli()
|
||||
payload = model.WorkerDiagnosticMessage{
|
||||
TraceID: traceID,
|
||||
SentAt: sentAt,
|
||||
Message: message,
|
||||
}
|
||||
)
|
||||
if err := s.publisher(ctx, consts.QueueWorkerDiagnostic, payload); err != nil {
|
||||
return nil, gerror.Wrap(err, "publish worker diagnostic message failed")
|
||||
}
|
||||
return &Result{
|
||||
TraceID: traceID,
|
||||
Queue: consts.QueueWorkerDiagnostic,
|
||||
SentAt: sentAt,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package workerdiagnostic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model"
|
||||
)
|
||||
|
||||
func TestPublish(t *testing.T) {
|
||||
var (
|
||||
publishedQueue string
|
||||
publishedPayload model.WorkerDiagnosticMessage
|
||||
)
|
||||
service := New(func(ctx context.Context, queue string, data any) error {
|
||||
publishedQueue = queue
|
||||
var ok bool
|
||||
publishedPayload, ok = data.(model.WorkerDiagnosticMessage)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected payload type %T", data)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
result, err := service.Publish(context.Background(), "worker ping")
|
||||
if err != nil {
|
||||
t.Fatalf("Publish() error = %v", err)
|
||||
}
|
||||
if publishedQueue != consts.QueueWorkerDiagnostic {
|
||||
t.Fatalf("queue = %q, want %q", publishedQueue, consts.QueueWorkerDiagnostic)
|
||||
}
|
||||
if !strings.HasPrefix(result.TraceID, "worker-test-") {
|
||||
t.Fatalf("traceId = %q, want worker-test- prefix", result.TraceID)
|
||||
}
|
||||
if result.SentAt <= 0 {
|
||||
t.Fatalf("sentAt = %d, want positive timestamp", result.SentAt)
|
||||
}
|
||||
if result.Queue != consts.QueueWorkerDiagnostic {
|
||||
t.Fatalf("result queue = %q, want %q", result.Queue, consts.QueueWorkerDiagnostic)
|
||||
}
|
||||
if publishedPayload.TraceID != result.TraceID || publishedPayload.SentAt != result.SentAt {
|
||||
t.Fatalf("published identifiers = %+v, result = %+v", publishedPayload, result)
|
||||
}
|
||||
if publishedPayload.Message != "worker ping" {
|
||||
t.Fatalf("message = %q, want worker ping", publishedPayload.Message)
|
||||
}
|
||||
body, err := json.Marshal(publishedPayload)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
wantJSON := `{"traceId":"` + result.TraceID + `","sentAt":` + fmt.Sprint(result.SentAt) + `,"message":"worker ping"}`
|
||||
if string(body) != wantJSON {
|
||||
t.Fatalf("JSON = %s, want %s", body, wantJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishWrapsPublisherError(t *testing.T) {
|
||||
publishErr := errors.New("broker unavailable")
|
||||
service := New(func(ctx context.Context, queue string, data any) error {
|
||||
return publishErr
|
||||
})
|
||||
|
||||
result, err := service.Publish(context.Background(), "worker ping")
|
||||
if result != nil {
|
||||
t.Fatalf("result = %+v, want nil", result)
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatal("Publish() error = nil, want error")
|
||||
}
|
||||
if !errors.Is(err, publishErr) {
|
||||
t.Fatalf("Publish() error = %v, want wrapped publisher error", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "publish worker diagnostic message failed") {
|
||||
t.Fatalf("Publish() error = %v, want context", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user