sum_load.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const Ledger = require('../lib/ledger');
  10. class loadGclBaseTree {
  11. /**
  12. * 构造函数
  13. * @param {Array} tempData - 清单模板数据
  14. */
  15. constructor (ctx, setting) {
  16. this.ctx = ctx;
  17. this.parent = setting.parent;
  18. this.parent.children = [];
  19. this.defaultData = setting.defaultData;
  20. // 常量
  21. this.splitChar = '-';
  22. // 索引
  23. // 仅通过addNode或addNodeWithoutParent添加节点
  24. this.items = [];
  25. // this.parent下原来的节点
  26. this.baseNodes = [];
  27. this.ignoreParent = setting.ignoreParent;
  28. // 缓存
  29. this.keyNodeId = setting.maxId ? setting.maxId + 1 : 1;
  30. }
  31. /**
  32. * 根据 编号 查找 父项项目节
  33. * @param {String} code - 子项编号
  34. * @returns {*}
  35. */
  36. findNode(node, parent, check) {
  37. parent = parent || this.parent;
  38. if (!parent.children) return null;
  39. for (const child of parent.children) {
  40. const checkLeaf = (child.is_leaf && node.is_leaf) || (!child.is_leaf && !node.is_leaf);
  41. if (child.b_code === node.b_code && child.name === node.name && child.unit === node.unit
  42. && checkLeaf && !child.hasPos && (!check || check(child, node))) {
  43. return child;
  44. }
  45. }
  46. return null;
  47. }
  48. /**
  49. * 添加 树节点 并完善该节点的树结构
  50. * @param {Object} node - 添加节点
  51. * @param {Object} parent - 父项
  52. * @returns {*}
  53. */
  54. addNode(source, parent, check) {
  55. parent = parent ? parent : this.parent;
  56. let node = this.findNode(source, parent, check);
  57. if (!node) {
  58. if (!parent.children) parent.children = [];
  59. node = {
  60. id: this.ctx.app.uuid.v4(),
  61. tender_id: this.ctx.tender.id,
  62. ledger_id: this.keyNodeId,
  63. ledger_pid: parent.ledger_id,
  64. level: parent.level +1,
  65. full_path: parent.full_path + '-' + this.keyNodeId,
  66. order: parent.children.length + 1,
  67. children: [],
  68. b_code: source.b_code,
  69. name: source.name,
  70. unit: source.unit,
  71. deal_qty: 0,
  72. sgfh_qty: 0,
  73. qtcl_qty: 0,
  74. sjcl_qyt: 0,
  75. quantity: 0,
  76. is_leaf: source.is_leaf,
  77. hasPos: false,
  78. };
  79. this.keyNodeId += 1;
  80. parent.children.push(node);
  81. this.items.push(node);
  82. }
  83. return node;
  84. }
  85. findLeaf(node, check) {
  86. for (const bn of this.baseNodes) {
  87. if (bn.b_code === node.b_code && bn.name === node.name && bn.unit === node.unit
  88. && bn.is_leaf && !bn.hasPos && (!check || check(bn, node))) return bn;
  89. }
  90. for (const i of this.items) {
  91. if (i.b_code === node.b_code && i.name === node.name && i.unit === node.unit
  92. && i.is_leaf && !i.hasPos && (!check || check(i, node))) return i;
  93. }
  94. return null;
  95. }
  96. addNodeWithoutParent(source, check) {
  97. let node = this.findLeaf(source, check);
  98. if (!node) {
  99. node = {
  100. id: this.ctx.app.uuid.v4(),
  101. tender_id: this.ctx.tender.id,
  102. ledger_id: this.keyNodeId,
  103. ledger_pid: this.parent.ledger_id,
  104. level: this.parent.level + 1,
  105. full_path: this.parent.full_path + '-' + this.keyNodeId,
  106. order: this.parent.children.length + 1,
  107. b_code: source.b_code,
  108. name: source.name,
  109. unit: source.unit,
  110. deal_qty: 0,
  111. sgfh_qty: 0,
  112. qtcl_qty: 0,
  113. sjcl_qty: 0,
  114. quantity: 0,
  115. is_leaf: source.is_leaf,
  116. hasPos: false,
  117. };
  118. this.keyNodeId += 1;
  119. this.parent.children.push(node);
  120. this.items.push(node);
  121. }
  122. return node;
  123. }
  124. gather(source, parent) {}
  125. getUpdateData() {}
  126. resortChildrenByCode(node) {
  127. const helper = this.ctx.helper;
  128. if (!node.children || node.children.length === 0) return;
  129. node.children.sort((x, y) => {
  130. return helper.compareCode(x.b_code, y.b_code);
  131. });
  132. for (const [i, c] of node.children.entries()) {
  133. this.resortChildrenByCode(c);
  134. c.order = i + 1;
  135. }
  136. }
  137. resortByCode() {
  138. this.resortChildrenByCode(this.parent);
  139. }
  140. recursiveCalculate(dealBills, node) {
  141. if (node.children && node.children.length > 0) {
  142. for (const child of node.children) {
  143. this.recursiveCalculate(dealBills, child);
  144. }
  145. } else {
  146. const p = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, node.unit);
  147. node.deal_qty = this.ctx.helper.round(node.deal_qty, p.value);
  148. node.sgfh_qty = this.ctx.helper.round(node.sgfh_qty, p.value);
  149. node.sjcl_qty = this.ctx.helper.round(node.sjcl_qty, p.value);
  150. node.qtcl_qty = this.ctx.helper.round(node.qtcl_qty, p.value);
  151. node.quantity = this.ctx.helper.round(node.quantity, p.value);
  152. if (!node.unit_price) {
  153. const db = dealBills.find(x => { return x.code === node.b_code && x.name === node.name && x.unit === node.unit });
  154. if (!db) return;
  155. node.unit_price = db.unit_price;
  156. }
  157. node.deal_tp = this.ctx.helper.mul(node.deal_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
  158. node.sgfh_tp = this.ctx.helper.mul(node.sgfh_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
  159. node.sjcl_tp = this.ctx.helper.mul(node.sjcl_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
  160. node.qtcl_tp = this.ctx.helper.mul(node.qtcl_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
  161. node.total_price = this.ctx.helper.mul(node.quantity, node.unit_price, this.ctx.tender.info.decimal.tp);
  162. }
  163. }
  164. calculateAll(dealBills) {
  165. this.recursiveCalculate(dealBills, this.parent);
  166. }
  167. }
  168. class loadLedgerGclTree extends loadGclBaseTree {
  169. gather(source, parent) {
  170. const node = this.addNode(source, parent);
  171. node.deal_qty = this.ctx.helper.add(node.deal_qty, source.deal_qty);
  172. node.sgfh_qty = this.ctx.helper.add(node.sgfh_qty, source.sgfh_qty);
  173. node.qtcl_qty = this.ctx.helper.add(node.qtcl_qty, source.qtcl_qty);
  174. node.sjcl_qty = this.ctx.helper.add(node.sjcl_qty, source.sjcl_qty);
  175. node.quantity = this.ctx.helper.add(node.quantity, source.quantity);
  176. return node;
  177. }
  178. getUpdateData() {
  179. const update = [];
  180. if (this.items.length > 0) update.push({id: this.parent.id, ledger_id: this.parent.ledger_id, is_leaf: 0});
  181. const create = [];
  182. for (const i of this.items) {
  183. create.push({
  184. id: i.id, tender_id: i.tender_id, ledger_id: i.ledger_id, ledger_pid: i.ledger_pid,
  185. level: i.level, order: i.order, full_path: i.full_path, is_leaf: !i.children || i.children.length === 0,
  186. b_code: i.b_code, name: i.name, unit: i.unit, unit_price: i.unit_price || 0,
  187. deal_qty: i.deal_qty, deal_tp: i.deal_tp || 0,
  188. sgfh_qty: i.sgfh_qty, sjcl_qty: i.sjcl_qty, qtcl_qty: i.qtcl_qty, quantity: i.quantity,
  189. sgfh_tp: i.sgfh_tp || 0, sjcl_tp: i.sjcl_tp || 0, qtcl_tp: i.qtcl_tp || 0, total_price: i.total_price || 0,
  190. });
  191. }
  192. return {update, create};
  193. }
  194. }
  195. class updateReviseGclTree extends loadGclBaseTree {
  196. constructor (ctx, setting) {
  197. super(ctx, setting);
  198. this.errors = [];
  199. }
  200. loadBase(datas, pos) {
  201. datas.sort((x, y) => { return x.level === y.level ? x.order - y.order : x.level - y.level; });
  202. const Index = {};
  203. for (const d of datas) {
  204. const parent = this.parent.ledger_id === d.ledger_pid ? this.parent : Index[d.ledger_pid];
  205. if (!parent) continue;
  206. if (!parent.children) parent.children = [];
  207. const relaPos = pos.filter(x => {return x.lid === d.id});
  208. const baseNode = {
  209. id: d.id,
  210. ledger_id: d.ledger_id,
  211. ledger_pid: d.ledger_pid,
  212. level: d.level,
  213. is_leaf: d.is_leaf,
  214. full_path: d.full_path,
  215. b_code: d.b_code,
  216. name: d.name,
  217. unit: d.unit,
  218. unit_price: d.unit_price,
  219. org_deal_qty: d.deal_qty || 0,
  220. org_sgfh_qty: d.sgfh_qty || 0,
  221. org_sjcl_qty: d.sjcl_qty || 0,
  222. org_qtcl_qty: d.qtcl_qty || 0,
  223. org_qty: d.quantity || 0,
  224. org_order: d.order,
  225. sgfh_qty: 0,
  226. sjcl_qty: 0,
  227. qtcl_qty: 0,
  228. quantity: 0,
  229. hasPos: relaPos.length > 0,
  230. };
  231. parent.children.push(baseNode);
  232. Index[baseNode.ledger_id] = baseNode;
  233. this.baseNodes.push(baseNode);
  234. }
  235. }
  236. gather(source, parent) {
  237. const node = this.addNode(source, parent);
  238. node.deal_qty = this.ctx.helper.add(node.deal_qty, source.deal_qty);
  239. node.sgfh_qty = this.ctx.helper.add(node.sgfh_qty, source.sgfh_qty);
  240. node.qtcl_qty = this.ctx.helper.add(node.qtcl_qty, source.qtcl_qty);
  241. node.sjcl_qty = this.ctx.helper.add(node.sjcl_qty, source.sjcl_qty);
  242. node.quantity = this.ctx.helper.add(node.quantity, source.quantity);
  243. return node;
  244. }
  245. getUpdateData() {
  246. const result = {update: [], errors: [], create: []};
  247. if (this.baseNodes.length === 0) {
  248. if (this.items.length > 0) result.update.push({id: this.parent.id, ledger_id: this.parent.ledger_id, is_leaf: 0});
  249. } else {
  250. for (const bn of this.baseNodes) {
  251. if (bn.children && bn.children.length > 0) {
  252. if (bn.order !== bn.org_order) {
  253. result.update.push({
  254. id: bn.id, ledger_id: bn.ledger_id, order: bn.order,
  255. });
  256. }
  257. continue;
  258. }
  259. if (bn.deal_qty < bn.org_deal_qty || bn.sjcl_qty < bn.org_sjcl_qty || bn.qtcl_qty < bn.org_qtcl_qty || bn.sgfh_qty < bn.org_sgfh_qty) {
  260. result.errors.push({
  261. ledger_id: bn.ledger_id,
  262. b_code: bn.b_code, name: bn.name, unit: bn.unit,
  263. deal_qty: bn.deal_qty, sgfh_qty: bn.sgfh_qty, sjcl_qty: bn.sjcl_qty, qtcl_qty: bn.qtcl_qty, qty: bn.quantity, type: 'less',
  264. });
  265. if (bn.order !== bn.org_order) {
  266. result.update.push({
  267. id: bn.id, ledger_id: bn.ledger_id, order: bn.order,
  268. });
  269. }
  270. } else if (bn.sjcl_qty !== bn.org_sjcl_qty || bn.qtcl_qty !== bn.org_qtcl_qty || bn.sgfh_qty !== bn.org_sgfh_qty) {
  271. result.update.push({
  272. id: bn.id, ledger_id: bn.ledger_id, unit_price: bn.unit_price || 0, order: bn.order,
  273. deal_qty: bn.deal_qty, deal_tp: bn.deal_tp || 0,
  274. sgfh_qty: bn.sgfh_qty, sjcl_qty: bn.sjcl_qty, qtcl_qty: bn.qtcl_qty, quantity: bn.quantity,
  275. sgfh_tp: bn.sgfh_tp || 0, sjcl_tp: bn.sjcl_tp || 0, qtcl_tp: bn.qtcl_tp || 0, total_price: bn.total_price || 0,
  276. });
  277. } else if (bn.order !== bn.org_order) {
  278. result.update.push({
  279. id: bn.id, ledger_id: bn.ledger_id, order: bn.order,
  280. });
  281. }
  282. }
  283. }
  284. for (const i of this.items) {
  285. result.create.push({
  286. id: i.id, tender_id: i.tender_id, ledger_id: i.ledger_id, ledger_pid: i.ledger_pid,
  287. level: i.level, order: i.order, full_path: i.full_path, is_leaf: !i.children || i.children.length === 0,
  288. b_code: i.b_code, name: i.name, unit: i.unit, unit_price: i.unit_price || 0,
  289. deal_qty: i.deal_qty, deal_tp: i.deal_tp || 0,
  290. sgfh_qty: i.sgfh_qty, sjcl_qty: i.sjcl_qty, qtcl_qty: i.qtcl_qty, quantity: i.quantity,
  291. sgfh_tp: i.sgfh_tp || 0, sjcl_tp: i.sjcl_tp || 0, qtcl_tp: i.qtcl_tp || 0, total_price: i.total_price || 0,
  292. })
  293. }
  294. return result;
  295. }
  296. }
  297. class gatherStageGclTree extends loadGclBaseTree {
  298. constructor (ctx, setting) {
  299. super(ctx, setting);
  300. this.cover = setting.cover;
  301. }
  302. loadBase(datas, pos) {
  303. datas.sort((x, y) => { return x.level === y.level ? x.order - y.order : x.level - y.level; });
  304. const Index = {};
  305. for (const d of datas) {
  306. const parent = this.parent.ledger_id === d.ledger_pid ? this.parent : Index[d.ledger_pid];
  307. if (!parent) continue;
  308. if (!parent.children) parent.children = [];
  309. const relaPos = pos.filter(x => {return x.lid === d.id});
  310. const baseNode = {
  311. id: d.id,
  312. ledger_id: d.ledger_id,
  313. ledger_pid: d.ledger_pid,
  314. level: d.level,
  315. is_leaf: d.is_leaf,
  316. full_path: d.full_path,
  317. b_code: d.b_code,
  318. name: d.name,
  319. unit: d.unit,
  320. unit_price: d.unit_price,
  321. org_contract_qty: this.cover ? d.contract_qty || 0 : 0,
  322. org_contract_tp: this.cover ? d.contract_tp || 0 : 0,
  323. org_order: d.order,
  324. contract_qty: 0,
  325. contract_tp: 0,
  326. is_tp: d.is_tp,
  327. hasPos: relaPos.length > 0,
  328. };
  329. parent.children.push(baseNode);
  330. Index[baseNode.ledger_id] = baseNode;
  331. this.baseNodes.push(baseNode);
  332. }
  333. }
  334. _gatherChange(node, source) {
  335. if (!source.change_detail || source.change_detail.length === 0) return;
  336. if (!node.change_detail) node.change_detail = [];
  337. for (const cd of source.change_detail) {
  338. if (!cd.qty) continue;
  339. let ncd = node.change_detail.find(x => { return x.cid === cd.cid; });
  340. if (!ncd) {
  341. ncd = { cid: cd.cid, c_code: cd.c_code };
  342. node.change_detail.push(ncd);
  343. }
  344. ncd.qty = this.ctx.helper.add(ncd.qty, cd.qty);
  345. }
  346. }
  347. gather(source, parent) {
  348. parent = parent ? parent : this.parent;
  349. const checkFun = function (node, source) {
  350. return (source.is_tp && node.is_tp) || (!source.is_tp && !node.is_tp);
  351. };
  352. const node = this.ignoreParent ? this.addNodeWithoutParent(source, checkFun) : this.addNode(source, parent, checkFun);
  353. if (node.is_tp) {
  354. node.contract_tp = this.ctx.helper.add(node.contract_tp, source.contract_tp);
  355. } else {
  356. node.contract_qty = this.ctx.helper.add(node.contract_qty, source.contract_qty);
  357. node.contract_tp = this.ctx.helper.mul(node.unit_price, node.contract_qty, this.ctx.tender.info.decimal.tp);
  358. }
  359. this._gatherChange(node, source);
  360. return node;
  361. }
  362. getUpdateData() {
  363. const result = {update: [], errors: []};
  364. for (const bn of this.baseNodes) {
  365. if (bn.contract_qty !== bn.org_contract_qty || bn.contract_tp !== bn.org_contract_tp) {
  366. result.update.push({lid: bn.id, contract_qty: bn.contract_qty, contract_tp: bn.contract_tp });
  367. }
  368. if (bn.change_detail && bn.change_detail.length > 0) {
  369. for (const cd of bn.change_detail) {
  370. result.errors.push({
  371. ledger_id: bn.ledger_id,
  372. b_code: bn.b_code, name: bn.name, unit: bn.unit,
  373. c_code: cd.c_code, qty: cd.qty, type: 'qc',
  374. });
  375. }
  376. }
  377. }
  378. console.log(result.update.length);
  379. for (const i of this.items) {
  380. result.errors.push({ b_code: i.b_code, name: i.name, unit: i.unit, qty: i.contract_qty, type: 'miss' });
  381. if (i.change_detail && i.change_detail.length > 0) {
  382. for (const cd of i.change_detail) {
  383. result.errors.push({
  384. b_code: i.b_code, name: i.name, unit: i.unit,
  385. c_code: cd.c_code, qty: cd.qty, type: 'miss-qc',
  386. });
  387. }
  388. }
  389. }
  390. return result;
  391. }
  392. }
  393. class sumLoad {
  394. constructor (ctx) {
  395. this.ctx = ctx;
  396. }
  397. recusiveLoadGatherGcl(node, parent, ignoreParent = false) {
  398. const isLeaf = !node.children || node.children.length === 0;
  399. const cur = (!ignoreParent || isLeaf) && node.b_code ? this.loadTree.gather(node, parent) : parent;
  400. if (isLeaf) return;
  401. for (const child of node.children) {
  402. this.recusiveLoadGatherGcl(child, cur, ignoreParent);
  403. }
  404. }
  405. async loadGatherGcl(select, maxId, tenders, defaultData) {
  406. this.loadTree = new loadLedgerGclTree(this.ctx, {
  407. parent: select, maxId, type: 'ledger', defaultData,
  408. });
  409. for (const tender of tenders) {
  410. const billsData = await this.ctx.service.ledger.getData(tender.tid);
  411. const billsTree = new Ledger.billsTree(this.ctx, {
  412. id: 'ledger_id',
  413. pid: 'ledger_pid',
  414. order: 'order',
  415. level: 'level',
  416. rootId: -1,
  417. keys: ['id', 'tender_id', 'ledger_id'],
  418. stageId: 'id',
  419. });
  420. billsTree.loadDatas(billsData);
  421. for (const top of billsTree.children) {
  422. if ([1].indexOf(top.node_type) < 0) continue;
  423. this.recusiveLoadGatherGcl(top, null);
  424. }
  425. }
  426. this.loadTree.resortByCode();
  427. const dealBills = await this.ctx.service.dealBills.getAllDataByCondition({ where: { tender_id: this.ctx.tender.id } });
  428. this.loadTree.calculateAll(dealBills);
  429. return this.loadTree;
  430. }
  431. async updateGatherGcl(select, maxId, tenders, defaultData) {
  432. this.loadTree = new updateReviseGclTree(this.ctx, {
  433. parent: select, maxId, type: 'ledger', defaultData,
  434. });
  435. const posterity = await this.ctx.service.reviseBills.getPosterityByParentId(this.ctx.tender.id, select.ledger_id);
  436. const pos = await this.ctx.service.revisePos.getData(this.ctx.tender.id);
  437. this.loadTree.loadBase(posterity, pos);
  438. for (const tender of tenders) {
  439. const billsData = await this.ctx.service.ledger.getData(tender.tid);
  440. const billsTree = new Ledger.billsTree(this.ctx, {
  441. id: 'ledger_id',
  442. pid: 'ledger_pid',
  443. order: 'order',
  444. level: 'level',
  445. rootId: -1,
  446. keys: ['id', 'tender_id', 'ledger_id'],
  447. stageId: 'id',
  448. });
  449. billsTree.loadDatas(billsData);
  450. for (const top of billsTree.children) {
  451. if ([1].indexOf(top.node_type) < 0) continue;
  452. this.recusiveLoadGatherGcl(top, null);
  453. }
  454. }
  455. this.loadTree.resortByCode();
  456. const dealBills = await this.ctx.service.dealBills.getAllDataByCondition({ where: { tender_id: this.ctx.tender.id } });
  457. this.loadTree.calculateAll(dealBills);
  458. return this.loadTree;
  459. }
  460. _loadCurStageAndChange(billsData, curStageBills, curStageChange) {
  461. const billsIndex = {};
  462. for (const b of billsData) {
  463. billsIndex[b.id] = b;
  464. }
  465. for (const csb of curStageBills) {
  466. const b = billsIndex[csb.lid];
  467. if (!b) continue;
  468. b.contract_qty = csb.contract_qty;
  469. b.contract_tp = csb.contract_tp;
  470. }
  471. for (const csc of curStageChange) {
  472. if (!csc.qty) continue;
  473. const b = billsIndex[csc.lid];
  474. if (!b) continue;
  475. if (!b.change_detail) b.change_detail = [];
  476. let c = b.change_detail.find(x => { return x.cid === csc.cid });
  477. if (!c) {
  478. c = { cid: csc.cid };
  479. b.change_detail.push(c);
  480. }
  481. c.qty = this.ctx.helper.add(c.qty, csc.qty);
  482. }
  483. }
  484. async stageGatherGcl(select, maxId, tenders, defaultData, cover) {
  485. const ignoreParent = this.ctx.tender.info.fun_rela.sum_load.ignoreParent;
  486. this.loadTree = new gatherStageGclTree(this.ctx, {
  487. parent: select, maxId, type: 'ledger', defaultData, ignoreParent, cover,
  488. });
  489. const posterity = await this.ctx.service.ledger.getPosterityByParentId(this.ctx.tender.id, select.ledger_id);
  490. const stageBills = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
  491. this.ctx.helper.assignRelaData(posterity, [
  492. { data: stageBills, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp' ], prefix: '', relaId: 'lid' },
  493. ]);
  494. const pos = await this.ctx.service.revisePos.getData(this.ctx.tender.id);
  495. this.loadTree.loadBase(posterity, pos);
  496. for (const tender of tenders) {
  497. if (!tender.stage) continue;
  498. const billsData = await this.ctx.service.ledger.getData(tender.tid);
  499. const stage = await this.ctx.service.stage.getDataByCondition({tid: tender.tid, order: tender.stage});
  500. if (!stage) throw '选择的期不存在';
  501. const curStageData = await this.ctx.service.stageBills.getLastestStageData2(tender.tid, stage.id);
  502. const curStageChange = await this.ctx.service.stageChangeFinal.getSumLoadFinalData(stage.id);
  503. this._loadCurStageAndChange(billsData, curStageData, curStageChange);
  504. const billsTree = new Ledger.billsTree(this.ctx, {
  505. id: 'ledger_id',
  506. pid: 'ledger_pid',
  507. order: 'order',
  508. level: 'level',
  509. rootId: -1,
  510. keys: ['id', 'tender_id', 'ledger_id'],
  511. stageId: 'id',
  512. });
  513. billsTree.loadDatas(billsData);
  514. for (const top of billsTree.children) {
  515. if ([1].indexOf(top.node_type) < 0) continue;
  516. this.recusiveLoadGatherGcl(top, null, ignoreParent);
  517. }
  518. }
  519. return this.loadTree;
  520. }
  521. }
  522. module.exports = sumLoad;