| | |
| | | const dataStr = await this.midwayCache.get(`push:yingshiyun:queue:${messageId}`) as string | null; |
| | | if (!dataStr) return; |
| | | const body = JSON.parse(dataStr); |
| | | |
| | | const type = body?.header?.type; |
| | | |
| | | console.log(`---------------------------------${type}`); |
| | | try { |
| | | switch (type) { |
| | | |
| | | // 设备上下线 |
| | | case 'ys.onoffline': { |
| | | await this.pushDeviceOnoffEntity.save({ |
| | | deviceId:body.header.deviceId, |
| | | channelNo: body.header.channelNo, |
| | | const onoffData: any = { |
| | | deviceId: body.header.deviceId, |
| | | channelNo: Number(body.header.channelNo) || 0, |
| | | messageId: body.header.messageId, |
| | | messageTime: new Date(body.header.messageTime), |
| | | messageTime: new Date(Number(body.header.messageTime)), |
| | | msgType: body.body.msgType, |
| | | devType: body.body.devType, |
| | | deviceName: body.body.deviceName, |
| | | subSerial: body.body.subSerial, |
| | | dasId: body.body.dasId, |
| | | natIp: body.body.natIp, |
| | | occurTime: body.body.occurTime, |
| | | regTime: body.body.regTime |
| | | }); |
| | | devType: body.body.devType || '', |
| | | deviceName: body.body.deviceName || '', |
| | | subSerial: body.body.subSerial || '', |
| | | dasId: body.body.dasId || '', |
| | | natIp: body.body.natIp || '', |
| | | occurTime: body.body.occurTime ? new Date(body.body.occurTime.replace(' ', 'T')) : null, |
| | | regTime: body.body.regTime ? new Date(body.body.regTime.replace(' ', 'T')) : null, |
| | | }; |
| | | await this.pushDeviceOnoffEntity.save(onoffData); |
| | | break; |
| | | } |
| | | |
| | | // 萤石告警 |
| | | case 'ys.alarm': { |
| | | // 图片下载并上传到本地/对象存储 pictureList: Array<{ url: string; id: string }>; |
| | | const localUrls: Record<string, string>[] = []; |
| | | if (body.body.pictureList && Array.isArray(body.body.pictureList)) { |
| | | const filePlugin = await this.pluginService.getInstance('upload'); |
| | | for (const item of body.body.pictureList) { |
| | | try { |
| | | const result = await filePlugin.downAndUpload(item.url); |
| | | localUrls.push({url: result, id: item.id}); |
| | | } catch (err) { |
| | | console.error(`图片下载失败: ${item.url}`, err); |
| | | } |
| | | } |
| | | } |
| | | await this.pushDevicealarmEntity.save({ |
| | | const alarmData: any = { |
| | | devSerial: body.body.devSerial, |
| | | channelNo: body.body.channelNo || String(body.body.channel), |
| | | alarmId: body.body.alarmId, |
| | | alarmTime: body.body.alarmTime, |
| | | alarmTime: body.body.alarmTime ? new Date(body.body.alarmTime.replace('T', ' ')) : new Date(), |
| | | alarmType: body.body.alarmType, |
| | | channelName: body.body.channelName, |
| | | channelType: body.body.channelType ? Number(body.body.channelType) : 1, |
| | | checksum: body.body.checksum, |
| | | crypt: body.body.crypt ? Number(body.body.crypt) : 0, |
| | | customInfo: body.body.customInfo, |
| | | customType: body.body.customType, |
| | | describe: body.body.describe, |
| | | location: body.body.location, |
| | | relationId: body.body.relationId, |
| | | status: body.body.status ? Number(body.body.status) : 1, |
| | | pictureList: localUrls || [] |
| | | }); |
| | | channelType: Number(body.body.channelType) || 1, |
| | | customInfo: body.body.customInfo || '', |
| | | customType: body.body.customType || '', |
| | | describe: body.body.describe || '', |
| | | location: body.body.location || '', |
| | | relationId: body.body.relationId || '', |
| | | status: Number(body.body.status) || 1, |
| | | channelNo: String(body.body.channel ?? body.body.channelNo ?? ''), |
| | | }; |
| | | if (body.body.checksum) alarmData.checksum = body.body.checksum; |
| | | if (body.body.crypt !== undefined) alarmData.crypt = Number(body.body.crypt); |
| | | // 图片处理(有则处理,无则跳过) |
| | | const localUrls: Record<string, string>[] = []; |
| | | if (body.body.pictureList?.length) { |
| | | try { |
| | | const filePlugin = await this.pluginService.getInstance('upload'); |
| | | for (const item of body.body.pictureList) { |
| | | try { |
| | | const result = await filePlugin.downAndUpload(item.url); |
| | | localUrls.push({ url: result, id: item.id }); |
| | | } catch (err) { |
| | | console.error(`图片下载失败: ${item.url}`, err); |
| | | } |
| | | } |
| | | } catch (err) { |
| | | console.error('filePlugin init failed:', err); |
| | | } |
| | | } |
| | | alarmData.pictureList = localUrls; |
| | | await this.pushDevicealarmEntity.save(alarmData); |
| | | break; |
| | | } |
| | | |
| | | // 海康 ISAPI |
| | | //case 'ys.open.isapi': { |
| | | //processCameraGpsAsync(body) |
| | | //await this.pushIsapiRepo.save({ |
| | | // messageId, |
| | | // raw: JSON.stringify(body), |
| | | // createTime: new Date(), |
| | | //}); |
| | | //break; |
| | | //} |
| | | |
| | | //海康 ISAPI |
| | | case 'ys.open.isapi': { |
| | | console.log(`---------start ys.isapi-------------------------------`); |
| | | console.log(body); |
| | | //TODO: 解析海康 ISAPI 消息,入库 |
| | | // 消息类型: ys.open.isapi | messageId: 6a69a482d05a3d0d7cdb5c83 打印内容如下: |
| | | // ---------------------------------ys.open.isapi |
| | | // ---------start ys.isapi------------------------------- |
| | | // { |
| | | // body: { |
| | | // payload: '{"ipAddress": "10.83.239.158", "protocol": "HTTP", "dateTime": "2026-07-29T14:58:07+08:00", "activePostCount": 1, "eventType": "deviceStatus", "deviceID": "RkYmx96HhzkQHnK+te7tNB89AAHahWc=", "eventState": "active", "eventDescription": "device Status", "DeviceStatus": {"sleepStatus": "sleep", "batteryList": [{"id": 1, "voltage": 3595, "current": 137, "batteryPercentage": 33, "temperature": 36, "remainingBattery": 16.829, "state": "charing", "protocolType": "ADC", "lowTemperatureHeatingStatus": "stop", "protocolVersion": "1.0"}], "solarPanelStatus": {"voltage": 4.919, "current": 918, "power": 4.509, "powerGeneration": 3.790}, "powerConsumptionStatus": {"voltage": 0.000, "current": 0, "power": 0.000, "powerConsumption": 0.220}, "dialStatusList": [{"dialSignalStrength": 5, "band": "B39", "PCI": 63}]}}' |
| | | // }, |
| | | // header: { |
| | | // channelNo: 0, |
| | | // deviceId: 'GN3665733', |
| | | // messageId: '6a69a482d05a3d0d7cdb5c83', |
| | | // messageTime: 1785308290000, |
| | | // type: 'ys.open.isapi' |
| | | // } |
| | | // } |
| | | // processCameraGpsAsync(body) |
| | | // await this.pushIsapiRepo.save({ |
| | | // messageId, |
| | | // raw: JSON.stringify(body), |
| | | // createTime: new Date(), |
| | | // }); |
| | | break; |
| | | } |
| | | default: |
| | | console.warn('Unknown yingshi webhook type:', type); |
| | | } |
| | |
| | | errorMessage: err, |
| | | }); |
| | | } |
| | | |
| | | // 不管成功与否,删除缓存中的任务队列 |
| | | await this.midwayCache.del(`push:yingshiyun:queue:${messageId}`); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | * 异步解析车载监控的GPS数据,存储并添加业务表 |
| | | */ |
| | | async processCameraGpsAsync(body: any) { |
| | | |
| | | |
| | | try { |
| | | let vehicleNo = ''; |
| | | if (body.sn) { |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 保存摄像头主动上报告警事件 |
| | | * @param alarmData |
| | | */ |
| | | async saveCameraAlarmEvent(alarmData: any) { |
| | | const { eventType, targetType, ipAddress, dateTime } = alarmData; |
| | | if (eventType === 'VMD') { |
| | | console.log(`【移动侦测告警】设备${ipAddress},时间:${dateTime},目标类型:${targetType}`); |
| | | // TODO: 完成摄像机侦测数据保存 |
| | | } else { |
| | | console.log(`【未知摄像头事件类型】type:${eventType}`); |
| | | } |
| | | return Date.now(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |