|
@@ -71,25 +71,25 @@ module.exports = app => {
|
|
|
* @return {Promise<void>} - 新增备份id
|
|
|
* @private
|
|
|
*/
|
|
|
- async backupStageLedgerHistory(stage) {
|
|
|
- const sbCount = await this.ctx.service.ledger.count({ tender_id: this.ctx.stage.tid });
|
|
|
- const spCount = await this.ctx.service.pos.count({ tid: this.ctx.stage.tid });
|
|
|
- const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(this.ctx.tender.id);
|
|
|
+ async checkBackupLedgerHistory(tid, sid = 0, rid = '') {
|
|
|
+ const sbCount = await this.ctx.service.ledger.count({ tender_id: tid });
|
|
|
+ const spCount = await this.ctx.service.pos.count({ tid: tid });
|
|
|
+ const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(tid);
|
|
|
if (sbCount === ledgerHis.bills_count && spCount === ledgerHis.pos_count) return ledgerHis.id;
|
|
|
|
|
|
const now = new Date();
|
|
|
const timestamp = (now).getTime();
|
|
|
|
|
|
- const billsHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/bills${timestamp}-s.json`;
|
|
|
- const bills = await this.ctx.service.ledger.getData(stage.tid);
|
|
|
+ const billsHis = `${this.ctx.session.sessionProject.id}/${tid}/ledger/bills${timestamp}-s.json`;
|
|
|
+ const bills = await this.ctx.service.ledger.getData(tid);
|
|
|
await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
|
|
|
|
|
|
- const posHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/pos${timestamp}-s.json`;
|
|
|
- const pos = await this.ctx.service.pos.getPosData({ tid: stage.tid });
|
|
|
+ const posHis = `${this.ctx.session.sessionProject.id}/${tid}/ledger/pos${timestamp}-s.json`;
|
|
|
+ const pos = await this.ctx.service.pos.getPosData({ tid: tid });
|
|
|
await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
|
|
|
|
|
|
const result = await this.db.insert(this.tableName, {
|
|
|
- pid: this.ctx.session.sessionProject.id, tid: stage.tid, sid: stage.id,
|
|
|
+ pid: this.ctx.session.sessionProject.id, tid, sid, rid,
|
|
|
in_time: now,
|
|
|
bills_file: billsHis, pos_file: posHis,
|
|
|
bills_count: bills.length, pos_count: pos.length,
|