change mysql connection to connection pool
This commit is contained in:
parent
404fb8c346
commit
493dd36e18
@ -64,5 +64,6 @@
|
||||
"ERR8001": "資料新增失敗",
|
||||
"ERR8002": "資料更新失敗",
|
||||
"ERR8003": "資料刪除失敗",
|
||||
"ERR8100": "DB連線失敗",
|
||||
"ERR9000": "操作權限不足"
|
||||
}
|
@ -2,6 +2,7 @@ const errList = require('../includes/errorManager');
|
||||
|
||||
function send(req, res) {
|
||||
if ('db' in res && typeof res.db == 'object' && 'close' in res.db && typeof res.db.close == 'function') res.db.close();
|
||||
if ('db' in res && typeof res.db == 'object' && 'release' in res.db && typeof res.db.release == 'function') res.db.release();
|
||||
|
||||
let lngs = req.headers['accept-language'].split(',');
|
||||
let lng = null;
|
||||
|
@ -3,7 +3,7 @@ const router = express.Router();
|
||||
const rt = require('../ResTool');
|
||||
const config = require('../../config.json');
|
||||
const fs = require('fs');
|
||||
const mysql = require('../../libs/mysql_cls');
|
||||
const mysql = require('../../libs/mysql_pool');
|
||||
const tool = require('../../includes/apiTool');
|
||||
const exec = require('child_process').exec;
|
||||
const so = require('../../includes/storeObject');
|
||||
@ -65,7 +65,7 @@ router
|
||||
})
|
||||
.catch(e => n());
|
||||
})
|
||||
.post('/dotrun', (req, res, n) => {
|
||||
.post('/dotrun', (req, res, n) => {
|
||||
if (!config.permission.dio) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
@ -77,14 +77,6 @@ router
|
||||
record: []
|
||||
};
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let obj = so.get(req.headers['x-auth-token']);
|
||||
let u = '';
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
|
||||
@ -101,17 +93,9 @@ router
|
||||
});
|
||||
});
|
||||
})
|
||||
.post('/getdioinfo', (req, res, n) => {
|
||||
.post('/getdioinfo', (req, res, n) => {
|
||||
if (!config.permission.dio) return n('ERR9000');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let q = "select * from ??.??";
|
||||
let pdi = tool.promiseQuery(res, q, [config.db.db1, 'dilist'], 'di');
|
||||
let pdo = tool.promiseQuery(res, q, [config.db.db1, 'dolist'], 'do');
|
||||
@ -146,14 +130,6 @@ router
|
||||
record: []
|
||||
}
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "update ??.?? set ?? = unix_timestamp() , ";
|
||||
let sub = " ?? = case ?? ";
|
||||
let dos = [];
|
||||
|
@ -2,12 +2,13 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const errMng = require('../../includes/errorManager');
|
||||
const so = require('../../includes/storeObject');
|
||||
const mysql = require('../../libs/mysql_pool');
|
||||
|
||||
router
|
||||
.get('/', (req, res) => {
|
||||
res.send({ name: 'WebIO API System' });
|
||||
})
|
||||
.all('*', (req,res,n)=>{
|
||||
.all('*', async(req,res,n)=>{
|
||||
if('x-auth-token' in req.headers) {
|
||||
let token = req.headers['x-auth-token'];
|
||||
if(so.chkKey(token)){
|
||||
@ -17,6 +18,11 @@ router
|
||||
}
|
||||
}
|
||||
}
|
||||
try{
|
||||
res.db = await mysql.getConn();
|
||||
}catch(e){
|
||||
return n('ERR8100');
|
||||
}
|
||||
n();
|
||||
})
|
||||
.get('/showallso', (req,res)=>{
|
||||
@ -36,6 +42,7 @@ router
|
||||
// api error handler
|
||||
router.use((err, req, res, n) => {
|
||||
if ('db' in res && typeof res.db == 'object' && 'close' in res.db && typeof res.db.close == 'function') res.db.close();
|
||||
if ('db' in res && typeof res.db == 'object' && 'release' in res.db && typeof res.db.release == 'function') res.db.release();
|
||||
|
||||
let lngs = req.headers['accept-language'].split(',');
|
||||
let lng = null;
|
||||
|
@ -30,15 +30,6 @@ router
|
||||
data.record = [];
|
||||
res.api_res = data;
|
||||
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let dos = [];
|
||||
let les = [];
|
||||
let ios = [];
|
||||
|
@ -19,14 +19,6 @@ router
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
}
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? ";
|
||||
let order = " order by `iogroupuid` desc ";
|
||||
let param = [config.db.db1, 'iogroup'];
|
||||
@ -99,14 +91,6 @@ router
|
||||
if (!arr.data.name) return n('ERR0026');
|
||||
if (!arr.data.devs) return n('ERR0029');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "insert into ??.?? (`iogroupname`,`iogroupid`,`iogroup_add_date`) values (?, ?, unix_timestamp())";
|
||||
let param = [config.db.db1, 'iogroup', arr.data.name, arr.data.devs];
|
||||
|
||||
@ -128,14 +112,6 @@ router
|
||||
if (!arr.data.name) return n('ERR0026');
|
||||
if (!arr.data.devs) return n('ERR0029');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "update ??.?? set \
|
||||
`iogroupname` = ?, \
|
||||
`iogroupid` = ?, \
|
||||
@ -159,14 +135,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete from ??.?? where `iogroupuid` = ? ";
|
||||
let param = [config.db.db1, 'iogroup', arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
|
@ -24,38 +24,23 @@ router
|
||||
.post('/getipcamlist', async (req,res,n) => {
|
||||
if(!config.permission.ipcam) return n('ERR9000');
|
||||
|
||||
// res.db = new mysql();
|
||||
// res.db.user = config.db.user;
|
||||
// res.db.password = config.db.pass;
|
||||
// res.db.host = config.db.host;
|
||||
// res.db.port = config.db.port;
|
||||
// res.db.database = config.db.db1;
|
||||
// res.db.connect();
|
||||
|
||||
// let query = "select * from ??.??";
|
||||
// let param = [config.db.db1, 'ipcam'];
|
||||
// res.db.query(query, param, (err, row) => {
|
||||
// if(err) return n('ERR8000');
|
||||
|
||||
// res.api_res = {
|
||||
// record: tool.checkArray(row)
|
||||
// }
|
||||
|
||||
// n();
|
||||
// });
|
||||
try{
|
||||
res.pdb = await mysql.getConn();
|
||||
res.pdb.query('select * from ??.??', [config.db.db1, 'dilist'], (err, row) => {
|
||||
console.log(err, row)
|
||||
if(err) return n('ERR8000')
|
||||
res.api_res = {
|
||||
record: row
|
||||
}
|
||||
n();
|
||||
})
|
||||
res.db = await mysql.getConn();
|
||||
}catch(e){
|
||||
return n('ERR8100');
|
||||
}
|
||||
|
||||
let query = "select * from ??.??";
|
||||
let param = [config.db.db1, 'ipcam'];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if(err) return n('ERR8000');
|
||||
|
||||
res.api_res = {
|
||||
record: tool.checkArray(row)
|
||||
}
|
||||
|
||||
n();
|
||||
});
|
||||
})
|
||||
.post('/addipcam', (req,res,n) => {
|
||||
if(!config.permission.ipcam) return n('ERR9000');
|
||||
|
@ -38,13 +38,6 @@ router
|
||||
! function chkEnd() {
|
||||
fs.exists(config.cmdpath.scanleone_end, exists => {
|
||||
if (exists) {
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select `leonename`, `leoneip`, `leonelistuid` from ??.?? where `temporary` = '1' ";
|
||||
let param = [config.db.db1, 'leonelist'];
|
||||
@ -73,14 +66,6 @@ router
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
}
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? where `temporary` = '0' ";
|
||||
let param = [config.db.db1, 'leonelist'];
|
||||
if (s) {
|
||||
@ -110,14 +95,6 @@ router
|
||||
if (!arr.data.ip) return n('ERR0010');
|
||||
if (!arr.data.password) return n('ERR0017');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select count(*) as num from ??.?? where `temporary` = '0' ";
|
||||
let param = [config.db.db1, 'leonelist'];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -150,14 +127,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete from ??.?? where `leonelistuid` = ? ";
|
||||
let param = [config.db.db1, 'leonelist', arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -177,14 +146,6 @@ router
|
||||
if (!arr.data.name) return n("ERR0026");
|
||||
if (!arr.data.password) return n('ERR0017');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "update ??.?? set \
|
||||
`leonename` = ?,\
|
||||
`leonepassword` = ?,\
|
||||
@ -220,14 +181,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id || !Array.isArray(arr.data.id)) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let ids = [];
|
||||
for (var i in arr.data.id) {
|
||||
let t = arr.data.id[i];
|
||||
@ -262,14 +215,6 @@ router
|
||||
if (!config.permission.leone) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete from ??.?? where `temporary` = '1'";
|
||||
let param = [config.db.db1, 'leonelist'];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
|
@ -12,14 +12,6 @@ router
|
||||
.post('/getlinklist', (req, res, n) => {
|
||||
if (!config.permission.link) return n('ERR9000');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db8;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? \
|
||||
where \
|
||||
`jcioclntuid` not in ( \
|
||||
@ -50,14 +42,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db8;
|
||||
res.db.connect();
|
||||
|
||||
res.api_res = {
|
||||
record: [{ root: arr.data.id }],
|
||||
rt: {
|
||||
@ -123,14 +107,6 @@ router
|
||||
if (!('active' in arr.data)) return n('ERR0032');
|
||||
if (!arr.data.action) return n('ERR0030');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db8;
|
||||
res.db.connect();
|
||||
|
||||
! function runLoop(unit, cb) {
|
||||
if (typeof unit != 'object' || Object.keys(unit).length == 0) return cb(0);
|
||||
if (unit.type == 'ln') {
|
||||
@ -204,14 +180,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db8;
|
||||
res.db.connect();
|
||||
|
||||
let query = "update ??.?? set \
|
||||
`lnactive` = (case when `lnactive` = 1 then 0 else 1 end), \
|
||||
`lnmodtst` = unix_timestamp() \
|
||||
@ -237,14 +205,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db8;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select ??.??(?) as ids";
|
||||
let param = [config.db.db8, 'getLink', arr.data.id];
|
||||
|
||||
|
@ -2,7 +2,7 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const rt = require('../ResTool');
|
||||
const config = require('../../config.json');
|
||||
const mysql = require('../../libs/mysql_cls');
|
||||
const mysql = require('../../libs/mysql_pool');
|
||||
const tool = require('../../includes/apiTool');
|
||||
|
||||
router
|
||||
@ -15,19 +15,11 @@ router
|
||||
let p = arr.data && arr.data.p && isFinite(arr.data.p) && arr.data.p > 0 ? arr.data.p : 1;
|
||||
let per = arr.data && arr.data.perpage && isFinite(arr.data.perpage) && arr.data.perpage > 0 ? arr.data.perpage : config.perpage;
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db2;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select count(*) as num from ??.??";
|
||||
let param = [config.db.db2, 'jciocert'];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if(err || row.length == 0) return n('ERR0023');
|
||||
let page = res.db.recordPage(row[0].num, p, per);
|
||||
let page = mysql.recordPage(row[0].num, p, per);
|
||||
|
||||
let query = "select * from ??.?? order by `ioeventtst` desc ";
|
||||
let limit = ` limit ${page.rec_start} , ${per} `;
|
||||
|
@ -14,14 +14,6 @@ router
|
||||
.post('/getmodbuslist', (req, res, n) => {
|
||||
if (!config.permission.modbus) return n('ERR9000');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? order by `uid` desc";
|
||||
let param = [config.db.db5, 'device'];
|
||||
|
||||
@ -42,14 +34,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? where `uid` = ?";
|
||||
let param = [config.db.db5, 'device', arr.data.id];
|
||||
|
||||
@ -93,14 +77,6 @@ router
|
||||
.post('/getporttype', (req, res, n) => {
|
||||
if (!config.permission.modbus) return n('ERR9000');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? order by `uid` ";
|
||||
let param = [config.db.db5, 'porttype'];
|
||||
|
||||
@ -120,14 +96,6 @@ router
|
||||
if (!arr.data.name) return n('ERR0026');
|
||||
if (!('node' in arr.data)) return n('ERR0038');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let u = '';
|
||||
let obj = so.get(req.headers['x-auth-token']);
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
|
||||
@ -154,14 +122,6 @@ router
|
||||
if (!arr.data.name) return n('ERR0026');
|
||||
if (!('node' in arr.data) || !('original_node' in arr.data)) return n('ERR0038');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select count(*) as num from ??.?? where `node` = ? and `uid` != ?";
|
||||
let param = [config.db.db5, 'device', arr.data.node, arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -202,14 +162,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete d,i,s,rt from ??.?? d \
|
||||
left join ??.?? i \
|
||||
on d.`uid` = i.`devuid` \
|
||||
@ -235,14 +187,6 @@ router
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
if (!arr.data.type) return n('ERR0009');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select rt.*, a.`name` as name from ??.?? rt \
|
||||
left join ??.?? d \
|
||||
on d.`node` = rt.`node` \
|
||||
@ -272,14 +216,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? where `uid` = ? ";
|
||||
let param = [config.db.db5, 'iolist', arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -302,14 +238,6 @@ router
|
||||
if (!arr.data.addr) return n('ERR0048');
|
||||
if (!arr.data.num) return n('ERR0049');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select count(*) as c from ??.?? \
|
||||
where \
|
||||
`devuid` = ? \
|
||||
@ -342,14 +270,6 @@ router
|
||||
if (!arr.data.addr) return n('ERR0048');
|
||||
if (!arr.data.num) return n('ERR0049');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select count(*) as c from ??.?? i \
|
||||
left join ??.?? i2 \
|
||||
on i2.`type` = i.`type` \
|
||||
@ -388,14 +308,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete i, a from ??.?? i \
|
||||
left join ??.?? a \
|
||||
on a.`iouid` = i.`uid` \
|
||||
@ -417,14 +329,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select a.* from ??.?? a \
|
||||
left join ??.?? i \
|
||||
on a.`iouid` = i.`uid` \
|
||||
@ -446,14 +350,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? where `uid` = ?";
|
||||
let param = [config.db.db5, 'aioset', arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -472,14 +368,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete from ??.?? where `uid` = ?";
|
||||
let param = [config.db.db5, 'aioset', arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -503,14 +391,6 @@ router
|
||||
if (!('scale_min' in arr.data)) return n('ERR0052');
|
||||
if (!('scale_max' in arr.data)) return n('ERR0053');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select count(*) as count from ??.?? where `iouid` = ? and `portnum` = ?";
|
||||
let param = [config.db.db5, 'aioset', arr.data.iouid, arr.data.portnum];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -546,14 +426,6 @@ router
|
||||
if (!('scale_min' in arr.data)) return n('ERR0052');
|
||||
if (!('scale_max' in arr.data)) return n('ERR0053');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db5;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select count(*) as count from ??.?? \
|
||||
where \
|
||||
`iouid` = ? \
|
||||
|
@ -23,14 +23,6 @@ router
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
}
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? ";
|
||||
let order = " order by `ioscheduleuid` desc ";
|
||||
let param = [config.db.db1, 'ioschedulet'];
|
||||
@ -116,14 +108,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete from ??.?? where `ioscheduleuid` = ? ";
|
||||
let param = [config.db.db1, 'ioschedulet', arr.data.id];
|
||||
|
||||
@ -145,14 +129,6 @@ router
|
||||
|
||||
// let active = arr.data.active == 1 ? 1 : 0;
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "update ??.?? set `ioscheduleactive` = (case when `ioscheduleactive` = '1' then '0' else '1' end) where `ioscheduleuid` = ? ";
|
||||
let param = [config.db.db1, 'ioschedulet', arr.data.id];
|
||||
|
||||
@ -184,14 +160,6 @@ router
|
||||
let tmp = arr.data.action.split(',');
|
||||
if (tmp.length != 2) return n('ERR0030');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let active = arr.data.active == 1 ? 1 : 0;
|
||||
|
||||
let d = '';
|
||||
@ -249,14 +217,6 @@ router
|
||||
let tmp = arr.data.action.split(',');
|
||||
if (tmp.length != 2) return n('ERR0030');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let active = arr.data.active == 1 ? 1 : 0;
|
||||
|
||||
let d = '';
|
||||
|
@ -101,14 +101,6 @@ router
|
||||
if (!arr.data.account) return n('ERR0016');
|
||||
if (!arr.data.password) return n('ERR0017');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.?? where `account` = ? and `user_password` = ?";
|
||||
res.db.query(query, [config.db.db1, 'userlist', arr.data.account, arr.data.password], (err, row) => {
|
||||
if (err) return n('ERR8000');
|
||||
@ -159,13 +151,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.account) return n('ERR0016');
|
||||
}
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "select * from ??.??";
|
||||
let param = [config.db.db1, 'userlist']
|
||||
@ -195,14 +180,6 @@ router
|
||||
if (!arr.data.account) return n('ERR0016');
|
||||
if (arr.data.account == 'admin') return n('ERR0037');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "delete from ??.?? where `account` = ?";
|
||||
let param = [config.db.db1, 'userlist', arr.data.account];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
@ -229,14 +206,6 @@ router
|
||||
r = 1;
|
||||
}
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "update ??.?? set `write_privilege` = ? , `read_privilege` = ? " +
|
||||
(pass.length > 0 ? " , `user_password` = ? " : "") + " where `account` = ? ";
|
||||
let param = [config.db.db1, 'userlist', w.toString(), r.toString()];
|
||||
@ -261,14 +230,6 @@ router
|
||||
let w = arr.data.write_privilege && arr.data.write_privilege == '1' ? 1 : 0;
|
||||
let r = arr.data.read_privilege && arr.data.read_privilege == '1' ? 1 : 0;
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
let query = "insert into ??.?? (`account`,`user_password`,`write_privilege`,`read_privilege`,`user_add_date`) values (?,?,?,?,unix_timestamp())";
|
||||
let param = [config.db.db1, 'userlist', arr.data.account, arr.data.password, w.toString(), r.toString()];
|
||||
|
||||
@ -282,14 +243,7 @@ router
|
||||
});
|
||||
})
|
||||
.post('/dashboard', (req, res, n) => {
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
|
||||
let data = {
|
||||
record: [],
|
||||
rt: {}
|
||||
@ -399,14 +353,6 @@ router
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.type) return n('ERR0009');
|
||||
|
||||
res.db = new mysql();
|
||||
res.db.user = config.db.user;
|
||||
res.db.password = config.db.pass;
|
||||
res.db.host = config.db.host;
|
||||
res.db.port = config.db.port;
|
||||
res.db.database = config.db.db1;
|
||||
res.db.connect();
|
||||
|
||||
res.api_res = {
|
||||
record: []
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user