调整列表工具类

This commit is contained in:
aixianling
2023-02-09 09:30:20 +08:00
parent 7acebbc35b
commit 88e2a1f47a
4 changed files with 25 additions and 7 deletions

View File

@@ -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 => {

View File

@@ -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 || ""})
})
}
}

View File

@@ -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 => {

View File

@@ -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(() => {