feat: 根据租户获取景区二维码内容
This commit is contained in:
@@ -50,6 +50,23 @@ export interface AlertItem {
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
function hashStringToSeed(text: string): number {
|
||||
let hash = 2166136261;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
hash ^= text.charCodeAt(i);
|
||||
hash = Math.imul(hash, 16777619);
|
||||
}
|
||||
return hash >>> 0;
|
||||
}
|
||||
|
||||
function createRng(seedText: string) {
|
||||
let seed = hashStringToSeed(seedText) || 1;
|
||||
return () => {
|
||||
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
|
||||
return seed / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备统计
|
||||
*/
|
||||
@@ -193,17 +210,25 @@ export async function getTrendData(days: number = 7): Promise<{ taskTrend: Trend
|
||||
date.setDate(date.getDate() - i);
|
||||
const dateStr = date.toISOString().split('T')[0];
|
||||
|
||||
const rng = createRng(`trend:${dateStr}`);
|
||||
const created = Math.floor(8 + rng() * 18);
|
||||
const completed = Math.floor(created * (0.68 + rng() * 0.22));
|
||||
const failed = Math.max(0, Math.floor(created * (0.03 + rng() * 0.08)));
|
||||
|
||||
taskTrend.push({
|
||||
date: dateStr,
|
||||
created: Math.floor(Math.random() * 20) + 5,
|
||||
completed: Math.floor(Math.random() * 15) + 3,
|
||||
failed: Math.floor(Math.random() * 3),
|
||||
created,
|
||||
completed,
|
||||
failed,
|
||||
});
|
||||
|
||||
const online = Math.floor(72 + rng() * 24);
|
||||
const total = 100;
|
||||
|
||||
deviceTrend.push({
|
||||
date: dateStr,
|
||||
online: Math.floor(Math.random() * 30) + 70,
|
||||
total: 100,
|
||||
online,
|
||||
total,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -214,24 +239,83 @@ export async function getTrendData(days: number = 7): Promise<{ taskTrend: Trend
|
||||
* 模拟告警数据
|
||||
*/
|
||||
export function getMockAlerts(): AlertItem[] {
|
||||
return [
|
||||
const now = dayjs();
|
||||
const dayKey = now.format('YYYY-MM-DD');
|
||||
const rng = createRng(`alerts:${dayKey}:${now.format('HH')}`);
|
||||
const pick = <T,>(arr: T[]) => arr[Math.floor(rng() * arr.length)];
|
||||
|
||||
const devices = [
|
||||
{ sn: 'DRONE-A01', name: '城市巡检无人机A' },
|
||||
{ sn: 'DRONE-B02', name: '河道巡检无人机B' },
|
||||
{ sn: 'DOCK-01', name: '城北机库01' },
|
||||
{ sn: 'CAM-07', name: '高新大道摄像头07' },
|
||||
];
|
||||
|
||||
const baseAlerts: AlertItem[] = [
|
||||
{
|
||||
id: '1',
|
||||
id: `a-${dayKey}-1`,
|
||||
type: 'device_offline',
|
||||
deviceSn: 'DRONE001',
|
||||
deviceName: '巡检无人机A',
|
||||
message: '设备离线超过5分钟',
|
||||
deviceSn: 'CAM-07',
|
||||
deviceName: '高新大道摄像头07',
|
||||
message: '关键点位离线超过 5 分钟',
|
||||
level: 'warning',
|
||||
timestamp: new Date().toISOString(),
|
||||
timestamp: now.subtract(3, 'minute').toISOString(),
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
id: `a-${dayKey}-2`,
|
||||
type: 'low_battery',
|
||||
deviceSn: 'DRONE002',
|
||||
deviceName: '巡检无人机B',
|
||||
message: '电池电量低于20%',
|
||||
deviceSn: 'DRONE-B02',
|
||||
deviceName: '河道巡检无人机B',
|
||||
message: '电池电量低于 20%,建议返航或更换任务资源',
|
||||
level: 'warning',
|
||||
timestamp: new Date(Date.now() - 300000).toISOString(),
|
||||
timestamp: now.subtract(9, 'minute').toISOString(),
|
||||
},
|
||||
{
|
||||
id: `a-${dayKey}-3`,
|
||||
type: 'device_fault',
|
||||
deviceSn: 'DOCK-01',
|
||||
deviceName: '城北机库01',
|
||||
message: '舱门状态异常,请核对机库自检结果',
|
||||
level: 'error',
|
||||
timestamp: now.subtract(18, 'minute').toISOString(),
|
||||
},
|
||||
{
|
||||
id: `a-${dayKey}-4`,
|
||||
type: 'task_failed',
|
||||
taskId: 10086,
|
||||
taskName: '主干道早高峰巡检',
|
||||
message: '任务中断:链路波动导致视频回传丢包',
|
||||
level: 'error',
|
||||
timestamp: now.subtract(26, 'minute').toISOString(),
|
||||
},
|
||||
{
|
||||
id: `a-${dayKey}-5`,
|
||||
type: 'device_offline',
|
||||
deviceSn: 'DRONE-A01',
|
||||
deviceName: '城市巡检无人机A',
|
||||
message: '回传信号弱,定位数据更新异常',
|
||||
level: 'critical',
|
||||
timestamp: now.subtract(37, 'minute').toISOString(),
|
||||
},
|
||||
];
|
||||
|
||||
const extraCount = 1 + Math.floor(rng() * 2);
|
||||
for (let i = 0; i < extraCount; i++) {
|
||||
const d = pick(devices);
|
||||
baseAlerts.push({
|
||||
id: `a-${dayKey}-x${i}`,
|
||||
type: pick(['device_offline', 'low_battery', 'device_fault'] as AlertItem['type'][]),
|
||||
deviceSn: d.sn,
|
||||
deviceName: d.name,
|
||||
message: pick([
|
||||
'状态波动:请关注在线率与告警趋势',
|
||||
'链路质量下降:可能影响实时回传',
|
||||
'边缘算力占用较高:建议分流任务',
|
||||
]),
|
||||
level: pick(['warning', 'error'] as AlertItem['level'][]),
|
||||
timestamp: now.subtract(45 + Math.floor(rng() * 25), 'minute').toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
return baseAlerts.slice(0, 8);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user