|
@@ -0,0 +1,46 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+ class GlobalLog extends app.BaseService {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx);
|
|
|
+ this.tableName = 'global_log';
|
|
|
+ }
|
|
|
+
|
|
|
+ async requestLog() {
|
|
|
+ if (!this.ctx.session) return;
|
|
|
+
|
|
|
+ await this.db.insert(this.tableName, {
|
|
|
+ id: this.ctx.logId,
|
|
|
+ project_id: this.ctx.session.sessionProject.id,
|
|
|
+ project_code: this.ctx.session.sessionProject.code,
|
|
|
+ user_id: this.ctx.session.sessionUser.accountId,
|
|
|
+ user_name: this.ctx.session.sessionUser.name,
|
|
|
+ url: this.ctx.url,
|
|
|
+ method: this.ctx.method,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async responseLog(runTime){
|
|
|
+ if (!this.ctx.session) return;
|
|
|
+
|
|
|
+ await this.defaultUpdate({ id: this.ctx.logId, is_response: 1, run_time: runTime });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return GlobalLog;
|
|
|
+};
|