Selaa lähdekoodia

新增修订前,检查一次台账与上一次台账历史是否存在新增数据

MaiXinRong 2 vuotta sitten
vanhempi
commit
b8fea3dab9
3 muutettua tiedostoa jossa 13 lisäystä ja 13 poistoa
  1. 9 9
      app/service/ledger_history.js
  2. 3 3
      app/service/ledger_revise.js
  3. 1 1
      app/service/stage_audit.js

+ 9 - 9
app/service/ledger_history.js

@@ -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,

+ 3 - 3
app/service/ledger_revise.js

@@ -176,11 +176,11 @@ module.exports = app => {
                 throw '数据错误';
             }
             const maxOrder = await this.getNewOrder(tid);
-            const latest = await this.ctx.service.ledgerHistory.getLatestHistory(tid);
-            if (!latest) throw '台账历史数据有误';
+            const preHisId = await this.ctx.service.ledgerHistory.checkBackupLedgerHistory(tid);
+            if (!preHisId) throw '台账历史数据有误';
             const data = {
                 id: this.uuid.v4(), tid: tid, uid: uid,
-                corder: maxOrder + 1, in_time: new Date(), status: audit.status.uncheck, pre_his_id: latest.id,
+                corder: maxOrder + 1, in_time: new Date(), status: audit.status.uncheck, pre_his_id: preHisId,
             };
             const transaction = await this.db.beginTransaction();
             try {

+ 1 - 1
app/service/stage_audit.js

@@ -479,7 +479,7 @@ module.exports = app => {
                     await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
                 } else {
                     await this.ctx.service.tenderTag.saveTenderTag(this.ctx.tender.id, {stage_time: new Date()}, transaction);
-                    const his_id = await this.ctx.service.ledgerHistory.backupStageLedgerHistory(this.ctx.stage);
+                    const his_id = await this.ctx.service.ledgerHistory.checkBackupLedgerHistory(this.ctx.stage.tid, this.ctx.stage.sid);
 
                     // 本期结束
                     // 生成截止本期数据 final数据