wuqun
2 years ago
11 changed files with 445 additions and 25 deletions
@ -0,0 +1,153 @@ |
|||
'use strict'; |
|||
const moment = require('moment'); |
|||
|
|||
//工作台
|
|||
async function getWorkbench(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { clickHouse } = ctx.app.fs |
|||
const { alarmId, limit, page } = ctx.query |
|||
ctx.status = 200; |
|||
ctx.body = [] |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
//项目概览
|
|||
async function getProjectsInfo(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { clickHouse } = ctx.app.fs |
|||
const { alarmId, limit, page } = ctx.query |
|||
ctx.status = 200; |
|||
ctx.body = [] |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
//BI分析
|
|||
async function getBiAnalysis(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { clickHouse } = ctx.app.fs |
|||
const { alarmId, limit, page } = ctx.query |
|||
ctx.status = 200; |
|||
ctx.body = [] |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
//最新动态
|
|||
async function getLatestDynamic(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { limit, page, projectCorrelationId } = ctx.query; |
|||
const { userInfo } = ctx.fs.api; |
|||
const { clickHouse } = ctx.app.fs; |
|||
|
|||
let where = {} |
|||
if (!userInfo.role.includes('SuperAdmin') && !userInfo.role.includes('admin')) { |
|||
where.projectCorrelationId = { $in: userInfo.correlationProject } |
|||
} |
|||
if (projectCorrelationId) {//查指定项目,控制台全局切换
|
|||
where.projectCorrelationId = projectCorrelationId |
|||
} |
|||
let news = await models.LatestDynamicList.findAll({//最新动态
|
|||
include: [{ |
|||
model: models.ProjectCorrelation, |
|||
where: { del: false }, |
|||
attributes: ['id', 'name', 'pepProjectId'], |
|||
}, { |
|||
model: models.AlarmAppearRecord |
|||
}, { |
|||
model: models.EmailSendLog |
|||
}, { |
|||
model: models.AlarmConfirmLog |
|||
}], |
|||
where: where, |
|||
offset: Number(page) * Number(limit), |
|||
limit: Number(limit), |
|||
order: [['time', 'desc']], |
|||
}); |
|||
|
|||
//查项目名称 查用户名
|
|||
let pepPojectIds = new Set(), notedUserIds = new Set(); |
|||
for (let p of news) { |
|||
pepPojectIds.add(p.projectCorrelation.pepProjectId); |
|||
|
|||
if (p.emailSendLog) { |
|||
notedUserIds.add(p.emailSendLog.toPepUserId);//通知 接收人
|
|||
} |
|||
if (p.alarmConfirmLog && p.alarmConfirmLog.pepUserId) { |
|||
notedUserIds.add(p.alarmConfirmLog.pepUserId);//确认 操作者
|
|||
} |
|||
} |
|||
let pepProjects = pepPojectIds.size ? await clickHouse.projectManage.query(` |
|||
SELECT id, project_name FROM t_pim_project WHERE id IN (${[...pepPojectIds]}) |
|||
`).toPromise() : [];
|
|||
|
|||
let userPepRes = notedUserIds.size ? await clickHouse.pepEmis.query( |
|||
`SELECT DISTINCT user.id AS id, "user"."name" AS name FROM user WHERE user.id IN (${[...notedUserIds].join(',')})
|
|||
`).toPromise() : []
|
|||
|
|||
|
|||
let appear = [], notice = [], confirm = []; |
|||
news.map(d => { |
|||
let projectName = d.projectCorrelation.name || pepProjects.find(pp => pp.id == d.projectCorrelation.pepProjectId).project_name; |
|||
if (d.alarmAppearId) { |
|||
appear.push({ |
|||
projectName, |
|||
...d.alarmAppearRecord |
|||
}); |
|||
} |
|||
if (d.emailSendId) { |
|||
notice.push({ |
|||
userName: userPepRes.find(u => u.id == d.emailSendLog.toPepUserId).name, |
|||
projectName, |
|||
...d.emailSendLog |
|||
}); |
|||
} |
|||
if (d.alarmConfirmId) { |
|||
confirm.push({ |
|||
userName: d.alarmConfirmLog.pepUserId ? userPepRes.find(u => u.id == d.alarmConfirmLog.pepUserId).name : '自动恢复', |
|||
projectName, |
|||
...d.alarmConfirmLog.dataValues |
|||
}); |
|||
} |
|||
}) |
|||
ctx.status = 200; |
|||
ctx.body = { |
|||
appear,//发现
|
|||
notice,//通知
|
|||
confirm//确认
|
|||
}; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
getWorkbench, |
|||
getProjectsInfo, |
|||
getBiAnalysis, |
|||
getLatestDynamic |
|||
}; |
@ -0,0 +1,53 @@ |
|||
/* eslint-disable*/ |
|||
|
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AlarmAppearRecord = sequelize.define("alarmAppearRecord", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "alarm_appear_record_id_uindex" |
|||
}, |
|||
projectCorrelationId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "project_correlation_id", |
|||
autoIncrement: false |
|||
}, |
|||
alarmInfo: { |
|||
type: DataTypes.JSON, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "alarm_info", |
|||
autoIncrement: false |
|||
}, |
|||
time: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "time", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "alarm_appear_record", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AlarmAppearRecord = AlarmAppearRecord; |
|||
return AlarmAppearRecord; |
|||
}; |
@ -0,0 +1,62 @@ |
|||
/* eslint-disable*/ |
|||
|
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const EmailSendLog = sequelize.define("emailSendLog", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "email_send_log_id_uindex" |
|||
}, |
|||
projectCorrelationId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "project_correlation_id", |
|||
autoIncrement: false |
|||
}, |
|||
toPepUserId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "to_pep_user_id", |
|||
autoIncrement: false |
|||
}, |
|||
by: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "by", |
|||
autoIncrement: false |
|||
}, |
|||
time: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "time", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "email_send_log", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.EmailSendLog = EmailSendLog; |
|||
return EmailSendLog; |
|||
}; |
@ -0,0 +1,71 @@ |
|||
/* eslint-disable*/ |
|||
|
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const LatestDynamicList = sequelize.define("latestDynamicList", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "latest_dynamic_list_id_uindex" |
|||
}, |
|||
time: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "time", |
|||
autoIncrement: false |
|||
}, |
|||
alarmAppearId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "alarm_appear_id", |
|||
autoIncrement: false |
|||
}, |
|||
emailSendId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "email_send_id", |
|||
autoIncrement: false |
|||
}, |
|||
alarmConfirmId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "alarm_confirm_id", |
|||
autoIncrement: false |
|||
}, |
|||
projectCorrelationId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "project_correlation_id", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "latest_dynamic_list", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.LatestDynamicList = LatestDynamicList; |
|||
return LatestDynamicList; |
|||
}; |
@ -0,0 +1,23 @@ |
|||
|
|||
|
|||
'use strict'; |
|||
|
|||
const console = require('../../controllers/console/index'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
//我的工作台
|
|||
app.fs.api.logAttr['GET/user/:userId/workbench'] = { content: '查询工作台问题', visible: false }; |
|||
router.get('/user/:userId/workbench', console.getWorkbench); |
|||
|
|||
//项目概览
|
|||
app.fs.api.logAttr['GET/user/:userId/projects/info'] = { content: '查询项目概览', visible: false }; |
|||
router.get('/user/:userId/projects/info', console.getProjectsInfo); |
|||
|
|||
//BI分析模块
|
|||
app.fs.api.logAttr['GET/user/:userId/bi/analysis'] = { content: '查询BI分析数据', visible: false }; |
|||
router.get('/user/:userId/bi/analysis', console.getBiAnalysis); |
|||
|
|||
//最新动态
|
|||
app.fs.api.logAttr['GET/user/:userId/latest/dynamic'] = { content: '查询最新动态', visible: false }; |
|||
router.get('/user/:userId/latest/dynamic', console.getLatestDynamic); |
|||
}; |
Loading…
Reference in new issue