فهرست منبع

检查计算相关 2.0

MaiXinRong 5 سال پیش
والد
کامیت
ca5f2afb25

+ 14 - 0
app/controller/ledger_controller.js

@@ -441,6 +441,20 @@ module.exports = app => {
             }
         }
 
+        async check(ctx) {
+            try {
+                const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
+                const posData = this.ctx.tender.data.measure_type === measureType.tz.value
+                    ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
+                const data = ctx.helper.checkBillsWithPos(ledgerData, posData,
+                    ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity']);
+                ctx.body = { err: 0, msg: '', data: data };
+            } catch (err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '检查数据错误');
+            }
+        }
+
         /**
          * 更新 部位明细数据
          *

+ 24 - 0
app/controller/revise_controller.js

@@ -433,6 +433,30 @@ module.exports = app => {
             }
         }
 
+        async check(ctx) {
+            try {
+                const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
+                if (!revise) throw '台账修订数据有误';
+
+                const billsFile = revise.bills_file ? this.ctx.app.config.filePath + revise.bills_file : undefined;
+                const reviseBills = billsFile && fs.existsSync(billsFile)
+                    ? JSON.parse(await fs.readFileSync(billsFile, 'utf8'))
+                    : await ctx.service.reviseBills.getData(ctx.tender.id);
+
+                const posFile = revise.pos_file ? this.ctx.app.config.filePath + revise.pos_file : undefined;
+                const revisePos = posFile && fs.existsSync(posFile)
+                    ? JSON.parse(await fs.readFileSync(posFile, 'utf8'))
+                    : await ctx.service.revisePos.getData(ctx.tender.id);
+
+                const data = ctx.helper.checkBillsWithPos(reviseBills, revisePos,
+                    ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity']);
+                ctx.body = { err: 0, msg: '', data: data };
+            } catch (err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '检查数据错误');
+            }
+        }
+
         async history(ctx) {
             try {
                 const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id, false);

+ 14 - 1
app/controller/stage_controller.js

@@ -323,6 +323,18 @@ module.exports = app => {
             }
         }
 
+        async check(ctx) {
+            try {
+                const ledgerData = await this._getStageLedgerData(ctx);
+                const posData = await this._getStagePosData(ctx);
+                const data = ctx.helper.checkBillsWithPos(ledgerData, posData, ['contract_qty', 'qc_qty']);
+                ctx.body = { err: 0, msg: '', data: data };
+            } catch (err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '检查数据错误');
+            }
+        }
+
         /**
          * 获取期数据(截止上期 & 本期) (Ajax)
          * @param ctx
@@ -396,7 +408,8 @@ module.exports = app => {
                         responseData.data.curStageData = await ctx.service.stageBills.updateStageData(data.bills.stage);
                     }
                     if (data.bills.calcType) {
-                        responseData.data = await ctx.service.stageBills.updateStageBillsCalcType(data.bills.calcType);                    }
+                        responseData.data = await ctx.service.stageBills.updateStageBillsCalcType(data.bills.calcType);
+                    }
                 }
                 await ctx.service.stage.updateCheckCalcFlag(ctx.stage.id, true);
                 await ctx.service.stage.updateCacheTime(ctx.stage.id);

+ 37 - 0
app/extend/helper.js

@@ -982,4 +982,41 @@ module.exports = {
     isWap(request) {
         return request.url.indexOf('/wap/') !== -1;
     },
+
+    checkBillsWithPos(bills, pos, fields) {
+        const result = {
+            error: [],
+            source: {
+                bills: [],
+                pos: [],
+            }
+        };
+        for (const b of bills) {
+            const pr = _.remove(pos, {lid: b.id});
+            const checkData = {}, calcData = {};
+            if (pr && pr.length > 0) {
+                for (const field of fields) {
+                    checkData[field] = b[field] ? b[field] : 0;
+                }
+                for (const p of pr) {
+                    for (const field of fields) {
+                        calcData[field] = this.add(calcData[field], p[field]);
+                    }
+                }
+                if (!_.isMatch(checkData, calcData)) {
+                    result.error.push({
+                        ledger_id: b.ledger_id,
+                        b_code: b.b_code,
+                        name: b.name,
+                        error: {checkData: checkData, calcData: calcData}
+                    });
+                    result.source.bills.push(b);
+                    for (const p of pr) {
+                        result.source.pos.push(p);
+                    }
+                }
+            }
+        }
+        return result;
+    }
 }

+ 7 - 38
app/public/js/ledger.js

@@ -2579,46 +2579,15 @@ $(document).ready(function() {
     });
 
     const dataChecker = DataChecker({
-        loadUrl: window.location.pathname + '/load',
-        loadData: {},
-        checkFun: function (data, progress) {
-            ledgerTree.loadDatas(data.bills);
-            treeCalc.calculateAll(ledgerTree);
-            SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
-
-            pos.loadDatas(data.pos);
+        checkUrl: window.location.pathname + '/check',
+        completeData: function (data) {
+            pos.updateDatas({update: data.source.pos});
+            const loadResult = ledgerTree.loadPostData({update: data.source.bills});
+            treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
             posOperationObj.loadCurPosData();
-
-            const checkFields = ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'], result = [];
-            const iLen = data.bills.length;
-            for (const [i, b] of data.bills.entries()) {
-                const pr = _.filter(data.pos, {lid: b.id});
-                if (pr && pr.length > 0) {
-                    const checkData = {}, calcData = {};
-                    for (const field of checkFields) {
-                        checkData[field] = b[field] ? b[field] : 0;
-                    }
-                    for (const p of pr) {
-                        for (const field of checkFields) {
-                            calcData[field] = ZhCalc.add(calcData[field], p[field]);
-                        }
-                    }
-                    for (const field of checkFields) {
-                        calcData[field] = calcData[field] ? calcData[field] : 0;
-                    }
-                    if (!_.isMatch(checkData, calcData)) {
-                        result.push({
-                            ledger_id: b.ledger_id,
-                            b_code: b.b_code,
-                            name: b.name,
-                            serialNo: ledgerTree.getNodeIndex(ledgerTree.getItems(b.ledger_id)) + 1,
-                            error: {checkData: checkData, calcData: calcData}
-                        })
-                    }
-                    progress(parseInt((i+1)/iLen*100));
-                }
+            for (const e of data.error) {
+                e.serialNo = ledgerTree.getNodeIndex(ledgerTree.getItems(e.ledger_id)) + 1;
             }
-            return result;
         },
         errorList: errorList,
     });

+ 7 - 38
app/public/js/revise.js

@@ -2181,46 +2181,15 @@ $(document).ready(() => {
     })('a[name=showLevel]', billsSheet);
 
     const dataChecker = DataChecker({
-        loadUrl: window.location.pathname + '/load',
-        loadData: {},
-        checkFun: function (data, progress) {
-            billsTree.loadDatas(data.bills);
-            treeCalc.calculateAll(billsTree);
-            SpreadJsObj.loadSheetData(billsSheet, 'tree', billsTree);
-
-            pos.loadDatas(data.pos);
+        checkUrl: window.location.pathname + '/check',
+        completeData: function (data) {
+            pos.updateDatas({update: data.source.pos});
+            const loadResult = billsTree.loadPostData({update: data.source.bills});
+            billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
             posSpreadObj.loadCurPosData();
-
-            const checkFields = ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'], result = [];
-            const iLen = data.bills.length;
-            for (const [i, b] of data.bills.entries()) {
-                const pr = _.filter(data.pos, {lid: b.id});
-                if (pr && pr.length > 0) {
-                    const checkData = {}, calcData = {};
-                    for (const field of checkFields) {
-                        checkData[field] = b[field] ? b[field] : 0;
-                    }
-                    for (const p of pr) {
-                        for (const field of checkFields) {
-                            calcData[field] = ZhCalc.add(calcData[field], p[field]);
-                        }
-                    }
-                    for (const field of checkFields) {
-                        calcData[field] = calcData[field] ? calcData[field] : 0;
-                    }
-                    if (!_.isMatch(checkData, calcData)) {
-                        result.push({
-                            ledger_id: b.ledger_id,
-                            b_code: b.b_code,
-                            name: b.name,
-                            serialNo: billsTree.getNodeIndex(billsTree.getItems(b.ledger_id)) + 1,
-                            error: {checkData: checkData, calcData: calcData}
-                        })
-                    }
-                    progress(parseInt((i+1)/iLen*100));
-                }
+            for (const e of data.error) {
+                e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
             }
-            return result;
         },
         errorList: errorList,
     });

+ 7 - 42
app/public/js/stage.js

@@ -2890,50 +2890,15 @@ $(document).ready(() => {
     })('a[name=showLevel]', slSpread.getActiveSheet());
 
     const dataChecker = DataChecker({
-        loadUrl: window.location.pathname + '/load',
-        loadData: { filter: 'ledger;pos' },
-        checkFun: function (data, progress) {
-            const checkFields = ['contract_qty', 'qc_qty'], result = [];
-            const differBills = [], differPos = [];
-            const iLen = data.ledgerData.length;
-            for (const [i, b] of data.ledgerData.entries()) {
-                const pr = _.filter(data.posData, {lid: b.id});
-                if (pr && pr.length > 0) {
-                    const checkData = {}, calcData = {};
-                    for (const field of checkFields) {
-                        checkData[field] = b[field] ? b[field] : 0;
-                    }
-                    for (const p of pr) {
-                        for (const field of checkFields) {
-                            calcData[field] = ZhCalc.add(calcData[field], p[field]);
-                        }
-                    }
-                    for (const field of checkFields) {
-                        calcData[field] = calcData[field] ? calcData[field] : 0;
-                    }
-                    if (!_.isMatch(checkData, calcData)) {
-                        result.push({
-                            ledger_id: b.ledger_id,
-                            b_code: b.b_code,
-                            name: b.name,
-                            serialNo: stageTree.getNodeIndex(stageTree.getItems(b.ledger_id)) + 1,
-                            error: {checkData: checkData, calcData: calcData}
-                        });
-                        differBills.push(b);
-                        for (const p of pr) {
-                            differPos.push(p);
-                        }
-                    }
-                    progress(parseInt((i+1)/iLen*90));
-                }
-            }
-
-            stagePos.updateDatas({update: differPos});
-            const refreshData = stageTree.loadPostStageData({bills: differBills});
-            progress(95);
+        checkUrl: window.location.pathname + '/check',
+        completeData: function (data) {
+            stagePos.updateDatas({pos: data.source.pos});
+            const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
             stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
             stagePosSpreadObj.loadCurPosData();
-            return result;
+            for (const e of data.error) {
+                e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
+            }
         },
         errorList: errorList,
     });

+ 3 - 0
app/router.js

@@ -109,6 +109,7 @@ module.exports = app => {
     app.post('/tender/:id/pos/update', sessionAuth, tenderCheck, 'ledgerController.posUpdate');
     app.post('/tender/:id/pos/paste', sessionAuth, tenderCheck, 'ledgerController.posPaste');
     app.post('/tender/:id/ledger/deal2sgfh', sessionAuth, tenderCheck, 'ledgerController.deal2sgfh');
+    app.post('/tender/:id/ledger/check', sessionAuth, tenderCheck, 'ledgerController.check');
     // 台账审批相关
     app.get('/tender/:id/ledger/audit', sessionAuth, tenderCheck, 'ledgerAuditController.index');
     app.post('/tender/:id/ledger/audit/add', sessionAuth, tenderCheck, 'ledgerAuditController.add');
@@ -136,6 +137,7 @@ module.exports = app => {
     app.post('/tender/:id/revise/info/load', sessionAuth, tenderCheck, 'reviseController.loadInfoData');
     app.post('/tender/:id/revise/info/update', sessionAuth, tenderCheck, 'reviseController.update');
     app.post('/tender/:id/revise/info/upload-excel/:ueType', sessionAuth, tenderCheck, 'reviseController.uploadExcel');
+    app.post('/tender/:id/revise/info/check', sessionAuth, tenderCheck, 'reviseController.check');
     // 查看修订数据
     app.get('/tender/:id/revise/history', sessionAuth, tenderCheck, 'reviseController.history');
     app.post('/tender/:id/revise/history/load', sessionAuth, tenderCheck, 'reviseController.loadHistoryData');
@@ -172,6 +174,7 @@ module.exports = app => {
     app.post('/tender/:id/measure/stage/:order/update', sessionAuth, tenderCheck, stageCheck, 'stageController.updateStageData');
     app.post('/tender/:id/measure/stage/:order/valid-change', sessionAuth, tenderCheck, stageCheck, 'stageController.searchValidChange');
     app.post('/tender/:id/measure/stage/:order/use-change', sessionAuth, tenderCheck, stageCheck, 'stageController.useChange');
+    app.post('/tender/:id/measure/stage/:order/check', sessionAuth, tenderCheck, stageCheck, 'stageController.check');
     // 计量附件
     app.post('/tender/:id/measure/stage/:order/upload/file', sessionAuth, tenderCheck, stageCheck, 'stageController.uploadFile');
     app.get('/tender/:id/measure/stage/:order/download/file/:fid', sessionAuth, 'stageController.downloadFile');

+ 37 - 60
app/view/shares/check_data_modal.ejs

@@ -8,7 +8,7 @@
             <div class="modal-body">
                 <h5>数据计算中,完成后会自动进入审批流程设置。</h5>
                 <div class="progress">
-                    <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
+                    <div class="progress-bar" id="check-progress" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
                 </div>
             </div>
         </div>
@@ -37,9 +37,9 @@
      *
      * @param setting
      * {
-     *      loadUrl,
-     *      loadData,
-     *      checkFun,
+     *      checkUrl,
+     *      checkData,
+     *      reloadDifferSource,
      *      errorList
      * }
      */
@@ -49,82 +49,59 @@
             $('#check').modal('hide');
             setting.errorList.show();
         });
-        const loadCheckData = function () {
-            const promise = new Promise(function (resolve, reject) {
-                postData(setting.loadUrl, setting.loadData, function (result) {
-                    resolve(result);
-                });
-            });
-            return promise;
-        }
         const progress = function (percent) {
-            $('.progress-bar').attr('aria-valuenow', percent).width(percent + '%').html(percent + '%');
+            $('#check-progress').attr('aria-valuenow', percent).width(percent + '%').html(percent + '%');
         }
-        const fakeProgresTo = function (percent) {
-            const processObj = $('.progress-bar');
+        const fakeProgress = function () {
+            const processObj = $('#check-progress');
             let count = 0;
             progressInterval = setInterval(function () {
                 const pos = parseInt(processObj.attr('aria-valuenow'));
-                if (pos < 10) {                                       // 1
-                    processObj.attr('aria-valuenow', pos + 2);
-                    processObj.width((pos + 2) + '%');
-                } else if (pos < 20) {                                // 2
-                    processObj.attr('aria-valuenow', pos + 1);
-                    processObj.width((pos + 1) + '%');
-                } else if (pos < 30) {                         // 4
+                if (pos < 10) {                        // 1
+                    progress(pos + 2);
+                } else if (pos < 20) {                 // 2
+                    progress(pos + 1);
+                } else if (pos < 90) {                 // 4
                     count += 1;
                     if (count % 2 === 0) {
-                        processObj.attr('aria-valuenow', pos + 1);
-                        processObj.width((pos + 1) + '%');
-                    }
-                } else if (pos < 40) {                         // 10
-                    count += 1;
-                    if (count % 5 === 0) {
-                        processObj.attr('aria-valuenow', pos + 1);
-                        processObj.width((pos + 1) + '%');
-                    }
-                } else if (pos < 45) {                        // 15
-                    count += 1;
-                    if (count % 15 === 0) {
-                        processObj.attr('aria-valuenow', pos + 1);
-                        processObj.width((pos + 1) + '%');
+                        progress(pos + 1);
                     }
-                }  else if (pos < 50) {                       // 20
+                }  else if (pos < 100) {               // 20
                     count += 1;
                     if (count % 40 === 0) {
-                        processObj.attr('aria-valuenow', pos + 1);
-                        processObj.width((pos + 1) + '%');
+                        progress(pos + 1);
                     }
                 }
             }, 100);
         }
-        const stopFakeProgress = function (percent) {
+        const stopFakeProgess = function (fun) {
+            progress(100);
             clearInterval(progressInterval);
-            progress(percent);
-        }
-        const addProgress = function (percent) {
-            const oldPercent = parseInt($('.progress-bar').attr('aria-valuenow'));
-            progress(oldPercent + parseInt(percent/2));
         }
         const checkAndPost = async function (postUrl, postForm) {
-            progress(0);
             $('#check').modal('show');
-            fakeProgresTo(50);
-            const lastestData = await loadCheckData();
-            stopFakeProgress(50);
-            const result = setting.checkFun(lastestData, addProgress);
-            progress(100);
-            setTimeout(function () {
-                if (result && result.length > 0) {
-                    $('#check-error-hint').modal('show');
-                    setting.errorList.loadErrorData(result);
+            fakeProgress();
+            postData(setting.checkUrl, setting.checkData ? setting.checkData : {}, function (result) {
+                if (result.error && result.error.length > 0) {
+                    setting.completeData(result);
+                    setting.errorList.loadErrorData(result.error);
+                    stopFakeProgess();
+                    setTimeout(function () {
+                        $('#check-error-hint').modal('show');
+                    }, 300);
                 } else {
-                    setting.errorList.clearErrorData();
-                    postDataWithFile(postUrl, postForm, function () {
-                        window.location.reload();
-                    });
+                    stopFakeProgess();
+                    setTimeout(function () {
+                        setting.errorList.clearErrorData();
+                        postDataWithFile(postUrl, postForm, function () {
+                            window.location.reload();
+                        });
+                    }, 300);
                 }
-            }, 1000);
+            }, function () {
+                $('#check').modal('hide');
+                stopFakeProgess();
+            });
         }
         return {checkAndPost};
     }