|
@@ -24,6 +24,14 @@ module.exports = app => {
|
|
|
this.tableName = 'ledger_revise';
|
|
|
}
|
|
|
|
|
|
+ _analysisData(data) {
|
|
|
+ if (!data) return;
|
|
|
+ const datas = data instanceof Array ? data : [data];
|
|
|
+ for (const d of datas) {
|
|
|
+ if (d.sum) d.sum = JSON.parse(d.sum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取标段下,修订(分页,且按时间倒序)
|
|
|
* @param {Number}tid - 标段id
|
|
@@ -39,7 +47,9 @@ module.exports = app => {
|
|
|
' LIMIT ?, ?';
|
|
|
const Len = this.app.config.pageSize;
|
|
|
const sqlParam = [tid, (this.ctx.page - 1) * Len, Len];
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
+ const result = await this.db.query(sql, sqlParam);
|
|
|
+ this._analysisData(result);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -55,7 +65,9 @@ module.exports = app => {
|
|
|
' WHERE lc.tid = ?' +
|
|
|
' ORDER BY lc.in_time DESC';
|
|
|
const sqlParam = [tid];
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
+ const result = await this.db.query(sql, sqlParam);
|
|
|
+ this._analysisData(result);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
async getLastestRevise(tid, valid = true) {
|
|
@@ -67,7 +79,9 @@ module.exports = app => {
|
|
|
' ORDER BY lc.in_time DESC' +
|
|
|
' LIMIT 0, 1';
|
|
|
const sqlParam = [tid];
|
|
|
- return await this.db.queryOne(sql, sqlParam);
|
|
|
+ const result = await this.db.queryOne(sql, sqlParam);
|
|
|
+ this._analysisData(result);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
async getRevise(tid, rid) {
|
|
@@ -79,7 +93,9 @@ module.exports = app => {
|
|
|
' ORDER BY lc.in_time DESC' +
|
|
|
' LIMIT 0, 1';
|
|
|
const sqlParam = [tid, rid];
|
|
|
- return await this.db.queryOne(sql, sqlParam);
|
|
|
+ const result = await this.db.queryOne(sql, sqlParam);
|
|
|
+ this._analysisData(result);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -191,12 +207,12 @@ module.exports = app => {
|
|
|
* @returns {Promise<void>}
|
|
|
*/
|
|
|
async cancelRevise(revise) {
|
|
|
- const his_id = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
|
|
|
+ const [his_id, sum] = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
const result = await transaction.update(this.tableName, {
|
|
|
id: revise.id, valid: false, end_time: new Date(),
|
|
|
- his_id,
|
|
|
+ his_id, sum: JSON.stringify(sum),
|
|
|
});
|
|
|
await transaction.update(this.ctx.service.ledgerHistory.tableName, { id: his_id, valid: 0 });
|
|
|
if (revise.his_id > 0) await transaction.update(this.ctx.service.ledgerHistory.tableName, { id: revise.his_id, valid: 0 });
|