rpt_data_analysis.test.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. const reportDataAnalysis = require('../../../app/lib/rpt_data_analysis');
  13. describe('test/app/service/report_memory.test.js', () => {
  14. // 准备测试数据
  15. before(function* () {
  16. const ctx = app.mockContext();
  17. // 模拟登录session
  18. // const postData = {
  19. // account: 'fuqingqing',
  20. // project: 'P0505',
  21. // project_password: '123456',
  22. // };
  23. const postData = {
  24. account: '734406061@qq.com',
  25. project: 'T201711273363',
  26. project_password: 'mai654321',
  27. };
  28. ctx.session = {};
  29. const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
  30. assert(loginResult);
  31. mockData.session = ctx.session;
  32. });
  33. // 数据
  34. it('test changeSort', function* () {
  35. const ctx = app.mockContext(mockData);
  36. // test12 - 第6期
  37. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  38. const params = {
  39. tender_id: stage.tid,
  40. stage_id: stage.id,
  41. };
  42. const filters = ['change', 'change_audit_list'];
  43. const data = yield ctx.service.report.getReportData(params, filters);
  44. reportDataAnalysis.analysisObj.changeSort.fun(ctx, data);
  45. assert(data.change[0].code === 'test7-BG-001');
  46. assert(data.change[2].code === 'test7-BG-003');
  47. const changeCid = ctx.helper._.map(data.change, 'cid');
  48. const changeBillsCid = ctx.helper._.uniq(ctx.helper._.map(data.change_audit_list, 'cid'));
  49. assert(changeCid.length === changeBillsCid.length);
  50. changeCid.forEach(function (a, i) {
  51. assert(a === changeBillsCid[i]);
  52. });
  53. });
  54. it('test gatherGcl && sortGcl', function* () {
  55. const ctx = app.mockContext(mockData);
  56. // test12 - 第6期
  57. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  58. const params = {
  59. tender_id: stage.tid,
  60. stage_id: stage.id,
  61. };
  62. const filters = ['mem_stage_bills'];
  63. const data = yield ctx.service.report.getReportData(params, filters, {
  64. mem_stage_bills: [
  65. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  66. 'code', 'b_code', 'name', 'unit', 'unit_price',
  67. 'deal_qty', 'deal_tp',
  68. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  69. 'dgn_qty1', 'dgn_qty2',
  70. 'drawing_code', 'memo', 'node_type', 'is_tp',
  71. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  72. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  73. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  74. 'final_tp', 'final_ratio',
  75. 'qc_bgl_code',
  76. 'chapter',
  77. ]
  78. });
  79. assert(data.mem_stage_bills.length === 216);
  80. reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
  81. {field: 'b_code', table: 'mem_stage_bills'},
  82. {field: 'name', table: 'mem_stage_bills'},
  83. {field: 'unit', table: 'mem_stage_bills'},
  84. {field: 'unit_price', table: 'mem_stage_bills'},
  85. {field: 'is_leaf', table: 'mem_stage_bills'},
  86. ]);
  87. assert(data.mem_stage_bills.length === 43);
  88. reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
  89. {field: 'b_code', table: 'mem_stage_bills'},
  90. ]);
  91. const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
  92. const codeIndex100 = ['103-1', '103-2', '103-3-a', '103-3-b', '103-4', '104-1'];
  93. const codeIndex200 = [
  94. '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',
  95. '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',
  96. ];
  97. const codeIndex400 = [
  98. '403-1-a', '403-1-b', '403-2-a', '403-2-b', '403-3-a', '403-3-b', '403-4-a', '403-4-b',
  99. '405-1-b-5', '405-1-b-6', '410-1-b', '410-1-c', '410-2-b', '410-2-c', '410-6-c',
  100. '411-5', '411-7-a', '411-8-a', '413-1-a', '417-5-a'
  101. ];
  102. let codeResult = codeIndex100.concat(codeIndex200, codeIndex400);
  103. codeIndex.forEach(function (a, i) {
  104. assert(a === codeResult[i]);
  105. });
  106. });
  107. it('test gatherChapter', function* () {
  108. const ctx = app.mockContext(mockData);
  109. // test12 - 第6期
  110. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  111. const params = {
  112. tender_id: stage.tid,
  113. stage_id: stage.id,
  114. };
  115. const filters = ['mem_stage_bills', 'tender_info'];
  116. const data = yield ctx.service.report.getReportData(params, filters, {
  117. mem_stage_bills: [
  118. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  119. 'code', 'b_code', 'name', 'unit', 'unit_price',
  120. 'deal_qty', 'deal_tp',
  121. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  122. 'dgn_qty1', 'dgn_qty2',
  123. 'drawing_code', 'memo', 'node_type', 'is_tp',
  124. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  125. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  126. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  127. 'final_tp', 'final_ratio',
  128. 'qc_bgl_code',
  129. 'chapter',
  130. ]
  131. });
  132. reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  133. {field: 'b_code', table: 'mem_stage_bills'},
  134. {field: 'is_leaf', table: 'mem_stage_bills'},
  135. ]);
  136. const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  137. assert(chapter100.total_price === 1045756);
  138. const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  139. assert(chapter200.total_price.toFixed(0) == 3813369);
  140. assert(chapter200.contract_tp == 700.5);
  141. const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'});
  142. assert(chapter400.total_price.toFixed(0) == 1231018);
  143. });
  144. it('test gatherChapter', function* () {
  145. const ctx = app.mockContext(mockData);
  146. // test12 - 第6期
  147. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  148. const params = {
  149. tender_id: stage.tid,
  150. stage_id: stage.id,
  151. };
  152. const filters = ['mem_stage_bills', 'tender_info'];
  153. const data = yield ctx.service.report.getReportData(params, filters, {
  154. mem_stage_bills: [
  155. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  156. 'code', 'b_code', 'name', 'unit', 'unit_price',
  157. 'deal_qty', 'deal_tp',
  158. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  159. 'dgn_qty1', 'dgn_qty2',
  160. 'drawing_code', 'memo', 'node_type', 'is_tp',
  161. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  162. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  163. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  164. 'final_tp', 'final_ratio',
  165. 'qc_bgl_code',
  166. 'chapter',
  167. ]
  168. });
  169. reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  170. {field: 'b_code', table: 'mem_stage_bills'},
  171. {field: 'is_leaf', table: 'mem_stage_bills'},
  172. ]);
  173. const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  174. assert(chapter100.total_price === 1045756);
  175. const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  176. assert(chapter200.total_price.toFixed(0) == 3813369);
  177. assert(chapter200.contract_tp == 700.5);
  178. const chapter400 = ctx.helper._.find(data.mem_stage_bills, {code: '400'});
  179. assert(chapter400.total_price.toFixed(0) == 1231018);
  180. });
  181. it('test join', function* () {
  182. const ctx = app.mockContext(mockData);
  183. // test12 - 第6期
  184. const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
  185. const params = {
  186. tender_id: stage.tid,
  187. stage_id: stage.id,
  188. };
  189. const filters = ['mem_stage_bills', 'deal_bills'];
  190. const data = yield ctx.service.report.getReportData(params, filters, {
  191. mem_stage_bills: [
  192. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  193. 'code', 'b_code', 'name', 'unit', 'unit_price',
  194. 'deal_qty', 'deal_tp',
  195. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  196. 'dgn_qty1', 'dgn_qty2',
  197. 'drawing_code', 'memo', 'node_type', 'is_tp',
  198. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  199. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  200. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  201. 'final_tp', 'final_ratio',
  202. 'qc_bgl_code',
  203. 'chapter',
  204. ]
  205. });
  206. assert(data.mem_stage_bills.length === 216);
  207. reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
  208. {field: 'b_code', table: 'mem_stage_bills'},
  209. {field: 'name', table: 'mem_stage_bills'},
  210. {field: 'unit', table: 'mem_stage_bills'},
  211. {field: 'unit_price', table: 'mem_stage_bills'},
  212. {field: 'is_leaf', table: 'mem_stage_bills'},
  213. ]);
  214. assert(data.mem_stage_bills.length === 43);
  215. const joinOptions = {
  216. main: 'mem_stage_bills',
  217. sub: 'deal_bills',
  218. keyFields: [
  219. {main: 'b_code', sub: 'code', type: 'string'},
  220. {main: 'name', sub: 'name',type: 'string'},
  221. {main: 'unit', sub: 'unit',type: 'string'},
  222. {main: 'unit_price', sub: 'unit_price',type: 'number'},
  223. ],
  224. importFields: [
  225. {main: 'ex_value1', sub: 'quantity', type: 'number'},
  226. {main: 'ex_value2', sub: 'total_price', type: 'number'}
  227. ],
  228. joinType: 'outer', //'outer', 'main', 'sub', 'inner'
  229. };
  230. yield ctx.helper.saveBufferFile(JSON.stringify(joinOptions, '', '\t'), ctx.app.baseDir + '/analysis_join_options.json');
  231. reportDataAnalysis.analysisObj.join.fun(ctx, data, [], joinOptions);
  232. assert(data.mem_stage_bills.length === 132);
  233. reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
  234. {field: 'b_code', table: 'mem_stage_bills'},
  235. ]);
  236. const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
  237. const codeIndex100 = ['101-1-b', '102-2', '102-3', '102-4', '102-5', '103-1', '103-2',
  238. '103-3', '103-3-a', '103-3-b', '103-4', '104-1', '123-1'];
  239. const codeIndex200 = [
  240. '203-1-a', '203-1-a', '203-1-b', '203-1-b', '203-1-d', '203-1-d', '204-1-b', '204-1-b',
  241. '204-1-c', '204-1-d',
  242. '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',
  243. '207-1-b',
  244. '207-2-a', '207-2-a',
  245. '207-2-b', '207-2-c', '207-3-a',
  246. '207-4-a', '207-4-a',
  247. '207-4-c', '207-10-a',
  248. '208-1-a', '208-1-a', '208-3-a', '208-3-a',
  249. '208-3-b',
  250. '208-3-c', '208-3-c', '208-4-b-1', '208-4-b-1', '209-1-a', '209-1-a',
  251. '209-3', '209-3-b', '215-12', '215-12-a'
  252. ];
  253. let codeResult = codeIndex100.concat(codeIndex200);
  254. codeResult.forEach(function (a, i) {
  255. assert(a === codeIndex[i]);
  256. });
  257. });
  258. // it('test gatherChapter custom', function* () {
  259. // const ctx = app.mockContext(mockData);
  260. //
  261. // const params = {tender_id: 2072};
  262. // const filters = ['mem_stage_bills', 'tender_info'];
  263. // const data = yield ctx.service.report.getReportData(params, filters, {
  264. // mem_stage_bills: [
  265. // 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  266. // 'code', 'b_code', 'name', 'unit', 'unit_price',
  267. // 'deal_qty', 'deal_tp',
  268. // 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  269. // 'dgn_qty1', 'dgn_qty2',
  270. // 'drawing_code', 'memo', 'node_type', 'is_tp',
  271. // 'qc_bgl_code',
  272. // 'chapter',
  273. // ]
  274. // });
  275. // reportDataAnalysis.analysisObj.gatherChapter.fun(ctx, data, [
  276. // {field: 'b_code', table: 'mem_stage_bills'},
  277. // {field: 'is_leaf', table: 'mem_stage_bills'},
  278. // ], {
  279. // count: 7,
  280. // gclSum: {
  281. // name: '第100章至700章清单合计',
  282. // order: 1,
  283. // },
  284. // custom: [
  285. // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  286. // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  287. // {name: '计日工合计', node_type: '计日工', order: 4},
  288. // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  289. // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  290. // ],
  291. // });
  292. // const chapter100 = ctx.helper._.find(data.mem_stage_bills, {code: '100'});
  293. // assert(ctx.helper.checkZero(chapter100.total_price));
  294. // const chapter200 = ctx.helper._.find(data.mem_stage_bills, {code: '200'});
  295. // assert(chapter200.total_price === 33211);
  296. // const chapterGclSum = ctx.helper._.find(data.mem_stage_bills, {cType: 11});
  297. // assert(chapterGclSum.total_price == 33211);
  298. // const chapterJRG = ctx.helper._.find(data.mem_stage_bills, {name: '计日工合计'});
  299. // assert(chapterJRG.total_price === 1076);
  300. // const chapterSumWithoutZGJ = ctx.helper._.find(data.mem_stage_bills, {serialNo: 11});
  301. // assert(chapterSumWithoutZGJ.total_price === 33211);
  302. // const chapterZL = ctx.helper._.find(data.mem_stage_bills, {serialNo: 13});
  303. // assert(chapterZL.total_price === 500000);
  304. // const chapterSum = ctx.helper._.find(data.mem_stage_bills, {serialNo: 14});
  305. // assert(chapterSum.total_price === 534287);
  306. // });
  307. it('test analysisDefine', function() {
  308. const ctx = app.mockContext(mockData);
  309. const define = reportDataAnalysis.analysisDefine;
  310. assert(define.length === 5);
  311. assert(define[0].key === 'changeSort');
  312. assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name);
  313. assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint);
  314. assert(define[1].key === 'gatherGcl');
  315. assert(define[1].name === reportDataAnalysis.analysisObj.gatherGcl.name);
  316. assert(define[1].hint === reportDataAnalysis.analysisObj.gatherGcl.hint);
  317. assert(define[2].key === 'sortGcl');
  318. assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name);
  319. assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint);
  320. const x = {
  321. count: 7,
  322. gclSum: {
  323. name: '第100章至700章清单合计',
  324. order: 1,
  325. },
  326. custom: [
  327. {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
  328. {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  329. {name: '计日工合计', node_type: '计日工', order: 4},
  330. {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
  331. {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  332. ],
  333. };
  334. ctx.helper.saveBufferFile(JSON.stringify(x, "", "\t"), ctx.app.baseDir + '/mem_stage_pos.json');
  335. });
  336. });