'use strict'; async function getLog(ctx, next) { try { const models = ctx.fs.dc.models; const { limit, page, startTime, endTime, keyword } = ctx.query let findOption = { where: {}, order: [['time', 'DESC']], include: [{ model: models.User, attributes: ["name", "username"], }], distinct: true } if (limit) { findOption.limit = Number(limit) } if (page && limit) { findOption.offset = page * limit } if (startTime && endTime) { findOption.where.time = { $between: [startTime, endTime] }; } if (keyword) { findOption.where['$or'] = { clientType: { $like: `%${keyword}%` }, content: { $like: `%${keyword}%` }, parameter: { $like: `%${keyword}%` }, } } const res = await models.OperationLog.findAndCountAll(findOption) ctx.status = 200; ctx.body = res } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { "message": "获取操作日志失败" } } } module.exports = { getLog, }