12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 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: <any>info.t});
- }
- static async removed(info: IPrjLogInfo) {
- info.content = `删除了: <span style="color: red;"><del>${info.content}</del></span>`;
- await PrjLogger.log(info);
- }
- static async added(info: IPrjLogInfo) {
- info.content = `添加了: <span style="color: green;"><ins>${info.content}</ins></span>`;
- await PrjLogger.log(info);
- }
- static async created(info: IPrjLogInfo) {
- info.content = `创建了: <span style="color: green;"><ins>${info.content}</ins></span>`;
- await PrjLogger.log(info);
- }
- static async updated(info: IPrjLogInfo) {
- /// 以修改了: <旧内容>-><新内容>的格式生成日志内容
- if (info.old_content) {
- info.content = `修改了: <span style="color: red;">${info.old_content}</span>-><span style="color: blue;">${info.content}</span>`;
- } else {
- info.content = `修改了: ${info.content}`;
- }
- await PrjLogger.log(info);
- }
- static async status_changed(info: IPrjLogInfo) {
- info.content = `状态变更为: <span style="color: blue;">${info.content}</span>`;
- await PrjLogger.log(info);
- }
- }
|