From 69b016796bb4803be92d257cff9e6f7969a0c8b3 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Thu, 22 Sep 2022 16:24:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=91=8A=E8=AD=A6=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.vscode/launch.json | 2 +- api/app/lib/controllers/alarm/app.js | 10 +++++++--- api/app/lib/controllers/alarm/data.js | 23 ++++++++++++++++++++--- api/app/lib/models/app_alarm.js | 11 ++++++++++- api/sequelize-automate.config.js | 2 +- script/0.0.4/schema/1.alert_table.sql | 2 ++ 6 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 script/0.0.4/schema/1.alert_table.sql diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index e31a344..8f919f3 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -50,7 +50,7 @@ // "--clickHouseDataAlarm default", // 测试 - "--clickHouseAnxincloud Anxinyun8", + "--clickHouseAnxincloud Anxinyun11", "--clickHousePepEmis pepca8", "--clickHouseProjectManage peppm8", "--clickHouseVcmp video_accrss1", diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index 7600c14..e97305d 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -132,16 +132,20 @@ async function notedInspection (ctx) { async function apiError (ctx) { try { const models = ctx.fs.dc.models; - const { projectAppId, alarmContent, router, statusCode, screenshot = '' } = ctx.request.body + const { projectAppId, alarmContent, router, statusCode, screenshot = '', type } = ctx.request.body const now = moment().format() + if (!type) { + throw '请标明告警类型 type' + } + let storageData = { - projectAppId, alarmContent, router, statusCode + projectAppId, alarmContent, router, statusCode, type } const existRes = await models.AppAlarm.findOne({ where: { projectAppId, alarmContent, router, statusCode, - confirm: null + confirm: null, type } }) if (existRes) { diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index 3618f3a..403ca88 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -6,21 +6,38 @@ async function list (ctx) { const { clickHouse } = ctx.app.fs const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs const { database: anxinyun } = clickHouse.anxinyun.opts.config - const { pepProjectId } = ctx.query + const { pepProjectId, groupId, sustainTimeStart, sustainTimeEnd } = ctx.query const isSuper = judgeSuper(ctx) let anxinStrucIds = null if (!isSuper || pepProjectId) { anxinStrucIds = await anxinStrucIdRange({ ctx, pepProjectId }) } + let whereOption = [] + if (anxinStrucIds) { + whereOption.push(`${anxinyun}.t_structure.id IN (${anxinStrucIds.join(",")})`) + } + if (groupId) { + whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`) + } + if (groupUnitId) { + whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`) + } + if (sustainTimeStart && sustainTimeEnd) { + whereOption.push(``) + } const alarmRes = await clickHouse.dataAlarm.query(` SELECT - AlarmId, SourceName, name AS StructureName, StructureId + AlarmId, SourceName, + ${anxinyun}.t_structure.name AS StructureName, StructureId, + ${anxinyun}.t_alarm_code.name AS AlarmCodeDescribe FROM alarms LEFT JOIN ${anxinyun}.t_structure ON ${anxinyun}.t_structure.id = alarms.StructureId - ${anxinStrucIds ? 'WHERE ' + anxinyun + '.t_structure.id IN (' + anxinStrucIds.join(",") + ')' : ''} + LEFT JOIN ${anxinyun}.t_alarm_code + ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode + ${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''} `).toPromise(); ctx.status = 200; diff --git a/api/app/lib/models/app_alarm.js b/api/app/lib/models/app_alarm.js index 38082f9..a6caed4 100644 --- a/api/app/lib/models/app_alarm.js +++ b/api/app/lib/models/app_alarm.js @@ -34,7 +34,7 @@ module.exports = dc => { autoIncrement: false, references: { key: "id", - model: "projectApp" + model: "app" } }, appDomain: { @@ -126,6 +126,15 @@ module.exports = dc => { primaryKey: false, field: "confirm_auto", autoIncrement: false + }, + type: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "type", + autoIncrement: false } }, { tableName: "app_alarm", diff --git a/api/sequelize-automate.config.js b/api/sequelize-automate.config.js index 41e326f..e34d53b 100644 --- a/api/sequelize-automate.config.js +++ b/api/sequelize-automate.config.js @@ -26,7 +26,7 @@ module.exports = { dir: './app/lib/models', // 指定输出 models 文件的目录 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` - tables: ['project_app'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 + tables: ['app_alarm'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 diff --git a/script/0.0.4/schema/1.alert_table.sql b/script/0.0.4/schema/1.alert_table.sql new file mode 100644 index 0000000..ef66da0 --- /dev/null +++ b/script/0.0.4/schema/1.alert_table.sql @@ -0,0 +1,2 @@ +alter table app_alarm + add type int; \ No newline at end of file