diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 2995642..8b41ecf 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -13,25 +13,15 @@ "NODE_ENV": "development" }, "args": [ - "-p 4600", - "-f http://localhost:4600", + "-p 4700", + "-f http://localhost:4700", // 研发 - // "-g postgres://postgres:123@10.8.30.32:5432/orational_service", - // 测试 - "-g postgres://FashionAdmin:123456@10.8.30.156:5432/POMS", - "-k node35:6667,node36:6667,node37:6667", - "--iotaProxy http://10.8.30.157:17007", + "-g postgres://postgres:123@10.8.30.32:5432/orational_service", "--redisHost 10.8.30.112", "--redisPort 6379", - "--axyApiUrl http://127.0.0.1:4100", // "--apiEmisUrl http://10.8.30.112:14000", // 测试 "--apiEmisUrl http://10.8.30.161:1111", - "--apiVcmpUrl http://localhost:4000", - "--apiIotAuth http://localhost:4200", - "--godUrl https://restapi.amap.com/v3", - "--godKey 21c2d970e1646bb9a795900dd00093ce", - "--mqttVideoServer mqtt://10.8.30.71:30883", "--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5", "--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa", "--qnbkt dev-operational-service", @@ -49,22 +39,11 @@ // "--clickHousePassword ", // 研发 - // "--clickHouseAnxincloud anxinyun", // "--clickHousePepEmis pepca", - // "--clickHouseProjectManage peppm", - // "--clickHouseVcmp video_accrss1", - // "--clickHouseDataAlarm default", // 测试 - "--clickHouseAnxincloud Anxinyun13", "--clickHousePepEmis pepca8", - "--clickHouseProjectManage peppm8", - "--clickHouseVcmp video_access_dev", - "--clickHouseDataAlarm default", - "--confirmAlarmAnxinUserId 1", - "--vcmpAppId 5048b08d-c449-4d7f-b1ec-f741012aefe8", - "--vcmpAppSecret 5ba8c0ab-9fbd-4f07-9817-c48017c3cbad", ] }, { diff --git a/api/app/lib/index.js b/api/app/lib/index.js index dd3661c..87abdb9 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -6,11 +6,9 @@ const utils = require('./utils') const routes = require('./routes'); const redisConnect = require('./service/redis') const socketConect = require('./service/socket') -const mqttVideoServer = require('./service/mqttServer') const paasRequest = require('./service/paasRequest'); const authenticator = require('./middlewares/authenticator'); const clickHouseClient = require('./service/clickHouseClient') -const kafka = require('./service/kafka') const schedule = require('./schedule') // const apiLog = require('./middlewares/api-log'); @@ -25,13 +23,10 @@ module.exports.entry = function (app, router, opts) { // 顺序固定 ↓ redisConnect(app, opts) socketConect(app, opts) - mqttVideoServer(app, opts) // 实例其他平台请求方法 paasRequest(app, opts) - kafka(app, opts) - // clickHouse 数据库 client clickHouseClient(app, opts) @@ -57,23 +52,8 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq require(`./models/${filename}`)(dc) }); -// const { -// AppInspection, ProjectApp, ProjectCorrelation, AppAlarm, App -// } = dc.models; - -// AppInspection.belongsTo(App, { foreignKey: 'projectAppId', targetKey: 'id' }); -// App.hasMany(AppInspection, { foreignKey: 'projectAppId', sourceKey: 'id' }); - -// ProjectApp.belongsTo(ProjectCorrelation, { foreignKey: 'projectId', targetKey: 'id' }); -// ProjectCorrelation.hasMany(ProjectApp, { foreignKey: 'projectId', sourceKey: 'id' }); - -// ProjectApp.belongsTo(App, { foreignKey: 'appId', targetKey: 'id' }); -// App.hasMany(ProjectApp, { foreignKey: 'appId', sourceKey: 'id' }); - -// ProjectCorrelation.belongsToMany(App, { through: ProjectApp, foreignKey: 'projectId', otherKey: 'appId' }); - -// App.belongsToMany(ProjectCorrelation, { through: ProjectApp, foreignKey: 'appId', otherKey: 'projectId' }); + const { + + } = dc.models; -// AppAlarm.belongsTo(App, { foreignKey: 'projectAppId', targetKey: 'id' }); -// App.hasMany(AppAlarm, { foreignKey: 'projectAppId', sourceKey: 'id' }); }; diff --git a/api/app/lib/middlewares/duration-calc.js b/api/app/lib/middlewares/duration-calc.js deleted file mode 100644 index bd338c0..0000000 --- a/api/app/lib/middlewares/duration-calc.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; -const moment = require('moment'); - -async function factory (ctx, next) { - try { - const start = moment() - await next() - ctx.fs.logger.log(`DurationCalc: ${ctx.path} 用时 ${moment().diff(start, 'milliseconds')}`); - } catch (error) { - ctx.fs.logger.error(`DurationCalc, error: ${error}`); - } -} - -module.exports = factory; \ No newline at end of file diff --git a/api/app/lib/service/kafka.js b/api/app/lib/service/kafka.js deleted file mode 100644 index f164eee..0000000 --- a/api/app/lib/service/kafka.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -const Kafka = require('kafka-node'); - -module.exports = async function factory (app, opts) { - const client = new Kafka.KafkaClient({ kafkaHost: opts.kafka.rootURL }); - const producer = new Kafka.HighLevelProducer(client); - - producer.on('error', function (err) { - app.fs.logger.log('error', "[FS-KAFKA]", err); - }); - - const kafka = { - producer: producer, - configUpdateMessage: opts.configUpdateMessage || {} - }; - - app.fs.kafka = kafka; - app.fs.logger.log('debug', "[FS-KAFKA]", "Init.Success"); -} \ No newline at end of file diff --git a/api/app/lib/service/mqttServer.js b/api/app/lib/service/mqttServer.js deleted file mode 100644 index c09a62a..0000000 --- a/api/app/lib/service/mqttServer.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; -const mqtt = require('mqtt'); - -module.exports = async function factory (app, opts) { - // console.info(`mqtt connecting ${opts.mqtt.mqttVideoServer}`); - - // const client = mqtt.connect(opts.mqtt.mqttVideoServer); - - // client.on('connect', function () { - // console.info(`mqtt connect success ${opts.mqtt.mqttVideoServer}`); - // client.subscribe('topic/test', { qos: 0 });//订阅主题为test的消息 - // }) - // client.on('error', function (e) { - // console.error(`mqtt connect failed ${opts.mqtt.mqttVideoServer}`); - // app.fs.logger.error('info', '[FS-AUTH-MQTT]', `mqtt connect failed ${opts.mqtt.mqttVideoServer}`); - // }) - - // client.on('message', async (top, message) => { - - // }); - - // app.mqttVideoServer = client -} diff --git a/api/app/lib/utils/dataRange.js b/api/app/lib/utils/dataRange.js deleted file mode 100644 index a50c886..0000000 --- a/api/app/lib/utils/dataRange.js +++ /dev/null @@ -1,173 +0,0 @@ -'use strict'; -const fs = require('fs'); -const moment = require('moment') - -module.exports = function (app, opts) { - - function judgeSuper (ctx) { - try { - const { userInfo = {} } = ctx.fs.api || {}; - const { role = [] } = userInfo - return role.some(r => r == 'SuperAdmin' || r == 'admin') - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - } - } - - async function anxinStrucIdRange ({ ctx, pepProjectId, keywordTarget, keyword }) { - const { models } = ctx.fs.dc; - const { userInfo = {} } = ctx.fs.api || {}; - const { clickHouse } = ctx.app.fs - const { correlationProject = [] } = userInfo - - const isSuper = judgeSuper(ctx) - let findOption = { - where: { - del: false - } - } - if (pepProjectId) { - // 有 特定的项目id 就按此查询 - findOption.where.pepProjectId = pepProjectId - } else if (!isSuper) { - // 还不是超管或管理员就按关联的项目id的数据范围查 - findOption.where.id = { $in: correlationProject } - } - - let pepProjectWhereOptions = [] - if (keywordTarget == 'pepProject' && keyword) { - pepProjectWhereOptions.push(`t_pim_project.project_name LIKE '%${keyword}%'`) - findOption.where.name = { - $or: [{ - $eq: null - }, { - $like: `%${keyword}%` - }] - } - } - - // TODO 这儿也许需要判断传进来的 pepProjectId 在不在当前用户的关注范围内 - // 根据 poms 的项目绑定关系查相关联的项企项目、安心云项目id信息 - const bindRes = await models.ProjectCorrelation.findAll(findOption) - - // 获取不重复的 项企项目id - let pepProjectIds = [] - for (let b of bindRes) { - if (b.pepProjectId) { - pepProjectIds.push(b.pepProjectId) - } - } - - // 查询项企项目的信息 - const pepProjectRes = pepProjectIds.length ? - await clickHouse.projectManage.query( - ` - SELECT - t_pim_project.id AS id, - t_pim_project.project_name AS projectName, - t_pim_project.isdelete AS isdelete, - t_pim_project_construction.construction_status_id AS constructionStatusId, - t_pim_project_state.construction_status AS constructionStatus - FROM - t_pim_project - LEFT JOIN t_pim_project_construction - ON t_pim_project.id = t_pim_project_construction.project_id - LEFT JOIN t_pim_project_state - ON t_pim_project_construction.construction_status_id = t_pim_project_state.id - WHERE - id IN (${pepProjectIds.join(',')}) - ${pepProjectWhereOptions.length ? `AND ${pepProjectWhereOptions.join(' AND ')}` - : ''} - ` - ).toPromise() : - [] - - - // 获取不重复的 安心云项目 id - const anxinProjectIds = [ - ...( - keywordTarget == 'pepProject' && keyword ? - bindRes.filter(b => b.name || pepProjectRes.some(pp => pp.id == b.pepProjectId)) : - bindRes - ).reduce( - (arr, b) => { - for (let sid of b.anxinProjectId) { - arr.add(sid); - } - return arr; - }, - new Set() - ) - ] - - - // 查询安心云项目及结构物信息 - let undelStrucWhereOptions = [] - if (keywordTarget && keyword) { - if (keywordTarget == 'struc') { - undelStrucWhereOptions.push(`t_structure.name LIKE '%${keyword}%'`) - } - } - const undelStrucRes = anxinProjectIds.length ? - await clickHouse.anxinyun.query( - ` - SELECT - t_project.id AS projectId, - t_structure.id AS strucId, - t_structure.name AS strucName, - project_state - FROM - t_project - LEFT JOIN - t_project_structure - ON t_project_structure.project = t_project.id - LEFT JOIN - t_project_structuregroup - ON t_project_structuregroup.project = t_project.id - LEFT JOIN - t_structuregroup_structure - ON t_structuregroup_structure.structuregroup = t_project_structuregroup.structuregroup - RIGHT JOIN - t_structure - ON t_structure.id = t_project_structure.structure - OR t_structure.id = t_structuregroup_structure.structure - WHERE - project_state != -1 - AND - t_project.id IN (${anxinProjectIds.join(',')}) - ${undelStrucWhereOptions.length ? `AND ${undelStrucWhereOptions.join(' AND ')}` : ''} - ` - ).toPromise() : - [] - - // 构建安心云结构物和项企项目的关系 - // 并保存信息至数据 - let undelStruc = [] - for (let s of undelStrucRes) { - if (!undelStruc.some(us => us.strucId == s.strucId)) { - let pomsProject = [] - for (let { dataValues: br } of bindRes) { - if (br.anxinProjectId.some(braId => braId == s.projectId)) { - let corPepProject = pepProjectRes.find(pp => pp.id == br.pepProjectId) - pomsProject.push({ - ...br, - pepProject: corPepProject - }) - } - } - undelStruc.push({ - strucId: s.strucId, - strucName: s.strucName, - // projectId: s.projectId, - pomsProject: pomsProject - }) - } - } - return undelStruc - } - - return { - judgeSuper, - anxinStrucIdRange - } -} \ No newline at end of file diff --git a/api/app/lib/utils/kafkaSend.js b/api/app/lib/utils/kafkaSend.js deleted file mode 100644 index 2956b8a..0000000 --- a/api/app/lib/utils/kafkaSend.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -module.exports = function (app, opts) { - - async function kfkSendAsync (payloads) { - const { producer } = app.fs.kafka - return new Promise((resolve, reject) => { - producer.send(payloads, function (err) { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }) - } - - return { - kfkSendAsync - } -} \ No newline at end of file diff --git a/api/app/lib/utils/vcmpAuth.js b/api/app/lib/utils/vcmpAuth.js deleted file mode 100644 index f8b0c2a..0000000 --- a/api/app/lib/utils/vcmpAuth.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; -const moment = require('moment') - -module.exports = function (app, opts) { - - async function vcmpAuth () { - const { vcmp: { app: vcApp } } = opts - const vcmpAuth = await app.redis.hgetall('vcmpAuth'); - if (vcmpAuth.token && moment().isBefore(moment(vcmpAuth.expires))) { - return vcmpAuth.token - } else { - let res = await app.fs.iotAuthRequest.post('oauth2/token', { - data: { - grant_type: 'client_credentials' - }, - header: { - Authorization: `Basic ${Buffer.from(`${encodeURIComponent(vcApp.id)}:${encodeURIComponent(vcApp.secret)}`).toString('base64')}` - } - }) - await app.redis.hmset('vcmpAuth', { - ...res - }); - return res.token - } - } - - return { - vcmpAuth - } -} \ No newline at end of file diff --git a/api/config.js b/api/config.js index a7badf7..c8c7345 100644 --- a/api/config.js +++ b/api/config.js @@ -11,23 +11,12 @@ const dev = process.env.NODE_ENV == 'development'; args.option(['p', 'port'], '启动端口'); args.option(['g', 'pg'], 'postgre 服务 URL'); args.option(['f', 'fileHost'], '文件中心本地化存储: WebApi 服务器地址(必填), 该服务器提供文件上传Web服务'); -args.option(['k', 'kafka'], 'kafka 服务 URL'); - -args.option('iotaProxy', '以太代理') args.option('redisHost', 'redisHost'); args.option('redisPort', 'redisPort'); args.option('redisPswd', 'redisPassword'); -args.option('axyApiUrl', '安心云 api'); args.option('apiEmisUrl', '企业管理 api'); -args.option('apiVcmpUrl', '视频平台 api'); -args.option('apiIotAuth', 'IOT 鉴权平台') - -args.option('godUrl', '高德地图API请求地址'); -args.option('godKey', '高德地图API key'); - -args.option('mqttVideoServer', '视频后台 mqtt 服务 URL'); // 七牛云存储参数 args.option('qnak', 'qiniuAccessKey'); @@ -38,49 +27,20 @@ args.option('qndmn', 'qiniuDomain'); // clickHouse args.option('clickHouseUrl', 'clickHouse Url'); args.option('clickHousePort', 'clickHouse Port'); -args.option('clickHouseAnxincloud', 'clickHouse 安心云数据库名称'); args.option('clickHousePepEmis', 'clickHouse 项企数据库名称'); -args.option('clickHouseProjectManage', 'clickHouse 项目管理数据库名称'); -args.option('clickHouseVcmp', 'clickHouse 视频平台数据库名称'); -args.option('clickHouseDataAlarm', 'clickHouse 视频平台数据告警库名称'); - -args.option('confirmAlarmAnxinUserId', '确认告警时保存到 ES 的安心云的用户的 id'); - -// 视频应用秘钥 -args.option('vcmpAppId', '视频平台 应用 id') -args.option('vcmpAppSecret', '视频平台 应用秘钥') const flags = args.parse(process.argv); const POMS_DB = process.env.POMS_DB || flags.pg; const LOCAL_SVR_ORIGIN = process.env.LOCAL_SVR_ORIGIN || flags.fileHost; -// kafka -const ANXINCLOUD_KAFKA_BROKERS = process.env.ANXINCLOUD_KAFKA_BROKERS || flags.kafka; - -// 以太代理 -const IOT_PROXY = process.env.IOT_PROXY || flags.iotaProxy; - // Redis 参数 const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口 const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码 -// 安心云api -const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.axyApiUrl; // 企业管理 api const API_EMIS_URL = process.env.API_EMIS_URL || flags.apiEmisUrl; -// 视频平台 api -const API_VCMP_URL = process.env.API_VCMP_URL || flags.apiVcmpUrl; -// iot鉴权平台 api -const API_IOT_AUTH = process.env.API_IOT_AUTH || flags.apiIotAuth; - -// 高德地图的参数 -const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3'; -const GOD_KEY = process.env.GOD_KEY || flags.godKey; - -// 视频后台 mqtt 信息推送地址 -const MQTT_VIDEO_SERVER = process.env.MQTT_VIDEO_SERVER || flags.mqttVideoServer; // 七牛云存储参数 const QINIU_DOMAIN_QNDMN_RESOURCE = process.env.ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE || flags.qndmn; @@ -93,34 +53,15 @@ const CLICKHOUST_URL = process.env.CLICKHOUST_URL || flags.clickHouseUrl const CLICKHOUST_PORT = process.env.CLICKHOUST_PORT || flags.clickHousePort const CLICKHOUST_USER = process.env.CLICKHOUST_USER || flags.clickHouseUser const CLICKHOUST_PASSWORD = process.env.CLICKHOUST_PASSWORD || flags.clickHousePassword -const CLICKHOUST_ANXINCLOUD = process.env.CLICKHOUST_ANXINCLOUD || flags.clickHouseAnxincloud 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 - -const CONFIRM_ALARM_ANXIN_USER_ID = process.env.CONFIRM_ALARM_ANXIN_USER_ID || flags.confirmAlarmAnxinUserId - -const PLATFORM_NAME = process.env.PLATFORM_NAME || flags.platformName || 'anxinyun'; - -// 视频平台应用秘钥 -const VCMP_APP_ID = process.env.VCMP_APP_ID || flags.vcmpAppId -const VCMP_APP_SECRET = process.env.VCMP_APP_SECRET || flags.vcmpAppSecret if ( !POMS_DB || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT - || !ANXINCLOUD_KAFKA_BROKERS - || !GOD_KEY - || !API_ANXINYUN_URL || !API_EMIS_URL - || !API_VCMP_URL - || !API_IOT_AUTH || !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_DATA_ALARM - || !CONFIRM_ALARM_ANXIN_USER_ID - || !VCMP_APP_ID || !VCMP_APP_SECRET + || !CLICKHOUST_PEP_EMIS ) { console.log('缺少启动参数,异常退出'); args.showHelp(); @@ -147,32 +88,13 @@ const product = { opts: { dev, exclude: [ - { p: '/attachments/:p', o: 'POST' }, - { p: '/alarm/application/inspection', o: 'POST' }, - { p: '/project/app_list', o: 'GET' }, - { p: '/alarm/application/api', o: 'POST' } + ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 - anxinCloud: { - confirmAlarmAnxinUserId: CONFIRM_ALARM_ANXIN_USER_ID - }, - vcmp: { - app: { - id: VCMP_APP_ID, - secret: VCMP_APP_SECRET - } - }, - kafka: { - rootURL: ANXINCLOUD_KAFKA_BROKERS, - topicPrefix: PLATFORM_NAME - }, redis: { host: IOTA_REDIS_SERVER_HOST, port: IOTA_REDIS_SERVER_PORT, pwd: IOTA_REDIS_SERVER_PWD }, - mqtt: { - mqttVideoServer: MQTT_VIDEO_SERVER, - }, sms: { ///阿里云-安心云 accessKey: 'LTAI5tAFdjz7j38aNF2C9Qe8', @@ -183,34 +105,14 @@ const product = { host: 'smtp.exmail.qq.com', port: 465, sender: { - name: '运维服务', + name: '人资服务', address: 'fsiot@free-sun.com.cn', password: 'Fs2689' } }, - pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs - name: 'axyRequest', - root: API_ANXINYUN_URL - }, { + pssaRequest: [{ name: 'emisRequest', root: API_EMIS_URL - }, { - name: 'vcmpRequest', - root: API_VCMP_URL - }, { - name: 'iotAuthRequest', - root: API_IOT_AUTH - }, { - name: 'iotRequest', - root: IOT_PROXY + '/_iota_api' - }, { - name: 'godRequest', - root: GOD_URL, - params: { - query: { - key: GOD_KEY - } - } },], clickHouse: { url: CLICKHOUST_URL, @@ -219,20 +121,8 @@ const product = { 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 - }, { - name: 'dataAlarm', - db: CLICKHOUST_DATA_ALARM } ] } diff --git a/web/client/index.ejs b/web/client/index.ejs index 9cbe876..54e5c56 100644 --- a/web/client/index.ejs +++ b/web/client/index.ejs @@ -8,14 +8,12 @@ - -
- +