'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'; } getRptTplInfo(data) { if (!data || !data.params) return ''; try { const params = JSON.parse(data.params); return JSON.stringify({ rpt_tpl_id: params.rpt_tpl_id, project_id: params.project_id, tender_id: params.tender_id, stage_id: params.stage_id }); } catch(err) { return ''; } } getMemo(url, data) { if (url.indexOf('report_api/getReport') === -1) return ''; return this.getRptTplInfo(data); } async requestLog() { if (!this.ctx.session || !this.ctx.session.sessionProject || !this.ctx.session.sessionUser) 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, memo: this.getMemo(this.ctx.url, this.ctx.request.body), }); } async responseLog(runTime){ if (!this.ctx.session || !this.ctx.session.sessionProject || !this.ctx.session.sessionUser) return; await this.defaultUpdate({ id: this.ctx.logId, is_response: 1, run_time: runTime }); } } return GlobalLog; };