From 88e2a1f47a26ec672fc4260b833d15e615d56b27 Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 9 Feb 2023 09:30:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=97=E8=A1=A8=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rest/custom/list.js | 4 ++-- src/rest/monitorApi/list.js | 16 ++++++++++++++++ src/rest/wechat/list.js | 4 ++-- src/utils/dbUitls.js | 8 +++++--- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 src/rest/monitorApi/list.js diff --git a/src/rest/custom/list.js b/src/rest/custom/list.js index b66743f..477325b 100644 --- a/src/rest/custom/list.js +++ b/src/rest/custom/list.js @@ -5,8 +5,8 @@ module.exports = { execute: (request, response) => { let {size, current, name, type} = request.query dbUtils.list({ - table: 'node_custom_config', con: name, - search: {size, current, type}, sort: 'download' + table: 'node_custom_config', + search: {size, current, type, name}, sort: 'download' }).then(data => { response.send({code: 0, data}) }).catch(err => { diff --git a/src/rest/monitorApi/list.js b/src/rest/monitorApi/list.js new file mode 100644 index 0000000..bfb2440 --- /dev/null +++ b/src/rest/monitorApi/list.js @@ -0,0 +1,16 @@ +const dbUtils = require("../../utils/dbUitls"); +module.exports = { + action: "/node/monitorApi/list", + method: "post", + execute: (request, response) => { + let {size, current, name: path, status} = request.query + dbUtils.list({ + table: 'node_api_logs', con: 'path', + search: {size, current, status, path}, sort: 'createTime' + }).then(data => { + response.send({code: 0, data}) + }).catch(err => { + response.send({code: 1, err: err?.sqlMessage || err || ""}) + }) + } +} diff --git a/src/rest/wechat/list.js b/src/rest/wechat/list.js index 3738afd..41accdf 100644 --- a/src/rest/wechat/list.js +++ b/src/rest/wechat/list.js @@ -5,8 +5,8 @@ module.exports = { execute: (request, response) => { const {size, current, name, type} = request.query dbUtils.list({ - table: 'node_wxmp_deploy', con: name, - search: {size, current, type} + table: 'node_wxmp_deploy', + search: {size, current, type, name} }).then(data => { response.send({code: 0, data}) }).catch(err => { diff --git a/src/utils/dbUitls.js b/src/utils/dbUitls.js index 17e2c81..79a872c 100644 --- a/src/utils/dbUitls.js +++ b/src/utils/dbUitls.js @@ -26,19 +26,21 @@ module.exports = { console.log(`${chalk.bgBlue.black(" DATABASE ")} 数据库已连接`) }, query, - list: ({table, search, con = '', sort}) => { + list: ({table, search, con = 'name', sort}) => { //列表查询 let total = 0, records = [] if (table) { const {current, size = 10} = search, params = JSON.parse(JSON.stringify(search)) + const conValue = params[con] delete params.current delete params.size + delete params[con] const sqlCon = Object.keys(params).map(e => `and ${e}='${params[e]}'`).join(" ") return Promise.all([ - query(`select 1 from ${table} where name like '%${con}%' ${sqlCon}`).then(res => { + query(`select 1 from ${table} where ${con} like '%${conValue}%' ${sqlCon}`).then(res => { return total = res.length }), - query(`select * from ${table} where name like '%${con}%' ${sqlCon} order by ${sort||'createTime'} desc limit ${((current-1)||0)*size},${size}`).then(res => { + query(`select * from ${table} where ${con} like '%${conValue}%' ${sqlCon} order by ${sort||'createTime'} desc limit ${((current-1)||0)*size},${size}`).then(res => { return records = res }) ]).then(() => {