From ad1ea820efbc3ffc157006ae6cd35ca3d9d4fa9c Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期六, 18 七月 2026 22:30:10 +0800
Subject: [PATCH] 增加设备告警消息

---
 src/modules/push/service/devicealarm.ts          |   15 +++++
 pnpm-workspace.yaml                              |    4 +
 src/modules/push/service/open.ts                 |   26 ++++++--
 package.json                                     |    3 
 src/modules/push/entity/devicealarm.ts           |   57 +++++++++++++++++++
 src/modules/push/controller/admin/devicealarm.ts |   44 ++++++++++++++
 6 files changed, 142 insertions(+), 7 deletions(-)

diff --git a/package.json b/package.json
index 2ce7de5..3a7cf85 100644
--- a/package.json
+++ b/package.json
@@ -86,5 +86,6 @@
     "url": "https://cool-js.com"
   },
   "author": "COOL",
-  "license": "MIT"
+  "license": "MIT",
+  "packageManager": "pnpm@11.12.0+sha512.820a6fbd0d9f04c226638002aead1e45340a9139dd5dc077c1d83ef44aa2481c8eb6637b4c9aa696a3c7e35ba818e49cf27213e5f2b91138d09b7a3e26e898ba"
 }
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
new file mode 100644
index 0000000..525e4c9
--- /dev/null
+++ b/pnpm-workspace.yaml
@@ -0,0 +1,4 @@
+allowBuilds:
+  esbuild: true
+  javascript-obfuscator: true
+  msgpackr-extract: true
diff --git a/src/modules/push/controller/admin/devicealarm.ts b/src/modules/push/controller/admin/devicealarm.ts
new file mode 100644
index 0000000..27a6d0f
--- /dev/null
+++ b/src/modules/push/controller/admin/devicealarm.ts
@@ -0,0 +1,44 @@
+import { CoolController, BaseController } from '@cool-midway/core';
+import { PushDevicealarmEntity } from '../../entity/devicealarm';
+import { PushDevicealarmService } from '../../service/devicealarm';
+import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department';
+
+/**
+ * 璁惧鍛婅娑堟伅
+ */
+@CoolController({
+  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
+  entity: PushDevicealarmEntity,
+  service: PushDevicealarmService,
+  pageQueryOp: {
+    keyWordLikeFields: ['b.iotName', 'a.devSerial', 'c.name'],
+    select: [
+      'a.*',
+      'c.name as departmentName',
+      'b.iotName as deviceName'
+    ],
+    join: [
+      {
+        entity: 't_basicdata_iot' as any,
+        alias: 'b',
+        condition: 'a.devSerial = b.iotCode',
+        type: 'leftJoin'
+      },
+      {
+        entity: BaseSysDepartmentEntity,
+        alias: 'c',
+        condition: 'b.departmentId = c.id',
+        type: 'leftJoin'
+      }
+    ],
+    fieldEq: [
+      { column: 'a.devSerial', requestParam: 'devSerial' },
+      { column: 'a.alarmType', requestParam: 'alarmType' },
+      { column: 'c.name', requestParam: 'departmentName' }
+    ],
+    fieldLike: [
+      { column: 'c.name', requestParam: 'departmentName' }
+    ]
+  }
+})
+export class AdminPushDevicealarmController extends BaseController {}
\ No newline at end of file
diff --git a/src/modules/push/entity/devicealarm.ts b/src/modules/push/entity/devicealarm.ts
new file mode 100644
index 0000000..0d0f84c
--- /dev/null
+++ b/src/modules/push/entity/devicealarm.ts
@@ -0,0 +1,57 @@
+import { BaseEntity } from '../../base/entity/base';
+import { Column, Entity, Index } from 'typeorm';
+
+/**
+ * 璁惧鍛婅娑堟伅
+ */
+@Entity('t_push_device_alarm')
+export class PushDevicealarmEntity extends BaseEntity {
+  @Index()
+  @Column({ comment: '璁惧搴忓垪鍙�' })
+  devSerial: string;
+
+  @Column({ comment: '閫氶亾鍙�' })
+  channelNo: string;
+
+  @Column({ comment: '鎶ヨ娑堟伅ID' })
+  alarmId: string;
+
+  @Column({ comment: '鎶ヨ鏃堕棿鎴�' })
+  alarmTime: string;
+
+  @Column({ comment: '鎶ヨ绫诲瀷' })
+  alarmType: string;
+
+  @Column({ comment: '閫氶亾鍚嶇О' })
+  channelName: string;
+
+  @Column({ comment: '閫氶亾绫诲瀷', dict: ['瑙嗛閫氶亾', 'IO閫氶亾'], default: 0 })
+  channelType: number;
+
+  @Column({ comment: '鍔犲瘑瀵嗙爜', nullable: true })
+  checksum: string;
+
+  @Column({ comment: '鍥剧墖鍔犲瘑绫诲瀷', dict: ['涓嶅姞瀵�', '鐢ㄦ埛鍔犲瘑', '骞冲彴鍔犲瘑'], default: 0 })
+  crypt: number;
+
+  @Column({ comment: '鑷畾涔変俊鎭�', nullable: true })
+  customInfo: string;
+
+  @Column({ comment: '鑷畾涔夊崗璁被鍨�', nullable: true })
+  customType: string;
+
+  @Column({ comment: '鍛婅鎻忚堪', nullable: true })
+  describe: string;
+
+  @Column({ comment: '浣嶇疆淇℃伅', nullable: true })
+  location: string;
+
+  @Column({ comment: '鍏宠仈ID', nullable: true })
+  relationId: string;
+
+  @Column({ comment: '鎶ヨ鐘舵��', dict: ['寮�濮�', '鍋滄'], default: 0 })
+  status: number;
+
+  @Column({ comment: '鍛婅鍥剧墖鍒楄〃', type: 'json', nullable: true })
+  pictureList: Array<{ url: string; id: string }>;
+}
\ No newline at end of file
diff --git a/src/modules/push/service/devicealarm.ts b/src/modules/push/service/devicealarm.ts
new file mode 100644
index 0000000..a5511a0
--- /dev/null
+++ b/src/modules/push/service/devicealarm.ts
@@ -0,0 +1,15 @@
+import { Provide } from '@midwayjs/core';
+import { BaseService } from '@cool-midway/core';
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import { PushDevicealarmEntity } from '../entity/devicealarm';
+
+/**
+ * 璁惧鍛婅娑堟伅鏈嶅姟
+ */
+@Provide()
+export class PushDevicealarmService extends BaseService {
+  @InjectEntityModel(PushDevicealarmEntity)
+  pushDevicealarmEntity: Repository<PushDevicealarmEntity>;
+
+}
\ No newline at end of file
diff --git a/src/modules/push/service/open.ts b/src/modules/push/service/open.ts
index d126d26..ee49cbb 100644
--- a/src/modules/push/service/open.ts
+++ b/src/modules/push/service/open.ts
@@ -8,6 +8,7 @@
 import { PushCameraGpsEntity } from '../entity/cameragps';
 import { PushVehicleGpsEntity } from '../entity/vehiclegps';
 import { PushDeviceOnoffEntity } from '../entity/deviceonoff';
+import { PushDevicealarmEntity } from '../entity/devicealarm';
 import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
 
 /**
@@ -30,6 +31,8 @@
   @InjectEntityModel(PushDeviceOnoffEntity)
   pushDeviceOnoffEntity: Repository<PushDeviceOnoffEntity>;
 
+  @InjectEntityModel(PushDevicealarmEntity)
+  pushDevicealarmEntity: Repository<PushDevicealarmEntity>;
 
   @InjectEntityModel(PushAuditlogEntity)
   pushAuditlogEntity: Repository<PushAuditlogEntity>;
@@ -135,16 +138,27 @@
         }
 
         // 钀ょ煶鍛婅
-        /*
         case 'ys.alarm': {
-          await this.pushAlarmRepo.save({
-            messageId,
-            raw: JSON.stringify(body),
-            createTime: new Date(),
+          await this.pushDevicealarmEntity.save({
+            devSerial: body.devSerial,
+            channelNo: body.channelNo || String(body.channel),
+            alarmId: body.alarmId,
+            alarmTime: body.alarmTime,
+            alarmType: body.alarmType,
+            channelName: body.channelName,
+            channelType: body.channelType ? Number(body.channelType) : 1,
+            checksum: body.checksum,
+            crypt: body.crypt ? Number(body.crypt) : 0,
+            customInfo: body.customInfo,
+            customType: body.customType,
+            describe: body.describe,
+            location: body.location,
+            relationId: body.relationId,
+            status: body.status ? Number(body.status) : 1,
+            pictureList: body.pictureList || []
           });
           break;
         }
-          */
 
         // 娴峰悍 ISAPI
         //case 'ys.open.isapi': {

--
Gitblit v1.9.1