Files
junhong_cmp_fiber/internal/exporter/registry.go
邹进 eb9f12d160
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m34s
feat: 后台订单按平台、代理商、在线支付拆分列表与导出
- 新增 GET /orders/platform、/orders/agent、/orders/online,类别由路径固定,参数、响应、权限同原订单列表
- 新增导出场景 order_platform、order_agent、order_online,筛选与表头同 order
- 类别按钱从哪来划分:客户端下单为在线支付;后台代理钱包扣款(含平台代扣)为代理商;其余后台订单为平台
- 列表与导出共用 internal/query/ordercategory 的类别条件
- 企业账号访问订单列表、详情、购买预检改为无权限,修复其可看到全部订单的问题
- 原订单列表与 order 导出场景保留不变

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 12:53:24 +09:00

109 lines
3.1 KiB
Go

package exporter
import (
"context"
"github.com/break/junhong_cmp_fiber/internal/polling/carrierqueue"
"sort"
"gorm.io/gorm"
"github.com/break/junhong_cmp_fiber/pkg/constants"
)
// Registry 导出数据源注册中心。
type Registry struct {
sources map[string]DataSource
}
// NewRegistry 创建导出数据源注册中心。
func NewRegistry(sources ...DataSource) *Registry {
m := make(map[string]DataSource, len(sources))
for _, source := range sources {
if source == nil {
continue
}
m[source.Scene()] = source
}
return &Registry{sources: m}
}
// NewDefaultRegistry 创建默认导出数据源注册中心。
func NewDefaultRegistry(db *gorm.DB) *Registry {
return NewRegistry(
NewDeviceDataSource(db),
NewIotCardDataSource(db),
NewOrderDataSource(db, ""),
NewOrderDataSource(db, constants.OrderCategoryPlatform),
NewOrderDataSource(db, constants.OrderCategoryAgent),
NewOrderDataSource(db, constants.OrderCategoryOnline),
NewPackageDataSource(db),
NewAgentWalletTransactionDataSource(db),
NewAgentRechargeDataSource(db),
NewRefundDataSource(db),
NewExchangeDataSource(db),
NewCommissionRecordDataSource(db),
NewPackageTrafficAlertDataSource(db),
NewExpiringAssetDataSource(db),
NewOperationsActivationDataSource(db),
NewOperationsRenewalDataSource(db),
NewStopResumeRuleDataSource(db),
NewPollingPauseDataSource(db),
NewStopRefusedAlertDataSource(db, stopResumeAlertThreshold(db)),
)
}
// Get 获取指定场景数据源。
func (r *Registry) Get(scene string) (DataSource, bool) {
source, ok := r.sources[scene]
return source, ok
}
// IsSupported 判断场景是否支持。
func (r *Registry) IsSupported(scene string) bool {
_, ok := r.sources[scene]
return ok
}
// Scenes 返回当前支持的场景列表。
func (r *Registry) Scenes() []string {
result := make([]string, 0, len(r.sources))
for scene := range r.sources {
result = append(result, scene)
}
sort.Strings(result)
return result
}
// IsSupportedScene 判断是否为受支持的场景。
func IsSupportedScene(scene string) bool {
switch scene {
case constants.ExportTaskSceneDevice,
constants.ExportTaskSceneIotCard,
constants.ExportTaskSceneOrder,
constants.ExportTaskSceneOrderPlatform,
constants.ExportTaskSceneOrderAgent,
constants.ExportTaskSceneOrderOnline,
constants.ExportTaskScenePackage,
constants.ExportTaskSceneAgentWalletTransaction,
constants.ExportTaskSceneAgentRecharge,
constants.ExportTaskSceneRefund,
constants.ExportTaskSceneExchange,
constants.ExportTaskSceneCommissionRecord,
constants.ExportTaskScenePackageTrafficAlert,
constants.ExportTaskSceneExpiringAsset,
constants.ExportTaskSceneOperationsActivation,
constants.ExportTaskSceneOperationsRenewal,
constants.ExportTaskSceneStopResumeRuleDryRun:
return true
default:
return false
}
}
// stopResumeAlertThreshold 读取停复机连续失败告警阈值(停机被拒视图口径)。
func stopResumeAlertThreshold(db *gorm.DB) func(ctx context.Context) int {
settings := carrierqueue.NewDefaultSettingsProvider(db, nil, nil)
return func(ctx context.Context) int { return settings.Current(ctx).SRAlertFailCount }
}