From 6e210cdaada04907dd127ce6db5a67f2e6e11f58 Mon Sep 17 00:00:00 2001
From: wangzhibo <wangzhibo@shsening.com>
Date: 星期五, 17 七月 2026 11:34:09 +0800
Subject: [PATCH] add
---
src/modules/push/service/open.ts | 109 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 92 insertions(+), 17 deletions(-)
diff --git a/src/modules/push/service/open.ts b/src/modules/push/service/open.ts
index 9750669..d126d26 100644
--- a/src/modules/push/service/open.ts
+++ b/src/modules/push/service/open.ts
@@ -7,6 +7,7 @@
import { PushAuditlogEntity } from '../entity/auditlog';
import { PushCameraGpsEntity } from '../entity/cameragps';
import { PushVehicleGpsEntity } from '../entity/vehiclegps';
+import { PushDeviceOnoffEntity } from '../entity/deviceonoff';
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
/**
@@ -25,6 +26,10 @@
@InjectEntityModel(PushVehicleGpsEntity)
pushVehicleGpsEntity: Repository<PushVehicleGpsEntity>;
+
+ @InjectEntityModel(PushDeviceOnoffEntity)
+ pushDeviceOnoffEntity: Repository<PushDeviceOnoffEntity>;
+
@InjectEntityModel(PushAuditlogEntity)
pushAuditlogEntity: Repository<PushAuditlogEntity>;
@@ -76,34 +81,105 @@
} else {
siteWeight.businessId = 'UNKNOWN';
siteWeight.departmentId = -1;
- await this.writePushAuditLog("weight",{ "deviceNo": data.deviceNo, "requestContent": data, "errorMessage": "鐢靛瓙绉よ繕鏈垎閰嶅埌鍨冨溇鏀堕泦鐐�." });
+ await this.writePushAuditLog("weight", { "deviceNo": data.deviceNo, "requestContent": data, "errorMessage": "鐢靛瓙绉よ繕鏈垎閰嶅埌鍨冨溇鏀堕泦鐐�." });
}
} catch (err) {
- await this.writePushAuditLog("weight",{ "deviceNo": data.deviceNo || "UNKNOW", "requestContent": data, "errorMessage": err });
+ await this.writePushAuditLog("weight", { "deviceNo": data.deviceNo || "UNKNOW", "requestContent": data, "errorMessage": err });
}
}
/**
- * 鎺ユ敹GPS娑堟伅骞剁紦瀛�
+ * 鎺ユ敹钀ょ煶浜� 娑堟伅骞剁紦瀛�
*/
- async receiveCameraGpsMessage(body: any) {
- const messageId = body.msgSeq || Math.random().toString(36).substring(2);
- await this.midwayCache.set(`push:cameragps:queue:${messageId}`, JSON.stringify(body), 24 * 3600);
- this.processCameraGpsAsync(messageId).catch(err => {
+ async saveYingshiyunMessage(body: any) {
+ const messageId = body?.header?.messageId || Math.random().toString(36).substring(2);
+ await this.midwayCache.set(`push:yingshiyun:queue:${messageId}`, JSON.stringify(body), 24 * 3600);
+ this.processYingshiyunAsync(messageId).catch(err => {
console.error('寮傛澶勭悊GPS娑堟伅澶辫触:', err);
});
- return messageId ;
+ return messageId;
}
/**
- * 寮傛瑙f瀽杞﹁浇鐩戞帶瑙嗛鐨勪綅缃暟鎹苟鍏ュ簱
+ * 寮傛瑙f瀽钀ょ煶浜戞秷鎭紝鎸夌収娑堟伅绫诲瀷 鍏ュ簱
*/
- async processCameraGpsAsync(messageId: string) {
- const dataStr = await this.midwayCache.get(`push:cameragps:queue:${messageId}`) as string | null;
+ async processYingshiyunAsync(messageId: string) {
+ 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;
+
+ try {
+ switch (type) {
+
+ // 璁惧涓婁笅绾�
+ case 'ys.onoffline': {
+ await this.pushDeviceOnoffEntity.save({
+ deviceId:body.header.deviceId,
+ channelNo: body.header.channelNo,
+ messageId: body.header.messageId,
+ messageTime: new Date(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
+ });
+ break;
+ }
+
+ // 钀ょ煶鍛婅
+ /*
+ case 'ys.alarm': {
+ await this.pushAlarmRepo.save({
+ messageId,
+ raw: JSON.stringify(body),
+ createTime: new Date(),
+ });
+ break;
+ }
+ */
+
+ // 娴峰悍 ISAPI
+ //case '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);
+ }
+ } catch (err) {
+ await this.writePushAuditLog(type || 'unknown', {
+ deviceNo: body?.sn || 'UNKNOWN',
+ requestContent: body,
+ errorMessage: err,
+ });
+ }
+
+ // 涓嶇鎴愬姛涓庡惁锛屽垹闄ょ紦瀛樹腑鐨勪换鍔¢槦鍒�
+ await this.midwayCache.del(`push:yingshiyun:queue:${messageId}`);
+
+}
+
+
+
+ /**
+ * 寮傛瑙f瀽杞﹁浇鐩戞帶鐨凣PS鏁版嵁锛屽瓨鍌ㄥ苟娣诲姞涓氬姟琛�
+ */
+ async processCameraGpsAsync(body: any) {
+
try {
let vehicleNo = '';
@@ -155,21 +231,20 @@
});
} else {
- await this.writePushAuditLog("camera_gps",{ "deviceNo": body.sn, "requestContent": body, "errorMessage": "杞﹁浇鐩戞帶杩樻湭鍒嗛厤鍒拌溅杈�" });
+ await this.writePushAuditLog("camera_gps", { "deviceNo": body.sn, "requestContent": body, "errorMessage": "杞﹁浇鐩戞帶杩樻湭鍒嗛厤鍒拌溅杈�" });
}
} else {
- await this.writePushAuditLog("camera_gps",{ "deviceNo": "UNKOWN", "requestContent": body, "errorMessage": "鏈寘鍚澶囧彿SN" });
+ await this.writePushAuditLog("camera_gps", { "deviceNo": "UNKOWN", "requestContent": body, "errorMessage": "鏈寘鍚澶囧彿SN" });
}
- await this.midwayCache.del(`push:gps:queue:${messageId}`);
-
} catch (err: any) {
- await this.writePushAuditLog("camera_gps",{ "deviceNo": body.sn || "UNKNOW", "requestContent": body, "errorMessage": err });
+
+ await this.writePushAuditLog("camera_gps", { "deviceNo": body.sn || "UNKNOW", "requestContent": body, "errorMessage": err });
}
}
- async writePushAuditLog(pushType:string,data: any) {
+ async writePushAuditLog(pushType: string, data: any) {
let isSuccess = true;
let errorMsg = '';
try {
--
Gitblit v1.9.1