From a38d71ec5a29a48fa7fd6f6132d78eb924bf7bd1 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Thu, 8 Sep 2022 19:53:13 +0800 Subject: [PATCH] A CAT --- api/app/lib/controllers/alarm/app.js | 73 +++++++++++++++++++++++++++- api/app/lib/models/app_alarm.js | 24 +++++++-- api/app/lib/routes/alarm/index.js | 9 +++- api/sequelize-automate.config.js | 2 +- web/client/src/app.jsx | 13 +++++ 5 files changed, 114 insertions(+), 7 deletions(-) diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index d6c7e38..0a13f29 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -28,7 +28,7 @@ async function inspection (ctx) { } } -async function noted (ctx) { +async function notedInspection (ctx) { try { const models = ctx.fs.dc.models; const { inspectionId } = ctx.request.body @@ -53,7 +53,76 @@ async function noted (ctx) { } } +async function apiError (ctx) { + try { + const models = ctx.fs.dc.models; + const { projectAppId, alarmContent, router, statusCode } = ctx.request.body + const now = moment().format() + + let storageData = { + projectAppId, alarmContent, router, statusCode + } + const existRes = await models.AppAlarm.findOne({ + where: { + projectAppId, alarmContent, router, statusCode, + confirm: null + } + }) + if (existRes) { + await models.AppAlarm.update({ + updateTime: now + }, { + where: { + id: existRes.id + } + }) + } else { + const existCount = await models.AppAlarm.count({ + where: { + + } + }) + storageData.serialNumber = 'WEB' + (existCount < 9 ? '0' + (existCount + 1) : existCount) + storageData.createTime = now + await models.AppAlarm.create(storageData) + } + + ctx.status = 200; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + +async function confirmApiError (ctx) { + try { + const models = ctx.fs.dc.models; + const { confirm, appAlarmId } = ctx.request.body + + await models.AppAlarm.update({ + confirm, + }, { + where: { + id: appAlarmId + } + }) + + ctx.status = 204; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + module.exports = { inspection, - noted, + notedInspection, + apiError, + confirmApiError, }; \ No newline at end of file diff --git a/api/app/lib/models/app_alarm.js b/api/app/lib/models/app_alarm.js index f179e2b..6d6bdbb 100644 --- a/api/app/lib/models/app_alarm.js +++ b/api/app/lib/models/app_alarm.js @@ -24,18 +24,18 @@ module.exports = dc => { field: "serial_number", autoIncrement: false }, - pepProjectId: { + projectAppId: { type: DataTypes.INTEGER, allowNull: true, defaultValue: null, comment: "对应的项目id", primaryKey: false, - field: "pep_project_id", + field: "project_app_id", autoIncrement: false }, appDomain: { type: DataTypes.STRING, - allowNull: false, + allowNull: true, defaultValue: null, comment: "应用域名", primaryKey: false, @@ -77,6 +77,24 @@ module.exports = dc => { primaryKey: false, field: "confirm", autoIncrement: false + }, + router: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "路由", + primaryKey: false, + field: "router", + autoIncrement: false + }, + statusCode: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "状态码", + primaryKey: false, + field: "status_code", + autoIncrement: false } }, { tableName: "app_alarm", diff --git a/api/app/lib/routes/alarm/index.js b/api/app/lib/routes/alarm/index.js index ad9e34f..50dc0cb 100644 --- a/api/app/lib/routes/alarm/index.js +++ b/api/app/lib/routes/alarm/index.js @@ -5,9 +5,16 @@ const application = require('../../controllers/alarm/app'); module.exports = function (app, router, opts) { + // 应用告警 app.fs.api.logAttr['POST/alarm/application/inspection'] = { content: '保存应用巡检信息', visible: true }; router.post('/alarm/application/inspection', application.inspection); app.fs.api.logAttr['PUT/alarm/application/noted'] = { content: '保存检验状态', visible: true }; - router.put('/alarm/application/noted', application.noted); + router.put('/alarm/application/noted', application.notedInspection); + + app.fs.api.logAttr['POST/alarm/application/api'] = { content: '保存应用接口错误信息', visible: true }; + router.post('/alarm/application/api', application.apiError); + + app.fs.api.logAttr['POST/alarm/application/api_confirm'] = { content: '确认应用接口错误信息', visible: true }; + router.post('/alarm/application/api_confirm', application.confirmApiError); }; diff --git a/api/sequelize-automate.config.js b/api/sequelize-automate.config.js index ae7d5c4..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: ['app_inspection'], // 指定生成哪些表的 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/web/client/src/app.jsx b/web/client/src/app.jsx index 064eeb2..d14239c 100644 --- a/web/client/src/app.jsx +++ b/web/client/src/app.jsx @@ -14,6 +14,19 @@ const App = props => { useEffect(() => { document.title = projectName; + + console.log(` + _ _ +        />  フ +       |  _  _ l +       /\` ミ_xノ +      /      | +     /  ヽ   ノ +     │  | | | +  / ̄|   | | | +  | ( ̄ヽ__ヽ_)__) +  \二つ ​ + `); }, []) return (