This commit is contained in:
179
src/api/modules/asset.ts
Normal file
179
src/api/modules/asset.ts
Normal file
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* 资产管理 API 服务
|
||||
* 对应文档:asset-detail-refactor-api-changes.md
|
||||
*/
|
||||
|
||||
import { BaseService } from '../BaseService'
|
||||
import type {
|
||||
BaseResponse,
|
||||
AssetType,
|
||||
AssetResolveResponse,
|
||||
AssetRealtimeStatusResponse,
|
||||
AssetRefreshResponse,
|
||||
AssetPackageUsageRecord,
|
||||
AssetCurrentPackageResponse,
|
||||
DeviceStopResponse,
|
||||
DeviceStartResponse,
|
||||
CardStopResponse,
|
||||
CardStartResponse,
|
||||
AssetWalletTransactionListResponse,
|
||||
AssetWalletTransactionParams,
|
||||
AssetWalletResponse
|
||||
} from '@/types/api'
|
||||
|
||||
export class AssetService extends BaseService {
|
||||
/**
|
||||
* 通过任意标识符查询设备或卡的完整详情
|
||||
* 支持虚拟号、ICCID、IMEI、SN、MSISDN
|
||||
* GET /api/admin/assets/resolve/:identifier
|
||||
* @param identifier 资产标识符(虚拟号、ICCID、IMEI、SN、MSISDN)
|
||||
*/
|
||||
static resolveAsset(identifier: string): Promise<BaseResponse<AssetResolveResponse>> {
|
||||
return this.getOne<AssetResolveResponse>(`/api/admin/assets/resolve/${identifier}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取资产实时状态(直接读 DB/Redis,不调网关)
|
||||
* GET /api/admin/assets/:asset_type/:id/realtime-status
|
||||
* @param assetType 资产类型 (card 或 device)
|
||||
* @param id 资产ID
|
||||
*/
|
||||
static getRealtimeStatus(
|
||||
assetType: AssetType,
|
||||
id: number
|
||||
): Promise<BaseResponse<AssetRealtimeStatusResponse>> {
|
||||
return this.getOne<AssetRealtimeStatusResponse>(
|
||||
`/api/admin/assets/${assetType}/${id}/realtime-status`
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动调网关拉取最新数据后返回
|
||||
* POST /api/admin/assets/:asset_type/:id/refresh
|
||||
* 注意:设备有 30 秒冷却期,冷却中调用返回 429
|
||||
* @param assetType 资产类型 (card 或 device)
|
||||
* @param id 资产ID
|
||||
*/
|
||||
static refreshAsset(
|
||||
assetType: AssetType,
|
||||
id: number
|
||||
): Promise<BaseResponse<AssetRefreshResponse>> {
|
||||
return this.post<BaseResponse<AssetRefreshResponse>>(
|
||||
`/api/admin/assets/${assetType}/${id}/refresh`,
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询该资产所有套餐记录,含虚流量换算字段
|
||||
* GET /api/admin/assets/:asset_type/:id/packages
|
||||
* @param assetType 资产类型 (card 或 device)
|
||||
* @param id 资产ID
|
||||
*/
|
||||
static getAssetPackages(
|
||||
assetType: AssetType,
|
||||
id: number
|
||||
): Promise<BaseResponse<AssetPackageUsageRecord[]>> {
|
||||
return this.get<BaseResponse<AssetPackageUsageRecord[]>>(
|
||||
`/api/admin/assets/${assetType}/${id}/packages`
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前生效中的主套餐
|
||||
* GET /api/admin/assets/:asset_type/:id/current-package
|
||||
* 无生效套餐时返回 404
|
||||
* @param assetType 资产类型 (card 或 device)
|
||||
* @param id 资产ID
|
||||
*/
|
||||
static getCurrentPackage(
|
||||
assetType: AssetType,
|
||||
id: number
|
||||
): Promise<BaseResponse<AssetCurrentPackageResponse>> {
|
||||
return this.getOne<AssetCurrentPackageResponse>(
|
||||
`/api/admin/assets/${assetType}/${id}/current-package`
|
||||
)
|
||||
}
|
||||
|
||||
// ========== 设备停复机操作 ==========
|
||||
|
||||
/**
|
||||
* 批量停机设备下所有已实名卡
|
||||
* POST /api/admin/assets/device/:device_id/stop
|
||||
* 停机成功后设置 1 小时停机保护期(保护期内禁止复机)
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
static stopDevice(deviceId: number): Promise<BaseResponse<DeviceStopResponse>> {
|
||||
return this.post<BaseResponse<DeviceStopResponse>>(
|
||||
`/api/admin/assets/device/${deviceId}/stop`,
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量复机设备下所有已实名卡
|
||||
* POST /api/admin/assets/device/:device_id/start
|
||||
* 复机成功后设置 1 小时复机保护期(保护期内禁止停机)
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
static startDevice(deviceId: number): Promise<BaseResponse<void>> {
|
||||
return this.post<BaseResponse<void>>(`/api/admin/assets/device/${deviceId}/start`, {})
|
||||
}
|
||||
|
||||
// ========== 单卡停复机操作 ==========
|
||||
|
||||
/**
|
||||
* 手动停机单张卡(通过 ICCID)
|
||||
* POST /api/admin/assets/card/:iccid/stop
|
||||
* 若卡绑定的设备在复机保护期内,返回 403
|
||||
* @param iccid ICCID
|
||||
*/
|
||||
static stopCard(iccid: string): Promise<BaseResponse<void>> {
|
||||
return this.post<BaseResponse<void>>(`/api/admin/assets/card/${iccid}/stop`, {})
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动复机单张卡(通过 ICCID)
|
||||
* POST /api/admin/assets/card/:iccid/start
|
||||
* 若卡绑定的设备在停机保护期内,返回 403
|
||||
* @param iccid ICCID
|
||||
*/
|
||||
static startCard(iccid: string): Promise<BaseResponse<void>> {
|
||||
return this.post<BaseResponse<void>>(`/api/admin/assets/card/${iccid}/start`, {})
|
||||
}
|
||||
|
||||
// ========== 钱包查询 ==========
|
||||
|
||||
/**
|
||||
* 查询指定卡或设备的钱包余额概况
|
||||
* GET /api/admin/assets/:asset_type/:id/wallet
|
||||
* 企业账号禁止调用
|
||||
* @param assetType 资产类型 (card 或 device)
|
||||
* @param id 资产ID
|
||||
*/
|
||||
static getAssetWallet(
|
||||
assetType: AssetType,
|
||||
id: number
|
||||
): Promise<BaseResponse<AssetWalletResponse>> {
|
||||
return this.getOne<AssetWalletResponse>(`/api/admin/assets/${assetType}/${id}/wallet`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询指定资产的钱包收支流水
|
||||
* GET /api/admin/assets/:asset_type/:id/wallet/transactions
|
||||
* 企业账号禁止调用
|
||||
* @param assetType 资产类型 (card 或 device)
|
||||
* @param id 资产ID
|
||||
* @param params 查询参数
|
||||
*/
|
||||
static getWalletTransactions(
|
||||
assetType: AssetType,
|
||||
id: number,
|
||||
params?: AssetWalletTransactionParams
|
||||
): Promise<BaseResponse<AssetWalletTransactionListResponse>> {
|
||||
return this.get<BaseResponse<AssetWalletTransactionListResponse>>(
|
||||
`/api/admin/assets/${assetType}/${id}/wallet/transactions`,
|
||||
params
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user