Files
junhong_cmp_fiber/internal/routes/asset.go
huang 80c6f6c756
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m21s
feat: 资产标识符标准化、资产历史订单查询及导入虚拟号强制验证
主要变更:
- 新增 AssetIdentifier 模型及 Store,统一管理资产标识符(ICCID/IMEI/SN 等)
- 新增迁移:asset_identifier 表、order 表新增 asset_identifier 字段、iot_card.virtual_no NOT NULL 约束
- 资产 Handler/Service/Route 全面重构,支持标识符路由查询与解析
- 新增资产历史订单查询接口,支持跨设备/卡/钱包维度的订单聚合
- 设备与物联卡导入任务强制校验虚拟号,缺失时直接拒绝
- Excel 工具函数优化,前端导入指引文档同步更新
- 归档三个 OpenSpec 提案:asset-identifier-standardization、asset-historical-orders、import-mandatory-virtual-no
- 更新 OpenAPI 文档及相关 DTO

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-07 17:39:36 +08:00

122 lines
4.9 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 解析设备或卡的完整详情。企业账号禁止调用。",
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 中的持久化状态,不调网关。",
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: "查询该资产所有套餐记录,含虚流量换算结果。支持分页。",
Tags: []string{"资产管理"},
Input: new(dto.AssetIdentifierRequest),
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, "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, "PATCH", "/:identifier/polling-status", handler.UpdatePollingStatus, RouteSpec{
Summary: "更新资产轮询状态",
Description: "启用或禁用指定资产IoT卡或设备的定期状态轮询。",
Tags: []string{"资产管理"},
Input: new(dto.UpdateAssetPollingStatusRequest),
Output: new(dto.UpdateAssetPollingStatusResponse),
Auth: true,
})
}