rpt_data_analysis.test.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. describe('test/app/service/report_memory.test.js', () => {
  15. // 准备测试数据
  16. before(function* () {
  17. const ctx = app.mockContext();
  18. savePath = path.join(ctx.app.baseDir,'report_temp');
  19. // 模拟登录session
  20. // const postData = {
  21. // account: 'fuqingqing',
  22. // project: 'P0505',
  23. // project_password: '123456',
  24. // };
  25. const postData = {
  26. account: '734406061@qq.com',
  27. project: 'T201711273363',
  28. project_password: 'mai654321',
  29. };
  30. ctx.session = {};
  31. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  32. assert(loginResult);
  33. mockData.session = ctx.session;
  34. });
  35. // 数据
  36. it('test changeSort', function* () {
  37. const ctx = app.mockContext(mockData);
  38. // test12 - 第6期
  39. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  40. const params = {
  41. tender_id: stage.tid,
  42. stage_id: stage.id,
  43. };
  44. const filters = ['change', 'change_audit_list'];
  45. const data = yield ctx.service.report.getReportData(params, filters);
  46. reportDataAnalysis.analysisObj.changeSort.fun(ctx, data);
  47. assert(data.change[0].code === 'test7-BG-001');
  48. assert(data.change[2].code === 'test7-BG-003');
  49. const changeCid = ctx.helper._.map(data.change, 'cid');
  50. const changeBillsCid = ctx.helper._.uniq(ctx.helper._.map(data.change_audit_list, 'cid'));
  51. assert(changeCid.length === changeBillsCid.length);
  52. changeCid.forEach(function (a, i) {
  53. assert(a === changeBillsCid[i]);
  54. });
  55. });
  56. it('test gatherGcl && sortGcl', function* () {
  57. const ctx = app.mockContext(mockData);
  58. // test12 - 第6期
  59. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  60. const params = {
  61. tender_id: stage.tid,
  62. stage_id: stage.id,
  63. };
  64. const filters = ['mem_stage_bills'];
  65. const data = yield ctx.service.report.getReportData(params, filters, {
  66. mem_stage_bills: [
  67. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  68. 'code', 'b_code', 'name', 'unit', 'unit_price',
  69. 'deal_qty', 'deal_tp',
  70. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  71. 'dgn_qty1', 'dgn_qty2',
  72. 'drawing_code', 'memo', 'node_type', 'is_tp',
  73. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  74. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  75. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  76. 'final_tp', 'final_ratio',
  77. 'qc_bgl_code',
  78. 'chapter',
  79. ]
  80. });
  81. assert(data.mem_stage_bills.length === 216);
  82. reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
  83. {field: 'b_code', table: 'mem_stage_bills'},
  84. {field: 'name', table: 'mem_stage_bills'},
  85. {field: 'unit', table: 'mem_stage_bills'},
  86. {field: 'unit_price', table: 'mem_stage_bills'},
  87. {field: 'is_leaf', table: 'mem_stage_bills'},
  88. ]);
  89. assert(data.mem_stage_bills.length === 43);
  90. reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
  91. {field: 'b_code', table: 'mem_stage_bills'},
  92. ]);
  93. const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
  94. const codeIndex100 = ['103-1', '103-2', '103-3-a', '103-3-b', '103-4', '104-1'];
  95. const codeIndex200 = [
  96. '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',
  97. '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',
  98. ];
  99. const codeIndex400 = [
  100. '403-1-a', '403-1-b', '403-2-a', '403-2-b', '403-3-a', '403-3-b', '403-4-a', '403-4-b',
  101. '405-1-b-5', '405-1-b-6', '410-1-b', '410-1-c', '410-2-b', '410-2-c', '410-6-c',
  102. '411-5', '411-7-a', '411-8-a', '413-1-a', '417-5-a'
  103. ];
  104. let codeResult = codeIndex100.concat(codeIndex200, codeIndex400);
  105. codeIndex.forEach(function (a, i) {
  106. assert(a === codeResult[i]);
  107. });
  108. });
  109. it('test gatherChapter', function* () {
  110. const ctx = app.mockContext(mockData);
  111. // test12 - 第6期
  112. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  113. const params = {
  114. tender_id: stage.tid,
  115. stage_id: stage.id,
  116. };
  117. const filters = ['mem_stage_bills', 'tender_info'];
  118. const data = yield ctx.service.report.getReportData(params, filters, {
  119. mem_stage_bills: [
  120. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  121. 'code', 'b_code', 'name', 'unit', 'unit_price',
  122. 'deal_qty', 'deal_tp',
  123. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  124. 'dgn_qty1', 'dgn_qty2',
  125. 'drawing_code', 'memo', 'node_type', 'is_tp',
  126. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  127. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  128. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  129. 'final_tp', 'final_ratio',
  130. 'qc_bgl_code',
  131. 'chapter',
  132. ]
  133. });
  134. reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  135. {field: 'b_code', table: 'mem_stage_bills'},
  136. {field: 'is_leaf', table: 'mem_stage_bills'},
  137. ]);
  138. const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  139. assert(chapter100.total_price === 1045756);
  140. const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  141. assert(chapter200.total_price.toFixed(0) == 3813369);
  142. assert(chapter200.contract_tp == 700.5);
  143. const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'});
  144. assert(chapter400.total_price.toFixed(0) == 1231018);
  145. });
  146. it('test gatherChapter', function* () {
  147. const ctx = app.mockContext(mockData);
  148. // test12 - 第6期
  149. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  150. const params = {
  151. tender_id: stage.tid,
  152. stage_id: stage.id,
  153. };
  154. const filters = ['mem_stage_bills', 'tender_info'];
  155. const data = yield ctx.service.report.getReportData(params, filters, {
  156. mem_stage_bills: [
  157. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  158. 'code', 'b_code', 'name', 'unit', 'unit_price',
  159. 'deal_qty', 'deal_tp',
  160. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  161. 'dgn_qty1', 'dgn_qty2',
  162. 'drawing_code', 'memo', 'node_type', 'is_tp',
  163. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  164. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  165. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  166. 'final_tp', 'final_ratio',
  167. 'qc_bgl_code',
  168. 'chapter',
  169. ]
  170. });
  171. reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  172. {field: 'b_code', table: 'mem_stage_bills'},
  173. {field: 'is_leaf', table: 'mem_stage_bills'},
  174. ]);
  175. const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  176. assert(chapter100.total_price === 1045756);
  177. const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  178. assert(chapter200.total_price.toFixed(0) == 3813369);
  179. assert(chapter200.contract_tp == 700.5);
  180. const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'});
  181. assert(chapter400.total_price.toFixed(0) == 1231018);
  182. });
  183. it('test join', function* () {
  184. const ctx = app.mockContext(mockData);
  185. // test12 - 第6期
  186. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  187. const params = {
  188. tender_id: stage.tid,
  189. stage_id: stage.id,
  190. };
  191. const filters = ['mem_stage_bills', 'deal_bills'];
  192. const data = yield ctx.service.report.getReportData(params, filters, {
  193. mem_stage_bills: [
  194. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  195. 'code', 'b_code', 'name', 'unit', 'unit_price',
  196. 'deal_qty', 'deal_tp',
  197. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  198. 'dgn_qty1', 'dgn_qty2',
  199. 'drawing_code', 'memo', 'node_type', 'is_tp',
  200. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  201. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  202. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  203. 'final_tp', 'final_ratio',
  204. 'qc_bgl_code',
  205. 'chapter',
  206. ]
  207. });
  208. assert(data.mem_stage_bills.length === 216);
  209. reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
  210. {field: 'b_code', table: 'mem_stage_bills'},
  211. {field: 'name', table: 'mem_stage_bills'},
  212. {field: 'unit', table: 'mem_stage_bills'},
  213. {field: 'unit_price', table: 'mem_stage_bills'},
  214. {field: 'is_leaf', table: 'mem_stage_bills'},
  215. ]);
  216. assert(data.mem_stage_bills.length === 43);
  217. const joinOptions = {
  218. main: 'mem_stage_bills',
  219. sub: 'deal_bills',
  220. keyFields: [
  221. {main: 'b_code', sub: 'code', type: 'string'},
  222. {main: 'name', sub: 'name',type: 'string'},
  223. {main: 'unit', sub: 'unit',type: 'string'},
  224. {main: 'unit_price', sub: 'unit_price',type: 'number'},
  225. ],
  226. importFields: [
  227. {main: 'ex_value1', sub: 'quantity', type: 'number'},
  228. {main: 'ex_value2', sub: 'total_price', type: 'number'}
  229. ],
  230. joinType: 'outer', //'outer', 'main', 'sub', 'inner'
  231. };
  232. yield ctx.helper.saveBufferFile(JSON.stringify(joinOptions, '', '\t'), ctx.app.baseDir + '/analysis_join_options.json');
  233. reportDataAnalysis.analysisObj.join.fun(ctx, data, [], joinOptions);
  234. assert(data.mem_stage_bills.length === 132);
  235. reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
  236. {field: 'b_code', table: 'mem_stage_bills'},
  237. ]);
  238. const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
  239. const codeIndex100 = ['101-1-b', '102-2', '102-3', '102-4', '102-5', '103-1', '103-2',
  240. '103-3', '103-3-a', '103-3-b', '103-4', '104-1', '123-1'];
  241. const codeIndex200 = [
  242. '203-1-a', '203-1-a', '203-1-b', '203-1-b', '203-1-d', '203-1-d', '204-1-b', '204-1-b',
  243. '204-1-c', '204-1-d',
  244. '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',
  245. '207-1-b',
  246. '207-2-a', '207-2-a',
  247. '207-2-b', '207-2-c', '207-3-a',
  248. '207-4-a', '207-4-a',
  249. '207-4-c', '207-10-a',
  250. '208-1-a', '208-1-a', '208-3-a', '208-3-a',
  251. '208-3-b',
  252. '208-3-c', '208-3-c', '208-4-b-1', '208-4-b-1', '209-1-a', '209-1-a',
  253. '209-3', '209-3-b', '215-12', '215-12-a'
  254. ];
  255. let codeResult = codeIndex100.concat(codeIndex200);
  256. codeResult.forEach(function (a, i) {
  257. assert(a === codeIndex[i]);
  258. });
  259. });
  260. it('test filter', function* () {
  261. const ctx = app.mockContext(mockData);
  262. const orgData = {
  263. test: [
  264. {a: 'aaa', b: 0, c: true, order: 1},
  265. {a: 'aaa', b: 1, c: false, order: 2},
  266. {a: 'aaa', b: 2, c: false, order: 3},
  267. {a: 'bbb', b: 3, c: true, order: 4},
  268. {a: 'bbb', b: null, c: true, order: 5},
  269. {a: 'ccc', b: 0, c: false, order: 6},
  270. {a: 'ccc', b: -1, c: false, order: 7},
  271. {a: 'ddd', b: 8, c: true, order: 8},
  272. ]
  273. };
  274. let data, result;
  275. // test boolean;
  276. const b1 = {
  277. table: 'test',
  278. condition: [{ field: "c", type: "bool", value: 'false'}]
  279. };
  280. data = JSON.parse(JSON.stringify(orgData));
  281. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b1);
  282. result = ctx.helper._.map(data.test, 'order');
  283. assert(ctx.helper._.isEqual(result, [2, 3, 6, 7]));
  284. const b2 = {
  285. table: 'test',
  286. condition: [{ field: "c", type: "bool", value: 'true'}]
  287. };
  288. data = JSON.parse(JSON.stringify(orgData));
  289. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b2);
  290. result = ctx.helper._.map(data.test, 'order');
  291. assert(ctx.helper._.isEqual(result, [1, 4, 5, 8]));
  292. // test number
  293. const n1 = {
  294. table: 'test',
  295. condition: [{ field: "b", type: "num", operate: 'non-zero'}]
  296. };
  297. data = JSON.parse(JSON.stringify(orgData));
  298. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n1);
  299. result = ctx.helper._.map(data.test, 'order');
  300. assert(ctx.helper._.isEqual(result, [2, 3, 4, 7, 8]));
  301. const n2 = {
  302. table: 'test',
  303. condition: [{ field: "b", type: "num", operate: '=', value: 1}]
  304. };
  305. data = JSON.parse(JSON.stringify(orgData));
  306. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n2);
  307. result = ctx.helper._.map(data.test, 'order');
  308. assert(ctx.helper._.isEqual(result, [2]));
  309. const n3 = {
  310. table: 'test',
  311. condition: [{ field: "b", type: "num", operate: '>', value: 1}]
  312. };
  313. data = JSON.parse(JSON.stringify(orgData));
  314. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n3);
  315. result = ctx.helper._.map(data.test, 'order');
  316. assert(ctx.helper._.isEqual(result, [3, 4, 8]));
  317. const n4 = {
  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, [], n4);
  323. result = ctx.helper._.map(data.test, 'order');
  324. assert(ctx.helper._.isEqual(result, [2, 3, 4, 8]));
  325. const n5 = {
  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, [], n5);
  331. result = ctx.helper._.map(data.test, 'order');
  332. assert(ctx.helper._.isEqual(result, [1, 6, 7]));
  333. const n6 = {
  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, [], n6);
  339. result = ctx.helper._.map(data.test, 'order');
  340. assert(ctx.helper._.isEqual(result, [1, 2, 6, 7]));
  341. // string
  342. const s1 = {
  343. table: 'test',
  344. condition: [{ field: "a", type: "str", operate: '=', value: 'aaa'}]
  345. };
  346. data = JSON.parse(JSON.stringify(orgData));
  347. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s1);
  348. result = ctx.helper._.map(data.test, 'order');
  349. assert(ctx.helper._.isEqual(result, [1, 2, 3]));
  350. const s2 = {
  351. table: 'test',
  352. condition: [{ field: "a", type: "str", operate: 'part', value: 'b'}]
  353. };
  354. data = JSON.parse(JSON.stringify(orgData));
  355. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s2);
  356. result = ctx.helper._.map(data.test, 'order');
  357. assert(ctx.helper._.isEqual(result, [4, 5]));
  358. const s3 = {
  359. table: 'test',
  360. condition: [{ field: "a", type: "str", operate: 'enum', value: ['ccc', 'ddd']}]
  361. };
  362. data = JSON.parse(JSON.stringify(orgData));
  363. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s3);
  364. result = ctx.helper._.map(data.test, 'order');
  365. assert(ctx.helper._.isEqual(result, [6, 7, 8]));
  366. // mix
  367. const m1 = {
  368. table: 'test',
  369. condition: [
  370. { field: "c", type: "bool", value: 'true'},
  371. { field: "b", type: "num", operate: 'non-zero'},
  372. { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd']},
  373. ]
  374. };
  375. data = JSON.parse(JSON.stringify(orgData));
  376. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m1);
  377. result = ctx.helper._.map(data.test, 'order');
  378. assert(ctx.helper._.isEqual(result, [8]));
  379. // mix2
  380. const m2 = {
  381. table: 'test',
  382. condition: [
  383. { field: "c", type: "bool", value: 'true'},
  384. { field: "b", type: "num", operate: 'non-zero', rela: "or"},
  385. { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd'], rela: "and"},
  386. ],
  387. };
  388. data = JSON.parse(JSON.stringify(orgData));
  389. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m2, true);
  390. result = ctx.helper._.map(data.test, 'order');
  391. assert(ctx.helper._.isEqual(result, [1, 2, 3, 8]));
  392. });
  393. // it('test gatherChapter custom', function* () {
  394. // const ctx = app.mockContext(mockData);
  395. //
  396. // const params = {tender_id: 2072};
  397. // const filters = ['mem_stage_bills', 'tender_info'];
  398. // const data = yield ctx.service.report.getReportData(params, filters, {
  399. // mem_stage_bills: [
  400. // 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  401. // 'code', 'b_code', 'name', 'unit', 'unit_price',
  402. // 'deal_qty', 'deal_tp',
  403. // 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  404. // 'dgn_qty1', 'dgn_qty2',
  405. // 'drawing_code', 'memo', 'node_type', 'is_tp',
  406. // 'qc_bgl_code',
  407. // 'chapter',
  408. // ]
  409. // });
  410. // reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  411. // {field: 'b_code', table: 'mem_stage_bills'},
  412. // {field: 'is_leaf', table: 'mem_stage_bills'},
  413. // ], {
  414. // count: 7,
  415. // gclSum: {
  416. // name: '第100章至700章清单合计',
  417. // order: 1,
  418. // },
  419. // custom: [
  420. // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  421. // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  422. // {name: '计日工合计', node_type: '计日工', order: 4},
  423. // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  424. // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  425. // ],
  426. // });
  427. // const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  428. // assert(ctx.helper.checkZero(chapter100.total_price));
  429. // const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  430. // assert(chapter200.total_price === 33211);
  431. // const chapterGclSum = ctx.helper._.find(data.mem_stage_bills, {cType: 11});
  432. // assert(chapterGclSum.total_price == 33211);
  433. // const chapterJRG = ctx.helper._.find(data.mem_stage_bills, {name: '计日工合计'});
  434. // assert(chapterJRG.total_price === 1076);
  435. // const chapterSumWithoutZGJ = ctx.helper._.find(data.mem_stage_bills, {serialNo: 11});
  436. // assert(chapterSumWithoutZGJ.total_price === 33211);
  437. // const chapterZL = ctx.helper._.find(data.mem_stage_bills, {serialNo: 13});
  438. // assert(chapterZL.total_price === 500000);
  439. // const chapterSum = ctx.helper._.find(data.mem_stage_bills, {serialNo: 14});
  440. // assert(chapterSum.total_price === 534287);
  441. // });
  442. it('test analysisDefine', function() {
  443. const ctx = app.mockContext(mockData);
  444. const define = reportDataAnalysis.analysisDefine;
  445. assert(define.length === 7);
  446. assert(define[0].key === 'changeSort');
  447. assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name);
  448. assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint);
  449. assert(define[1].key === 'gatherGcl');
  450. assert(define[1].name === reportDataAnalysis.analysisObj.gatherGcl.name);
  451. assert(define[1].hint === reportDataAnalysis.analysisObj.gatherGcl.hint);
  452. assert(define[2].key === 'sortGcl');
  453. assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name);
  454. assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint);
  455. // const x = {
  456. // count: 7,
  457. // gclSum: {
  458. // name: '第100章至700章清单合计',
  459. // order: 1,
  460. // },
  461. // custom: [
  462. // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  463. // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  464. // {name: '计日工合计', node_type: '计日工', order: 4},
  465. // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  466. // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  467. // ],
  468. // };
  469. // ctx.helper.saveBufferFile(JSON.stringify(x, "", "\t"), ctx.app.baseDir + '/mem_stage_pos.json');
  470. });
  471. it('test sortPos/unionPos', function* () {
  472. const ctx = app.mockContext(mockData);
  473. // test12 - 第6期
  474. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  475. const params = {
  476. tender_id: stage.tid,
  477. stage_id: stage.id,
  478. };
  479. const filters = ['mem_stage_bills', 'tender_info', 'mem_stage_pos'];
  480. const data = yield ctx.service.report.getReportData(params, filters, {
  481. mem_stage_bills: [
  482. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  483. 'code', 'b_code', 'name', 'unit', 'unit_price',
  484. 'deal_qty', 'deal_tp',
  485. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  486. 'dgn_qty1', 'dgn_qty2',
  487. 'drawing_code', 'memo', 'node_type', 'is_tp',
  488. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  489. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  490. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  491. 'final_tp', 'final_ratio',
  492. 'qc_bgl_code',
  493. 'chapter',
  494. ],
  495. mem_stage_pos: [],
  496. });
  497. // sortPos
  498. // reportDataAnalysis.analysisObj.sortPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'});
  499. // yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json'));
  500. // yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_pos, "", "\t"), path.join(savePath, 'mem_stage_pos.json'));
  501. // unionPos
  502. reportDataAnalysis.analysisObj.unionPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'});
  503. yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json'));
  504. });
  505. });