From b27355fe55abf32a32c744d68831643a0e6091e6 Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期一, 03 八月 2026 19:23:04 +0800
Subject: [PATCH] 更新页面标题和内容,优化萤石云接口处理逻辑,增加摄像头告警事件保存功能
---
src/modules/push/service/open.ts | 153 ++++++++++++++++++++++++++++++---------------------
1 files changed, 90 insertions(+), 63 deletions(-)
diff --git a/src/modules/push/service/open.ts b/src/modules/push/service/open.ts
index f0882da..b6421f5 100644
--- a/src/modules/push/service/open.ts
+++ b/src/modules/push/service/open.ts
@@ -115,78 +115,98 @@
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: 瑙f瀽娴峰悍 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);
}
@@ -197,11 +217,9 @@
errorMessage: err,
});
}
-
// 涓嶇鎴愬姛涓庡惁锛屽垹闄ょ紦瀛樹腑鐨勪换鍔¢槦鍒�
await this.midwayCache.del(`push:yingshiyun:queue:${messageId}`);
-
-}
+ }
@@ -209,8 +227,6 @@
* 寮傛瑙f瀽杞﹁浇鐩戞帶鐨凣PS鏁版嵁锛屽瓨鍌ㄥ苟娣诲姞涓氬姟琛�
*/
async processCameraGpsAsync(body: any) {
-
-
try {
let vehicleNo = '';
if (body.sn) {
@@ -292,8 +308,19 @@
}
+ /**
+ * 淇濆瓨鎽勫儚澶翠富鍔ㄤ笂鎶ュ憡璀︿簨浠�
+ * @param alarmData
+ */
+ async saveCameraAlarmEvent(alarmData: any) {
+ const { eventType, targetType, ipAddress, dateTime } = alarmData;
+ if (eventType === 'VMD') {
+ console.log(`銆愮Щ鍔ㄤ睛娴嬪憡璀︺�戣澶�${ipAddress}锛屾椂闂达細${dateTime},鐩爣绫诲瀷:${targetType}`);
+ // TODO: 瀹屾垚鎽勫儚鏈轰睛娴嬫暟鎹繚瀛�
+ } else {
+ console.log(`銆愭湭鐭ユ憚鍍忓ご浜嬩欢绫诲瀷銆憈ype:${eventType}`);
+ }
+ return Date.now();
+ }
-
-
-
-}
+}
\ No newline at end of file
--
Gitblit v1.9.1