prj_logger.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {PrjLogs} from "@core-models/PrjLogs";
  2. import {IdGen} from "@util/IdGen";
  3. import {Transaction} from "sequelize";
  4. export interface IPrjLogInfo {
  5. creator_id: string;
  6. creator_name: string;
  7. prj_id: string;
  8. task_id?:string;
  9. content: string;
  10. old_content?:string;
  11. t?: Transaction;
  12. }
  13. export class PrjLogger {
  14. static async log(info: IPrjLogInfo) {
  15. await PrjLogs.create({
  16. id: IdGen.id(),
  17. ts: new Date().getTime(),
  18. creator_id: info.creator_id,
  19. creator_name: info.creator_name,
  20. content: info.content,
  21. prj_id: info.prj_id,
  22. task_id: info.task_id
  23. }, {transaction: <any>info.t});
  24. }
  25. static async removed(info: IPrjLogInfo) {
  26. info.content = `删除了: <span style="color: red;"><del>${info.content}</del></span>`;
  27. await PrjLogger.log(info);
  28. }
  29. static async added(info: IPrjLogInfo) {
  30. info.content = `添加了: <span style="color: green;"><ins>${info.content}</ins></span>`;
  31. await PrjLogger.log(info);
  32. }
  33. static async created(info: IPrjLogInfo) {
  34. info.content = `创建了: <span style="color: green;"><ins>${info.content}</ins></span>`;
  35. await PrjLogger.log(info);
  36. }
  37. static async updated(info: IPrjLogInfo) {
  38. /// 以修改了: <旧内容>-><新内容>的格式生成日志内容
  39. if (info.old_content) {
  40. info.content = `修改了: <span style="color: red;">${info.old_content}</span>-><span style="color: blue;">${info.content}</span>`;
  41. } else {
  42. info.content = `修改了: ${info.content}`;
  43. }
  44. await PrjLogger.log(info);
  45. }
  46. static async status_changed(info: IPrjLogInfo) {
  47. info.content = `状态变更为: <span style="color: blue;">${info.content}</span>`;
  48. await PrjLogger.log(info);
  49. }
  50. }