import {PrjLogs} from "@core-models/PrjLogs"; import {IdGen} from "@util/IdGen"; import {Transaction} from "sequelize"; export interface IPrjLogInfo { creator_id: string; creator_name: string; prj_id: string; task_id?:string; content: string; old_content?:string; t?: Transaction; } export class PrjLogger { static async log(info: IPrjLogInfo) { await PrjLogs.create({ id: IdGen.id(), ts: new Date().getTime(), creator_id: info.creator_id, creator_name: info.creator_name, content: info.content, prj_id: info.prj_id, task_id: info.task_id }, {transaction: info.t}); } static async removed(info: IPrjLogInfo) { info.content = `删除了: ${info.content}`; await PrjLogger.log(info); } static async added(info: IPrjLogInfo) { info.content = `添加了: ${info.content}`; await PrjLogger.log(info); } static async created(info: IPrjLogInfo) { info.content = `创建了: ${info.content}`; await PrjLogger.log(info); } static async updated(info: IPrjLogInfo) { /// 以修改了: <旧内容>-><新内容>的格式生成日志内容 if (info.old_content) { info.content = `修改了: ${info.old_content}->${info.content}`; } else { info.content = `修改了: ${info.content}`; } await PrjLogger.log(info); } static async status_changed(info: IPrjLogInfo) { info.content = `状态变更为: ${info.content}`; await PrjLogger.log(info); } }