浏览代码

新增两张内存表数据

MaiXinRong 5 年之前
父节点
当前提交
54793200d5
共有 4 个文件被更改,包括 152 次插入0 次删除
  1. 8 0
      app/controller/report_controller.js
  2. 16 0
      app/lib/ledger.js
  3. 106 0
      app/service/report_memory.js
  4. 22 0
      test/app/service/report_memory.test.js

+ 8 - 0
app/controller/report_controller.js

@@ -367,6 +367,14 @@ async function getReportData(ctx, params, filters, memFieldKeys) {
                     runnableRst.push(ctx.service.reportMemory.getMonthProgress(params.tender_id));
                     runnableKey.push('mem_month_progress');
                     break;
+                case 'mem_stage_bills':
+                    runnableRst.push(ctx.service.reportMemory.getStageBillsData(params.tender_id, params.stage_id));
+                    runnableKey.push('mem_stage_pos');
+                    break;
+                case 'mem_stage_pos':
+                    runnableRst.push(ctx.service.reportMemory.getStagePosData(params.tender_id, params.stage_id));
+                    runnableKey.push('mem_stage_pos');
+                    break;
                 case 'change':
                     runnableRst.push(ctx.service.change.getListByStatus(params.tender_id, 3)); // 获取所有审核通过的变更主信息
                     runnableKey.push('change');

+ 16 - 0
app/lib/ledger.js

@@ -244,6 +244,18 @@ class billsTree {
             }
         }
     }
+
+    getDatas (fields) {
+        const datas = [];
+        for (const node of this.nodes) {
+            const data = {};
+            for (const field of fields) {
+                data[field] = node[field];
+            }
+            datas.push(data);
+        }
+        return datas;
+    }
 }
 
 class pos {
@@ -306,6 +318,10 @@ class pos {
             this.setting.calc(pos);
         }
     }
+
+    getDatas () {
+        return this.datas;
+    }
 }
 
 module.exports = {

+ 106 - 0
app/service/report_memory.js

@@ -19,6 +19,8 @@ const stageImTzBills = 'mem_stage_im_tz_bills';
 const stageImZl = 'mem_stage_im_zl';
 const stageImVersion = '1.0';
 
+const Ledger = require('../lib/ledger');
+
 module.exports = app => {
     class ReportMemory extends app.BaseService {
 
@@ -30,7 +32,45 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
+            const self = this;
             this.tableName = 'report_memory';
+            // 基础数据类
+            // mainData
+            this.billsTree = new Ledger.billsTree(this.ctx, {
+                id: 'ledger_id',
+                pid: 'ledger_pid',
+                order: 'order',
+                level: 'level',
+                rootId: -1,
+                keys: ['id', 'tender_id', 'ledger_id'],
+                stageId: 'id',
+                calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp'],
+                calc: function (node) {
+                    if (node.children && node.children.length === 0) {
+                        node.pre_gather_qty = self.ctx.helper.add(node.pre_contract_qty, node.pre_qc_qty);
+                        node.gather_qty = self.ctx.helper.add(node.contract_qty, node.qc_qty);
+                        node.end_contract_qty = self.ctx.helper.add(node.pre_contract_qty, node.contract_qty);
+                        node.end_qc_qty = self.ctx.helper.add(node.pre_qc_qty, node.qc_qty);
+                        node.end_gather_qty = self.ctx.helper.add(node.pre_gather_qty, node.gather_qty);
+                    }
+                    node.pre_gather_tp = self.ctx.helper.add(node.pre_contract_tp, node.pre_qc_tp);
+                    node.gather_tp = self.ctx.helper.add(node.contract_tp, node.qc_tp);
+                    node.end_contract_tp = self.ctx.helper.add(node.pre_contract_tp, node.contract_tp);
+                    node.end_qc_tp = self.ctx.helper.add(node.pre_qc_tp, node.qc_tp);
+                    node.end_gather_tp = self.ctx.helper.add(node.pre_gather_tp, node.gather_tp);
+                }
+            });
+            this.pos = new Ledger.pos({
+                id: 'id', ledgerId: 'lid',
+                updateFields: ['contract_qty', 'qc_qty', 'postil'],
+                calc: function (p) {
+                    p.pre_gather_qty = ctx.helper.add(p.pre_contract_qty, p.pre_qc_qty);
+                    p.gather_qty = ctx.helper.add(p.contract_qty, p.qc_qty);
+                    p.end_contract_qty = self.ctx.helper.add(p.pre_contract_qty, p.contract_qty);
+                    p.end_qc_qty = self.ctx.helper.add(p.pre_qc_qty, p.qc_qty);
+                    p.end_gather_qty = self.ctx.helper.add(p.pre_gather_qty, p.gather_qty);
+                }
+            });
             // 需要缓存的数据
             this.stageImData = null;
         }
@@ -236,6 +276,72 @@ module.exports = app => {
             }
             return monthProgress;
         }
+
+        async getStageBillsData(tid, sid, fields) {
+            await this.ctx.service.tender.checkTender(tid);
+            await this.ctx.service.stage.checkStage(sid);
+
+
+            const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
+            if (this.ctx.stage.readOnly) {
+                const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
+                    this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
+                this.ctx.helper.assignRelaData(billsData, [
+                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
+                ]);
+            } else {
+                const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
+                this.ctx.helper.assignRelaData(billsData, [
+                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
+                ]);
+            }
+            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.calculateAll();
+
+            return this.billsTree.getDatas([
+                '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',
+                'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil',
+                'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp',
+                'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp',
+            ]);
+        }
+
+        async getStagePosData(tid, sid, fields) {
+            await this.ctx.service.tender.checkTender(tid);
+            await this.ctx.service.stage.checkStage(sid);
+
+            const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
+            if (this.ctx.stage.readOnly) {
+                const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
+                    this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
+                this.ctx.helper.assignRelaData(posData, [
+                    {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
+                ]);
+            } else {
+                const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
+                this.ctx.helper.assignRelaData(posData, [
+                    {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
+                ]);
+            }
+            const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
+            this.ctx.helper.assignRelaData(posData, [
+                {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
+            ]);
+            this.pos.loadDatas(posData);
+            this.pos.calculateAll();
+
+            return this.pos.getDatas();
+        }
     }
 
     return ReportMemory;

+ 22 - 0
test/app/service/report_memory.test.js

@@ -69,4 +69,26 @@ describe('test/app/service/report_memory.test.js', () => {
             yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_month_progress.json');
         }
     });
+    // 月进度数据
+    it('test getStageBills', function* () {
+        const ctx = app.mockContext(mockData);
+
+        // test12 - 第6期
+        const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
+        const mainData = yield ctx.service.reportMemory.getStageBillsData(12, stage.id);
+        if (mainData instanceof Array) {
+            yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_bills.json');
+        }
+    });
+    // 月进度数据
+    it('test getStagePos', function* () {
+        const ctx = app.mockContext(mockData);
+
+        // test12 - 第6期
+        const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
+        const mainData = yield ctx.service.reportMemory.getStagePosData(12, stage.id);
+        if (mainData instanceof Array) {
+            yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_pos.json');
+        }
+    });
 });