205 lines
6.4 KiB
TypeScript
205 lines
6.4 KiB
TypeScript
/**
|
||
* 资产管理 API 服务
|
||
* 对应文档:asset-detail-refactor-api-changes.md
|
||
*/
|
||
|
||
import { BaseService } from '../BaseService'
|
||
import type {
|
||
BaseResponse,
|
||
AssetResolveResponse,
|
||
AssetRealtimeStatusResponse,
|
||
AssetRefreshResponse,
|
||
AssetPackageListResponse,
|
||
AssetPackageParams,
|
||
AssetCurrentPackageResponse,
|
||
DeviceStopResponse,
|
||
AssetWalletTransactionListResponse,
|
||
AssetWalletTransactionParams,
|
||
AssetWalletResponse,
|
||
AssetOrdersParams,
|
||
AssetOrdersResponse
|
||
} 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/:identifier/realtime-status
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
*/
|
||
static getRealtimeStatus(identifier: string): Promise<BaseResponse<AssetRealtimeStatusResponse>> {
|
||
return this.getOne<AssetRealtimeStatusResponse>(
|
||
`/api/admin/assets/${identifier}/realtime-status`,
|
||
undefined,
|
||
{
|
||
requestOptions: {
|
||
show404Error: false // 404时不显示错误提示
|
||
}
|
||
}
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 主动调网关拉取最新数据后返回
|
||
* POST /api/admin/assets/:identifier/refresh
|
||
* 注意:设备有 30 秒冷却期,冷却中调用返回 429
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
*/
|
||
static refreshAsset(identifier: string): Promise<BaseResponse<AssetRefreshResponse>> {
|
||
return this.post<BaseResponse<AssetRefreshResponse>>(
|
||
`/api/admin/assets/${identifier}/refresh`,
|
||
{}
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 查询该资产所有套餐记录,含虚流量换算字段(分页)
|
||
* GET /api/admin/assets/:identifier/packages?page=1&page_size=50
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
* @param params 查询参数(可选分页参数)
|
||
*/
|
||
static getAssetPackages(
|
||
identifier: string,
|
||
params?: AssetPackageParams
|
||
): Promise<BaseResponse<AssetPackageListResponse>> {
|
||
return this.get<BaseResponse<AssetPackageListResponse>>(
|
||
`/api/admin/assets/${identifier}/packages`,
|
||
params,
|
||
{
|
||
requestOptions: {
|
||
show404Error: false // 404时不显示错误提示
|
||
}
|
||
}
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 查询当前生效中的主套餐
|
||
* GET /api/admin/assets/:identifier/current-package
|
||
* 无生效套餐时返回 404
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
*/
|
||
static getCurrentPackage(identifier: string): Promise<BaseResponse<AssetCurrentPackageResponse>> {
|
||
return this.getOne<AssetCurrentPackageResponse>(
|
||
`/api/admin/assets/${identifier}/current-package`,
|
||
undefined,
|
||
{
|
||
requestOptions: {
|
||
show404Error: false // 404时不显示错误提示
|
||
}
|
||
}
|
||
)
|
||
}
|
||
|
||
// ========== 资产停复机操作(统一接口)==========
|
||
|
||
/**
|
||
* 停机资产(卡或设备)
|
||
* POST /api/admin/assets/:identifier/stop
|
||
* 停机成功后设置 1 小时停机保护期(保护期内禁止复机)
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
*/
|
||
static stopAsset(identifier: string): Promise<BaseResponse<DeviceStopResponse | void>> {
|
||
return this.post<BaseResponse<DeviceStopResponse | void>>(
|
||
`/api/admin/assets/${identifier}/stop`,
|
||
{}
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 复机资产(卡或设备)
|
||
* POST /api/admin/assets/:identifier/start
|
||
* 复机成功后设置 1 小时复机保护期(保护期内禁止停机)
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
*/
|
||
static startAsset(identifier: string): Promise<BaseResponse<void>> {
|
||
return this.post<BaseResponse<void>>(`/api/admin/assets/${identifier}/start`, {})
|
||
}
|
||
|
||
// ========== 资产停用 ==========
|
||
|
||
/**
|
||
* 手动停用资产(卡或设备)
|
||
* PATCH /api/admin/assets/:identifier/deactivate
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
*/
|
||
static deactivateAsset(identifier: string): Promise<BaseResponse> {
|
||
return this.patch<BaseResponse>(`/api/admin/assets/${identifier}/deactivate`, {})
|
||
}
|
||
|
||
// ========== 钱包查询 ==========
|
||
|
||
/**
|
||
* 查询指定卡或设备的钱包余额概况
|
||
* GET /api/admin/assets/:identifier/wallet
|
||
* 企业账号禁止调用
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
*/
|
||
static getAssetWallet(identifier: string): Promise<BaseResponse<AssetWalletResponse>> {
|
||
return this.getOne<AssetWalletResponse>(`/api/admin/assets/${identifier}/wallet`, undefined, {
|
||
requestOptions: {
|
||
show404Error: false // 404时不显示错误提示
|
||
}
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 分页查询指定资产的钱包收支流水
|
||
* GET /api/admin/assets/:identifier/wallet/transactions
|
||
* 企业账号禁止调用
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
* @param params 查询参数
|
||
*/
|
||
static getWalletTransactions(
|
||
identifier: string,
|
||
params?: AssetWalletTransactionParams
|
||
): Promise<BaseResponse<AssetWalletTransactionListResponse>> {
|
||
return this.get<BaseResponse<AssetWalletTransactionListResponse>>(
|
||
`/api/admin/assets/${identifier}/wallet/transactions`,
|
||
params
|
||
)
|
||
}
|
||
|
||
// ========== 轮询状态更新 ==========
|
||
|
||
/**
|
||
* 更新资产轮询状态
|
||
* PATCH /api/admin/assets/:identifier/polling-status
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
* @param data 轮询状态数据
|
||
*/
|
||
static updatePollingStatus(
|
||
identifier: string,
|
||
data: { enable_polling: boolean }
|
||
): Promise<BaseResponse> {
|
||
return this.patch<BaseResponse>(`/api/admin/assets/${identifier}/polling-status`, data)
|
||
}
|
||
|
||
// ========== 资产历史订单 ==========
|
||
|
||
/**
|
||
* 查询资产历史订单
|
||
* GET /api/admin/assets/:identifier/orders
|
||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||
* @param params 查询参数
|
||
*/
|
||
static getAssetOrders(
|
||
identifier: string,
|
||
params?: AssetOrdersParams
|
||
): Promise<BaseResponse<AssetOrdersResponse>> {
|
||
return this.get<BaseResponse<AssetOrdersResponse>>(
|
||
`/api/admin/assets/${identifier}/orders`,
|
||
params
|
||
)
|
||
}
|
||
}
|