运维服务中台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.5 KiB

'use strict';
const moment = require('moment');
//系统可用性
async function getCalculability(ctx) {
try {
const { models } = ctx.fs.dc
const query = ctx.query
const sequelize = ctx.fs.dc.ORM;
const { eTime, sTime } = query
const timer = (new Date(eTime) - new Date(sTime)) / 1000 //时间之间的秒数
//console.log('timer', timer)
let recordRes = await models.MaintenanceRecord.findAndCount({
attributes: ['occurrenceTime', 'solvingTime'],
where: {
$and: [
sequelize.where(sequelize.fn('date', sequelize.col('occurrence_time')), '>=', moment(sTime).format('YYYY-MM-DD HH:mm:ss')),
sequelize.where(sequelize.fn('date', sequelize.col('occurrence_time')), '<=', moment(eTime).format('YYYY-MM-DD HH:mm:ss')),
]
}
})
let problemtime = 0
recordRes.rows.forEach((item) => {
let diff = (item.solvingTime - item.occurrenceTime) / 1000;
problemtime += diff;
})
console.log('recordRes', recordRes)
//console.log(time, 'time1')
const abilty = (timer - problemtime) / timer
console.log('timer', timer, problemtime)
//console.log('abc', abilty)
console.log('query2', query, problemtime, timer, abilty)
ctx.status = 200
ctx.body = abilty
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
ctx.status = 400
ctx.body = {
message: `查询系统可用性失败`
}
}
}
module.exports = {
getCalculability
}