diff --git a/src/api/rfid/dashboard/index.ts b/src/api/rfid/dashboard/index.ts index 77b21fa..e96f39f 100644 --- a/src/api/rfid/dashboard/index.ts +++ b/src/api/rfid/dashboard/index.ts @@ -1,11 +1,92 @@ import request from '@/utils/request'; +import { AxiosPromise } from 'axios'; +import { + DashboardVO, + RealtimeStats, + DeviceStatusVO, + SuccessRateTrend, + StatisticsOverview, + AlarmStatVO +} from './types'; + +// ==================== 新增接口(按需刷新) ==================== /** - * 获取首页统计数据 + * 【新接口1】获取实时统计数据(按秒刷新) + * 包含:顶部统计(设备数量、在线数量、离线数量、告警数量)+ 告警统计列表 + * + * @param alarmLimit 告警列表限制数量(默认10条) */ -export const getDashboardStats = () => { +export const getRealtimeStats = (alarmLimit?: number): AxiosPromise => { return request({ - url: '/rfid/dashboard/stats', + url: '/rfid/dashboard/realtime', + method: 'get', + params: { alarmLimit } + }); +}; + +/** + * 【新接口2】获取设备状态列表(定时刷新) + * 包含每个设备的在线状态、告警状态及最新读取记录 + * + * @param locationId 位置ID(可选,用于按位置筛选) + */ +export const getDeviceStatusList = (locationId?: number): AxiosPromise => { + return request({ + url: '/rfid/dashboard/deviceStatus', + method: 'get', + params: { locationId } + }); +}; + +/** + * 【新接口3】获取成功率趋势(按小时统计) + * 不需要频繁刷新 + * + * @param type 类型:today-今日(默认),yesterday-昨日 + */ +export const getSuccessRateTrends = (type?: string): AxiosPromise => { + return request({ + url: '/rfid/dashboard/successRate', + method: 'get', + params: { type } + }); +}; + +// ==================== 原有接口(保留) ==================== + +/** + * 获取完整看板数据 + * + * @param locationId 位置ID(可选) + */ +export const getDashboardData = (locationId?: number): AxiosPromise => { + return request({ + url: '/rfid/dashboard/data', + method: 'get', + params: { locationId } + }); +}; + +/** + * 获取统计概览 + */ +export const getOverview = (): AxiosPromise => { + return request({ + url: '/rfid/dashboard/overview', method: 'get' - }) -} + }); +}; + +/** + * 获取告警统计列表 + * + * @param limit 限制数量(默认10条) + */ +export const getAlarmStats = (limit?: number): AxiosPromise => { + return request({ + url: '/rfid/dashboard/alarmStats', + method: 'get', + params: { limit } + }); +}; diff --git a/src/api/rfid/dashboard/types.ts b/src/api/rfid/dashboard/types.ts new file mode 100644 index 0000000..c24ce0d --- /dev/null +++ b/src/api/rfid/dashboard/types.ts @@ -0,0 +1,106 @@ +/** + * 看板数据类型定义 + */ + +/** + * 完整看板数据(原接口返回) + */ +export interface DashboardVO { + /** 统计概览 */ + overview: StatisticsOverview; + /** 设备状态列表 */ + deviceStatusList: DeviceStatusVO[]; + /** 成功率趋势数据 */ + successRateTrends: SuccessRateTrend[]; + /** 告警统计列表 */ + alarmStats: AlarmStatVO[]; +} + +/** + * 统计概览 + */ +export interface StatisticsOverview { + /** 设备总数 */ + deviceTotal: number; + /** 在线数量 */ + onlineCount: number; + /** 离线数量 */ + offlineCount: number; + /** 告警数量 */ + alarmCount: number; +} + +/** + * 告警统计 + */ +export interface AlarmStatVO { + /** 告警时间 */ + alarmTime: string; + /** 设备名称 */ + deviceName: string; + /** 位置 */ + location: string; + /** 告警级别 */ + alarmLevel: string; + /** 告警行为 */ + alarmAction: string; +} + +/** + * 实时统计数据(接口1返回) + * 按秒刷新:顶部统计 + 告警列表 + */ +export interface RealtimeStats { + /** 统计概览 */ + overview: StatisticsOverview; + /** 告警统计列表 */ + alarmStats: AlarmStatVO[]; +} + +/** + * 最新读取记录 + */ +export interface LatestReadRecord { + /** 工位名称 */ + stationName: string; + /** 条码信息 */ + barcode: string; + /** 读取时间 */ + recordTime: string; + /** 读取状态 (1-成功;0-失败) */ + readStatus: string; +} + +/** + * 设备状态(接口2返回) + * 定时刷新:设备树 + 设备最新读取记录 + */ +export interface DeviceStatusVO { + /** 设备ID */ + deviceId: number; + /** 设备编号 */ + deviceCode: string; + /** 设备名称 */ + deviceName: string; + /** 所属位置ID */ + locationId: number; + /** 位置别名 */ + locationAlias: string; + /** 在线状态 (1-在线;0-离线) */ + onlineStatus: string; + /** 告警状态 (0-正常;1-告警) */ + alarmStatus: string; + /** 最新读取记录 */ + latestRecord?: LatestReadRecord; +} + +/** + * 成功率趋势(接口3返回) + * 按小时统计 + */ +export interface SuccessRateTrend { + /** 时间点(小时,如 "09:00") */ + timePoint: string; + /** 成功率(百分比,如 98.5) */ + successRate: number | null; +}