wenlele
2 years ago
10 changed files with 631 additions and 0 deletions
@ -0,0 +1,165 @@ |
|||
'use strict'; |
|||
const fs = require('fs'); |
|||
const moment = require('moment') |
|||
const { alarmConfirmLog } = require('./alarmConfirmLog'); |
|||
|
|||
|
|||
|
|||
async function postDataContinuity (ctx) { |
|||
try { |
|||
const { utils: { sendAppearToWeb }, clickHouse } = ctx.app.fs |
|||
const models = ctx.fs.dc.models; |
|||
const { type, file, } = ctx.request.body |
|||
const now = moment().format() |
|||
|
|||
if (!type) { |
|||
throw '请标明数据类型 type' |
|||
} |
|||
let dataNumber = await models.AlarmDataContinuityType.findOne({ |
|||
where: { typeNumber: type } |
|||
}); |
|||
|
|||
if (!dataNumber) { |
|||
throw '不存在该数据类型' |
|||
} |
|||
|
|||
await models.AlarmDataContinuity.create({ |
|||
type, file, createTime: now |
|||
}); |
|||
|
|||
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 st (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { clickHouse } = ctx.app.fs |
|||
const { utils: { anxinStrucIdRange, pomsProjectRange } } = ctx.app.fs |
|||
const { keyword, errType, confirmState, state, sustainTimeStart, sustainTimeEnd, limit, page, pepProjectId, toExport } = ctx.query |
|||
|
|||
let pomsProject = await pomsProjectRange({ |
|||
ctx, pepProjectId, |
|||
keywordTarget: 'pepProject', |
|||
keyword, |
|||
}) |
|||
const pomsProjectIds = pomsProject.map(p => p.id) |
|||
let findOption = { |
|||
distinct: true, |
|||
where: { |
|||
$or: [] |
|||
}, |
|||
include: [{ |
|||
model: models.App, |
|||
where: { |
|||
|
|||
}, |
|||
attributes: { |
|||
exclude: ['projectId'] |
|||
}, |
|||
include: [{ |
|||
model: models.ProjectCorrelation, |
|||
where: { |
|||
|
|||
}, |
|||
attributes: { |
|||
exclude: ['createTime', 'createUser', 'anxinProjectId',] |
|||
}, |
|||
}] |
|||
}] |
|||
} |
|||
if (keyword) { |
|||
findOption.where.$or.push( |
|||
{ |
|||
'$app->projectCorrelations.id$': { |
|||
$in: pomsProjectIds |
|||
}, |
|||
} |
|||
) |
|||
findOption.where.$or.push( |
|||
{ |
|||
'$app.name$': { $like: `%${keyword}%` } |
|||
}, |
|||
) |
|||
} else { |
|||
// findOption.where['$app->projectCorrelations.id$'] = {
|
|||
// $in: pomsProjectIds
|
|||
// }
|
|||
findOption.include[0].include[0].where.id = { $in: pomsProjectIds } |
|||
} |
|||
|
|||
if (errType) { |
|||
findOption.where.type = errType // element / apiError
|
|||
} |
|||
if (confirmState || state) { |
|||
if (confirmState == 'confirmd' || state == 'histroy') { |
|||
findOption.where.confirmTime = { $ne: null } |
|||
} else if (confirmState == 'unconfirmed' || state == 'new') { |
|||
findOption.where.confirmTime = null |
|||
} |
|||
} |
|||
if (sustainTimeStart && sustainTimeEnd) { |
|||
findOption.where.$or = findOption.where.$or.concat([ |
|||
{ |
|||
createTime: { $between: [moment(sustainTimeStart).format(), moment(sustainTimeEnd).format()] }, |
|||
}, |
|||
{ |
|||
updateTime: { $between: [moment(sustainTimeStart).format(), moment(sustainTimeEnd).format()] } |
|||
}, |
|||
{ |
|||
createTime: { $lte: moment(sustainTimeStart).format() }, |
|||
updateTime: { $gte: moment(sustainTimeEnd).format() }, |
|||
} |
|||
]) |
|||
} |
|||
if (!toExport) {//非导出时考虑分页
|
|||
if (limit) { |
|||
findOption.limit = limit |
|||
} |
|||
if (page && limit) { |
|||
findOption.offset = page * limit |
|||
} |
|||
} |
|||
if (!findOption.where.$or.length) { |
|||
delete findOption.where.$or |
|||
} |
|||
const listRes = await models.AppAlarm.findAndCountAll(findOption) |
|||
|
|||
for (let lr of listRes.rows) { |
|||
if (lr.app && lr.app.projectCorrelations) { |
|||
for (let p of lr.app.projectCorrelations) { |
|||
let corProjectCorrelations = pomsProject.find(pr => pr.id == p.id) |
|||
if (corProjectCorrelations) { |
|||
p.dataValues = corProjectCorrelations |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if (toExport) {//数据导出相关
|
|||
await exportAppAlarms(ctx, listRes); |
|||
} else { |
|||
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 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
postDataContinuity, |
|||
st, |
|||
}; |
@ -0,0 +1,166 @@ |
|||
'use strict'; |
|||
const fs = require('fs'); |
|||
const moment = require('moment') |
|||
const { alarmConfirmLog } = require('./alarmConfirmLog'); |
|||
|
|||
|
|||
|
|||
async function serviceError (ctx) { |
|||
try { |
|||
const { utils: { sendAppearToWeb }, clickHouse } = ctx.app.fs |
|||
const models = ctx.fs.dc.models; |
|||
const { type, file, comment } = ctx.request.body |
|||
const now = moment().format() |
|||
|
|||
if (!type) { |
|||
throw '请标明服务告警类型 type' |
|||
} |
|||
|
|||
let serviceNumber = await models.AlarmServiceType.findOne({ |
|||
where: { typeNumber: type } |
|||
}); |
|||
|
|||
if (!serviceNumber) { |
|||
throw '不存在该服务告警类型' |
|||
} |
|||
|
|||
await models.AlarmService.create({ |
|||
type, file, createTime: now, comment |
|||
}); |
|||
|
|||
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 serviceErrorList (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { clickHouse } = ctx.app.fs |
|||
const { utils: { anxinStrucIdRange, pomsProjectRange } } = ctx.app.fs |
|||
const { keyword, errType, confirmState, state, sustainTimeStart, sustainTimeEnd, limit, page, pepProjectId, toExport } = ctx.query |
|||
|
|||
let pomsProject = await pomsProjectRange({ |
|||
ctx, pepProjectId, |
|||
keywordTarget: 'pepProject', |
|||
keyword, |
|||
}) |
|||
const pomsProjectIds = pomsProject.map(p => p.id) |
|||
let findOption = { |
|||
distinct: true, |
|||
where: { |
|||
$or: [] |
|||
}, |
|||
include: [{ |
|||
model: models.App, |
|||
where: { |
|||
|
|||
}, |
|||
attributes: { |
|||
exclude: ['projectId'] |
|||
}, |
|||
include: [{ |
|||
model: models.ProjectCorrelation, |
|||
where: { |
|||
|
|||
}, |
|||
attributes: { |
|||
exclude: ['createTime', 'createUser', 'anxinProjectId',] |
|||
}, |
|||
}] |
|||
}] |
|||
} |
|||
if (keyword) { |
|||
findOption.where.$or.push( |
|||
{ |
|||
'$app->projectCorrelations.id$': { |
|||
$in: pomsProjectIds |
|||
}, |
|||
} |
|||
) |
|||
findOption.where.$or.push( |
|||
{ |
|||
'$app.name$': { $like: `%${keyword}%` } |
|||
}, |
|||
) |
|||
} else { |
|||
// findOption.where['$app->projectCorrelations.id$'] = {
|
|||
// $in: pomsProjectIds
|
|||
// }
|
|||
findOption.include[0].include[0].where.id = { $in: pomsProjectIds } |
|||
} |
|||
|
|||
if (errType) { |
|||
findOption.where.type = errType // element / apiError
|
|||
} |
|||
if (confirmState || state) { |
|||
if (confirmState == 'confirmd' || state == 'histroy') { |
|||
findOption.where.confirmTime = { $ne: null } |
|||
} else if (confirmState == 'unconfirmed' || state == 'new') { |
|||
findOption.where.confirmTime = null |
|||
} |
|||
} |
|||
if (sustainTimeStart && sustainTimeEnd) { |
|||
findOption.where.$or = findOption.where.$or.concat([ |
|||
{ |
|||
createTime: { $between: [moment(sustainTimeStart).format(), moment(sustainTimeEnd).format()] }, |
|||
}, |
|||
{ |
|||
updateTime: { $between: [moment(sustainTimeStart).format(), moment(sustainTimeEnd).format()] } |
|||
}, |
|||
{ |
|||
createTime: { $lte: moment(sustainTimeStart).format() }, |
|||
updateTime: { $gte: moment(sustainTimeEnd).format() }, |
|||
} |
|||
]) |
|||
} |
|||
if (!toExport) {//非导出时考虑分页
|
|||
if (limit) { |
|||
findOption.limit = limit |
|||
} |
|||
if (page && limit) { |
|||
findOption.offset = page * limit |
|||
} |
|||
} |
|||
if (!findOption.where.$or.length) { |
|||
delete findOption.where.$or |
|||
} |
|||
const listRes = await models.AppAlarm.findAndCountAll(findOption) |
|||
|
|||
for (let lr of listRes.rows) { |
|||
if (lr.app && lr.app.projectCorrelations) { |
|||
for (let p of lr.app.projectCorrelations) { |
|||
let corProjectCorrelations = pomsProject.find(pr => pr.id == p.id) |
|||
if (corProjectCorrelations) { |
|||
p.dataValues = corProjectCorrelations |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if (toExport) {//数据导出相关
|
|||
await exportAppAlarms(ctx, listRes); |
|||
} else { |
|||
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 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
serviceError, |
|||
serviceErrorList, |
|||
}; |
@ -0,0 +1,52 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AlarmDataContinuity = sequelize.define("alarmDataContinuity", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "alarm_data_continuity_id_uindex" |
|||
}, |
|||
file: { |
|||
type: DataTypes.TEXT, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "file", |
|||
autoIncrement: false |
|||
}, |
|||
type: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "type", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
}, { |
|||
tableName: "alarm_data_continuity", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AlarmDataContinuity = AlarmDataContinuity; |
|||
return AlarmDataContinuity; |
|||
}; |
@ -0,0 +1,43 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AlarmDataContinuityType = sequelize.define("alarmDataContinuityType", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "alarm_data_continuity_type_id_uindex" |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "name", |
|||
autoIncrement: false |
|||
}, |
|||
typeNumber: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "type_number", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "alarm_data_continuity_type", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AlarmDataContinuityType = AlarmDataContinuityType; |
|||
return AlarmDataContinuityType; |
|||
}; |
@ -0,0 +1,61 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AlarmService = sequelize.define("alarmService", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "alarm_service_id_uindex" |
|||
}, |
|||
file: { |
|||
type: DataTypes.TEXT, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "file", |
|||
autoIncrement: false |
|||
}, |
|||
type: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "type", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
comment: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "comment", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "alarm_service", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AlarmService = AlarmService; |
|||
return AlarmService; |
|||
}; |
@ -0,0 +1,43 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AlarmServiceType = sequelize.define("alarmServiceType", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "alarm_service_type_id_uindex" |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "name", |
|||
autoIncrement: false |
|||
}, |
|||
typeNumber: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "type_number", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "alarm_service_type", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AlarmServiceType = AlarmServiceType; |
|||
return AlarmServiceType; |
|||
}; |
@ -0,0 +1,41 @@ |
|||
create table alarm_data_continuity |
|||
( |
|||
id serial not null, |
|||
file text not null, |
|||
type int not null, |
|||
create_time timestamp not null |
|||
); |
|||
|
|||
comment on column alarm_data_continuity.type is '数据连续性的类型编号'; |
|||
|
|||
create unique index alarm_data_continuity_id_uindex |
|||
on alarm_data_continuity (id); |
|||
|
|||
alter table alarm_data_continuity |
|||
add constraint alarm_data_continuity_pk |
|||
primary key (id); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
create table alarm_data_continuity_type |
|||
( |
|||
id serial not null, |
|||
name varchar not null, |
|||
type_number int not null |
|||
); |
|||
|
|||
comment on column alarm_data_continuity_type.type_number is '类型编号'; |
|||
|
|||
create unique index alarm_data_continuity_type_id_uindex |
|||
on alarm_data_continuity_type (id); |
|||
|
|||
create unique index alarm_data_continuity_type_type_number_uindex |
|||
on alarm_data_continuity_type (type_number); |
|||
|
|||
alter table alarm_data_continuity_type |
|||
add constraint alarm_data_continuity_type_pk |
|||
primary key (id); |
@ -0,0 +1,36 @@ |
|||
create table alarm_service |
|||
( |
|||
id serial not null, |
|||
file text not null, |
|||
type int not null, |
|||
create_time timestamp not null, |
|||
comment varchar |
|||
); |
|||
|
|||
comment on column alarm_service.type is '服务告警类型编号'; |
|||
|
|||
create unique index alarm_service_id_uindex |
|||
on alarm_service (id); |
|||
|
|||
alter table alarm_service |
|||
add constraint alarm_service_pk |
|||
primary key (id); |
|||
|
|||
|
|||
|
|||
|
|||
create table alarm_service_type |
|||
( |
|||
id serial not null, |
|||
name varchar not null, |
|||
type_number int not null |
|||
); |
|||
|
|||
comment on column alarm_service_type.type_number is '编号'; |
|||
|
|||
create unique index alarm_service_type_id_uindex |
|||
on alarm_service_type (id); |
|||
|
|||
alter table alarm_service_type |
|||
add constraint alarm_service_type_pk |
|||
primary key (id); |
Loading…
Reference in new issue