| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 | 'use strict';/** * * * @author Mai * @date * @version */const { app, assert } = require('egg-mock/bootstrap');const path = require('path');let savePath;const mockData = {};const dataType = {    int: 'int',    str: 'string',    double: 'double',    currency: 'currency',};const addFields = function(table, name, field, type, tag) {    const data = {};    data.ID = table.ID * 100 + table.items.length + 1;    data.Name = name + '(' + field + ')';    data.DataType = type;    data.TableName = table.key;    data.descr = '';    data.mapExpression = "$PROJECT.REPORT.getProperty('" + table.key + "', '" + field + "')";    if (tag) {        switch (tag.type) {            case 'up':                data.Precision = { type: "fixed", fixedMapExpression: "$PROJECT.REPORT.getProperty('tender_info', 'decimal.up')" };                break;            case 'tp':                if (tag.subType) {                    data.Precision = { type: "fixed", fixedMapExpression: "$PROJECT.REPORT.getProperty('tender_info', 'decimal." + "_" + tag.subType + "_tp')" };                } else {                    data.Precision = { type: "fixed", fixedMapExpression: "$PROJECT.REPORT.getProperty('tender_info', 'decimal.tp')" };                }                break;            case 'qty':                data.Precision = { type: "flexible", flexibleRefFieldID: table.ID * 100 + tag.unitKey, flexibleMapExpression: "$PROJECT.REPORT.getProperty('tender_info', 'precision')" };                break;        }    }    table.items.push(data);};const saveTableDefine = async function (ctx, tableDefine, file) {    delete tableDefine.ID;    delete tableDefine.key;    let defineStr = JSON.stringify(tableDefine, "", "\t");    const replaceStr = [        {match: '"Name":', str: 'Name:'},        {match: '"remark":', str: 'remark:'},        {match: '"items":', str: 'items:'},        {match: '"ID":', str: 'ID:'},        {match: '"DataType":', str: 'DataType:'},        {match: '"TableName":', str: 'TableName:'},        {match: '"descr":', str: 'descr:'},        {match: '"mapExpression":', str: 'mapExpression:'},        {match: '"Precision":', str: 'Precision:'},        {match: '"type":', str: 'type:'},        {match: '"flexibleRefFieldID":', str: 'flexibleRefFieldID:'},        {match: '"fixedMapExpression":', str: 'fixedMapExpression:'},        {match: '"flexibleMapExpression":', str: 'flexibleMapExpression:'},    ];    for (const rs of replaceStr) {        const reg = new RegExp(rs.match, 'gm');        defineStr = defineStr.replace(reg, rs.str);    }    await ctx.helper.saveBufferFile(defineStr, file);};describe('test/app/service/report_memory.test.js', () => {    // 准备测试数据    before(function* () {        const ctx = app.mockContext();        savePath = path.join(ctx.app.baseDir,'report_temp');        // 模拟登录session        // const postData = {        //     account: '734406061@qq.com',        //     project: 'T201711273363',        //     project_password: 'mai654321',        // };        // const postData = {        //     account: 'chente',        //     project: 'T201711273363',        //     project_password: '123456',        // };        const postData = {            account: 'zengpeiwen',            project: 'P1201',            project_password: '123456',        };        ctx.session = {};        const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);        assert(loginResult);        mockData.session = ctx.session;    });    // 中间计量表数据 - 台账    it('test getStageImTzData & getStageImTzBillsData', 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.getStageImTzData(12, stage.id);        const billsData = yield ctx.service.reportMemory.getStageImTzBillsData(12, stage.id);        if (mainData instanceof Array) {            yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_im_tz.json');        }        if (billsData instanceof Array) {            yield ctx.helper.saveBufferFile(JSON.stringify(billsData,"","\t"), ctx.app.baseDir + '/mem_stage_im_tz_bills.json');        }    });    // 中间计量表数据 - 总量    it('test getStageImZlData', 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.getStageImZlData(12, stage.id);        if (mainData instanceof Array) {            yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_im_zl.json');        }    });    // 月进度数据    it('test getMonthProgress', function* () {        const ctx = app.mockContext(mockData);        // test12        const mainData = yield ctx.service.reportMemory.getMonthProgress(12);        if (mainData instanceof Array) {            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, [            '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', 'gather_qty', 'gather_tp', 'postil',            'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',            'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',            'final_tp', 'final_ratio',            'qc_bgl_code',            'chapter',        ]);        if (mainData instanceof Array) {            yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), path.join(savePath, '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"), path.join(savePath, '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"), path.join(savePath, 'mem_stage_bills_compare.json'));        }    });    it('test getStagePay', function* () {        const ctx = app.mockContext(mockData);        // test12 - 第4期        const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});        const data = yield ctx.service.reportMemory.getStagePayData(stage.tid, stage.id, ['r0_tp', 'r1_tp']);        if (data instanceof Array) {            yield ctx.helper.saveBufferFile(JSON.stringify(data, '', '\t'), path.join(savePath, 'mem_stage_pay.json'));        }    });    it('test mem_union_data', function* () {        const ctx = app.mockContext(mockData);        const tableDefine = {};        tableDefine.Name = '预留扩展数据-合并(mem_union_data)';        tableDefine.remark = '';        tableDefine.ID = 28;        tableDefine.key = 'mem_union_data';        tableDefine.items = [];        const prefix = '预留扩展数据-合并-';        addFields(tableDefine, prefix + '字符串1', 'str1', dataType.str);        addFields(tableDefine, prefix + '字符串2', 'str2', dataType.str);        addFields(tableDefine, prefix + '字符串3', 'str3', dataType.str);        addFields(tableDefine, prefix + '字符串4', 'str4', dataType.str);        addFields(tableDefine, prefix + '字符串5', 'str5', dataType.str);        addFields(tableDefine, prefix + '字符串6', 'str6', dataType.str);        addFields(tableDefine, prefix + '字符串7', 'str7', dataType.str);        addFields(tableDefine, prefix + '字符串8', 'str8', dataType.str);        addFields(tableDefine, prefix + '字符串9', 'str9', dataType.str);        addFields(tableDefine, prefix + '字符串10', 'str10', dataType.str);        addFields(tableDefine, prefix + '整数1', 'int1', dataType.int);        addFields(tableDefine, prefix + '整数2', 'int2', dataType.int);        addFields(tableDefine, prefix + '整数3', 'int3', dataType.int);        addFields(tableDefine, prefix + '整数4', 'int4', dataType.int);        addFields(tableDefine, prefix + '整数5', 'int5', dataType.int);        addFields(tableDefine, prefix + '整数6', 'int6', dataType.int);        addFields(tableDefine, prefix + '数量1', 'qty1', dataType.currency);        addFields(tableDefine, prefix + '数量2', 'qty2', dataType.currency);        addFields(tableDefine, prefix + '数量3', 'qty3', dataType.currency);        addFields(tableDefine, prefix + '数量4', 'qty4', dataType.currency);        addFields(tableDefine, prefix + '数量5', 'qty5', dataType.currency);        addFields(tableDefine, prefix + '数量6', 'qty6', dataType.currency);        addFields(tableDefine, prefix + '数量7', 'qty7', dataType.currency);        addFields(tableDefine, prefix + '数量8', 'qty8', dataType.currency);        addFields(tableDefine, prefix + '数量9', 'qty9', dataType.currency);        addFields(tableDefine, prefix + '数量10', 'qty10', dataType.currency);        addFields(tableDefine, prefix + '金额1', 'tp1', dataType.currency);        addFields(tableDefine, prefix + '金额2', 'tp2', dataType.currency);        addFields(tableDefine, prefix + '金额3', 'tp3', dataType.currency);        addFields(tableDefine, prefix + '金额4', 'tp4', dataType.currency);        addFields(tableDefine, prefix + '金额5', 'tp5', dataType.currency);        addFields(tableDefine, prefix + '金额6', 'tp6', dataType.currency);        addFields(tableDefine, prefix + '金额7', 'tp7', dataType.currency);        addFields(tableDefine, prefix + '金额8', 'tp8', dataType.currency);        addFields(tableDefine, prefix + '金额9', 'tp9', dataType.currency);        addFields(tableDefine, prefix + '金额10', 'tp10', dataType.currency);        yield saveTableDefine(ctx, tableDefine, path.join(savePath, 'mem_union_data.json'));    });    it('test mem_change_bills && mem_change ', function* () {        const ctx = app.mockContext(mockData);        const change = yield ctx.service.reportMemory.getChangeData(12);        if (change instanceof Array) {            yield ctx.helper.saveBufferFile(JSON.stringify(change, '', '\t'), path.join(savePath, 'mem_change.json'));        }        const data = yield ctx.service.reportMemory.getChangeBillsData(12);        if (data instanceof Array) {            yield ctx.helper.saveBufferFile(JSON.stringify(data, '', '\t'), path.join(savePath, 'mem_change_bills.json'));        }    });});
 |