'use strict'; /** * * * @author Mai * @date * @version */ const { app, assert } = require('egg-mock/bootstrap'); const mockData = {}; const path = require('path'); let savePath; const reportDataAnalysis = require('../../../app/lib/rpt_data_analysis'); 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: 'fuqingqing', // project: 'P0505', // project_password: '123456', // }; const postData = { account: '734406061@qq.com', project: 'T201711273363', project_password: 'mai654321', }; ctx.session = {}; const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2); assert(loginResult); mockData.session = ctx.session; }); // 数据 it('test changeSort', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['change', 'change_audit_list']; const data = yield ctx.service.report.getReportData(params, filters); reportDataAnalysis.analysisObj.changeSort.fun(ctx, data); assert(data.change[0].code === 'test7-BG-001'); assert(data.change[2].code === 'test7-BG-003'); const changeCid = ctx.helper._.map(data.change, 'cid'); const changeBillsCid = ctx.helper._.uniq(ctx.helper._.map(data.change_audit_list, 'cid')); assert(changeCid.length === changeBillsCid.length); changeCid.forEach(function (a, i) { assert(a === changeBillsCid[i]); }); }); it('test gatherGcl && sortGcl', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['mem_stage_bills']; const data = yield ctx.service.report.getReportData(params, filters, { mem_stage_bills: [ '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', ] }); assert(data.mem_stage_bills.length === 216); reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, {field: 'name', table: 'mem_stage_bills'}, {field: 'unit', table: 'mem_stage_bills'}, {field: 'unit_price', table: 'mem_stage_bills'}, {field: 'is_leaf', table: 'mem_stage_bills'}, ]); assert(data.mem_stage_bills.length === 43); reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, ]); const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code'); const codeIndex100 = ['103-1', '103-2', '103-3-a', '103-3-b', '103-4', '104-1']; const codeIndex200 = [ '203-1-a', '203-1-b', '203-1-d', '204-1-b', '204-1-g-4', '204-1-j', '205-1-o-1', '206-2', '207-1-b', '207-2-a', '207-3-a', '207-4-a', '208-1-a', '208-3-a', '208-3-c', '208-4-b-1', '209-1-a', ]; const codeIndex400 = [ '403-1-a', '403-1-b', '403-2-a', '403-2-b', '403-3-a', '403-3-b', '403-4-a', '403-4-b', '405-1-b-5', '405-1-b-6', '410-1-b', '410-1-c', '410-2-b', '410-2-c', '410-6-c', '411-5', '411-7-a', '411-8-a', '413-1-a', '417-5-a' ]; let codeResult = codeIndex100.concat(codeIndex200, codeIndex400); codeIndex.forEach(function (a, i) { assert(a === codeResult[i]); }); }); it('test gatherChapter', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['mem_stage_bills', 'tender_info']; const data = yield ctx.service.report.getReportData(params, filters, { mem_stage_bills: [ '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', ] }); reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, {field: 'is_leaf', table: 'mem_stage_bills'}, ]); const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'}); assert(chapter100.total_price === 1045756); const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'}); assert(chapter200.total_price.toFixed(0) == 3813369); assert(chapter200.contract_tp == 700.5); const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'}); assert(chapter400.total_price.toFixed(0) == 1231018); }); it('test gatherChapter', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['mem_stage_bills', 'tender_info']; const data = yield ctx.service.report.getReportData(params, filters, { mem_stage_bills: [ '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', ] }); reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, {field: 'is_leaf', table: 'mem_stage_bills'}, ]); const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'}); assert(chapter100.total_price === 1045756); const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'}); assert(chapter200.total_price.toFixed(0) == 3813369); assert(chapter200.contract_tp == 700.5); const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'}); assert(chapter400.total_price.toFixed(0) == 1231018); }); it('test loadCooperationData', function* () { const ctx = app.mockContext(mockData); const stage = yield ctx.service.stage.getDataByCondition({tid: 3301, order: 1}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const data = yield ctx.service.report.getReportData(params, ['mem_stage_bills', 'stage', 'stage_audit', 'ledger_cooperation', 'mem_stage_im_zl'], { mem_stage_bills: [ 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf' ], mem_stage_im_zl: ['lid', 'code'], }); reportDataAnalysis.analysisObj.loadCooperationData.fun(ctx, data, [], {table: 'mem_stage_im_zl', co_sign: [0, 1, 2, 3]}, null); console.log(data.mem_stage_im_zl); }); it('test join', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6}); const params = { tender_id: stage.tid, stage_id: stage.id, }; const filters = ['mem_stage_bills', 'deal_bills']; const data = yield ctx.service.report.getReportData(params, filters, { mem_stage_bills: [ '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', ] }); assert(data.mem_stage_bills.length === 216); reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, {field: 'name', table: 'mem_stage_bills'}, {field: 'unit', table: 'mem_stage_bills'}, {field: 'unit_price', table: 'mem_stage_bills'}, {field: 'is_leaf', table: 'mem_stage_bills'}, ]); assert(data.mem_stage_bills.length === 43); const joinOptions = { main: 'mem_stage_bills', sub: 'deal_bills', keyFields: [ {main: 'b_code', sub: 'code', type: 'string'}, {main: 'name', sub: 'name',type: 'string'}, {main: 'unit', sub: 'unit',type: 'string'}, {main: 'unit_price', sub: 'unit_price',type: 'number'}, ], importFields: [ {main: 'ex_value1', sub: 'quantity', type: 'number'}, {main: 'ex_value2', sub: 'total_price', type: 'number'} ], joinType: 'outer', //'outer', 'main', 'sub', 'inner' }; yield ctx.helper.saveBufferFile(JSON.stringify(joinOptions, '', '\t'), ctx.app.baseDir + '/analysis_join_options.json'); reportDataAnalysis.analysisObj.join.fun(ctx, data, [], joinOptions); assert(data.mem_stage_bills.length === 132); reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [ {field: 'b_code', table: 'mem_stage_bills'}, ]); const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code'); const codeIndex100 = ['101-1-b', '102-2', '102-3', '102-4', '102-5', '103-1', '103-2', '103-3', '103-3-a', '103-3-b', '103-4', '104-1', '123-1']; const codeIndex200 = [ '203-1-a', '203-1-a', '203-1-b', '203-1-b', '203-1-d', '203-1-d', '204-1-b', '204-1-b', '204-1-c', '204-1-d', '204-1-g-4', '204-1-g-4', '204-1-j', '204-1-j', '205-1-o-1', '205-1-o-1', '206-2', '206-2', '207-1-b', '207-2-a', '207-2-a', '207-2-b', '207-2-c', '207-3-a', '207-4-a', '207-4-a', '207-4-c', '207-10-a', '208-1-a', '208-1-a', '208-3-a', '208-3-a', '208-3-b', '208-3-c', '208-3-c', '208-4-b-1', '208-4-b-1', '209-1-a', '209-1-a', '209-3', '209-3-b', '215-12', '215-12-a' ]; let codeResult = codeIndex100.concat(codeIndex200); codeResult.forEach(function (a, i) { assert(a === codeIndex[i]); }); }); it('test filter', function* () { const ctx = app.mockContext(mockData); const orgData = { test: [ {a: 'aaa', b: 0, c: true, order: 1}, {a: 'aaa', b: 1, c: false, order: 2}, {a: 'aaa', b: 2, c: false, order: 3}, {a: 'bbb', b: 3, c: true, order: 4}, {a: 'bbb', b: null, c: true, order: 5}, {a: 'ccc', b: 0, c: false, order: 6}, {a: 'ccc', b: -1, c: false, order: 7}, {a: 'ddd', b: 8, c: true, order: 8}, ] }; let data, result; // test boolean; const b1 = { table: 'test', condition: [{ field: "c", type: "bool", value: 'false'}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b1); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [2, 3, 6, 7])); const b2 = { table: 'test', condition: [{ field: "c", type: "bool", value: 'true'}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b2); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [1, 4, 5, 8])); // test number const n1 = { table: 'test', condition: [{ field: "b", type: "num", operate: 'non-zero'}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n1); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [2, 3, 4, 7, 8])); const n2 = { table: 'test', condition: [{ field: "b", type: "num", operate: '=', value: 1}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n2); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [2])); const n3 = { table: 'test', condition: [{ field: "b", type: "num", operate: '>', value: 1}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n3); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [3, 4, 8])); const n4 = { table: 'test', condition: [{ field: "b", type: "num", operate: '>=', value: 1}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n4); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [2, 3, 4, 8])); const n5 = { table: 'test', condition: [{ field: "b", type: "num", operate: '<', value: 1}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n5); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [1, 6, 7])); const n6 = { table: 'test', condition: [{ field: "b", type: "num", operate: '<=', value: 1}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n6); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [1, 2, 6, 7])); // string const s1 = { table: 'test', condition: [{ field: "a", type: "str", operate: '=', value: 'aaa'}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s1); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [1, 2, 3])); const s2 = { table: 'test', condition: [{ field: "a", type: "str", operate: 'part', value: 'b'}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s2); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [4, 5])); const s3 = { table: 'test', condition: [{ field: "a", type: "str", operate: 'enum', value: ['ccc', 'ddd']}] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s3); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [6, 7, 8])); // mix const m1 = { table: 'test', condition: [ { field: "c", type: "bool", value: 'true'}, { field: "b", type: "num", operate: 'non-zero'}, { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd']}, ] }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m1); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [8])); // mix2 const m2 = { table: 'test', condition: [ { field: "c", type: "bool", value: 'true'}, { field: "b", type: "num", operate: 'non-zero', rela: "or"}, { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd'], rela: "and"}, ], }; data = JSON.parse(JSON.stringify(orgData)); reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m2, true); result = ctx.helper._.map(data.test, 'order'); assert(ctx.helper._.isEqual(result, [1, 2, 3, 8])); }); // it('test gatherChapter custom', function* () { // const ctx = app.mockContext(mockData); // // const params = {tender_id: 2072}; // const filters = ['mem_stage_bills', 'tender_info']; // const data = yield ctx.service.report.getReportData(params, filters, { // mem_stage_bills: [ // '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', // 'qc_bgl_code', // 'chapter', // ] // }); // reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [ // {field: 'b_code', table: 'mem_stage_bills'}, // {field: 'is_leaf', table: 'mem_stage_bills'}, // ], { // count: 7, // gclSum: { // name: '第100章至700章清单合计', // order: 1, // }, // custom: [ // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2}, // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3}, // {name: '计日工合计', node_type: '计日工', order: 4}, // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5}, // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6}, // ], // }); // const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'}); // assert(ctx.helper.checkZero(chapter100.total_price)); // const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'}); // assert(chapter200.total_price === 33211); // const chapterGclSum = ctx.helper._.find(data.mem_stage_bills, {cType: 11}); // assert(chapterGclSum.total_price == 33211); // const chapterJRG = ctx.helper._.find(data.mem_stage_bills, {name: '计日工合计'}); // assert(chapterJRG.total_price === 1076); // const chapterSumWithoutZGJ = ctx.helper._.find(data.mem_stage_bills, {serialNo: 11}); // assert(chapterSumWithoutZGJ.total_price === 33211); // const chapterZL = ctx.helper._.find(data.mem_stage_bills, {serialNo: 13}); // assert(chapterZL.total_price === 500000); // const chapterSum = ctx.helper._.find(data.mem_stage_bills, {serialNo: 14}); // assert(chapterSum.total_price === 534287); // }); it('test analysisDefine', function() { const ctx = app.mockContext(mockData); const define = reportDataAnalysis.analysisDefine; assert(define.length === 7); assert(define[0].key === 'changeSort'); assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name); assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint); assert(define[1].key === 'gatherGcl'); assert(define[1].name === reportDataAnalysis.analysisObj.gatherGcl.name); assert(define[1].hint === reportDataAnalysis.analysisObj.gatherGcl.hint); assert(define[2].key === 'sortGcl'); assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name); assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint); // const x = { // count: 7, // gclSum: { // name: '第100章至700章清单合计', // order: 1, // }, // custom: [ // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2}, // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3}, // {name: '计日工合计', node_type: '计日工', order: 4}, // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5}, // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6}, // ], // }; // ctx.helper.saveBufferFile(JSON.stringify(x, "", "\t"), ctx.app.baseDir + '/mem_stage_pos.json'); }); it('test sortPos/unionPos', function* () { const ctx = app.mockContext(); const postData = { account: 'zengpeiwen', project: 'P1201', project_password: '123456', }; ctx.session = {}; const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2); // test12 - 第6期 const params = { tender_id: 2546, }; const filters = ['mem_stage_bills', 'tender_info', 'mem_stage_pos']; const data = yield ctx.service.report.getReportData(params, filters, { mem_stage_bills: [ 'id' ], mem_stage_pos: ['name'], }); // sortPos reportDataAnalysis.analysisObj.sortPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'}); yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json')); yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_pos, "", "\t"), path.join(savePath, 'mem_stage_pos.json')); // unionPos // reportDataAnalysis.analysisObj.unionPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'}); // yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json')); }); it('test splitXmjCode', function* () { const ctx = app.mockContext(mockData); // test12 - 第6期 const testData11 = { bills: [ { code: '1', level: 1 }, { code: '1-1', level: 2 }, { code: '1-1-1', level: 3 }, { code: '1-1-1-1', level: 4 }, { code: '1-1-1-1-1', level: 5 }, { code: '1-1-1-1-1-1', level: 6 }, ] }; reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData11, [], {table: 'bills', type: '11', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']}); assert(testData11.bills[1].xiang === '一' ); assert(testData11.bills[2].mu ==='1'); assert(testData11.bills[3].jie === '1'); assert(testData11.bills[4].ximu === '1'); assert(testData11.bills[5].ximu === '1-1'); reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData11, [], {table: 'bills', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']}); assert(testData11.bills[1].xiang === '1-1' ); assert(testData11.bills[2].mu === '1-1-1'); assert(testData11.bills[3].jie === '1-1-1-1'); assert(testData11.bills[4].ximu === '1-1-1-1-1'); assert(testData11.bills[5].ximu === '1-1-1-1-1-1'); const testData18 = { bills: [ { code: '1', level: 1, ledger_id: 1, ledger_pid: -1, full_path: '1' }, // 0 { code: '101', level: 2, ledger_id: 2, ledger_pid: 1, full_path: '1-2' }, { code: '10101', level: 3, ledger_id: 3, ledger_pid: 2, full_path: '1-2-3' }, { code: '1010101', level: 4, ledger_id: 4, ledger_pid: 3, full_path: '1-2-3-4' }, { code: '1010103', level: 4, ledger_id: 5, ledger_pid: 3, full_path: '1-2-3-5' }, { code: '101010301', level: 5, ledger_id: 6, ledger_pid: 5, full_path: '1-2-3-5-6' }, // 5 { code: '102', level: 2, ledger_id: 7, ledger_pid: 1, full_path: '1-7' }, { code: 'LJ05', level: 3, ledger_id: 8, ledger_pid: 7, full_path: '1-7-8' }, { code: 'LJ0502', level: 4, ledger_id: 9, ledger_pid: 8, full_path: '1-7-8-9' }, { code: 'LJ050204', level: 5, ledger_id: 10, ledger_pid: 9, full_path: '1-7-8-9-10' }, { code: 'GDLJ05020401', level: 6, ledger_id: 11, ledger_pid: 10, full_path: '1-7-8-9-10-11' }, // 10 ] }; reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']}); assert(testData18.bills[1].xiang === '01'); assert(testData18.bills[2].mu === '01'); assert(testData18.bills[3].jie === '01'); assert(testData18.bills[4].jie === '03'); assert(testData18.bills[5].ximu === '01'); assert(testData18.bills[6].xiang === '02'); assert(testData18.bills[7].mu === 'LJ05'); assert(testData18.bills[8].jie === 'LJ0502'); assert(testData18.bills[9].ximu === 'LJ050204'); assert(testData18.bills[10].ximu === 'LJ05020401'); reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']}); assert(testData18.bills[1].xiang === '01'); assert(testData18.bills[2].mu === '01'); assert(testData18.bills[3].jie === '01'); assert(testData18.bills[4].jie === '03'); assert(testData18.bills[5].ximu === '01'); assert(testData18.bills[6].xiang === '02'); assert(testData18.bills[7].mu === 'LJ05'); assert(testData18.bills[8].jie === '02'); assert(testData18.bills[9].ximu === '04'); assert(testData18.bills[10].ximu === '0401'); reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-0-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']}); assert(testData18.bills[1].xiang === '01'); assert(testData18.bills[2].mu === '01'); assert(testData18.bills[3].jie === '01'); assert(testData18.bills[4].jie === '03'); assert(testData18.bills[5].ximu === '01'); assert(testData18.bills[6].xiang === '02'); assert(testData18.bills[7].mu === 'LJ05'); assert(testData18.bills[8].jie === 'LJ0502'); assert(testData18.bills[9].ximu === 'LJ050204'); assert(testData18.bills[10].ximu === 'GDLJ05020401'); reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-1-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']}); assert(testData18.bills[1].xiang === '01'); assert(testData18.bills[2].mu === '01'); assert(testData18.bills[3].jie === '01'); assert(testData18.bills[4].jie === '03'); assert(testData18.bills[5].ximu === '01'); assert(testData18.bills[6].xiang === '02'); assert(testData18.bills[7].mu === 'LJ05'); assert(testData18.bills[8].jie === '02'); assert(testData18.bills[9].ximu === '04'); assert(testData18.bills[10].ximu === 'GD0401'); }); it('test treeFilter', function* () { const ctx = app.mockContext(mockData); const orgData = [ { id: 1, pid: -1, order: 1, level: 1, full_path: '1', code: '1', is_leaf: false }, { id: 2, pid: 1, order: 1, level: 2, full_path: '1.2', code: '1-1', is_leaf: false }, { id: 6, pid: 2, order: 1, level: 3, full_path: '1.2.6', code: '1-1-1', is_leaf: false }, { id: 7, pid: 6, order: 1, level: 4, full_path: '1.2.6.7', code: '202-1', is_leaf: false }, { id: 10, pid: 7, order: 2, level: 5, full_path: '1.2.6.7.10', code: '202-1-a', is_leaf: true }, { id: 9, pid: 7, order: 1, level: 5, full_path: '1.2.6.7.9', code: '202-1-b', is_leaf: true }, { id: 8, pid: 6, order: 2, level: 4, full_path: '1.2.6.8', code: '202-2', is_leaf: false }, { id: 11, pid: 8, order: 1, level: 5, full_path: '1.2.6.8.11', code: '202-2-c', is_leaf: true }, { id: 12, pid: 8, order: 2, level: 5, full_path: '1.2.6.8.12', code: '202-2-e', is_leaf: true }, { id: 13, pid: 2, order: 2, level: 3, full_path: '1.2.13', code: '1-1-2', is_leaf: true }, { id: 14, pid: 2, order: 3, level: 3, full_path: '1.2.14', code: '1-1-3', is_leaf: true }, { id: 3, pid: 1, order: 2, level: 2, full_path: '1.3', code: '1-2', is_leaf: false }, { id: 15, pid: 3, order: 1, level: 3, full_path: '1.3.15', code: '1-2-1', is_leaf: true }, { id: 4, pid: 1, order: 3, level: 2, full_path: '1.4', code: '1-3', is_leaf: false }, { id: 16, pid: 4, order: 1, level: 3, full_path: '1.4.16', code: '1-3-1', is_leaf: true }, { id: 5, pid: 1, order: 4, level: 2, full_path: '1.5', code: '1-4', is_leaf: true }, ]; const data = { mem_stage_bills: orgData }; reportDataAnalysis.analysisObj.treeFilter.fun(ctx, data, [], { table: 'mem_stage_bills', type: 'match', subType: 'posterity', condition: [ { field: 'code', type: 'str', value: '1-1', operate: '=' }, ], }); assert(data.mem_stage_bills.length = 9); }); });