doomiwork 2.9.5 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/controller.js +1 -1
- package/core/database/mysqlbase.js +20 -4
- package/package.json +1 -1
- package/utilities/requestparser.js +11 -2
package/core/controller.js
CHANGED
|
@@ -29,7 +29,7 @@ class controller {
|
|
|
29
29
|
this.actionLogger = application.actionLogger;
|
|
30
30
|
///需要数据访问实体的实例
|
|
31
31
|
this._daoModel = dao?dao:new daoBase();
|
|
32
|
-
|
|
32
|
+
this._daoModel.actionLogger = this.actionLogger;
|
|
33
33
|
this._router = express.Router();
|
|
34
34
|
///实现的集成类中只需要去重写此方法
|
|
35
35
|
this.initializeRouter(this);
|
|
@@ -24,6 +24,18 @@ class Database {
|
|
|
24
24
|
escape(value){
|
|
25
25
|
return mysql.escape(value);
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* 记录错误日志
|
|
29
|
+
*/
|
|
30
|
+
logError(scene,error,user=null){
|
|
31
|
+
///不需要记录错误日志
|
|
32
|
+
if (this.ingoreErrorLog === true || !this.actionLogger || typeof (this.actionLogger.logError)!=='function'){
|
|
33
|
+
return ;
|
|
34
|
+
}
|
|
35
|
+
///如果没有传场景,则记录数据库的业务值
|
|
36
|
+
if (!scene) scene = this.constructor.name;
|
|
37
|
+
this.actionLogger.logError({ scene, error, user})
|
|
38
|
+
}
|
|
27
39
|
/**
|
|
28
40
|
* 不事务执行SQL命令
|
|
29
41
|
* @param {*} sqlCommand
|
|
@@ -31,13 +43,16 @@ class Database {
|
|
|
31
43
|
*/
|
|
32
44
|
executeSql(sqlCommand, parameters) {
|
|
33
45
|
let logger = this.logger;
|
|
46
|
+
let that = this;
|
|
34
47
|
return new Promise((success, failed) => {
|
|
35
|
-
if (!this.pool)
|
|
48
|
+
if (!this.pool) {
|
|
49
|
+
return success(apiResult.DB_CONNECTED_FAILED);
|
|
50
|
+
}
|
|
36
51
|
///创建出数据库连接,准备执行
|
|
37
52
|
this.pool.getConnection(function (err, connection) {
|
|
38
53
|
if (err) {
|
|
39
54
|
logger.error("Database Connected Failed :"+ err);
|
|
40
|
-
return
|
|
55
|
+
return success(apiResult.DB_CONNECTED_FAILED);
|
|
41
56
|
}
|
|
42
57
|
else {
|
|
43
58
|
logger.trace("SqlCommand:", sqlCommand, "Parameters:", parameters);
|
|
@@ -45,6 +60,7 @@ class Database {
|
|
|
45
60
|
connection.release();
|
|
46
61
|
if (err) {
|
|
47
62
|
logger.error("Database Query Error :" + err, sqlCommand);
|
|
63
|
+
that.logError(null, '数据库操作错误:' + err + sqlCommand)
|
|
48
64
|
return success(Object.assign(apiResult.DB_EXECUTE_FAILED, { errmessage: err.message }));
|
|
49
65
|
}
|
|
50
66
|
return success({ successed: true, rows: rows });//,fields:fields});
|
|
@@ -62,12 +78,12 @@ class Database {
|
|
|
62
78
|
executeSqlWithTransaction(sqlCommand, parameters) {
|
|
63
79
|
let logger = this.logger;
|
|
64
80
|
return new Promise((success, failed) => {
|
|
65
|
-
if (!this.pool) return
|
|
81
|
+
if (!this.pool) return success(apiResult.DB_CONNECTED_FAILED);
|
|
66
82
|
///创建出数据库连接,准备执行
|
|
67
83
|
this.pool.getConnection(function (err, connection) {
|
|
68
84
|
if (err) {
|
|
69
85
|
logger.error("Database Connected Failed :"+ err);
|
|
70
|
-
return
|
|
86
|
+
return success(apiResult.DB_CONNECTED_FAILED);
|
|
71
87
|
}
|
|
72
88
|
logger.trace("SqlCommand:", sqlCommand, "Parameters:", parameters);
|
|
73
89
|
////开启事务保护
|
package/package.json
CHANGED
|
@@ -59,9 +59,18 @@ class RequestParser {
|
|
|
59
59
|
///确认是否是需要导出Excel
|
|
60
60
|
const export2Excel =(req.query.exportexcel+"").toLowerCase()==="true";
|
|
61
61
|
req.page = req.query.page || req.body.page|| 1;
|
|
62
|
-
req.pageSize = req.query.rows || req.body.rows ||
|
|
62
|
+
req.pageSize = req.query.rows || req.body.rows || 100;
|
|
63
63
|
req.sort = req.query.sort || req.body.sort;
|
|
64
|
-
|
|
64
|
+
//防止注入式Sql
|
|
65
|
+
if (isNaN(req.pageSize)){
|
|
66
|
+
req.pageSize = 30;
|
|
67
|
+
}
|
|
68
|
+
//防止注入式Sql
|
|
69
|
+
if (isNaN(req.page)) {
|
|
70
|
+
req.page = 1;
|
|
71
|
+
}
|
|
72
|
+
///最大允许获取100条数据
|
|
73
|
+
req.pageSize = Math.min(req.pageSize,100);
|
|
65
74
|
req.order =req.sort? utility.ifNull((req.body.order == null ? req.query.order : req.body.order), ""):'';
|
|
66
75
|
if (dataKey) {
|
|
67
76
|
req.dataConfig = dataconfig.getConfig(dataKey,cfgType);
|