From 11e81efacadd1d0084be072d603208074d3895da Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 13 Sep 2022 21:02:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E9=B8=BD=E6=8E=A8=E9=80=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/alarm/app.js | 1 + api/app/lib/controllers/push/config.js | 98 +++++++++++++++++++++++++- api/app/lib/routes/push/index.js | 14 ++++ api/package.json | 1 + 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 api/app/lib/routes/push/index.js diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index 62ec012..e970300 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -3,6 +3,7 @@ const moment = require('moment') async function inspection (ctx) { + // 巡查 try { const models = ctx.fs.dc.models; const { projectAppId, screenshot = [], } = ctx.request.body diff --git a/api/app/lib/controllers/push/config.js b/api/app/lib/controllers/push/config.js index e38565f..2af88bb 100644 --- a/api/app/lib/controllers/push/config.js +++ b/api/app/lib/controllers/push/config.js @@ -1,10 +1,102 @@ 'use strict'; +const moment = require('moment') + +async function list (ctx) { + try { + const models = ctx.fs.dc.models; + const { keyword, alarmType, state, } = ctx.request.body + + let findOption = { + where: { + + } + } + + if (keyword) { + findOption.where.$or = [ + { + name: { $like: `%${keyword}%` } + }, + ] + } + if (alarmType) { + findOption.where.alarmType = { $contains: [alarmType] } + } + if (state) { + if (state == 'enable') { + findOption.where.disable = false + } else if (state == 'disable') { + findOption.where.disable = true + } else if (state == 'overtime') { + + } + } + + const listRes = await models.AlarmPushConfig.findAndCountAll(findOption) + + ctx.status = 200; + ctx.body = listRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} async function edit (ctx) { try { const models = ctx.fs.dc.models; + const { userId } = ctx.fs.api + const { pushId, name, pepProjectId = [], alarmType = [], receiverPepUserId = [], timeType = [], disable } = ctx.request.body + + let storageData = { + name, pepProjectId, alarmType, receiverPepUserId, timeType, disable + } + if (pushId) { + await models.AlarmPushConfig.update(storageData, { + where: { + id: pushId + } + }) + } else { + storageData.createTime = moment().format() + storageData.createUserId = userId + await models.AlarmPushConfig.create(storageData) + } + + 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 + } + } +} + +async function state (ctx) { + try { + const models = ctx.fs.dc.models; + const { pushId } = ctx.params + const { disable = undefined, del = undefined, } = ctx.request.body - + if (del) { + await models.AlarmPushConfig.destroy({ + where: { + id: pushId + } + }) + } else { + await models.AlarmPushConfig.update({ + disable, + }, { + where: { + id: pushId + } + }) + } ctx.status = 204; } catch (error) { @@ -16,6 +108,8 @@ async function edit (ctx) { } } + + module.exports = { - edit + list, edit, state }; \ No newline at end of file diff --git a/api/app/lib/routes/push/index.js b/api/app/lib/routes/push/index.js new file mode 100644 index 0000000..560784d --- /dev/null +++ b/api/app/lib/routes/push/index.js @@ -0,0 +1,14 @@ +'use strict'; + +const push = require('../../controllers/push/config'); + +module.exports = function (app, router, opts) { + app.fs.api.logAttr['GET/push'] = { content: '获取推送配置列表', visible: true }; + router.get('/push', push.list); + + app.fs.api.logAttr['POST/push'] = { content: '新增/编辑推送配置', visible: true }; + router.get('/push', push.edit); + + app.fs.api.logAttr['PUT/push/:pushId'] = { content: '更改推送配置状态(禁用或删除)', visible: true }; + router.put('/push/:pushId', push.state); +}; \ No newline at end of file diff --git a/api/package.json b/api/package.json index 7eafc29..d2ec263 100644 --- a/api/package.json +++ b/api/package.json @@ -17,6 +17,7 @@ "@fs/attachment": "^1.0.0", "args": "^3.0.7", "better-xlsx": "^0.7.6", + "clickhouse": "^2.6.0", "crypto-js": "^4.0.0", "file-saver": "^2.0.2", "fs-web-server-scaffold": "^2.0.2",