Files
junhong_cmp_fiber/internal/handler/admin/asset_wallet.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

100 lines
3.0 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 admin
import (
"github.com/gofiber/fiber/v2"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
assetSvc "github.com/break/junhong_cmp_fiber/internal/service/asset"
assetWalletSvc "github.com/break/junhong_cmp_fiber/internal/service/asset_wallet"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
"github.com/break/junhong_cmp_fiber/pkg/middleware"
"github.com/break/junhong_cmp_fiber/pkg/response"
)
// AssetWalletHandler 资产钱包处理器
// 提供管理端资产(卡/设备)钱包概况和流水查询接口
type AssetWalletHandler struct {
service *assetWalletSvc.Service
assetService *assetSvc.Service
}
// NewAssetWalletHandler 创建资产钱包处理器
func NewAssetWalletHandler(svc *assetWalletSvc.Service) *AssetWalletHandler {
return &AssetWalletHandler{service: svc}
}
// SetAssetService 注入资产解析服务用于通过标识符解析资产类型和ID
func (h *AssetWalletHandler) SetAssetService(svc *assetSvc.Service) {
h.assetService = svc
}
// GetWallet 查询资产钱包概况
// GET /api/admin/assets/:identifier/wallet
func (h *AssetWalletHandler) GetWallet(c *fiber.Ctx) error {
userType := middleware.GetUserTypeFromContext(c.UserContext())
if userType == constants.UserTypeEnterprise {
return errors.New(errors.CodeForbidden, "企业账号无权查看钱包信息")
}
identifier := c.Params("identifier")
if identifier == "" {
return errors.New(errors.CodeInvalidParam, "标识符不能为空")
}
if h.assetService == nil {
return errors.New(errors.CodeInternalError, "资产服务未配置")
}
asset, err := h.assetService.Resolve(c.UserContext(), identifier)
if err != nil {
return err
}
result, err := h.service.GetWallet(c.UserContext(), asset.AssetType, asset.AssetID)
if err != nil {
return err
}
return response.Success(c, result)
}
// ListTransactions 查询资产钱包流水列表
// GET /api/admin/assets/:identifier/wallet/transactions
func (h *AssetWalletHandler) ListTransactions(c *fiber.Ctx) error {
userType := middleware.GetUserTypeFromContext(c.UserContext())
if userType == constants.UserTypeEnterprise {
return errors.New(errors.CodeForbidden, "企业账号无权查看钱包信息")
}
identifier := c.Params("identifier")
if identifier == "" {
return errors.New(errors.CodeInvalidParam, "标识符不能为空")
}
if h.assetService == nil {
return errors.New(errors.CodeInternalError, "资产服务未配置")
}
asset, err := h.assetService.Resolve(c.UserContext(), identifier)
if err != nil {
return err
}
var req dto.AssetWalletTransactionListRequest
if err := c.QueryParser(&req); err != nil {
return errors.New(errors.CodeInvalidParam)
}
if req.PageSize > 100 {
return errors.New(errors.CodeInvalidParam, "每页数量不能超过100")
}
result, err := h.service.ListTransactions(c.UserContext(), asset.AssetType, asset.AssetID, &req)
if err != nil {
return err
}
return response.Success(c, result)
}