change mysql connection to connection pool

This commit is contained in:
Jay 2017-03-27 17:32:25 +08:00
parent 404fb8c346
commit 493dd36e18
13 changed files with 29 additions and 425 deletions

View File

@ -64,5 +64,6 @@
"ERR8001": "資料新增失敗", "ERR8001": "資料新增失敗",
"ERR8002": "資料更新失敗", "ERR8002": "資料更新失敗",
"ERR8003": "資料刪除失敗", "ERR8003": "資料刪除失敗",
"ERR8100": "DB連線失敗",
"ERR9000": "操作權限不足" "ERR9000": "操作權限不足"
} }

View File

@ -2,6 +2,7 @@ const errList = require('../includes/errorManager');
function send(req, res) { 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' && '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 lngs = req.headers['accept-language'].split(',');
let lng = null; let lng = null;

View File

@ -3,7 +3,7 @@ const router = express.Router();
const rt = require('../ResTool'); const rt = require('../ResTool');
const config = require('../../config.json'); const config = require('../../config.json');
const fs = require('fs'); const fs = require('fs');
const mysql = require('../../libs/mysql_cls'); const mysql = require('../../libs/mysql_pool');
const tool = require('../../includes/apiTool'); const tool = require('../../includes/apiTool');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const so = require('../../includes/storeObject'); const so = require('../../includes/storeObject');
@ -65,7 +65,7 @@ router
}) })
.catch(e => n()); .catch(e => n());
}) })
.post('/dotrun', (req, res, n) => { .post('/dotrun', (req, res, n) => {
if (!config.permission.dio) return n('ERR9000'); if (!config.permission.dio) return n('ERR9000');
let arr = req.body; let arr = req.body;
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
@ -77,14 +77,6 @@ router
record: [] 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 obj = so.get(req.headers['x-auth-token']);
let u = ''; let u = '';
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account; 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'); 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 q = "select * from ??.??";
let pdi = tool.promiseQuery(res, q, [config.db.db1, 'dilist'], 'di'); let pdi = tool.promiseQuery(res, q, [config.db.db1, 'dilist'], 'di');
let pdo = tool.promiseQuery(res, q, [config.db.db1, 'dolist'], 'do'); let pdo = tool.promiseQuery(res, q, [config.db.db1, 'dolist'], 'do');
@ -146,14 +130,6 @@ router
record: [] 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 query = "update ??.?? set ?? = unix_timestamp() , ";
let sub = " ?? = case ?? "; let sub = " ?? = case ?? ";
let dos = []; let dos = [];

View File

@ -2,12 +2,13 @@ const express = require('express');
const router = express.Router(); const router = express.Router();
const errMng = require('../../includes/errorManager'); const errMng = require('../../includes/errorManager');
const so = require('../../includes/storeObject'); const so = require('../../includes/storeObject');
const mysql = require('../../libs/mysql_pool');
router router
.get('/', (req, res) => { .get('/', (req, res) => {
res.send({ name: 'WebIO API System' }); res.send({ name: 'WebIO API System' });
}) })
.all('*', (req,res,n)=>{ .all('*', async(req,res,n)=>{
if('x-auth-token' in req.headers) { if('x-auth-token' in req.headers) {
let token = req.headers['x-auth-token']; let token = req.headers['x-auth-token'];
if(so.chkKey(token)){ if(so.chkKey(token)){
@ -17,6 +18,11 @@ router
} }
} }
} }
try{
res.db = await mysql.getConn();
}catch(e){
return n('ERR8100');
}
n(); n();
}) })
.get('/showallso', (req,res)=>{ .get('/showallso', (req,res)=>{
@ -36,6 +42,7 @@ router
// api error handler // api error handler
router.use((err, req, res, n) => { 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' && '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 lngs = req.headers['accept-language'].split(',');
let lng = null; let lng = null;

View File

@ -30,15 +30,6 @@ router
data.record = []; data.record = [];
res.api_res = data; 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 dos = [];
let les = []; let les = [];
let ios = []; let ios = [];

View File

@ -19,14 +19,6 @@ router
if (!arr.data.id) return n('ERR0028'); 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 query = "select * from ??.?? ";
let order = " order by `iogroupuid` desc "; let order = " order by `iogroupuid` desc ";
let param = [config.db.db1, 'iogroup']; let param = [config.db.db1, 'iogroup'];
@ -99,14 +91,6 @@ router
if (!arr.data.name) return n('ERR0026'); if (!arr.data.name) return n('ERR0026');
if (!arr.data.devs) return n('ERR0029'); 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 query = "insert into ??.?? (`iogroupname`,`iogroupid`,`iogroup_add_date`) values (?, ?, unix_timestamp())";
let param = [config.db.db1, 'iogroup', arr.data.name, arr.data.devs]; 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.name) return n('ERR0026');
if (!arr.data.devs) return n('ERR0029'); 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 \ let query = "update ??.?? set \
`iogroupname` = ?, \ `iogroupname` = ?, \
`iogroupid` = ?, \ `iogroupid` = ?, \
@ -159,14 +135,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "delete from ??.?? where `iogroupuid` = ? ";
let param = [config.db.db1, 'iogroup', arr.data.id]; let param = [config.db.db1, 'iogroup', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {

View File

@ -24,38 +24,23 @@ router
.post('/getipcamlist', async (req,res,n) => { .post('/getipcamlist', async (req,res,n) => {
if(!config.permission.ipcam) return n('ERR9000'); 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{ try{
res.pdb = await mysql.getConn(); res.db = 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();
})
}catch(e){ }catch(e){
return n('ERR8100'); 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) => { .post('/addipcam', (req,res,n) => {
if(!config.permission.ipcam) return n('ERR9000'); if(!config.permission.ipcam) return n('ERR9000');

View File

@ -38,13 +38,6 @@ router
! function chkEnd() { ! function chkEnd() {
fs.exists(config.cmdpath.scanleone_end, exists => { fs.exists(config.cmdpath.scanleone_end, exists => {
if (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 query = "select `leonename`, `leoneip`, `leonelistuid` from ??.?? where `temporary` = '1' ";
let param = [config.db.db1, 'leonelist']; let param = [config.db.db1, 'leonelist'];
@ -73,14 +66,6 @@ router
if (!arr.data.id) return n('ERR0028'); 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 query = "select * from ??.?? where `temporary` = '0' ";
let param = [config.db.db1, 'leonelist']; let param = [config.db.db1, 'leonelist'];
if (s) { if (s) {
@ -110,14 +95,6 @@ router
if (!arr.data.ip) return n('ERR0010'); if (!arr.data.ip) return n('ERR0010');
if (!arr.data.password) return n('ERR0017'); 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 query = "select count(*) as num from ??.?? where `temporary` = '0' ";
let param = [config.db.db1, 'leonelist']; let param = [config.db.db1, 'leonelist'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -150,14 +127,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "delete from ??.?? where `leonelistuid` = ? ";
let param = [config.db.db1, 'leonelist', arr.data.id]; let param = [config.db.db1, 'leonelist', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -177,14 +146,6 @@ router
if (!arr.data.name) return n("ERR0026"); if (!arr.data.name) return n("ERR0026");
if (!arr.data.password) return n('ERR0017'); 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 \ let query = "update ??.?? set \
`leonename` = ?,\ `leonename` = ?,\
`leonepassword` = ?,\ `leonepassword` = ?,\
@ -220,14 +181,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id || !Array.isArray(arr.data.id)) return n('ERR0028'); 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 = []; let ids = [];
for (var i in arr.data.id) { for (var i in arr.data.id) {
let t = arr.data.id[i]; let t = arr.data.id[i];
@ -262,14 +215,6 @@ router
if (!config.permission.leone) return n('ERR9000'); if (!config.permission.leone) return n('ERR9000');
if (!tool.checkPermission(req)) 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 query = "delete from ??.?? where `temporary` = '1'";
let param = [config.db.db1, 'leonelist']; let param = [config.db.db1, 'leonelist'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {

View File

@ -12,14 +12,6 @@ router
.post('/getlinklist', (req, res, n) => { .post('/getlinklist', (req, res, n) => {
if (!config.permission.link) return n('ERR9000'); 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 ??.?? \ let query = "select * from ??.?? \
where \ where \
`jcioclntuid` not in ( \ `jcioclntuid` not in ( \
@ -50,14 +42,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 = { res.api_res = {
record: [{ root: arr.data.id }], record: [{ root: arr.data.id }],
rt: { rt: {
@ -123,14 +107,6 @@ router
if (!('active' in arr.data)) return n('ERR0032'); if (!('active' in arr.data)) return n('ERR0032');
if (!arr.data.action) return n('ERR0030'); 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) { ! function runLoop(unit, cb) {
if (typeof unit != 'object' || Object.keys(unit).length == 0) return cb(0); if (typeof unit != 'object' || Object.keys(unit).length == 0) return cb(0);
if (unit.type == 'ln') { if (unit.type == 'ln') {
@ -204,14 +180,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 \ let query = "update ??.?? set \
`lnactive` = (case when `lnactive` = 1 then 0 else 1 end), \ `lnactive` = (case when `lnactive` = 1 then 0 else 1 end), \
`lnmodtst` = unix_timestamp() \ `lnmodtst` = unix_timestamp() \
@ -237,14 +205,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "select ??.??(?) as ids";
let param = [config.db.db8, 'getLink', arr.data.id]; let param = [config.db.db8, 'getLink', arr.data.id];

View File

@ -2,7 +2,7 @@ const express = require('express');
const router = express.Router(); const router = express.Router();
const rt = require('../ResTool'); const rt = require('../ResTool');
const config = require('../../config.json'); const config = require('../../config.json');
const mysql = require('../../libs/mysql_cls'); const mysql = require('../../libs/mysql_pool');
const tool = require('../../includes/apiTool'); const tool = require('../../includes/apiTool');
router 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 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; 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 query = "select count(*) as num from ??.??";
let param = [config.db.db2, 'jciocert']; let param = [config.db.db2, 'jciocert'];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
if(err || row.length == 0) return n('ERR0023'); 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 query = "select * from ??.?? order by `ioeventtst` desc ";
let limit = ` limit ${page.rec_start} , ${per} `; let limit = ` limit ${page.rec_start} , ${per} `;

View File

@ -14,14 +14,6 @@ router
.post('/getmodbuslist', (req, res, n) => { .post('/getmodbuslist', (req, res, n) => {
if (!config.permission.modbus) return n('ERR9000'); 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 query = "select * from ??.?? order by `uid` desc";
let param = [config.db.db5, 'device']; let param = [config.db.db5, 'device'];
@ -42,14 +34,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "select * from ??.?? where `uid` = ?";
let param = [config.db.db5, 'device', arr.data.id]; let param = [config.db.db5, 'device', arr.data.id];
@ -93,14 +77,6 @@ router
.post('/getporttype', (req, res, n) => { .post('/getporttype', (req, res, n) => {
if (!config.permission.modbus) return n('ERR9000'); 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 query = "select * from ??.?? order by `uid` ";
let param = [config.db.db5, 'porttype']; let param = [config.db.db5, 'porttype'];
@ -120,14 +96,6 @@ router
if (!arr.data.name) return n('ERR0026'); if (!arr.data.name) return n('ERR0026');
if (!('node' in arr.data)) return n('ERR0038'); 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 u = '';
let obj = so.get(req.headers['x-auth-token']); let obj = so.get(req.headers['x-auth-token']);
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account; 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 (!arr.data.name) return n('ERR0026');
if (!('node' in arr.data) || !('original_node' in arr.data)) return n('ERR0038'); 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 query = "select count(*) as num from ??.?? where `node` = ? and `uid` != ?";
let param = [config.db.db5, 'device', arr.data.node, arr.data.id]; let param = [config.db.db5, 'device', arr.data.node, arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -202,14 +162,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 \ let query = "delete d,i,s,rt from ??.?? d \
left join ??.?? i \ left join ??.?? i \
on d.`uid` = i.`devuid` \ on d.`uid` = i.`devuid` \
@ -235,14 +187,6 @@ router
if (!arr.data.id) return n('ERR0028'); if (!arr.data.id) return n('ERR0028');
if (!arr.data.type) return n('ERR0009'); 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 \ let query = "select rt.*, a.`name` as name from ??.?? rt \
left join ??.?? d \ left join ??.?? d \
on d.`node` = rt.`node` \ on d.`node` = rt.`node` \
@ -272,14 +216,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "select * from ??.?? where `uid` = ? ";
let param = [config.db.db5, 'iolist', arr.data.id]; let param = [config.db.db5, 'iolist', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -302,14 +238,6 @@ router
if (!arr.data.addr) return n('ERR0048'); if (!arr.data.addr) return n('ERR0048');
if (!arr.data.num) return n('ERR0049'); 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 ??.?? \ let query = "select count(*) as c from ??.?? \
where \ where \
`devuid` = ? \ `devuid` = ? \
@ -342,14 +270,6 @@ router
if (!arr.data.addr) return n('ERR0048'); if (!arr.data.addr) return n('ERR0048');
if (!arr.data.num) return n('ERR0049'); 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 \ let query = "select count(*) as c from ??.?? i \
left join ??.?? i2 \ left join ??.?? i2 \
on i2.`type` = i.`type` \ on i2.`type` = i.`type` \
@ -388,14 +308,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 \ let query = "delete i, a from ??.?? i \
left join ??.?? a \ left join ??.?? a \
on a.`iouid` = i.`uid` \ on a.`iouid` = i.`uid` \
@ -417,14 +329,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 \ let query = "select a.* from ??.?? a \
left join ??.?? i \ left join ??.?? i \
on a.`iouid` = i.`uid` \ on a.`iouid` = i.`uid` \
@ -446,14 +350,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "select * from ??.?? where `uid` = ?";
let param = [config.db.db5, 'aioset', arr.data.id]; let param = [config.db.db5, 'aioset', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -472,14 +368,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "delete from ??.?? where `uid` = ?";
let param = [config.db.db5, 'aioset', arr.data.id]; let param = [config.db.db5, 'aioset', arr.data.id];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -503,14 +391,6 @@ router
if (!('scale_min' in arr.data)) return n('ERR0052'); if (!('scale_min' in arr.data)) return n('ERR0052');
if (!('scale_max' in arr.data)) return n('ERR0053'); 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 query = "select count(*) as count from ??.?? where `iouid` = ? and `portnum` = ?";
let param = [config.db.db5, 'aioset', arr.data.iouid, arr.data.portnum]; let param = [config.db.db5, 'aioset', arr.data.iouid, arr.data.portnum];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -546,14 +426,6 @@ router
if (!('scale_min' in arr.data)) return n('ERR0052'); if (!('scale_min' in arr.data)) return n('ERR0052');
if (!('scale_max' in arr.data)) return n('ERR0053'); 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 ??.?? \ let query = "select count(*) as count from ??.?? \
where \ where \
`iouid` = ? \ `iouid` = ? \

View File

@ -23,14 +23,6 @@ router
if (!arr.data.id) return n('ERR0028'); 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 query = "select * from ??.?? ";
let order = " order by `ioscheduleuid` desc "; let order = " order by `ioscheduleuid` desc ";
let param = [config.db.db1, 'ioschedulet']; let param = [config.db.db1, 'ioschedulet'];
@ -116,14 +108,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028'); 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 query = "delete from ??.?? where `ioscheduleuid` = ? ";
let param = [config.db.db1, 'ioschedulet', arr.data.id]; let param = [config.db.db1, 'ioschedulet', arr.data.id];
@ -145,14 +129,6 @@ router
// let active = arr.data.active == 1 ? 1 : 0; // 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 query = "update ??.?? set `ioscheduleactive` = (case when `ioscheduleactive` = '1' then '0' else '1' end) where `ioscheduleuid` = ? ";
let param = [config.db.db1, 'ioschedulet', arr.data.id]; let param = [config.db.db1, 'ioschedulet', arr.data.id];
@ -184,14 +160,6 @@ router
let tmp = arr.data.action.split(','); let tmp = arr.data.action.split(',');
if (tmp.length != 2) return n('ERR0030'); 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 active = arr.data.active == 1 ? 1 : 0;
let d = ''; let d = '';
@ -249,14 +217,6 @@ router
let tmp = arr.data.action.split(','); let tmp = arr.data.action.split(',');
if (tmp.length != 2) return n('ERR0030'); 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 active = arr.data.active == 1 ? 1 : 0;
let d = ''; let d = '';

View File

@ -101,14 +101,6 @@ router
if (!arr.data.account) return n('ERR0016'); if (!arr.data.account) return n('ERR0016');
if (!arr.data.password) return n('ERR0017'); 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` = ?"; 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) => { res.db.query(query, [config.db.db1, 'userlist', arr.data.account, arr.data.password], (err, row) => {
if (err) return n('ERR8000'); if (err) return n('ERR8000');
@ -159,13 +151,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.account) return n('ERR0016'); 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 query = "select * from ??.??";
let param = [config.db.db1, 'userlist'] let param = [config.db.db1, 'userlist']
@ -195,14 +180,6 @@ router
if (!arr.data.account) return n('ERR0016'); if (!arr.data.account) return n('ERR0016');
if (arr.data.account == 'admin') return n('ERR0037'); 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 query = "delete from ??.?? where `account` = ?";
let param = [config.db.db1, 'userlist', arr.data.account]; let param = [config.db.db1, 'userlist', arr.data.account];
res.db.query(query, param, (err, row) => { res.db.query(query, param, (err, row) => {
@ -229,14 +206,6 @@ router
r = 1; 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` = ? " + let query = "update ??.?? set `write_privilege` = ? , `read_privilege` = ? " +
(pass.length > 0 ? " , `user_password` = ? " : "") + " where `account` = ? "; (pass.length > 0 ? " , `user_password` = ? " : "") + " where `account` = ? ";
let param = [config.db.db1, 'userlist', w.toString(), r.toString()]; 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 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; 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 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()]; let param = [config.db.db1, 'userlist', arr.data.account, arr.data.password, w.toString(), r.toString()];
@ -282,13 +243,6 @@ router
}); });
}) })
.post('/dashboard', (req, res, n) => { .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 = { let data = {
record: [], record: [],
@ -399,14 +353,6 @@ router
if (!arr.data) return n('ERR0000'); if (!arr.data) return n('ERR0000');
if (!arr.data.type) return n('ERR0009'); 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 = { res.api_res = {
record: [] record: []
}; };