diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 0c90e89..4b7bd60 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -21,6 +21,7 @@ // 测试 // "-g postgres://FashionAdmin:123456@10.8.30.156:5432/POMS", "-k 10.8.30.72:29092,10.8.30.73:29092,10.8.30.74:29092", + "-e http://10.8.30.60:9200", "--iotaProxy http://10.8.30.157:17007", "--redisHost localhost", "--redisPort 6379", @@ -42,7 +43,7 @@ // "--qndmn http://resources.anxinyun.cn", // "--qndmn http://rhvqdivo5.hn-bkt.clouddn.com", // click 开发 - "--clickHouseUrl http://10.8.30.71", + "--clickHouseUrl http://10.8.30.95", "--clickHousePort 30123", // click 测试 // "--clickHouseUrl http://10.8.30.161", @@ -50,11 +51,11 @@ // "--clickHouseUrl http://10.8.30.156", // "--clickHousePort 8123", // "--clickHouseUrl https://clickhouse01.anxinyun.cn/play", - + // // click 测试 // "--clickHouseUrl http://10.8.30.156", // "--clickHousePort 8123", - + // // 似乎不能传空 先注释 * 2 // "--clickHouseUser ", // "--clickHousePassword ", @@ -66,7 +67,7 @@ // "--clickHouseDataAlarm default", // "--clickHouseIot iot", // 测试 - "--clickHouseAnxincloud anxinyun1", + "--clickHouseAnxincloud anxinyun88", "--clickHousePepEmis pepca8", "--clickHouseProjectManage peppm8", "--clickHouseVcmp video_access_dev", diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index 87ac48f..9e1f9a1 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -20,7 +20,7 @@ async function groupList (ctx) { } for (let g of groupRes) { - g.unit = await await clickHouse.anxinyun.query(` + g.unit = await clickHouse.anxinyun.query(` SELECT DISTINCT t_alarm_group_unit.id AS id,t_alarm_group_unit.name AS name,t_alarm_group_unit.group_id AS groupId FROM t_alarm_group_unit diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index eb7b113..a41cf3c 100644 --- a/api/app/lib/controllers/project/group.js +++ b/api/app/lib/controllers/project/group.js @@ -119,7 +119,11 @@ async function groupStatic (ctx) { // 获取全部的 poms 项目id 并构建关系 let pomsProjectIds = new Set() + let groupMap = { + + } for (let group of progectGroupList) { + groupMap[group.id] = groupMap[group.id] || {} for (let projectId of group.pomsProjectIds) { pomsProjectIds.add(projectId) } @@ -138,15 +142,30 @@ async function groupStatic (ctx) { for (let projectId of project.anxinProjectId) { anxinProjectIds.add(projectId) } + groupMap[group.id].anxinProjectCount = anxinProjectCount } let anxinProjectIdArr = Array.from(anxinProjectIds) - // // 统计安心云项目下的结构物个数 - // let strucRes = await clickHouse.anxinyun.query( - // ` - // SELECT - // ` - // ) + // 统计安心云项目下的结构物个数 + const strucCountRes = await clickHouse.anxinyun.query( + ` + SELECT project, COUNT(*) AS count + FROM t_project_structure + WHERE project IN (${[...anxinProjectIdArr].join(',')}, -1) + GROUP BY project + ` + ).toPromise() + + let rslt = [] + for (let pg of progectGroupList) { + let anxinProjectCount = 0 + for (let projectId of pg.pomsProjectIds) { + if (anxinProjectIdArr.includes(projectId)) { + anxinProjectCount++ + } + } + let strucCount = 0 + } ctx.status = 200; ctx.body = [] diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 432663a..d668b4e 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -8,6 +8,7 @@ const redisConnect = require('./service/redis') const socketConect = require('./service/socket') const mqttVideoServer = require('./service/mqttServer') const paasRequest = require('./service/paasRequest'); +const es = require('./service/es'); const authenticator = require('./middlewares/authenticator'); const clickHouseClient = require('./service/clickHouseClient') const kafka = require('./service/kafka') @@ -30,6 +31,8 @@ module.exports.entry = function (app, router, opts) { // 实例其他平台请求方法 paasRequest(app, opts) + es(app, opts) + // kafka(app, opts) // clickHouse 数据库 client diff --git a/api/app/lib/service/es.js b/api/app/lib/service/es.js new file mode 100644 index 0000000..432d115 --- /dev/null +++ b/api/app/lib/service/es.js @@ -0,0 +1,55 @@ +'use strict'; +const fs = require('fs'); +const path = require('path'); +const es = require('elasticsearch'); + +let initClient = (config, opts) => { + + let logOptions; + if (opts.dev) { + let filename = path.join(process.cwd(), 'log', 'elasticsearch-development.log'); + let dir = path.dirname(filename); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + logOptions = { + type: 'file', + level: 'info', + path: filename + }; + } else { + logOptions = { + type: 'stdio', + level: 'error' + }; + } + let client = new es.Client({ + host: config.rootURL, + log: logOptions, + apiVersion: '5.5' + }); + return client; +}; + +function factory (app, opts) { + if (opts.es) { + try { + app.fs.esclient = {} + let esclient = Object.keys(opts.es).reduce((p, esmodule) => { + console.log(`加载 ES ${esmodule}`); + let moduleCfg = opts.es[esmodule]; + let client = initClient(moduleCfg, opts); + p[esmodule] = client; + p[esmodule].config = moduleCfg; + return p; + }, {}); + + app.fs.esclient = esclient; + } catch (error) { + console.error(error) + process.exit(-1); + } + } +} + +module.exports = factory; \ No newline at end of file diff --git a/api/config.js b/api/config.js index 0c28363..b8da0ee 100644 --- a/api/config.js +++ b/api/config.js @@ -12,6 +12,7 @@ args.option(['p', 'port'], '启动端口'); args.option(['g', 'pg'], 'postgre 服务 URL'); args.option(['f', 'fileHost'], '文件中心本地化存储: WebApi 服务器地址(必填), 该服务器提供文件上传Web服务'); args.option(['k', 'kafka'], 'kafka 服务 URL'); +args.option(['e', 'es'], 'es 服务 URL'); args.option('iotaProxy', '以太代理') @@ -122,6 +123,10 @@ const VCMP_APP_SECRET = process.env.VCMP_APP_SECRET || flags.vcmpAppSecret const CAIYUN_API = process.env.CAIYUN_API || flags.caiyunApi || 'https://api.caiyunapp.com/v2'; const CAIYUN_KEY = process.env.CAIYUN_KEY || flags.caiyunKey || '1l0eNveMANMXEIJI'; +// ES +const ES_PLATFORM_NAME = process.env.ES_PLATFORM_NAME || flags.esPlatformName || 'anxinyun'; +const ANXINCLOUD_ES_NODES_REST = process.env.ANXINCLOUD_ES_NODES_REST || flags.es; + if ( !POMS_DB || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT @@ -270,6 +275,14 @@ const product = { db: CLICKHOUST_CAM_WORKFLOW }, ] + }, + es: { + alarm: { + //告警记录 + rootURL: ANXINCLOUD_ES_NODES_REST.split(','), + index: `${ES_PLATFORM_NAME}_alarms`, + type: flags.esType ? flags.esType : '_doc' + }, } } } diff --git a/api/package.json b/api/package.json index f630fc4..7722899 100644 --- a/api/package.json +++ b/api/package.json @@ -1,44 +1,45 @@ { - "name": "smart-emergency", - "version": "1.0.0", - "description": "fs smart emergency api", - "main": "server.js", - "scripts": { - "test": "set DEBUG=true&&\"node_modules/.bin/mocha\" --harmony --reporter spec app/test/*.test.js", - "start": "set NODE_ENV=development&&node server -p 4000 -g postgres://postgres:123@10.8.30.32:5432/video_access -f http://localhost:4000", - "start:linux": "export NODE_ENV=development&&node server -p 4000 -g postgres://FashionAdmin:123456@10.8.30.39:5432/pm1", - "automate": "sequelize-automate -c sequelize-automate.config.js" - }, - "author": "", - "license": "MIT", - "repository": {}, - "dependencies": { - "@alicloud/pop-core": "^1.7.12", - "@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", - "ioredis": "^5.0.4", - "kafka-node": "^5.0.0", - "koa-convert": "^1.2.0", - "koa-proxy": "^0.9.0", - "moment": "^2.24.0", - "mqtt": "^4.3.7", - "node-schedule": "^2.1.0", - "nodemailer": "^6.7.7", - "path": "^0.12.7", - "path-to-regexp": "^3.0.0", - "pg": "^7.9.0", - "redis": "^3.1.2", - "request": "^2.88.2", - "sequelize-automate-freesun": "^1.2.2", - "superagent": "^3.5.2", - "uuid": "^3.3.2" - }, - "devDependencies": { - "mocha": "^6.0.2" - } + "name": "smart-emergency", + "version": "1.0.0", + "description": "fs smart emergency api", + "main": "server.js", + "scripts": { + "test": "set DEBUG=true&&\"node_modules/.bin/mocha\" --harmony --reporter spec app/test/*.test.js", + "start": "set NODE_ENV=development&&node server -p 4000 -g postgres://postgres:123@10.8.30.32:5432/video_access -f http://localhost:4000", + "start:linux": "export NODE_ENV=development&&node server -p 4000 -g postgres://FashionAdmin:123456@10.8.30.39:5432/pm1", + "automate": "sequelize-automate -c sequelize-automate.config.js" + }, + "author": "", + "license": "MIT", + "repository": {}, + "dependencies": { + "@alicloud/pop-core": "^1.7.12", + "@fs/attachment": "^1.0.0", + "args": "^3.0.7", + "better-xlsx": "^0.7.6", + "clickhouse": "^2.6.0", + "crypto-js": "^4.0.0", + "elasticsearch": "^13.3.1", + "file-saver": "^2.0.2", + "fs-web-server-scaffold": "^2.0.2", + "ioredis": "^5.0.4", + "kafka-node": "^5.0.0", + "koa-convert": "^1.2.0", + "koa-proxy": "^0.9.0", + "moment": "^2.24.0", + "mqtt": "^4.3.7", + "node-schedule": "^2.1.0", + "nodemailer": "^6.7.7", + "path": "^0.12.7", + "path-to-regexp": "^3.0.0", + "pg": "^7.9.0", + "redis": "^3.1.2", + "request": "^2.88.2", + "sequelize-automate-freesun": "^1.2.2", + "superagent": "^3.5.2", + "uuid": "^3.3.2" + }, + "devDependencies": { + "mocha": "^6.0.2" + } }