From 6698bf90878025568bf418b8b84c4b47dc934140 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 21 Sep 2022 10:54:24 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=98=A0=E5=B0=84=E5=85=B3=E7=B3=BB?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=A1=B9=E7=9B=AE=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E9=80=89=E6=8B=A9PEP=E9=A1=B9=E7=9B=AE=E6=97=B6?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=B7=B2=E7=BB=91=E5=AE=9A=E8=BF=87=E7=9A=84?= =?UTF-8?q?PEP=E9=A1=B9=E7=9B=AE=E5=8F=AF=E4=BB=A5=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.vscode/launch.json | 9 ++++++ api/app/lib/controllers/alarm/data.js | 8 +++++- api/app/lib/controllers/project/bind.js | 24 ++++++++++++++++ api/app/lib/middlewares/authenticator.js | 3 +- api/app/lib/routes/alarm/index.js | 5 +++- api/app/lib/service/clickHouseClient.js | 1 + api/config.js | 35 ++++++++++++++---------- 7 files changed, 68 insertions(+), 17 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 524c11d..02b37cf 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -39,10 +39,19 @@ // "--clickHouseUser ", // "--clickHousePassword ", + // 研发 + // "--clickHouseAnxincloud anxinyun", + // "--clickHousePepEmis pepca", + // "--clickHouseProjectManage peppm", + // "--clickHouseVcmp video_accrss1", + // "--clickHouseDataAlarm default", + + // 测试 "--clickHouseAnxincloud Anxinyun8", "--clickHousePepEmis pepca8", "--clickHouseProjectManage peppm8", "--clickHouseVcmp video_accrss1", + "--clickHouseDataAlarm default123", ] }, { diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index b674d1c..e2e672f 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -3,8 +3,14 @@ async function list (ctx) { try { const models = ctx.fs.dc.models; + const { clickHouse } = ctx.app.fs - ctx.status = 20; + const alarmRes = await clickHouse.dataAlarm.query(` + SELECT * FROM alarms + `) + + ctx.status = 200; + ctx.body = [] } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.status = 400; diff --git a/api/app/lib/controllers/project/bind.js b/api/app/lib/controllers/project/bind.js index f78b7f3..69c954e 100644 --- a/api/app/lib/controllers/project/bind.js +++ b/api/app/lib/controllers/project/bind.js @@ -55,6 +55,30 @@ async function bindAnxin2pep (ctx) { })) { throw `已有相同名称【${name}】的自定义项目` } + } else { + const pomsRepeatProjectIdRes = await models.ProjectCorrelation.findAll({ + where: { + pepProjectId: pepProjectId + } + }) + if (pomsRepeatProjectIdRes.some((pr) => { + return ( + ( + // 有修改id但是不等于当前修改id的 + bindId && pr.id != bindId && !pr.del + ) || ( + !bindId && ( + ( + existRes && pr.id != existRes.id && !pr.del + ) || ( + !existRes && !pr.del + ) + ) + ) + ) + })) { + throw `当前项企项目已绑定` + } } let storageData = { diff --git a/api/app/lib/middlewares/authenticator.js b/api/app/lib/middlewares/authenticator.js index 617f596..fcac4c1 100644 --- a/api/app/lib/middlewares/authenticator.js +++ b/api/app/lib/middlewares/authenticator.js @@ -86,8 +86,9 @@ let authorizeToken = async function (ctx, token) { 'resources': (userInfo || {}).resources || [], }; ctx.fs.api.userId = pomsUser.id; + ctx.fs.api.userInfo = pomsUser; ctx.fs.api.pepUserId = userInfo.id; - ctx.fs.api.userInfo = userInfo; + ctx.fs.api.pepUserInfo = userInfo; ctx.fs.api.token = token; } } catch (err) { diff --git a/api/app/lib/routes/alarm/index.js b/api/app/lib/routes/alarm/index.js index d24b46e..9fe8165 100644 --- a/api/app/lib/routes/alarm/index.js +++ b/api/app/lib/routes/alarm/index.js @@ -3,6 +3,7 @@ 'use strict'; const application = require('../../controllers/alarm/app'); +const dataAlarm = require('../../controllers/alarm/data'); module.exports = function (app, router, opts) { // 应用告警 @@ -24,5 +25,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['POST/alarm/application/api_confirm'] = { content: '确认应用接口/元素错误信息', visible: true }; router.post('/alarm/application/api_confirm', application.confirmApiError); - // + // 数据告警 + app.fs.api.logAttr['GET/alarm/data/list'] = { content: '查询数据告警列表', visible: true }; + router.get('/alarm/data/list', dataAlarm.list); }; diff --git a/api/app/lib/service/clickHouseClient.js b/api/app/lib/service/clickHouseClient.js index c0a0418..f688681 100644 --- a/api/app/lib/service/clickHouseClient.js +++ b/api/app/lib/service/clickHouseClient.js @@ -21,6 +21,7 @@ function factory (app, opts) { database: d.db, }, }) + console.info(`ClickHouse ${d.name} 初始化完成`); } else { throw 'opts.clickHouse 参数错误!' } diff --git a/api/config.js b/api/config.js index e0ffff4..11e9062 100644 --- a/api/config.js +++ b/api/config.js @@ -37,6 +37,7 @@ args.option('clickHouseAnxincloud', 'clickHouse 安心云数据库名称'); args.option('clickHousePepEmis', 'clickHouse 项企数据库名称'); args.option('clickHouseProjectManage', 'clickHouse 项目管理数据库名称'); args.option('clickHouseVcmp', 'clickHouse 视频平台数据库名称'); +args.option('clickHouseDataAlarm', 'clickHouse 视频平台数据告警库名称'); const flags = args.parse(process.argv); @@ -75,6 +76,7 @@ const CLICKHOUST_ANXINCLOUD = process.env.CLICKHOUST_ANXINCLOUD || flags.clickHo const CLICKHOUST_PEP_EMIS = process.env.CLICKHOUST_PEP_EMIS || flags.clickHousePepEmis const CLICKHOUST_PROJECT_MANAGE = process.env.CLICKHOUST_PROJECT_MANAGE || flags.clickHouseProjectManage const CLICKHOUST_VCMP = process.env.CLICKHOUST_VCMP || flags.clickHouseVcmp +const CLICKHOUST_DATA_ALARM = process.env.CLICKHOUST_DATA_ALARM || flags.clickHouseDataAlarm if ( !POMS_DB @@ -84,7 +86,7 @@ if ( || !API_EMIS_URL || !QINIU_DOMAIN_QNDMN_RESOURCE || !QINIU_BUCKET_RESOURCE || !QINIU_AK || !QINIU_SK || !CLICKHOUST_URL || !CLICKHOUST_PORT - || !CLICKHOUST_ANXINCLOUD || !CLICKHOUST_PEP_EMIS || !CLICKHOUST_PROJECT_MANAGE || !CLICKHOUST_VCMP + || !CLICKHOUST_ANXINCLOUD || !CLICKHOUST_PEP_EMIS || !CLICKHOUST_PROJECT_MANAGE || !CLICKHOUST_VCMP || !CLICKHOUST_DATA_ALARM ) { console.log('缺少启动参数,异常退出'); args.showHelp(); @@ -159,19 +161,24 @@ const product = { port: CLICKHOUST_PORT, user: CLICKHOUST_USER, password: CLICKHOUST_PASSWORD, - db: [{ - name: 'anxinyun', - db: CLICKHOUST_ANXINCLOUD - }, { - name: 'pepEmis', - db: CLICKHOUST_PEP_EMIS - }, { - name: 'projectManage', - db: CLICKHOUST_PROJECT_MANAGE - }, { - name: 'vcmp', - db: CLICKHOUST_VCMP - },] + db: [ + { + name: 'anxinyun', + db: CLICKHOUST_ANXINCLOUD + }, { + name: 'pepEmis', + db: CLICKHOUST_PEP_EMIS + }, { + name: 'projectManage', + db: CLICKHOUST_PROJECT_MANAGE + }, { + name: 'vcmp', + db: CLICKHOUST_VCMP + }, { + name: 'dataAlarm', + db: CLICKHOUST_DATA_ALARM + } + ] } } }