change_project_history.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. /**
  3. * 变更新增部位插入记录表
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class ChangeProjectHistory extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'change_project_history';
  20. }
  21. async saveHistory(transaction, data) {
  22. await transaction.insert(this.tableName, {
  23. tid: data.tid,
  24. cpid: data.id,
  25. info_json: JSON.stringify(data),
  26. });
  27. }
  28. async returnHistory(transaction, cpid) {
  29. const data = await transaction.get(this.tableName, { cpid });
  30. if (!data) throw '撤销前数据不存在,无法撤销';
  31. const change_update = {};
  32. const oldInfo = JSON.parse(data.info_json);
  33. for (const key in oldInfo) {
  34. if (key !== 'in_time') {
  35. change_update[key] = oldInfo[key];
  36. }
  37. }
  38. await transaction.update(this.ctx.service.changeProject.tableName, change_update);
  39. }
  40. }
  41. return ChangeProjectHistory;
  42. };