Kaynağa Gözat

修复审批撤回4种情况合同计量数据保留问题

laiguoran 2 yıl önce
ebeveyn
işleme
1f4bd35fe7

+ 16 - 0
app/service/stage_audit.js

@@ -992,6 +992,7 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             const time = new Date();
             try {
+                await this._updateTender(transaction);
                 if (this.ctx.stage.cancancel === 1) {
                     // 原报撤回,判断是否为多次,多次则为退回状态
                     // 整理当前流程审核人状态更新
@@ -1041,6 +1042,9 @@ module.exports = app => {
                     await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
                     await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
                     await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
+                    // 先覆盖再删除
+                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, this.ctx.stage.user_id, this.ctx.stage.times, 0, curAudit.aid, this.ctx.stage.times, 1, transaction);
+                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, this.ctx.stage.user_id, this.ctx.stage.times, 0, curAudit.aid, this.ctx.stage.times, 1, transaction);
                 } else if (this.ctx.stage.cancancel === 2) {
                     const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
                     // 整理当前流程审核人状态更新
@@ -1117,6 +1121,10 @@ module.exports = app => {
                     await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
                     await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
 
+                    // 先覆盖再删除
+                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
+                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
+
                     // 锁定本人数据,保留锁定数据相关确认状态
                     // await this.ctx.service.stageAuditAss.lockConfirm4CheckNoPre(this.ctx.stage, curAudit.aid, preAudit.aid, transaction);
                 } else if (this.ctx.stage.cancancel === 3) {
@@ -1196,6 +1204,10 @@ module.exports = app => {
                     await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
                     await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
 
+                    // 先覆盖再删除
+                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
+                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
+
                     // 锁定本人数据,保留锁定数据相关确认状态
                     // await this.ctx.service.stageAuditAss.lockConfirm4CheckNoPre(this.ctx.stage, curAudit.aid, preAudit.aid, transaction);
                 } else if (this.ctx.stage.cancancel === 4) {
@@ -1271,6 +1283,10 @@ module.exports = app => {
                     await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
                     await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
                     await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
+
+                    // 先覆盖再删除
+                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, curAudit.aid, this.ctx.stage.times - 1, curAudit.order + 2, this.ctx.stage.user_id, this.ctx.stage.times, 0, transaction);
+                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, curAudit.aid, this.ctx.stage.times - 1, curAudit.order + 2, this.ctx.stage.user_id, this.ctx.stage.times, 0, transaction);
                 }
                 // 上报/审批 - 检查三方特殊推送
                 await this.ctx.service.specMsg.addStageMsg(transaction, this.ctx.session.sessionProject.id, this.ctx.stage, pushOperate.stage.flow);

+ 21 - 0
app/service/stage_bills.js

@@ -126,6 +126,27 @@ module.exports = app => {
             return stageBills[0];
         }
 
+        async updateAuditStageBills(sid, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction) {
+            const oldSBLists = await this.getAllDataByCondition({ where: { sid, times: oldTimes, order: oldOrder } });
+            const newSBLists = await this.getAllDataByCondition({ where: { sid, times: newTimes, order: newOrder } });
+            const delidList = [];
+            for (const o of oldSBLists) {
+                const newSBInfo = this._.find(newSBLists, { lid: o.lid });
+                if (newSBInfo) {
+                    // 删除
+                    delidList.push(newSBInfo.id);
+                }
+            }
+            if (delidList.length > 0) await transaction.delete(this.tableName, { id: delidList });
+            if (oldSBLists.length > 0) {
+                await transaction.update(this.tableName, {
+                    said: newSaid,
+                    times: newTimes,
+                    order: newOrder,
+                }, { where: { id: this._.map(oldSBLists, 'id') } });
+            }
+        }
+
         async getStageUsedBills(tid, sid) {
             const sql = 'SELECT Bills.lid, ((not IsNull(Bills.contract_qty) and Bills.contract_qty <> 0) or (not IsNull(Bills.contract_tp) and Bills.contract_tp <> 0) or (not IsNull(Bills.qc_qty) and Bills.qc_qty <> 0) or (not IsNull(Bills.qc_tp) and Bills.qc_tp <> 0)) As used' +
                 '  FROM ' + this.tableName + ' As Bills ' +

+ 21 - 0
app/service/stage_pos.js

@@ -125,6 +125,27 @@ module.exports = app => {
             return this._filterLastestData(stagePos);
         }
 
+        async updateAuditStagePos(sid, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction) {
+            const oldSBLists = await this.getAllDataByCondition({ where: { sid, times: oldTimes, order: oldOrder } });
+            const newSBLists = await this.getAllDataByCondition({ where: { sid, times: newTimes, order: newOrder } });
+            const delidList = [];
+            for (const o of oldSBLists) {
+                const newSBInfo = this._.find(newSBLists, { lid: o.lid, pid: o.pid });
+                if (newSBInfo) {
+                    // 删除
+                    delidList.push(newSBInfo.id);
+                }
+            }
+            if (delidList.length > 0) await transaction.delete(this.tableName, { id: delidList });
+            if (oldSBLists.length > 0) {
+                await transaction.update(this.tableName, {
+                    times: newTimes,
+                    order: newOrder,
+                    said: newSaid,
+                }, { where: { id: this._.map(oldSBLists, 'id') } });
+            }
+        }
+
         async getStageUsedPos(tid, sid, where) {
             const self = this;
             const stagePos = await this.getLastestStageData2(tid, sid, where);