Files
junhong_cmp_fiber/internal/routes/asset.go
break b3499adfca 固化七月迭代审计治理进展以隔离线上热修
Constraint: 切换 main 前必须保存当前七月分支全部项目进展,套餐生效提案仅属于 Iteration/7-11。

Rejected: 将七月套餐修复直接移植到 main | 两个分支的可靠投递架构不同。

Confidence: medium

Scope-risk: broad

Directive: 不得将本提交整体 cherry-pick 到 main;main 套餐热修必须基于其纯 Asynq 代码独立实施。

Tested: git diff --check;openspec validate fix-package-activation-starvation --strict。

Not-tested: 按用户要求未运行自动化测试;go build ./... 因当前审计改造中的 Enterprise 模型字面量和 role.recordFailure 参数类型错误未通过。
2026-08-03 09:47:22 +08:00

167 lines
7.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package routes
import (
"github.com/gofiber/fiber/v2"
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/pkg/openapi"
)
func registerAssetRoutes(router fiber.Router, handler *admin.AssetHandler, walletHandler *admin.AssetWalletHandler, doc *openapi.Generator, basePath string) {
assets := router.Group("/assets")
groupPath := basePath + "/assets"
Register(assets, doc, groupPath, "GET", "/resolve/:identifier", handler.Resolve, RouteSpec{
Summary: "解析资产",
Description: "通过虚拟号/ICCID/IMEI/SN/MSISDN 解析设备或卡的完整详情。exchange_trace 始终存在previous_asset/next_asset 无关系时为 null关联项仅在 can_view=true 且 asset_id 非空时允许跳转。企业账号禁止调用。",
Tags: []string{"资产管理"},
Input: new(dto.AssetResolveRequest),
Output: new(dto.AssetResolveResponse),
Auth: true,
})
Register(assets, doc, groupPath, "GET", "/:identifier/realtime-status", handler.RealtimeStatus, RouteSpec{
Summary: "资产实时状态",
Description: "查询资产实时状态。卡类型:读取 DB/Redis 持久化状态;设备类型:实时调用 Gateway sync-info 接口获取最新数据Gateway 失败不阻断主流程DeviceRealtime.gateway_msg 返回失败原因)。",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
Output: new(dto.AssetRealtimeStatusResponse),
Auth: true,
})
Register(assets, doc, groupPath, "POST", "/:identifier/refresh", handler.Refresh, RouteSpec{
Summary: "刷新资产状态",
Description: "主动调网关同步最新状态。设备有30秒冷却期。",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
Output: new(dto.AssetRealtimeStatusResponse),
Auth: true,
})
Register(assets, doc, groupPath, "GET", "/:identifier/packages", handler.Packages, RouteSpec{
Summary: "资产套餐列表",
Description: "查询该资产所有套餐记录,含虚流量换算结果。支持分页与 status 状态筛选。",
Tags: []string{"资产管理"},
Input: new(dto.AssetPackagesRequest),
Output: new(dto.AssetPackagesResult),
Auth: true,
})
Register(assets, doc, groupPath, "GET", "/:identifier/current-package", handler.CurrentPackage, RouteSpec{
Summary: "当前生效套餐",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
Output: new(dto.AssetPackageResponse),
Auth: true,
})
Register(assets, doc, groupPath, "PATCH", "/:identifier/packages/:package_usage_id/expires-at", handler.UpdatePackageExpiresAt, RouteSpec{
Summary: "修改资产套餐过期时间",
Description: "修改指定资产下某条套餐使用记录的过期时间。仅账号ID为2的账号可调用。",
Tags: []string{"资产管理"},
Input: new(dto.UpdateAssetPackageExpiresAtRequest),
Output: new(dto.AssetPackageResponse),
Auth: true,
})
Register(assets, doc, groupPath, "PATCH", "/:identifier/packages/:package_usage_id/used-data", handler.UpdatePackageUsage, RouteSpec{
Summary: "修改资产套餐已用量",
Description: "修改指定资产下某条套餐使用记录的真实已用量(MB)。仅账号ID为2的账号可调用。",
Tags: []string{"资产管理"},
Input: new(dto.UpdateAssetPackageUsageRequest),
Output: new(dto.AssetPackageResponse),
Auth: true,
})
Register(assets, doc, groupPath, "POST", "/:identifier/stop", handler.Stop, RouteSpec{
Summary: "停机",
Description: "设备批量停机设备下所有已实名卡;单卡手动停机。",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
Output: nil,
Auth: true,
})
Register(assets, doc, groupPath, "POST", "/:identifier/start", handler.Start, RouteSpec{
Summary: "复机",
Description: "设备批量复机;单卡手动复机。",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
Output: nil,
Auth: true,
})
Register(assets, doc, groupPath, "PATCH", "/:identifier/deactivate", handler.Deactivate, RouteSpec{
Summary: "停用资产",
Description: "将资产状态设置为停用(不可逆)。仅支持库存中或已售出的资产。",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
Output: nil,
Auth: true,
})
Register(assets, doc, groupPath, "GET", "/:identifier/wallet", walletHandler.GetWallet, RouteSpec{
Summary: "资产钱包概况",
Description: "查询指定卡或设备的钱包余额概况。企业账号禁止调用。",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
Output: new(dto.AssetWalletResponse),
Auth: true,
})
Register(assets, doc, groupPath, "GET", "/:identifier/wallet/transactions", walletHandler.ListTransactions, RouteSpec{
Summary: "资产钱包流水列表",
Description: "分页查询指定资产的钱包收支流水,含充值/扣款来源编号。企业账号禁止调用。",
Tags: []string{"资产管理"},
Input: new(dto.AssetWalletTransactionListRequest),
Output: new(dto.AssetWalletTransactionListResponse),
Auth: true,
})
Register(assets, doc, groupPath, "GET", "/:identifier/orders", handler.Orders, RouteSpec{
Summary: "资产历史订单",
Description: "查询资产本代历史订单,支持 include_previous=true 参数通过换货链追溯前代订单最多10代。",
Tags: []string{"资产管理"},
Input: new(dto.AssetOrdersRequest),
Output: new(dto.AssetOrdersResponse),
Auth: true,
})
Register(assets, doc, groupPath, "GET", "/:identifier/operation-logs", handler.OperationLogs, RouteSpec{
Summary: "查询平台旧资产操作日志",
Description: "仅超级管理员和平台账号可查询切换前旧资产日志;代理和企业必须使用独立资源活动接口。旧记录不接入统一审计时间线。",
Tags: []string{"资产管理"},
Input: new(dto.AssetOperationLogListRequest),
Output: new(dto.AssetOperationLogListResponse),
Auth: true,
})
Register(assets, doc, groupPath, "PATCH", "/:identifier/polling-status", handler.UpdatePollingStatus, RouteSpec{
Summary: "更新资产轮询状态",
Description: "启用或禁用指定资产IoT卡或设备的定期状态轮询。",
Tags: []string{"资产管理"},
Input: new(dto.UpdateAssetPollingStatusRequest),
Output: new(dto.UpdateAssetPollingStatusResponse),
Auth: true,
})
Register(assets, doc, groupPath, "PATCH", "/:identifier/realname-mode", handler.UpdateRealnamePolicy, RouteSpec{
Summary: "更新资产实名认证策略",
Description: "更新指定资产IoT卡或设备的实名认证策略支持 none/before_order/after_order 三种模式。",
Tags: []string{"资产管理"},
Input: new(dto.UpdateAssetRealnamePolicyRequest),
Output: new(dto.UpdateAssetRealnamePolicyResponse),
Auth: true,
})
Register(assets, doc, groupPath, "PATCH", "/:identifier/realname-status", handler.UpdateRealnameStatus, RouteSpec{
Summary: "手动更新卡实名状态",
Description: "手动将指定卡资产标记为已实名或未实名。状态更新后会触发停复机评估,并在标记为已实名时触发待实名套餐激活。",
Tags: []string{"资产管理"},
Input: new(dto.UpdateAssetRealnameStatusRequest),
Output: new(dto.UpdateAssetRealnameStatusResponse),
Auth: true,
})
}