123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 'use strict';
- /**
- * 变更新增部位插入记录表
- *
- * @author Mai
- * @date
- * @version
- */
- module.exports = app => {
- class ChangeProjectHistory extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'change_project_history';
- }
- async saveHistory(transaction, data) {
- await transaction.insert(this.tableName, {
- tid: data.tid,
- cpid: data.id,
- info_json: JSON.stringify(data),
- });
- }
- async returnHistory(transaction, cpid) {
- const data = await transaction.get(this.tableName, { cpid });
- if (!data) throw '撤销前数据不存在,无法撤销';
- const change_update = {};
- const oldInfo = JSON.parse(data.info_json);
- for (const key in oldInfo) {
- if (key !== 'in_time') {
- change_update[key] = oldInfo[key];
- }
- }
- await transaction.update(this.ctx.service.changeProject.tableName, change_update);
- }
- }
- return ChangeProjectHistory;
- };
|