Browse Source

1. 加密算法下,代码调整
2. 报表数据,期全参与人数据

MaiXinRong 5 years ago
parent
commit
4dbf4e135e

+ 30 - 7
app/lib/ledger.js

@@ -209,16 +209,18 @@ class billsTree {
         }
         return [maxLevel, map];
     }
-    _calculateNode (node) {
+    _calculateNode (node, fun) {
         const self = this;
         if (node.children && node.children.length > 0) {
             const gather = node.children.reduce(function (rst, x) {
-                const result = {};
                 for (const cf of self.setting.calcFields) {
-                    result[cf] = self.ctx.helper.add(rst[cf], x[cf]);
+                    rst[cf] = self.ctx.helper.add(rst[cf], x[cf]);
                 }
-                return result;
+                return rst;
             });
+            if (node.code === '1-1-6') {
+                console.log(gather);
+            }
             // 汇总子项
             for (const cf of this.setting.calcFields) {
                 if (gather[cf]) {
@@ -229,17 +231,19 @@ class billsTree {
             }
         }
         // 自身运算
-        if (this.setting.calc) {
+        if (fun) {
+            fun(node);
+        } else if (this.setting.calc) {
             this.setting.calc(node);
         }
     }
-    calculateAll() {
+    calculateAll(fun) {
         const [maxLevel, levelMap] = this._mapTreeNode();
         for (let i = maxLevel; i >= 0; i--) {
             const levelNodes = levelMap[i];
             if (levelNodes && levelNodes.length > 0) {
                 for (const node of levelNodes) {
-                    this._calculateNode(node);
+                    this._calculateNode(node, fun);
                 }
             }
         }
@@ -257,6 +261,25 @@ class billsTree {
         }
         return datas;
     }
+
+    getDatasWithout (fields) {
+        const datas = [];
+        for (const node of this.nodes) {
+            if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
+            const data = {};
+            for (const field in node) {
+                if (fields.indexOf(field) === -1) {
+                    data[field] = node[field];
+                }
+            }
+            datas.push(data);
+        }
+        return datas;
+    }
+
+    getDefaultDatas() {
+        return this.getDatasWithout(['expanded', 'visible', 'children', 'index']);
+    }
 }
 
 class pos {

+ 28 - 27
app/public/js/shares/bills_pos_convert.js

@@ -59,9 +59,10 @@ const billsPosConvertModel = (function () {
         tpDecimal = decimal;
     }
 
-    function convertXmj(node) {
-        return resultTree.addData(node, ['ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
+    function convertXmj(data) {
+        const xmj = resultTree.addData(data, ['ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
             'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'drawing_code', 'postil', 'memo']);
+        return xmj;
     }
     // v1
     function loadField(node, data, fields) {
@@ -132,46 +133,46 @@ const billsPosConvertModel = (function () {
         if (!nodes || !nodes instanceof Array || nodes.length === 0) return;
 
         for (const node of nodes) {
-            let cXmj = xmj;
             if (node.b_code && node.b_code !== '') {
                 if (!node.children || node.children.length === 0) {
                     convertGcl(node, xmj);
                 }
+                recursiveConvertNode(node.children, xmj);
             } else {
-                cXmj = convertXmj(node);
+                recursiveConvertNode(node.children, convertXmj(node));
             }
-            recursiveConvertNode(node.children, cXmj);
+
         }
     }
 
-    function calculateChild(node) {
-        node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
-        node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_gather_qty);
-        node.end_contract_qty = ZhCalc.add(node.contract_qty, node.pre_contract_qty);
-        node.end_qc_qty = ZhCalc.add(node.qc_qty, node.pre_qc_qty);
-        node.end_gather_qty = ZhCalc.add(node.gather_qty, node.pre_gather_qty);
+    function calculateChild(child) {
+        child.gather_qty = ZhCalc.add(child.contract_qty, child.qc_qty);
+        child.pre_gather_qty = ZhCalc.add(child.pre_contract_qty, child.pre_gather_qty);
+        child.end_contract_qty = ZhCalc.add(child.contract_qty, child.pre_contract_qty);
+        child.end_qc_qty = ZhCalc.add(child.qc_qty, child.pre_qc_qty);
+        child.end_gather_qty = ZhCalc.add(child.gather_qty, child.pre_gather_qty);
 
         // v1
-        // node.total_price = ZhCalc.mul(node.unit_price, node.quantity, tpDecimal);
-        // node.contract_tp = ZhCalc.mul(node.unit_price, node.contract_qty, tpDecimal);
-        // node.qc_tp = ZhCalc.mul(node.unit_price, node.qc_qty, tpDecimal);
-        // node.gather_tp = ZhCalc.mul(node.unit_price, node.gather_qty, tpDecimal);
-        // node.pre_contract_tp = ZhCalc.mul(node.unit_price, node.pre_contract_qty, tpDecimal);
-        // node.pre_qc_tp = ZhCalc.mul(node.unit_price, node.pre_qc_qty, tpDecimal);
-        // node.pre_gather_tp = ZhCalc.mul(node.unit_price, node.pre_gather_qty, tpDecimal);
-        // node.end_contract_tp = ZhCalc.mul(node.unit_price, node.end_contract_qty, tpDecimal);
-        // node.end_qc_tp = ZhCalc.mul(node.unit_price, node.end_qc_qty, tpDecimal);
-        // node.end_gather_tp = ZhCalc.mul(node.unit_price, node.end_gather_qty, tpDecimal);
+        // child.total_price = ZhCalc.mul(child.unit_price, child.quantity, tpDecimal);
+        // child.contract_tp = ZhCalc.mul(child.unit_price, child.contract_qty, tpDecimal);
+        // child.qc_tp = ZhCalc.mul(child.unit_price, child.qc_qty, tpDecimal);
+        // child.gather_tp = ZhCalc.mul(child.unit_price, child.gather_qty, tpDecimal);
+        // child.pre_contract_tp = ZhCalc.mul(child.unit_price, child.pre_contract_qty, tpDecimal);
+        // child.pre_qc_tp = ZhCalc.mul(child.unit_price, child.pre_qc_qty, tpDecimal);
+        // child.pre_gather_tp = ZhCalc.mul(child.unit_price, child.pre_gather_qty, tpDecimal);
+        // child.end_contract_tp = ZhCalc.mul(child.unit_price, child.end_contract_qty, tpDecimal);
+        // child.end_qc_tp = ZhCalc.mul(child.unit_price, child.end_qc_qty, tpDecimal);
+        // child.end_gather_tp = ZhCalc.mul(child.unit_price, child.end_gather_qty, tpDecimal);
 
         // v2
-        node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
-        node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
-        node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
+        child.gather_tp = ZhCalc.add(child.contract_tp, child.qc_tp);
+        child.pre_gather_tp = ZhCalc.add(child.pre_contract_tp, child.pre_qc_tp);
+        child.end_gather_tp = ZhCalc.add(child.end_contract_tp, child.end_qc_tp);
 
-        node.final_tp = ZhCalc.add(node.total_price, node.end_qc_tp);
-        node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.final_tp, 4), 100);
+        child.final_tp = ZhCalc.add(child.total_price, child.end_qc_tp);
+        child.end_gather_percent = ZhCalc.mul(ZhCalc.div(child.end_gather_tp, child.final_tp, 4), 100);
 
-        node.bgl_code = _.uniq(_.map(node.changes, 'c_code')).join(';');
+        child.bgl_code = _.uniq(_.map(child.changes, 'c_code')).join(';');
     }
     function calculateNode(node, children) {
         for (const child of children) {

+ 112 - 1
app/service/report_memory.js

@@ -310,7 +310,9 @@ module.exports = app => {
                 node.qc_bgl_code = '';
                 if (node.children && node.children.length > 0) continue;
 
-                const nodeBgl = helper._.pullAllBy(bglData, [{lid: node.id}], 'lid');
+                const nodeBgl = helper._.filter(bglData, {lid: node.id});
+                if (nodeBgl.length === 0) continue;
+                helper._.pullAll(bglData, nodeBgl);
                 const validBgl = helper._.filter(nodeBgl, function (x) {
                     return !helper.checkZero(x.qty);
                 });
@@ -392,6 +394,115 @@ module.exports = app => {
 
             return this.pos.getDatas();
         }
+
+        _getStageValidRole () {
+            if (!this.ctx.stage) throw '期数据错误,请重试';
+
+            const result = [{dataOrder: 0, flowOrder: 0, uid: this.ctx.stage.user_id}];
+            for (const auditor of this.ctx.stage.auditors) {
+                if (auditor.status === audit.stage.status.checked ||
+                    (auditor.status === audit.stage.status.checking && !this.ctx.stage.readOnly)) {
+                    const role = result.find(function (r) {
+                        return r.uid === auditor.aid;
+                    });
+                    if (role) {
+                        role.dataOrder = auditor.order;
+                    } else {
+                        result.push({
+                            dataOrder: auditor.order,
+                            flowOrder: result.length,
+                            uid: auditor.aid
+                        })
+                    }
+                }
+            }
+            return result;
+        };
+
+        async getStageBillsCompareData(tid, sid, fields) {
+            await this.ctx.service.tender.checkTender(tid);
+            await this.ctx.service.stage.checkStage(sid);
+
+            const stage = this.ctx.stage, helper = this.ctx.helper;
+            const validRole = this._getStageValidRole();
+            const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
+            const allStageBills = await this.ctx.service.stageBills.getAllDataByCondition({where: {sid: sid}});
+
+            const stageBillsIndex = {}, timesLen = 100;
+            for (const role of validRole) {
+                const stageBills = this.ctx.helper._.filter(allStageBills, function (x) {
+                    return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
+                });
+                this.ctx.helper._.pullAll(allStageBills, stageBills);
+                for (const sb of stageBills) {
+                    const key = 'sb-' + sb.lid;
+                    const sbi = stageBillsIndex[key];
+                    if (sbi) {
+                        if ((sbi.times * timesLen + sbi.order) < (sb.times * timesLen + sb.order)) stageBillsIndex[key] = sb;
+                    } else {
+                        stageBillsIndex[key] = sb;
+                    }
+                }
+                const filterStageBills = [];
+                for (const prop in stageBillsIndex) {
+                    filterStageBills.push(stageBillsIndex[prop]);
+                }
+                this.ctx.helper.assignRelaData(billsData, [
+                    {data: filterStageBills, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'r' + role.flowOrder + '_', relaId: 'lid'}
+                ]);
+            }
+
+            if (this._checkFieldsExist(fields, preFields)) {
+                const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
+                this.ctx.helper.assignRelaData(billsData, [
+                    {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
+                ]);
+            }
+            this.billsTree.loadDatas(billsData);
+
+            this.billsTree.setting.calcFields = ['deal_tp', 'total_price', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'];
+            for (const role of validRole) {
+                const prefix = 'r' + role.flowOrder + '_';
+                this.billsTree.setting.calcFields.push(prefix + 'contract_tp', prefix + 'qc_tp', prefix + 'gather_tp');
+            }
+
+            this.billsTree.calculateAll(function(node) {
+                let prefix = '';
+                if (node.children && node.children.length === 0) {
+                    node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
+                    for (const role of validRole) {
+                        prefix = 'r' + role.flowOrder + '_';
+                        node[prefix + 'gather_qty'] = helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
+                    }
+                }
+                node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
+                for (const role of validRole) {
+                    prefix = 'r' + role.flowOrder + '_';
+                    node[prefix + 'gather_tp'] = helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
+                }
+            });
+
+            return this.billsTree.getDefaultDatas();
+            // return this.billsTree.getDatas([
+            //     'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',                 //8
+            //     'code', 'b_code', 'name', 'unit', 'unit_price',                                                         //5
+            //     'deal_qty', 'deal_tp', 'quantity', 'total_price', 'dgn_qty1', 'dgn_qty2',                               //6
+            //     'drawing_code', 'memo', 'node_type', 'is_tp',                                                           //4
+            //     'r0_contract_qty', 'r0_contract_tp', 'r0_qc_qty', 'r0_qc_tp', 'r0_gather_qty', 'r0_gather_tp',          //6
+            //     'r1_contract_qty', 'r1_contract_tp', 'r1_qc_qty', 'r1_qc_tp', 'r1_gather_qty', 'r1_gather_tp',
+            //     'r2_contract_qty', 'r2_contract_tp', 'r2_qc_qty', 'r2_qc_tp', 'r2_gather_qty', 'r2_gather_tp',
+            //     'r3_contract_qty', 'r3_contract_tp', 'r3_qc_qty', 'r3_qc_tp', 'r3_gather_qty', 'r3_gather_tp',
+            //     'r4_contract_qty', 'r4_contract_tp', 'r4_qc_qty', 'r4_qc_tp', 'r4_gather_qty', 'r4_gather_tp',
+            //     'r5_contract_qty', 'r5_contract_tp', 'r5_qc_qty', 'r5_qc_tp', 'r5_gather_qty', 'r5_gather_tp',
+            //     'r6_contract_qty', 'r6_contract_tp', 'r6_qc_qty', 'r6_qc_tp', 'r6_gather_qty', 'r6_gather_tp',
+            //     'r7_contract_qty', 'r7_contract_tp', 'r7_qc_qty', 'r7_qc_tp', 'r7_gather_qty', 'r7_gather_tp',
+            //     'r8_contract_qty', 'r8_contract_tp', 'r8_qc_qty', 'r8_qc_tp', 'r8_gather_qty', 'r8_gather_tp',
+            //     'r9_contract_qty', 'r9_contract_tp', 'r9_qc_qty', 'r9_qc_tp', 'r9_gather_qty', 'r9_gather_tp',
+            //     'r10_contract_qty', 'r10_contract_tp', 'r10_qc_qty', 'r10_qc_tp', 'r10_gather_qty', 'r10_gather_tp',
+            //     'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
+            //     'chapter',                                                                                              //1
+            // ]);
+        }
     }
 
     return ReportMemory;

+ 84 - 2
test/app/service/report_memory.test.js

@@ -56,11 +56,9 @@ describe('test/app/service/report_memory.test.js', () => {
         const mainData = yield ctx.service.reportMemory.getStageImTzData(12, stage.id);
         const billsData = yield ctx.service.reportMemory.getStageImTzBillsData(12, stage.id);
         if (mainData instanceof Array) {
-            console.log('mem_stage_im_tz.length:' + mainData.length);
             yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_im_tz.json');
         }
         if (billsData instanceof Array) {
-            console.log('mem_stage_im_tz_bills.length:' + billsData.length);
             yield ctx.helper.saveBufferFile(JSON.stringify(billsData,"","\t"), ctx.app.baseDir + '/mem_stage_im_tz_bills.json');
         }
     });
@@ -193,4 +191,88 @@ describe('test/app/service/report_memory.test.js', () => {
             yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_pos.json');
         }
     });
+    // 期 全审核人 数据
+    it('test getStageBillsCompare', function* () {
+        const ctx = app.mockContext(mockData);
+        // test12 - 第4期
+        const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 4});
+        const mainData = yield ctx.service.reportMemory.getStageBillsCompareData(12, stage.id, [
+            'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
+            'code', 'b_code', 'name', 'unit', 'unit_price',
+            'deal_qty', 'deal_tp',
+            'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
+            'dgn_qty1', 'dgn_qty2',
+            'drawing_code', 'memo', 'node_type', 'is_tp',
+            'r0_contract_qty', 'r0_contract_tp', 'r0_qc_qty', 'r0_qc_tp', 'r0_gather_qty', 'r0_gather_tp',
+            'r1_contract_qty', 'r1_contract_tp', 'r1_qc_qty', 'r1_qc_tp', 'r1_gather_qty', 'r1_gather_tp',
+            'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
+            'chapter',
+        ]);
+        if (mainData instanceof Array) {
+            yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_bills_compare.json');
+
+            const tableDefine = {};
+            tableDefine.Name = '期-清单-全参与人数据表(mem_stage_bills_compare)';
+            tableDefine.remark = '';
+            tableDefine.ID = 26;
+            tableDefine.key = 'mem_stage_bills';
+            tableDefine.items = [];
+            addFields(tableDefine, '台账ID', 'id', dataType.int);
+            addFields(tableDefine, '标段ID', 'tender_id', dataType.int);
+            addFields(tableDefine, '树结构-ID', 'ledger_id', dataType.int);
+            addFields(tableDefine, '树结构-父项ID', 'ledger_pid', dataType.int);
+            addFields(tableDefine, '树结构-层级', 'level', dataType.int);
+            addFields(tableDefine, '树结构-同层排序', 'order', dataType.int);
+            addFields(tableDefine, '树结构-完整路径', 'full_path', dataType.int);
+            addFields(tableDefine, '树结构-是否子项', 'is_leaf', dataType.int);
+
+            addFields(tableDefine, '项目节编号', 'code', dataType.str);
+            addFields(tableDefine, '清单编号', 'b_code', dataType.str);
+            addFields(tableDefine, '名称', 'name', dataType.str);
+            addFields(tableDefine, '单位', 'unit', dataType.str);
+            addFields(tableDefine, '单价', 'unit_price', dataType.currency);
+
+            addFields(tableDefine, '签约-数量', 'deal_qty', dataType.currency);
+            addFields(tableDefine, '签约-金额', 'deal_tp', dataType.currency);
+
+            addFields(tableDefine, '施工复核-数量', 'sgfh_qty', dataType.currency);
+            addFields(tableDefine, '施工复核-金额', 'sgfh_tp', dataType.currency);
+            addFields(tableDefine, '设计错漏-数量', 'sjcl_qty', dataType.currency);
+            addFields(tableDefine, '设计错漏-金额', 'sjcl_tp', dataType.currency);
+            addFields(tableDefine, '其他错漏-数量', 'qtcl_qty', dataType.currency);
+            addFields(tableDefine, '其他错漏-金额', 'qtcl_tp', dataType.currency);
+            addFields(tableDefine, '台账-数量', 'quantity', dataType.currency);
+            addFields(tableDefine, '台账-金额', 'total_price', dataType.currency);
+
+            addFields(tableDefine, '项目节-数量1', 'dgn_qty1', dataType.currency);
+            addFields(tableDefine, '项目节-金额2', 'dgn_qty2', dataType.currency);
+
+            addFields(tableDefine, '图册号', 'drawing_code', dataType.str);
+            addFields(tableDefine, '备注', 'memo', dataType.str);
+            addFields(tableDefine, '节点类型', 'node_type', dataType.int);
+            addFields(tableDefine, '总额计量', 'is_tp', dataType.int);
+
+            addFields(tableDefine, '截止上期-合同-数量', 'pre_contract_qty', dataType.currency);
+            addFields(tableDefine, '截止上期-合同-金额', 'pre_contract_tp', dataType.currency);
+            addFields(tableDefine, '截止上期-数量变更-数量', 'pre_qc_qty', dataType.currency);
+            addFields(tableDefine, '截止上期-数量变更-金额', 'pre_qc_tp', dataType.currency);
+            addFields(tableDefine, '截止上期-完成-数量', 'pre_gather_qty', dataType.currency);
+            addFields(tableDefine, '截止上期-完成-金额', 'pre_gather_tp', dataType.currency);
+
+            for (let i = 0 ;i < 10; i++) {
+                addFields(tableDefine, '本期-合同-数量' + '_' + i, 'r' + i +'_' + 'contract_qty', dataType.currency);
+                addFields(tableDefine, '本期-合同-金额' + '_' + i, 'r' + i +'_' + 'contract_tp', dataType.currency);
+                addFields(tableDefine, '本期-数量变更-数量' + '_' + i, 'r' + i +'_' + 'qc_qty', dataType.currency);
+                addFields(tableDefine, '本期-数量变更-金额' + '_' + i, 'r' + i +'_' + 'qc_tp', dataType.currency);
+                addFields(tableDefine, '本期-完成-数量' + '_' + i, 'r' + i +'_' + 'gather_qty', dataType.currency);
+                addFields(tableDefine, '本期-完成-金额' + '_' + i, 'r' + i +'_' + 'gather_tp', dataType.currency);
+            }
+
+            addFields(tableDefine, '章节编号', 'chapter', dataType.str);
+
+            delete tableDefine.ID;
+            delete tableDefine.key;
+            yield ctx.helper.saveBufferFile(JSON.stringify(tableDefine,"","\t"), ctx.app.baseDir + '/mem_stage_bills_compare_define.json');
+        }
+    });
 });