北斗启航科技教育平台管理系统
This commit is contained in:
125
app/service/Monitoring.js
Normal file
125
app/service/Monitoring.js
Normal file
@@ -0,0 +1,125 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Monitoring";
|
||||
|
||||
class MonitoringService extends Service {
|
||||
// 查看危险操作记录
|
||||
async showMonitoring(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['operate', 'operate_msg', 'type', 'status', 'affect_entries', 'user', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['operate_msg', 'user'],
|
||||
key = ['type', 'status', 'operate'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const insiders = await ctx.model3.Insiders.findAll({ attributes: ['uid', 'name'] });
|
||||
if (searchOptions.name) {
|
||||
if (searchOptions.name == '*空') {
|
||||
where.user = [null, ''];
|
||||
} else {
|
||||
let uidArr = [];
|
||||
insiders.filter(item => {
|
||||
if (item.dataValues.name.includes(searchOptions.name)) {
|
||||
uidArr.push(item.dataValues.uid);
|
||||
}
|
||||
});
|
||||
where.user = [...uidArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model3.Monitoring.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.name = '';
|
||||
insiders.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user) {
|
||||
element.dataValues.name = item.dataValues.name;
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除危险操作记录
|
||||
async deleteMonitoring(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除危险操作记录',
|
||||
type: 2,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user, created_at } = requestMsg;
|
||||
where = { user, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user.push(element.user),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { user, created_at };
|
||||
}
|
||||
const resultList = await ctx.model3.Monitoring.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonitoringService;
|
||||
Reference in New Issue
Block a user