doomiwork 3.0.0 → 3.1.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 +19 -1
- package/package.json +1 -1
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,12 +43,17 @@ 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
|
+
that.logError(null,'无可用数据库链接池')
|
|
50
|
+
return failed(apiResult.DB_CONNECTED_FAILED);
|
|
51
|
+
}
|
|
36
52
|
///创建出数据库连接,准备执行
|
|
37
53
|
this.pool.getConnection(function (err, connection) {
|
|
38
54
|
if (err) {
|
|
39
55
|
logger.error("Database Connected Failed :"+ err);
|
|
56
|
+
that.logError(null, '数据库连接错误:' + err)
|
|
40
57
|
return failed(apiResult.DB_CONNECTED_FAILED);
|
|
41
58
|
}
|
|
42
59
|
else {
|
|
@@ -45,6 +62,7 @@ class Database {
|
|
|
45
62
|
connection.release();
|
|
46
63
|
if (err) {
|
|
47
64
|
logger.error("Database Query Error :" + err, sqlCommand);
|
|
65
|
+
that.logError(null, '数据库操作错误:' + err + sqlCommand)
|
|
48
66
|
return success(Object.assign(apiResult.DB_EXECUTE_FAILED, { errmessage: err.message }));
|
|
49
67
|
}
|
|
50
68
|
return success({ successed: true, rows: rows });//,fields:fields});
|