rpt_data_analysis.test.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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 loadCooperationData', function* () {
  184. const ctx = app.mockContext(mockData);
  185. const stage = yield ctx.service.stage.getDataByCondition({tid: 3301, order: 1});
  186. const params = {
  187. tender_id: stage.tid,
  188. stage_id: stage.id,
  189. };
  190. const data = yield ctx.service.report.getReportData(params, ['mem_stage_bills', 'stage', 'stage_audit', 'ledger_cooperation', 'mem_stage_im_zl'], {
  191. mem_stage_bills: [
  192. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf'
  193. ],
  194. mem_stage_im_zl: ['lid', 'code'],
  195. });
  196. reportDataAnalysis.analysisObj.loadCooperationData.fun(ctx, data, [], {table: 'mem_stage_im_zl', co_sign: [0, 1, 2, 3]}, null);
  197. });
  198. it('test join', function* () {
  199. const ctx = app.mockContext(mockData);
  200. // test12 - 第6期
  201. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  202. const params = {
  203. tender_id: stage.tid,
  204. stage_id: stage.id,
  205. };
  206. const filters = ['mem_stage_bills', 'deal_bills'];
  207. const data = yield ctx.service.report.getReportData(params, filters, {
  208. mem_stage_bills: [
  209. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  210. 'code', 'b_code', 'name', 'unit', 'unit_price',
  211. 'deal_qty', 'deal_tp',
  212. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  213. 'dgn_qty1', 'dgn_qty2',
  214. 'drawing_code', 'memo', 'node_type', 'is_tp',
  215. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  216. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  217. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  218. 'final_tp', 'final_ratio',
  219. 'qc_bgl_code',
  220. 'chapter',
  221. ]
  222. });
  223. assert(data.mem_stage_bills.length === 216);
  224. reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
  225. {field: 'b_code', table: 'mem_stage_bills'},
  226. {field: 'name', table: 'mem_stage_bills'},
  227. {field: 'unit', table: 'mem_stage_bills'},
  228. {field: 'unit_price', table: 'mem_stage_bills'},
  229. {field: 'is_leaf', table: 'mem_stage_bills'},
  230. ]);
  231. assert(data.mem_stage_bills.length === 43);
  232. const joinOptions = {
  233. main: 'mem_stage_bills',
  234. sub: 'deal_bills',
  235. keyFields: [
  236. {main: 'b_code', sub: 'code', type: 'string'},
  237. {main: 'name', sub: 'name',type: 'string'},
  238. {main: 'unit', sub: 'unit',type: 'string'},
  239. {main: 'unit_price', sub: 'unit_price',type: 'number'},
  240. ],
  241. importFields: [
  242. {main: 'ex_value1', sub: 'quantity', type: 'number'},
  243. {main: 'ex_value2', sub: 'total_price', type: 'number'}
  244. ],
  245. joinType: 'outer', //'outer', 'main', 'sub', 'inner'
  246. };
  247. yield ctx.helper.saveBufferFile(JSON.stringify(joinOptions, '', '\t'), ctx.app.baseDir + '/analysis_join_options.json');
  248. reportDataAnalysis.analysisObj.join.fun(ctx, data, [], joinOptions);
  249. assert(data.mem_stage_bills.length === 132);
  250. reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
  251. {field: 'b_code', table: 'mem_stage_bills'},
  252. ]);
  253. const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
  254. const codeIndex100 = ['101-1-b', '102-2', '102-3', '102-4', '102-5', '103-1', '103-2',
  255. '103-3', '103-3-a', '103-3-b', '103-4', '104-1', '123-1'];
  256. const codeIndex200 = [
  257. '203-1-a', '203-1-a', '203-1-b', '203-1-b', '203-1-d', '203-1-d', '204-1-b', '204-1-b',
  258. '204-1-c', '204-1-d',
  259. '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',
  260. '207-1-b',
  261. '207-2-a', '207-2-a',
  262. '207-2-b', '207-2-c', '207-3-a',
  263. '207-4-a', '207-4-a',
  264. '207-4-c', '207-10-a',
  265. '208-1-a', '208-1-a', '208-3-a', '208-3-a',
  266. '208-3-b',
  267. '208-3-c', '208-3-c', '208-4-b-1', '208-4-b-1', '209-1-a', '209-1-a',
  268. '209-3', '209-3-b', '215-12', '215-12-a'
  269. ];
  270. let codeResult = codeIndex100.concat(codeIndex200);
  271. codeResult.forEach(function (a, i) {
  272. assert(a === codeIndex[i]);
  273. });
  274. });
  275. it('test filter', function* () {
  276. const ctx = app.mockContext(mockData);
  277. const orgData = {
  278. test: [
  279. {a: 'aaa', b: 0, c: true, order: 1},
  280. {a: 'aaa', b: 1, c: false, order: 2},
  281. {a: 'aaa', b: 2, c: false, order: 3},
  282. {a: 'bbb', b: 3, c: true, order: 4},
  283. {a: 'bbb', b: null, c: true, order: 5},
  284. {a: 'ccc', b: 0, c: false, order: 6},
  285. {a: 'ccc', b: -1, c: false, order: 7},
  286. {a: 'ddd', b: 8, c: true, order: 8},
  287. ]
  288. };
  289. let data, result;
  290. // test boolean;
  291. const b1 = {
  292. table: 'test',
  293. condition: [{ field: "c", type: "bool", value: 'false'}]
  294. };
  295. data = JSON.parse(JSON.stringify(orgData));
  296. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b1);
  297. result = ctx.helper._.map(data.test, 'order');
  298. assert(ctx.helper._.isEqual(result, [2, 3, 6, 7]));
  299. const b2 = {
  300. table: 'test',
  301. condition: [{ field: "c", type: "bool", value: 'true'}]
  302. };
  303. data = JSON.parse(JSON.stringify(orgData));
  304. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b2);
  305. result = ctx.helper._.map(data.test, 'order');
  306. assert(ctx.helper._.isEqual(result, [1, 4, 5, 8]));
  307. // test number
  308. const n1 = {
  309. table: 'test',
  310. condition: [{ field: "b", type: "num", operate: 'non-zero'}]
  311. };
  312. data = JSON.parse(JSON.stringify(orgData));
  313. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n1);
  314. result = ctx.helper._.map(data.test, 'order');
  315. assert(ctx.helper._.isEqual(result, [2, 3, 4, 7, 8]));
  316. const n2 = {
  317. table: 'test',
  318. condition: [{ field: "b", type: "num", operate: '=', value: 1}]
  319. };
  320. data = JSON.parse(JSON.stringify(orgData));
  321. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n2);
  322. result = ctx.helper._.map(data.test, 'order');
  323. assert(ctx.helper._.isEqual(result, [2]));
  324. const n3 = {
  325. table: 'test',
  326. condition: [{ field: "b", type: "num", operate: '>', value: 1}]
  327. };
  328. data = JSON.parse(JSON.stringify(orgData));
  329. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n3);
  330. result = ctx.helper._.map(data.test, 'order');
  331. assert(ctx.helper._.isEqual(result, [3, 4, 8]));
  332. const n4 = {
  333. table: 'test',
  334. condition: [{ field: "b", type: "num", operate: '>=', value: 1}]
  335. };
  336. data = JSON.parse(JSON.stringify(orgData));
  337. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n4);
  338. result = ctx.helper._.map(data.test, 'order');
  339. assert(ctx.helper._.isEqual(result, [2, 3, 4, 8]));
  340. const n5 = {
  341. table: 'test',
  342. condition: [{ field: "b", type: "num", operate: '<', value: 1}]
  343. };
  344. data = JSON.parse(JSON.stringify(orgData));
  345. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n5);
  346. result = ctx.helper._.map(data.test, 'order');
  347. assert(ctx.helper._.isEqual(result, [1, 6, 7]));
  348. const n6 = {
  349. table: 'test',
  350. condition: [{ field: "b", type: "num", operate: '<=', value: 1}]
  351. };
  352. data = JSON.parse(JSON.stringify(orgData));
  353. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n6);
  354. result = ctx.helper._.map(data.test, 'order');
  355. assert(ctx.helper._.isEqual(result, [1, 2, 6, 7]));
  356. // string
  357. const s1 = {
  358. table: 'test',
  359. condition: [{ field: "a", type: "str", operate: '=', value: 'aaa'}]
  360. };
  361. data = JSON.parse(JSON.stringify(orgData));
  362. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s1);
  363. result = ctx.helper._.map(data.test, 'order');
  364. assert(ctx.helper._.isEqual(result, [1, 2, 3]));
  365. const s2 = {
  366. table: 'test',
  367. condition: [{ field: "a", type: "str", operate: 'part', value: 'b'}]
  368. };
  369. data = JSON.parse(JSON.stringify(orgData));
  370. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s2);
  371. result = ctx.helper._.map(data.test, 'order');
  372. assert(ctx.helper._.isEqual(result, [4, 5]));
  373. const s3 = {
  374. table: 'test',
  375. condition: [{ field: "a", type: "str", operate: 'enum', value: ['ccc', 'ddd']}]
  376. };
  377. data = JSON.parse(JSON.stringify(orgData));
  378. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s3);
  379. result = ctx.helper._.map(data.test, 'order');
  380. assert(ctx.helper._.isEqual(result, [6, 7, 8]));
  381. // mix
  382. const m1 = {
  383. table: 'test',
  384. condition: [
  385. { field: "c", type: "bool", value: 'true'},
  386. { field: "b", type: "num", operate: 'non-zero'},
  387. { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd']},
  388. ]
  389. };
  390. data = JSON.parse(JSON.stringify(orgData));
  391. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m1);
  392. result = ctx.helper._.map(data.test, 'order');
  393. assert(ctx.helper._.isEqual(result, [8]));
  394. // mix2
  395. const m2 = {
  396. table: 'test',
  397. condition: [
  398. { field: "c", type: "bool", value: 'true'},
  399. { field: "b", type: "num", operate: 'non-zero', rela: "or"},
  400. { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd'], rela: "and"},
  401. ],
  402. };
  403. data = JSON.parse(JSON.stringify(orgData));
  404. reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m2, true);
  405. result = ctx.helper._.map(data.test, 'order');
  406. assert(ctx.helper._.isEqual(result, [1, 2, 3, 8]));
  407. });
  408. // it('test gatherChapter custom', function* () {
  409. // const ctx = app.mockContext(mockData);
  410. //
  411. // const params = {tender_id: 2072};
  412. // const filters = ['mem_stage_bills', 'tender_info'];
  413. // const data = yield ctx.service.report.getReportData(params, filters, {
  414. // mem_stage_bills: [
  415. // 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  416. // 'code', 'b_code', 'name', 'unit', 'unit_price',
  417. // 'deal_qty', 'deal_tp',
  418. // 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  419. // 'dgn_qty1', 'dgn_qty2',
  420. // 'drawing_code', 'memo', 'node_type', 'is_tp',
  421. // 'qc_bgl_code',
  422. // 'chapter',
  423. // ]
  424. // });
  425. // reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  426. // {field: 'b_code', table: 'mem_stage_bills'},
  427. // {field: 'is_leaf', table: 'mem_stage_bills'},
  428. // ], {
  429. // count: 7,
  430. // gclSum: {
  431. // name: '第100章至700章清单合计',
  432. // order: 1,
  433. // },
  434. // custom: [
  435. // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  436. // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  437. // {name: '计日工合计', node_type: '计日工', order: 4},
  438. // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  439. // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  440. // ],
  441. // });
  442. // const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  443. // assert(ctx.helper.checkZero(chapter100.total_price));
  444. // const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  445. // assert(chapter200.total_price === 33211);
  446. // const chapterGclSum = ctx.helper._.find(data.mem_stage_bills, {cType: 11});
  447. // assert(chapterGclSum.total_price == 33211);
  448. // const chapterJRG = ctx.helper._.find(data.mem_stage_bills, {name: '计日工合计'});
  449. // assert(chapterJRG.total_price === 1076);
  450. // const chapterSumWithoutZGJ = ctx.helper._.find(data.mem_stage_bills, {serialNo: 11});
  451. // assert(chapterSumWithoutZGJ.total_price === 33211);
  452. // const chapterZL = ctx.helper._.find(data.mem_stage_bills, {serialNo: 13});
  453. // assert(chapterZL.total_price === 500000);
  454. // const chapterSum = ctx.helper._.find(data.mem_stage_bills, {serialNo: 14});
  455. // assert(chapterSum.total_price === 534287);
  456. // });
  457. it('test analysisDefine', function() {
  458. const ctx = app.mockContext(mockData);
  459. const define = reportDataAnalysis.analysisDefine;
  460. assert(define.length === 7);
  461. assert(define[0].key === 'changeSort');
  462. assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name);
  463. assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint);
  464. assert(define[1].key === 'gatherGcl');
  465. assert(define[1].name === reportDataAnalysis.analysisObj.gatherGcl.name);
  466. assert(define[1].hint === reportDataAnalysis.analysisObj.gatherGcl.hint);
  467. assert(define[2].key === 'sortGcl');
  468. assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name);
  469. assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint);
  470. // const x = {
  471. // count: 7,
  472. // gclSum: {
  473. // name: '第100章至700章清单合计',
  474. // order: 1,
  475. // },
  476. // custom: [
  477. // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  478. // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  479. // {name: '计日工合计', node_type: '计日工', order: 4},
  480. // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  481. // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  482. // ],
  483. // };
  484. // ctx.helper.saveBufferFile(JSON.stringify(x, "", "\t"), ctx.app.baseDir + '/mem_stage_pos.json');
  485. });
  486. it('test sortPos/unionPos', function* () {
  487. const ctx = app.mockContext();
  488. const postData = {
  489. account: 'zengpeiwen',
  490. project: 'P1201',
  491. project_password: '123456',
  492. };
  493. ctx.session = {};
  494. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  495. // test12 - 第6期
  496. const params = {
  497. tender_id: 2546,
  498. };
  499. const filters = ['mem_stage_bills', 'tender_info', 'mem_stage_pos'];
  500. const data = yield ctx.service.report.getReportData(params, filters, {
  501. mem_stage_bills: [
  502. 'id'
  503. ],
  504. mem_stage_pos: ['name'],
  505. });
  506. // sortPos
  507. reportDataAnalysis.analysisObj.sortPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'});
  508. yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json'));
  509. yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_pos, "", "\t"), path.join(savePath, 'mem_stage_pos.json'));
  510. // unionPos
  511. // reportDataAnalysis.analysisObj.unionPos.fun(ctx, data, [], {bills: 'mem_stage_bills', pos: 'mem_stage_pos'});
  512. // yield ctx.helper.saveBufferFile(JSON.stringify(data.mem_stage_bills, "", "\t"), path.join(savePath, 'mem_stage_bills.json'));
  513. });
  514. it('test splitXmjCode', function* () {
  515. const ctx = app.mockContext(mockData);
  516. // test12 - 第6期
  517. const testData11 = {
  518. bills: [
  519. { code: '1', level: 1 },
  520. { code: '1-1', level: 2 },
  521. { code: '1-1-1', level: 3 },
  522. { code: '1-1-1-1', level: 4 },
  523. { code: '1-1-1-1-1', level: 5 },
  524. { code: '1-1-1-1-1-1', level: 6 },
  525. ]
  526. };
  527. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData11, [], {table: 'bills', type: '11', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  528. assert(testData11.bills[1].xiang === '一' );
  529. assert(testData11.bills[2].mu ==='1');
  530. assert(testData11.bills[3].jie === '1');
  531. assert(testData11.bills[4].ximu === '1');
  532. assert(testData11.bills[5].ximu === '1-1');
  533. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData11, [], {table: 'bills', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  534. assert(testData11.bills[1].xiang === '1-1' );
  535. assert(testData11.bills[2].mu === '1-1-1');
  536. assert(testData11.bills[3].jie === '1-1-1-1');
  537. assert(testData11.bills[4].ximu === '1-1-1-1-1');
  538. assert(testData11.bills[5].ximu === '1-1-1-1-1-1');
  539. const testData18 = {
  540. bills: [
  541. { code: '1', level: 1, ledger_id: 1, ledger_pid: -1, full_path: '1' }, // 0
  542. { code: '101', level: 2, ledger_id: 2, ledger_pid: 1, full_path: '1-2' },
  543. { code: '10101', level: 3, ledger_id: 3, ledger_pid: 2, full_path: '1-2-3' },
  544. { code: '1010101', level: 4, ledger_id: 4, ledger_pid: 3, full_path: '1-2-3-4' },
  545. { code: '1010103', level: 4, ledger_id: 5, ledger_pid: 3, full_path: '1-2-3-5' },
  546. { code: '101010301', level: 5, ledger_id: 6, ledger_pid: 5, full_path: '1-2-3-5-6' }, // 5
  547. { code: '102', level: 2, ledger_id: 7, ledger_pid: 1, full_path: '1-7' },
  548. { code: 'LJ05', level: 3, ledger_id: 8, ledger_pid: 7, full_path: '1-7-8' },
  549. { code: 'LJ0502', level: 4, ledger_id: 9, ledger_pid: 8, full_path: '1-7-8-9' },
  550. { code: 'LJ050204', level: 5, ledger_id: 10, ledger_pid: 9, full_path: '1-7-8-9-10' },
  551. { code: 'GDLJ05020401', level: 6, ledger_id: 11, ledger_pid: 10, full_path: '1-7-8-9-10-11' }, // 10
  552. ]
  553. };
  554. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  555. assert(testData18.bills[1].xiang === '01');
  556. assert(testData18.bills[2].mu === '01');
  557. assert(testData18.bills[3].jie === '01');
  558. assert(testData18.bills[4].jie === '03');
  559. assert(testData18.bills[5].ximu === '01');
  560. assert(testData18.bills[6].xiang === '02');
  561. assert(testData18.bills[7].mu === 'LJ05');
  562. assert(testData18.bills[8].jie === 'LJ0502');
  563. assert(testData18.bills[9].ximu === 'LJ050204');
  564. assert(testData18.bills[10].ximu === 'LJ05020401');
  565. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  566. assert(testData18.bills[1].xiang === '01');
  567. assert(testData18.bills[2].mu === '01');
  568. assert(testData18.bills[3].jie === '01');
  569. assert(testData18.bills[4].jie === '03');
  570. assert(testData18.bills[5].ximu === '01');
  571. assert(testData18.bills[6].xiang === '02');
  572. assert(testData18.bills[7].mu === 'LJ05');
  573. assert(testData18.bills[8].jie === '02');
  574. assert(testData18.bills[9].ximu === '04');
  575. assert(testData18.bills[10].ximu === '0401');
  576. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-0-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  577. assert(testData18.bills[1].xiang === '01');
  578. assert(testData18.bills[2].mu === '01');
  579. assert(testData18.bills[3].jie === '01');
  580. assert(testData18.bills[4].jie === '03');
  581. assert(testData18.bills[5].ximu === '01');
  582. assert(testData18.bills[6].xiang === '02');
  583. assert(testData18.bills[7].mu === 'LJ05');
  584. assert(testData18.bills[8].jie === 'LJ0502');
  585. assert(testData18.bills[9].ximu === 'LJ050204');
  586. assert(testData18.bills[10].ximu === 'GDLJ05020401');
  587. reportDataAnalysis.analysisObj.splitXmjCode.fun(ctx, testData18, [], {table: 'bills', type:'18-1-1', code: 'code', targetField: ['xiang', 'mu', 'jie', 'ximu']});
  588. assert(testData18.bills[1].xiang === '01');
  589. assert(testData18.bills[2].mu === '01');
  590. assert(testData18.bills[3].jie === '01');
  591. assert(testData18.bills[4].jie === '03');
  592. assert(testData18.bills[5].ximu === '01');
  593. assert(testData18.bills[6].xiang === '02');
  594. assert(testData18.bills[7].mu === 'LJ05');
  595. assert(testData18.bills[8].jie === '02');
  596. assert(testData18.bills[9].ximu === '04');
  597. assert(testData18.bills[10].ximu === 'GD0401');
  598. });
  599. });