瀏覽代碼

进入计量台账时,删除无效的计量数据2

MaiXinRong 5 年之前
父節點
當前提交
37303673f3
共有 1 個文件被更改,包括 27 次插入3 次删除
  1. 27 3
      app/controller/stage_controller.js

+ 27 - 3
app/controller/stage_controller.js

@@ -150,9 +150,6 @@ module.exports = app => {
                 const renderData = await this._getDefaultRenderData(ctx);
                 [renderData.ledgerSpread, renderData.posSpread] = this._getSpreadSetting();
                 renderData.changeConst = changeConst;
-                // if (!ctx.stage.readOnly) {
-                //     await ctx.service.stage.deleteInvalidData(ctx.stage.id);
-                // }
                 // renderData.ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
                 // const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
                 // for (const d of dgnData) {
@@ -193,6 +190,24 @@ module.exports = app => {
             }
         }
 
+        _checkUniaData(data, field) {
+            const groupData = this.ctx.helper._.groupBy(data, field);
+            const surplus = [];
+            for (const gd in groupData) {
+                if (groupData[gd].length > 1) {
+                    const first = groupData[gd][0];
+                    for (let i = 1, iLen = groupData[gd].length; i < iLen; i++) {
+                        const check = groupData[gd][i];
+                        if (this.ctx.helper._.isMatch({field: check[field], sid: check.sid, order: check.order, times: check.times},
+                                {field: first[field], sid: first.sid, order: first.order, times: first.times})) {
+                            surplus.push(groupData[gd][i].id);
+                        }
+                    }
+                }
+            }
+            return surplus;
+        }
+
         async _getStageLedgerData(ctx) {
             const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
             const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
@@ -206,6 +221,10 @@ module.exports = app => {
                 curStageData = await ctx.service.stageBills.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
             } else {
                 curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, ctx.stage.id);
+                const surplus = this._checkUniaData(curStageData, 'lid');
+                if (surplus.length > 0) {
+                    await ctx.service.stageBills.deleteById(surplus);
+                }
             }
             // 查询截止上期数据
             if (ctx.stage.order > 1) {
@@ -230,6 +249,11 @@ module.exports = app => {
                     ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
             } else {
                 curStageData = await ctx.service.stagePos.getLastestStageData2(ctx.tender.id, ctx.stage.id);
+
+                const surplus = this._checkUniaData(curStageData, 'pid');
+                if (surplus.length > 0) {
+                    await ctx.service.stagePos.deleteById(surplus);
+                }
             }
             //console.timeEnd('cur');
             // 查询截止上期数据