rpt_data_analysis.test.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const { app, assert } = require('egg-mock/bootstrap');
  10. const mockData = {};
  11. const path = require('path');
  12. let savePath;
  13. const reportDataAnalysis = require('../../../app/lib/rpt_data_analysis');
  14. const sourceTypeConst = require('../const/source_type');
  15. describe('test/app/service/report_memory.test.js', () => {
  16. // 准备测试数据
  17. before(function* () {
  18. const ctx = app.mockContext();
  19. savePath = path.join(ctx.app.baseDir,'report_temp');
  20. // 模拟登录session
  21. // const postData = {
  22. // account: 'fuqingqing',
  23. // project: 'P0505',
  24. // project_password: '123456',
  25. // };
  26. const postData = {
  27. account: '734406061@qq.com',
  28. project: 'T201711273363',
  29. project_password: 'mai654321',
  30. };
  31. ctx.session = {};
  32. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  33. assert(loginResult);
  34. mockData.session = ctx.session;
  35. });
  36. // 数据
  37. it('test changeSort', function* () {
  38. const ctx = app.mockContext(mockData);
  39. // test12 - 第6期
  40. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  41. const params = {
  42. tender_id: stage.tid,
  43. stage_id: stage.id,
  44. };
  45. const filters = ['change', 'change_audit_list'];
  46. const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters);
  47. reportDataAnalysis.analysisObj.changeSort.fun(ctx, data);
  48. assert(data.change[0].code === 'test7-BG-001');
  49. assert(data.change[2].code === 'test7-BG-003');
  50. const changeCid = ctx.helper._.map(data.change, 'cid');
  51. const changeBillsCid = ctx.helper._.uniq(ctx.helper._.map(data.change_audit_list, 'cid'));
  52. assert(changeCid.length === changeBillsCid.length);
  53. changeCid.forEach(function (a, i) {
  54. assert(a === changeBillsCid[i]);
  55. });
  56. });
  57. it('test gatherGcl && sortGcl', function* () {
  58. const ctx = app.mockContext(mockData);
  59. // test12 - 第6期
  60. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  61. const params = {
  62. tender_id: stage.tid,
  63. stage_id: stage.id,
  64. };
  65. const filters = ['mem_stage_bills'];
  66. const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters, {
  67. mem_stage_bills: [
  68. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  69. 'code', 'b_code', 'name', 'unit', 'unit_price',
  70. 'deal_qty', 'deal_tp',
  71. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  72. 'dgn_qty1', 'dgn_qty2',
  73. 'drawing_code', 'memo', 'node_type', 'is_tp',
  74. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  75. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  76. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  77. 'final_tp', 'final_ratio',
  78. 'qc_bgl_code',
  79. 'chapter',
  80. ]
  81. });
  82. assert(data.mem_stage_bills.length === 216);
  83. reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
  84. {field: 'b_code', table: 'mem_stage_bills'},
  85. {field: 'name', table: 'mem_stage_bills'},
  86. {field: 'unit', table: 'mem_stage_bills'},
  87. {field: 'unit_price', table: 'mem_stage_bills'},
  88. {field: 'is_leaf', table: 'mem_stage_bills'},
  89. ]);
  90. assert(data.mem_stage_bills.length === 43);
  91. reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
  92. {field: 'b_code', table: 'mem_stage_bills'},
  93. ]);
  94. const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
  95. const codeIndex100 = ['103-1', '103-2', '103-3-a', '103-3-b', '103-4', '104-1'];
  96. const codeIndex200 = [
  97. '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',
  98. '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',
  99. ];
  100. const codeIndex400 = [
  101. '403-1-a', '403-1-b', '403-2-a', '403-2-b', '403-3-a', '403-3-b', '403-4-a', '403-4-b',
  102. '405-1-b-5', '405-1-b-6', '410-1-b', '410-1-c', '410-2-b', '410-2-c', '410-6-c',
  103. '411-5', '411-7-a', '411-8-a', '413-1-a', '417-5-a'
  104. ];
  105. let codeResult = codeIndex100.concat(codeIndex200, codeIndex400);
  106. codeIndex.forEach(function (a, i) {
  107. assert(a === codeResult[i]);
  108. });
  109. });
  110. it('test gatherChapter', function* () {
  111. const ctx = app.mockContext(mockData);
  112. // test12 - 第6期
  113. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  114. const params = {
  115. tender_id: stage.tid,
  116. stage_id: stage.id,
  117. };
  118. const filters = ['mem_stage_bills', 'tender_info'];
  119. const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters, {
  120. mem_stage_bills: [
  121. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  122. 'code', 'b_code', 'name', 'unit', 'unit_price',
  123. 'deal_qty', 'deal_tp',
  124. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  125. 'dgn_qty1', 'dgn_qty2',
  126. 'drawing_code', 'memo', 'node_type', 'is_tp',
  127. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  128. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  129. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  130. 'final_tp', 'final_ratio',
  131. 'qc_bgl_code',
  132. 'chapter',
  133. ]
  134. });
  135. reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  136. {field: 'b_code', table: 'mem_stage_bills'},
  137. {field: 'is_leaf', table: 'mem_stage_bills'},
  138. ]);
  139. const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  140. assert(chapter100.total_price === 1045756);
  141. const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  142. assert(chapter200.total_price.toFixed(0) == 3813369);
  143. assert(chapter200.contract_tp == 700.5);
  144. const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'});
  145. assert(chapter400.total_price.toFixed(0) == 1231018);
  146. });
  147. it('test gatherChapter', function* () {
  148. const ctx = app.mockContext(mockData);
  149. // test12 - 第6期
  150. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  151. const params = {
  152. tender_id: stage.tid,
  153. stage_id: stage.id,
  154. };
  155. const filters = ['mem_stage_bills', 'tender_info'];
  156. const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters, {
  157. mem_stage_bills: [
  158. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  159. 'code', 'b_code', 'name', 'unit', 'unit_price',
  160. 'deal_qty', 'deal_tp',
  161. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  162. 'dgn_qty1', 'dgn_qty2',
  163. 'drawing_code', 'memo', 'node_type', 'is_tp',
  164. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  165. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  166. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  167. 'final_tp', 'final_ratio',
  168. 'qc_bgl_code',
  169. 'chapter',
  170. ]
  171. });
  172. reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  173. {field: 'b_code', table: 'mem_stage_bills'},
  174. {field: 'is_leaf', table: 'mem_stage_bills'},
  175. ]);
  176. const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  177. assert(chapter100.total_price === 1045756);
  178. const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  179. assert(chapter200.total_price.toFixed(0) == 3813369);
  180. assert(chapter200.contract_tp == 700.5);
  181. const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'});
  182. assert(chapter400.total_price.toFixed(0) == 1231018);
  183. });
  184. it('test loadCooperationData', function* () {
  185. const ctx = app.mockContext(mockData);
  186. const stage = yield ctx.service.stage.getDataByCondition({tid: 3301, order: 1});
  187. const params = {
  188. tender_id: stage.tid,
  189. stage_id: stage.id,
  190. };
  191. const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, ['mem_stage_bills', 'stage', 'stage_audit', 'ledger_cooperation', 'mem_stage_im_zl'], {
  192. mem_stage_bills: [
  193. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf'
  194. ],
  195. mem_stage_im_zl: ['lid', 'code'],
  196. });
  197. reportDataAnalysis.analysisObj.loadCooperationData.fun(ctx, data, [], {table: 'mem_stage_im_zl', co_sign: [0, 1, 2, 3]}, null);
  198. });
  199. it('test join', function* () {
  200. const ctx = app.mockContext(mockData);
  201. // test12 - 第6期
  202. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  203. const params = {
  204. tender_id: stage.tid,
  205. stage_id: stage.id,
  206. };
  207. const filters = ['mem_stage_bills', 'deal_bills'];
  208. const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters, {
  209. mem_stage_bills: [
  210. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  211. 'code', 'b_code', 'name', 'unit', 'unit_price',
  212. 'deal_qty', 'deal_tp',
  213. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  214. 'dgn_qty1', 'dgn_qty2',
  215. 'drawing_code', 'memo', 'node_type', 'is_tp',
  216. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  217. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  218. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  219. 'final_tp', 'final_ratio',
  220. 'qc_bgl_code',
  221. 'chapter',
  222. ]
  223. });
  224. assert(data.mem_stage_bills.length === 216);
  225. reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
  226. {field: 'b_code', table: 'mem_stage_bills'},
  227. {field: 'name', table: 'mem_stage_bills'},
  228. {field: 'unit', table: 'mem_stage_bills'},
  229. {field: 'unit_price', table: 'mem_stage_bills'},
  230. {field: 'is_leaf', table: 'mem_stage_bills'},
  231. ]);
  232. assert(data.mem_stage_bills.length === 43);
  233. const joinOptions = {
  234. main: 'mem_stage_bills',
  235. sub: 'deal_bills',
  236. keyFields: [
  237. {main: 'b_code', sub: 'code', type: 'string'},
  238. {main: 'name', sub: 'name',type: 'string'},
  239. {main: 'unit', sub: 'unit',type: 'string'},
  240. {main: 'unit_price', sub: 'unit_price',type: 'number'},
  241. ],
  242. importFields: [
  243. {main: 'ex_value1', sub: 'quantity', type: 'number'},
  244. {main: 'ex_value2', sub: 'total_price', type: 'number'}
  245. ],
  246. joinType: 'outer', //'outer', 'main', 'sub', 'inner'
  247. };
  248. yield ctx.helper.saveBufferFile(JSON.stringify(joinOptions, '', '\t'), ctx.app.baseDir + '/analysis_join_options.json');
  249. reportDataAnalysis.analysisObj.join.fun(ctx, data, [], joinOptions);
  250. assert(data.mem_stage_bills.length === 132);
  251. reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
  252. {field: 'b_code', table: 'mem_stage_bills'},
  253. ]);
  254. const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
  255. const codeIndex100 = ['101-1-b', '102-2', '102-3', '102-4', '102-5', '103-1', '103-2',
  256. '103-3', '103-3-a', '103-3-b', '103-4', '104-1', '123-1'];
  257. const codeIndex200 = [
  258. '203-1-a', '203-1-a', '203-1-b', '203-1-b', '203-1-d', '203-1-d', '204-1-b', '204-1-b',
  259. '204-1-c', '204-1-d',
  260. '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',
  261. '207-1-b',
  262. '207-2-a', '207-2-a',
  263. '207-2-b', '207-2-c', '207-3-a',
  264. '207-4-a', '207-4-a',
  265. '207-4-c', '207-10-a',
  266. '208-1-a', '208-1-a', '208-3-a', '208-3-a',
  267. '208-3-b',
  268. '208-3-c', '208-3-c', '208-4-b-1', '208-4-b-1', '209-1-a', '209-1-a',
  269. '209-3', '209-3-b', '215-12', '215-12-a'
  270. ];
  271. let codeResult = codeIndex100.concat(codeIndex200);
  272. codeResult.forEach(function (a, i) {
  273. assert(a === codeIndex[i]);
  274. });
  275. });
  276. it('test filter', function* () {
  277. const ctx = app.mockContext(mockData);
  278. const orgData = {
  279. test: [
  280. {a: 'aaa', b: 0, c: true, order: 1},
  281. {a: 'aaa', b: 1, c: false, order: 2},
  282. {a: 'aaa', b: 2, c: false, order: 3},
  283. {a: 'bbb', b: 3, c: true, order: 4},
  284. {a: 'bbb', b: null, c: true, order: 5},
  285. {a: 'ccc', b: 0, c: false, order: 6},
  286. {a: 'ccc', b: -1, c: false, order: 7},
  287. {a: 'ddd', b: 8, c: true, order: 8},
  288. ]
  289. };
  290. let data, result;
  291. // test boolean;
  292. const b1 = {
  293. table: 'test',
  294. condition: [{ field: "c", type: "bool", value: 'false'}]
  295. };
  296. data = JSON.parse(JSON.stringify(orgData));
  297. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b1);
  298. result = ctx.helper._.map(data.test, 'order');
  299. assert(ctx.helper._.isEqual(result, [2, 3, 6, 7]));
  300. const b2 = {
  301. table: 'test',
  302. condition: [{ field: "c", type: "bool", value: 'true'}]
  303. };
  304. data = JSON.parse(JSON.stringify(orgData));
  305. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b2);
  306. result = ctx.helper._.map(data.test, 'order');
  307. assert(ctx.helper._.isEqual(result, [1, 4, 5, 8]));
  308. // test number
  309. const n1 = {
  310. table: 'test',
  311. condition: [{ field: "b", type: "num", operate: 'non-zero'}]
  312. };
  313. data = JSON.parse(JSON.stringify(orgData));
  314. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n1);
  315. result = ctx.helper._.map(data.test, 'order');
  316. assert(ctx.helper._.isEqual(result, [2, 3, 4, 7, 8]));
  317. const n2 = {
  318. table: 'test',
  319. condition: [{ field: "b", type: "num", operate: '=', value: 1}]
  320. };
  321. data = JSON.parse(JSON.stringify(orgData));
  322. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n2);
  323. result = ctx.helper._.map(data.test, 'order');
  324. assert(ctx.helper._.isEqual(result, [2]));
  325. const n3 = {
  326. table: 'test',
  327. condition: [{ field: "b", type: "num", operate: '>', value: 1}]
  328. };
  329. data = JSON.parse(JSON.stringify(orgData));
  330. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n3);
  331. result = ctx.helper._.map(data.test, 'order');
  332. assert(ctx.helper._.isEqual(result, [3, 4, 8]));
  333. const n4 = {
  334. table: 'test',
  335. condition: [{ field: "b", type: "num", operate: '>=', value: 1}]
  336. };
  337. data = JSON.parse(JSON.stringify(orgData));
  338. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n4);
  339. result = ctx.helper._.map(data.test, 'order');
  340. assert(ctx.helper._.isEqual(result, [2, 3, 4, 8]));
  341. const n5 = {
  342. table: 'test',
  343. condition: [{ field: "b", type: "num", operate: '<', value: 1}]
  344. };
  345. data = JSON.parse(JSON.stringify(orgData));
  346. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n5);
  347. result = ctx.helper._.map(data.test, 'order');
  348. assert(ctx.helper._.isEqual(result, [1, 6, 7]));
  349. const n6 = {
  350. table: 'test',
  351. condition: [{ field: "b", type: "num", operate: '<=', value: 1}]
  352. };
  353. data = JSON.parse(JSON.stringify(orgData));
  354. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n6);
  355. result = ctx.helper._.map(data.test, 'order');
  356. assert(ctx.helper._.isEqual(result, [1, 2, 6, 7]));
  357. // string
  358. const s1 = {
  359. table: 'test',
  360. condition: [{ field: "a", type: "str", operate: '=', value: 'aaa'}]
  361. };
  362. data = JSON.parse(JSON.stringify(orgData));
  363. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s1);
  364. result = ctx.helper._.map(data.test, 'order');
  365. assert(ctx.helper._.isEqual(result, [1, 2, 3]));
  366. const s2 = {
  367. table: 'test',
  368. condition: [{ field: "a", type: "str", operate: 'part', value: 'b'}]
  369. };
  370. data = JSON.parse(JSON.stringify(orgData));
  371. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s2);
  372. result = ctx.helper._.map(data.test, 'order');
  373. assert(ctx.helper._.isEqual(result, [4, 5]));
  374. const s3 = {
  375. table: 'test',
  376. condition: [{ field: "a", type: "str", operate: 'enum', value: ['ccc', 'ddd']}]
  377. };
  378. data = JSON.parse(JSON.stringify(orgData));
  379. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s3);
  380. result = ctx.helper._.map(data.test, 'order');
  381. assert(ctx.helper._.isEqual(result, [6, 7, 8]));
  382. // mix
  383. const m1 = {
  384. table: 'test',
  385. condition: [
  386. { field: "c", type: "bool", value: 'true'},
  387. { field: "b", type: "num", operate: 'non-zero'},
  388. { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd']},
  389. ]
  390. };
  391. data = JSON.parse(JSON.stringify(orgData));
  392. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m1);
  393. result = ctx.helper._.map(data.test, 'order');
  394. assert(ctx.helper._.isEqual(result, [8]));
  395. // mix2
  396. const m2 = {
  397. table: 'test',
  398. condition: [
  399. { field: "c", type: "bool", value: 'true'},
  400. { field: "b", type: "num", operate: 'non-zero', rela: "or"},
  401. { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd'], rela: "and"},
  402. ],
  403. };
  404. data = JSON.parse(JSON.stringify(orgData));
  405. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m2, true);
  406. result = ctx.helper._.map(data.test, 'order');
  407. assert(ctx.helper._.isEqual(result, [1, 2, 3, 8]));
  408. });
  409. // it('test gatherChapter custom', function* () {
  410. // const ctx = app.mockContext(mockData);
  411. //
  412. // const params = {tender_id: 2072};
  413. // const filters = ['mem_stage_bills', 'tender_info'];
  414. // const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters, {
  415. // mem_stage_bills: [
  416. // 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  417. // 'code', 'b_code', 'name', 'unit', 'unit_price',
  418. // 'deal_qty', 'deal_tp',
  419. // 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  420. // 'dgn_qty1', 'dgn_qty2',
  421. // 'drawing_code', 'memo', 'node_type', 'is_tp',
  422. // 'qc_bgl_code',
  423. // 'chapter',
  424. // ]
  425. // });
  426. // reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  427. // {field: 'b_code', table: 'mem_stage_bills'},
  428. // {field: 'is_leaf', table: 'mem_stage_bills'},
  429. // ], {
  430. // count: 7,
  431. // gclSum: {
  432. // name: '第100章至700章清单合计',
  433. // order: 1,
  434. // },
  435. // custom: [
  436. // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  437. // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  438. // {name: '计日工合计', node_type: '计日工', order: 4},
  439. // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  440. // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  441. // ],
  442. // });
  443. // const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  444. // assert(ctx.helper.checkZero(chapter100.total_price));
  445. // const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  446. // assert(chapter200.total_price === 33211);
  447. // const chapterGclSum = ctx.helper._.find(data.mem_stage_bills, {cType: 11});
  448. // assert(chapterGclSum.total_price == 33211);
  449. // const chapterJRG = ctx.helper._.find(data.mem_stage_bills, {name: '计日工合计'});
  450. // assert(chapterJRG.total_price === 1076);
  451. // const chapterSumWithoutZGJ = ctx.helper._.find(data.mem_stage_bills, {serialNo: 11});
  452. // assert(chapterSumWithoutZGJ.total_price === 33211);
  453. // const chapterZL = ctx.helper._.find(data.mem_stage_bills, {serialNo: 13});
  454. // assert(chapterZL.total_price === 500000);
  455. // const chapterSum = ctx.helper._.find(data.mem_stage_bills, {serialNo: 14});
  456. // assert(chapterSum.total_price === 534287);
  457. // });
  458. it('test analysisDefine', function() {
  459. const ctx = app.mockContext(mockData);
  460. const define = reportDataAnalysis.analysisDefine;
  461. assert(define.length === 7);
  462. assert(define[0].key === 'changeSort');
  463. assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name);
  464. assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint);
  465. assert(define[1].key === 'gatherGcl');
  466. assert(define[1].name === reportDataAnalysis.analysisObj.gatherGcl.name);
  467. assert(define[1].hint === reportDataAnalysis.analysisObj.gatherGcl.hint);
  468. assert(define[2].key === 'sortGcl');
  469. assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name);
  470. assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint);
  471. // const x = {
  472. // count: 7,
  473. // gclSum: {
  474. // name: '第100章至700章清单合计',
  475. // order: 1,
  476. // },
  477. // custom: [
  478. // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  479. // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  480. // {name: '计日工合计', node_type: '计日工', order: 4},
  481. // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  482. // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  483. // ],
  484. // };
  485. // ctx.helper.saveBufferFile(JSON.stringify(x, "", "\t"), ctx.app.baseDir + '/mem_stage_pos.json');
  486. });
  487. it('test sortPos/unionPos', function* () {
  488. const ctx = app.mockContext();
  489. const postData = {
  490. account: 'zengpeiwen',
  491. project: 'P1201',
  492. project_password: '123456',
  493. };
  494. ctx.session = {};
  495. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  496. // test12 - 第6期
  497. const params = {
  498. tender_id: 2546,
  499. };
  500. const filters = ['mem_stage_bills', 'tender_info', 'mem_stage_pos'];
  501. const data = yield ctx.service.report.getReportData(sourceTypeConst.defaultSourceType, params, filters, {
  502. mem_stage_bills: [
  503. 'id'
  504. ],
  505. mem_stage_pos: ['name'],
  506. });
  507. // sortPos
  508. reportDataAnalysis.analysisObj.sortPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'});
  509. yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json'));
  510. yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_pos, "", "\t"), path.join(savePath, 'mem_stage_pos.json'));
  511. // unionPos
  512. // reportDataAnalysis.analysisObj.unionPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'});
  513. // yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json'));
  514. });
  515. it('test splitXmjCode', function* () {
  516. const ctx = app.mockContext(mockData);
  517. // test12 - 第6期
  518. const testData11 = {
  519. bills: [
  520. { code: '1', level: 1 },
  521. { code: '1-1', level: 2 },
  522. { code: '1-1-1', level: 3 },
  523. { code: '1-1-1-1', level: 4 },
  524. { code: '1-1-1-1-1', level: 5 },
  525. { code: '1-1-1-1-1-1', level: 6 },
  526. ]
  527. };
  528. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData11, [], {table: 'bills', type: '11', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  529. assert(testData11.bills[1].xiang === '一' );
  530. assert(testData11.bills[2].mu ==='1');
  531. assert(testData11.bills[3].jie === '1');
  532. assert(testData11.bills[4].ximu === '1');
  533. assert(testData11.bills[5].ximu === '1-1');
  534. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData11, [], {table: 'bills', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  535. assert(testData11.bills[1].xiang === '1-1' );
  536. assert(testData11.bills[2].mu === '1-1-1');
  537. assert(testData11.bills[3].jie === '1-1-1-1');
  538. assert(testData11.bills[4].ximu === '1-1-1-1-1');
  539. assert(testData11.bills[5].ximu === '1-1-1-1-1-1');
  540. const testData18 = {
  541. bills: [
  542. { code: '1', level: 1, ledger_id: 1, ledger_pid: -1, full_path: '1' }, // 0
  543. { code: '101', level: 2, ledger_id: 2, ledger_pid: 1, full_path: '1-2' },
  544. { code: '10101', level: 3, ledger_id: 3, ledger_pid: 2, full_path: '1-2-3' },
  545. { code: '1010101', level: 4, ledger_id: 4, ledger_pid: 3, full_path: '1-2-3-4' },
  546. { code: '1010103', level: 4, ledger_id: 5, ledger_pid: 3, full_path: '1-2-3-5' },
  547. { code: '101010301', level: 5, ledger_id: 6, ledger_pid: 5, full_path: '1-2-3-5-6' }, // 5
  548. { code: '102', level: 2, ledger_id: 7, ledger_pid: 1, full_path: '1-7' },
  549. { code: 'LJ05', level: 3, ledger_id: 8, ledger_pid: 7, full_path: '1-7-8' },
  550. { code: 'LJ0502', level: 4, ledger_id: 9, ledger_pid: 8, full_path: '1-7-8-9' },
  551. { code: 'LJ050204', level: 5, ledger_id: 10, ledger_pid: 9, full_path: '1-7-8-9-10' },
  552. { code: 'GDLJ05020401', level: 6, ledger_id: 11, ledger_pid: 10, full_path: '1-7-8-9-10-11' }, // 10
  553. ]
  554. };
  555. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  556. assert(testData18.bills[1].xiang === '01');
  557. assert(testData18.bills[2].mu === '01');
  558. assert(testData18.bills[3].jie === '01');
  559. assert(testData18.bills[4].jie === '03');
  560. assert(testData18.bills[5].ximu === '01');
  561. assert(testData18.bills[6].xiang === '02');
  562. assert(testData18.bills[7].mu === 'LJ05');
  563. assert(testData18.bills[8].jie === 'LJ0502');
  564. assert(testData18.bills[9].ximu === 'LJ050204');
  565. assert(testData18.bills[10].ximu === 'LJ05020401');
  566. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  567. assert(testData18.bills[1].xiang === '01');
  568. assert(testData18.bills[2].mu === '01');
  569. assert(testData18.bills[3].jie === '01');
  570. assert(testData18.bills[4].jie === '03');
  571. assert(testData18.bills[5].ximu === '01');
  572. assert(testData18.bills[6].xiang === '02');
  573. assert(testData18.bills[7].mu === 'LJ05');
  574. assert(testData18.bills[8].jie === '02');
  575. assert(testData18.bills[9].ximu === '04');
  576. assert(testData18.bills[10].ximu === '0401');
  577. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-0-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  578. assert(testData18.bills[1].xiang === '01');
  579. assert(testData18.bills[2].mu === '01');
  580. assert(testData18.bills[3].jie === '01');
  581. assert(testData18.bills[4].jie === '03');
  582. assert(testData18.bills[5].ximu === '01');
  583. assert(testData18.bills[6].xiang === '02');
  584. assert(testData18.bills[7].mu === 'LJ05');
  585. assert(testData18.bills[8].jie === 'LJ0502');
  586. assert(testData18.bills[9].ximu === 'LJ050204');
  587. assert(testData18.bills[10].ximu === 'GDLJ05020401');
  588. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-1-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  589. assert(testData18.bills[1].xiang === '01');
  590. assert(testData18.bills[2].mu === '01');
  591. assert(testData18.bills[3].jie === '01');
  592. assert(testData18.bills[4].jie === '03');
  593. assert(testData18.bills[5].ximu === '01');
  594. assert(testData18.bills[6].xiang === '02');
  595. assert(testData18.bills[7].mu === 'LJ05');
  596. assert(testData18.bills[8].jie === '02');
  597. assert(testData18.bills[9].ximu === '04');
  598. assert(testData18.bills[10].ximu === 'GD0401');
  599. });
  600. it('test treeFilter', function* () {
  601. const ctx = app.mockContext(mockData);
  602. const orgData = [
  603. { id: 1, pid: -1, order: 1, level: 1, full_path: '1', code: '1', is_leaf: false },
  604. { id: 2, pid: 1, order: 1, level: 2, full_path: '1.2', code: '1-1', is_leaf: false },
  605. { id: 6, pid: 2, order: 1, level: 3, full_path: '1.2.6', code: '1-1-1', is_leaf: false },
  606. { id: 7, pid: 6, order: 1, level: 4, full_path: '1.2.6.7', code: '202-1', is_leaf: false },
  607. { id: 10, pid: 7, order: 2, level: 5, full_path: '1.2.6.7.10', code: '202-1-a', is_leaf: true },
  608. { id: 9, pid: 7, order: 1, level: 5, full_path: '1.2.6.7.9', code: '202-1-b', is_leaf: true },
  609. { id: 8, pid: 6, order: 2, level: 4, full_path: '1.2.6.8', code: '202-2', is_leaf: false },
  610. { id: 11, pid: 8, order: 1, level: 5, full_path: '1.2.6.8.11', code: '202-2-c', is_leaf: true },
  611. { id: 12, pid: 8, order: 2, level: 5, full_path: '1.2.6.8.12', code: '202-2-e', is_leaf: true },
  612. { id: 13, pid: 2, order: 2, level: 3, full_path: '1.2.13', code: '1-1-2', is_leaf: true },
  613. { id: 14, pid: 2, order: 3, level: 3, full_path: '1.2.14', code: '1-1-3', is_leaf: true },
  614. { id: 3, pid: 1, order: 2, level: 2, full_path: '1.3', code: '1-2', is_leaf: false },
  615. { id: 15, pid: 3, order: 1, level: 3, full_path: '1.3.15', code: '1-2-1', is_leaf: true },
  616. { id: 4, pid: 1, order: 3, level: 2, full_path: '1.4', code: '1-3', is_leaf: false },
  617. { id: 16, pid: 4, order: 1, level: 3, full_path: '1.4.16', code: '1-3-1', is_leaf: true },
  618. { id: 5, pid: 1, order: 4, level: 2, full_path: '1.5', code: '1-4', is_leaf: true },
  619. ];
  620. const data = { mem_stage_bills: orgData };
  621. reportDataAnalysis.analysisObj.treeFilter.fun(ctx, data, [], {
  622. table: 'mem_stage_bills',
  623. type: 'match',
  624. subType: 'posterity',
  625. condition: [
  626. { field: 'code', type: 'str', value: '1-1', operate: '=' },
  627. ],
  628. });
  629. assert(data.mem_stage_bills.length = 9);
  630. });
  631. });