stage_change.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. 'use strict';
  2. /**
  3. * 期 - 变更数据
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const defaultPid = -1; // 非pid
  10. const audit = require('../const/audit');
  11. const timesLen = audit.stage.timesLen;
  12. const changeConst = require('../const/change');
  13. module.exports = app => {
  14. class StageChange extends app.BaseService {
  15. /**
  16. * 构造函数
  17. *
  18. * @param {Object} ctx - egg全局变量
  19. * @return {void}
  20. */
  21. constructor(ctx) {
  22. super(ctx);
  23. this.tableName = 'stage_change';
  24. }
  25. /**
  26. * 查询 调用的变更令 最新数据
  27. * @param {Number} tid - 标段id
  28. * @param {Number} sid - 期id
  29. * @param {Number} lid - 台账节点id
  30. * @param {Number} pid - 部位明细id
  31. * @return {Promise<*>}
  32. */
  33. async getLastestStageData(tid, sid, lid, pid) {
  34. const sql = 'SELECT c.*,' +
  35. ' oc.p_code As c_code, oc.new_code As c_new_code' +
  36. ' FROM ' + this.tableName + ' As c ' +
  37. ' INNER JOIN ( ' +
  38. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
  39. ' WHERE tid = ? And sid = ? And lid = ? And pid = ?' +
  40. ' GROUP By `lid`, `pid`, `cid`, `cbid`' +
  41. ' ) As m ' +
  42. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
  43. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  44. ' ON c.cid = oc.cid' +
  45. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  46. ' ON c.cbid = ocb.id' +
  47. ' WHERE not ISNULL(ocb.id)';
  48. const sqlParam = [tid, sid, lid, pid ? pid : -1];
  49. return await this.db.query(sql, sqlParam);
  50. }
  51. /**
  52. * 查询 调用的变更令 某轮 某人的数据
  53. * @param {Number} tid - 标段id
  54. * @param {Number} sid - 期id
  55. * @param {Number} times - 第几轮
  56. * @param {Number} order - 第几人
  57. * @param {Number} lid - 台账节点id
  58. * @param {Number} pid - 部位明细id
  59. * @return {Promise<*>}
  60. */
  61. async getAuditorStageData(tid, sid, times, order, lid, pid) {
  62. const sql = 'SELECT c.*,' +
  63. ' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
  64. ' FROM ' + this.tableName + ' As c ' +
  65. ' INNER JOIN ( ' +
  66. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
  67. ' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' +
  68. ' GROUP By `lid`, `pid`, cid, cbid' +
  69. ' ) As m ' +
  70. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
  71. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  72. ' ON c.cid = oc.cid' +
  73. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  74. ' ON c.cbid = ocb.id' +
  75. ' WHERE not ISNULL(ocb.id)';
  76. const sqlParam = [tid, sid, times, times, order, lid, pid ? pid : -1];
  77. return await this.db.query(sql, sqlParam);
  78. }
  79. async getLastestAllStageData(tid, sid) {
  80. const sql = 'SELECT c.*,' +
  81. ' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
  82. ' FROM ' + this.tableName + ' As c ' +
  83. ' INNER JOIN ( ' +
  84. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
  85. ' WHERE tid = ? And sid = ?' +
  86. ' GROUP By `lid`, `pid`, cid, cbid' +
  87. ' ) As m ' +
  88. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
  89. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  90. ' ON c.cid = oc.cid' +
  91. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  92. ' ON c.cbid = ocb.id' +
  93. ' WHERE not ISNULL(ocb.id)';
  94. const sqlParam = [tid, sid];
  95. return await this.db.query(sql, sqlParam);
  96. }
  97. async getAuditorAllStageData(tid, sid, times, order) {
  98. const sql = 'SELECT c.*, ' +
  99. ' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
  100. ' FROM ' + this.tableName + ' As c ' +
  101. ' INNER JOIN ( ' +
  102. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
  103. ' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
  104. ' GROUP By `lid`, `pid`, cid, cbid' +
  105. ' ) As m ' +
  106. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
  107. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  108. ' ON c.cid = oc.cid' +
  109. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  110. ' ON c.cbid = ocb.id' +
  111. ' WHERE not ISNULL(ocb.id)';
  112. const sqlParam = [tid, sid, times, times, order];
  113. return await this.db.query(sql, sqlParam);
  114. }
  115. /**
  116. * 台账,调用变更令
  117. *
  118. * @param {Object} bills - 台账节点数据
  119. * @param {Array} changes - 调用的变更令
  120. * @return {Promise<void>}
  121. */
  122. async billsChange(bills, changes) {
  123. const self = this;
  124. function getNewChange(cid, cbid, times, order, qty) {
  125. return {
  126. tid: self.ctx.tender.id,
  127. sid: self.ctx.stage.id,
  128. lid: bills.id,
  129. pid: -1,
  130. cid,
  131. cbid,
  132. stimes: times,
  133. sorder: order,
  134. qty,
  135. };
  136. }
  137. const ledgerBills = await this.ctx.service.ledger.getDataById(bills.id);
  138. if (!ledgerBills || ledgerBills.tender_id !== this.ctx.tender.id) {
  139. throw '提交数据错误';
  140. }
  141. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerBills.unit);
  142. // 获取原变更令
  143. const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, bills.id, -1);
  144. // 获取更新数据
  145. const updateChanges = [],
  146. newChanges = [];
  147. let billsQty = 0;
  148. for (const oc of oldChanges) {
  149. const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
  150. if (!nc || nc.qty !== oc.qty) {
  151. const qty = nc ? this.round(nc.qty, precision.value) : null;
  152. const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty);
  153. billsQty = this.ctx.helper.add(billsQty, change.qty);
  154. if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
  155. change.id = oc.id;
  156. updateChanges.push(change);
  157. } else {
  158. newChanges.push(change);
  159. }
  160. } else {
  161. billsQty = this.ctx.helper.add(billsQty, oc.qty);
  162. }
  163. }
  164. for (const c of changes) {
  165. const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
  166. if (!nc) {
  167. const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value));
  168. billsQty = this.ctx.helper.add(billsQty, change.qty);
  169. newChanges.push(change);
  170. }
  171. }
  172. // 更新数据
  173. const transaction = await this.db.beginTransaction();
  174. try {
  175. if (newChanges.length > 0) {
  176. await transaction.insert(this.tableName, newChanges);
  177. }
  178. for (const c of updateChanges) {
  179. await transaction.update(this.tableName, c);
  180. }
  181. const stageBills = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, bills.id);
  182. await this.ctx.service.stageBills.updateStageBillsQty(transaction, ledgerBills, stageBills, { qc_qty: billsQty });
  183. await transaction.commit();
  184. } catch (err) {
  185. await transaction.rollback();
  186. throw err;
  187. }
  188. const result = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, [bills.id]);
  189. return { bills: { curStageData: result } };
  190. }
  191. /**
  192. * 部位明细,调用变更令
  193. *
  194. * @param {Object} pos - 部位明细数据
  195. * @param {Array} changes - 调用的变更令
  196. * @return {Promise<{}>}
  197. */
  198. async posChange(pos, changes) {
  199. const self = this;
  200. function getNewChange(cid, cbid, times, order, qty) {
  201. return {
  202. tid: self.ctx.tender.id,
  203. sid: self.ctx.stage.id,
  204. lid: pos.lid,
  205. pid: pos.id,
  206. cid,
  207. cbid,
  208. stimes: times,
  209. sorder: order,
  210. qty,
  211. };
  212. }
  213. const ledgerBills = await this.ctx.service.ledger.getDataById(pos.lid);
  214. if (!ledgerBills || ledgerBills.tender_id !== this.ctx.tender.id) {
  215. throw '提交数据错误';
  216. }
  217. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerBills.unit);
  218. // 获取原变更令
  219. const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, pos.lid, pos.id);
  220. const updateChanges = [],
  221. newChanges = [];
  222. let posQty = 0;
  223. for (const oc of oldChanges) {
  224. const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
  225. if (!nc || nc.qty !== oc.qty) {
  226. const qty = nc ? this.round(nc.qty, precision.value) : null;
  227. const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty);
  228. posQty = this.ctx.helper.add(posQty, change.qty);
  229. if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
  230. change.id = oc.id;
  231. updateChanges.push(change);
  232. } else {
  233. newChanges.push(change);
  234. }
  235. } else {
  236. posQty = this.ctx.helper.add(posQty, oc.qty);
  237. }
  238. }
  239. for (const c of changes) {
  240. const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
  241. if (!nc) {
  242. const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value));
  243. posQty = this.ctx.helper.add(posQty, change.qty);
  244. newChanges.push(change);
  245. }
  246. }
  247. // 更新数据
  248. const transaction = await this.db.beginTransaction();
  249. try {
  250. if (newChanges.length > 0) {
  251. await transaction.insert(this.tableName, newChanges);
  252. }
  253. for (const c of updateChanges) {
  254. await transaction.update(this.tableName, c);
  255. }
  256. await this.ctx.service.stagePos.updateChangeQuantity(transaction, pos, posQty);
  257. await transaction.commit();
  258. } catch (err) {
  259. await transaction.rollback();
  260. throw err;
  261. }
  262. // 获取返回数据
  263. try {
  264. const data = { bills: {}, pos: {} };
  265. data.bills.curStageData = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, [pos.lid]);
  266. data.pos.curStageData = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, { pid: pos.id });
  267. return data;
  268. } catch (err) {
  269. throw '获取数据错误,请刷新页面';
  270. }
  271. }
  272. /**
  273. * 获取 变更令 - 变更清单 使用情况
  274. * @param {Number} sid - 查询期id
  275. * @param {uuid} cid - 变更令id
  276. * @return {Promise<void>}
  277. */
  278. async getUsedData(tid, cid) {
  279. const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
  280. let filter;
  281. if (this.ctx.stage && lastStage.id === this.ctx.stage.id) {
  282. filter = this.db.format(' And (s.`order` < ? || (s.`order` = ? And sChange.`stimes` <= ? And sChange.`sorder` <= ?))',
  283. [lastStage.order, lastStage.order, this.ctx.stage.curTimes, this.ctx.stage.curOrder]);
  284. } else {
  285. if (lastStage.status === audit.stage.status.uncheck) {
  286. filter = 'And s.order < ' + lastStage.order;
  287. } else if (lastStage.status === audit.stage.status.checked) {
  288. filter = '';
  289. } else if (lastStage.status === audit.stage.status.checkNo) {
  290. filter = this.db.format(' And (s.`order` < ? || (s.`order` = ? And sChange.`stimes` <= ?))',
  291. [lastStage.order, lastStage.order, lastStage.times]);
  292. } else {
  293. const curAuditor = await this.ctx.service.stageAudit.getCurAuditor(lastStage.id, lastStage.times);
  294. filter = this.db.format(' And (s.`order` < ? || (s.`order` = ? And sChange.`stimes` <= ? And sChange.`sorder` <= ?))',
  295. [lastStage.order, lastStage.order, lastStage.times, curAuditor.order - 1]);
  296. }
  297. }
  298. const sql = 'SELECT c.lid, c.pid, SUM(c.qty) as used_qty,' +
  299. ' cb.tid, cb.cid, cb.id, cb.code, cb.name, cb.unit, cb.unit_price, cb.detail, cb.samount, cb.bwmx, cb.detail' +
  300. ' FROM ' + this.ctx.service.changeAuditList.tableName + ' As cb' +
  301. ' LEFT JOIN ' + this.tableName + ' As c ON cb.id = c.cbid ' +
  302. ' INNER JOIN (' +
  303. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, sChange.`sid`, `cid` ' +
  304. ' FROM ' + this.tableName + ' As sChange' +
  305. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' As s ON sChange.sid = s.id' +
  306. ' WHERE sChange.tid = ? AND cid = ?' + filter +
  307. ' GROUP By `lid`, `pid`, `cbid`, sChange.`sid`' +
  308. ' ) As m' +
  309. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.`cbid` = m.`cbid` AND c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`lid` = m.`lid` And c.`pid` = m.`pid`' +
  310. ' WHERE cb.cid = ?' +
  311. ' GROUP By c.`cbid`';
  312. const sqlParam = [tid, cid, cid];
  313. return await this.db.query(sql, sqlParam);
  314. }
  315. async getFinalUsedData(tid, cid) {
  316. const sql = 'SELECT c.lid, c.pid, SUM(c.qty) as used_qty,' +
  317. ' cb.tid, cb.cid, cb.id, cb.code, cb.name, cb.unit, cb.unit_price, cb.detail, cb.samount, cb.oamount, cb.bwmx, cb.gcl_id' +
  318. ' FROM ' + this.ctx.service.changeAuditList.tableName + ' As cb' +
  319. ' LEFT JOIN ' + this.tableName + ' As c ON cb.id = c.cbid ' +
  320. ' INNER JOIN (' +
  321. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, sChange.`sid`, `cid` ' +
  322. ' FROM ' + this.tableName + ' As sChange' +
  323. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' As s ON sChange.sid = s.id' +
  324. ' WHERE sChange.tid = ? AND cid = ?' +
  325. ' GROUP By `lid`, `pid`, `cbid`, sChange.`sid`' +
  326. ' ) As m' +
  327. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.`cbid` = m.`cbid` AND c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`lid` = m.`lid` And c.`pid` = m.`pid`' +
  328. ' WHERE cb.cid = ?' +
  329. ' GROUP By c.`cbid`';
  330. const sqlParam = [tid, cid, cid];
  331. return await this.db.query(sql, sqlParam);
  332. }
  333. /**
  334. * 获取 变更令 - 变更清单 当期使用情况
  335. * @param {Number} sid - 查询期id
  336. * @param {uuid} cid - 变更令id
  337. * @return {Promise<*>}
  338. */
  339. async getStageUsedData(sid, cid) {
  340. const sql = 'SELECT c.*, ' +
  341. ' l.ledger_id As `ledger_id`, l.b_code As `l_code`, l.name As `l_name`, l.unit As `l_unit`, l.unit_price As `l_up`,' +
  342. ' l.deal_qty As `l_deal_qty`, l.deal_tp As `l_deal_tp`, l.quantity As `l_qty`, l.total_price As `l_tp`, ' +
  343. ' l.drawing_code As `l_drawing_code`, ' +
  344. ' p.name As `p_name`, p.drawing_code As `p_drawing_code`, p.`quantity` As `p_qty`' +
  345. ' FROM ' + this.tableName + ' As c ' +
  346. ' INNER JOIN ( ' +
  347. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, `sid` From ' + this.tableName +
  348. ' WHERE sid = ? And cid = ?' +
  349. ' GROUP By `lid`, `pid`, `cbid`' +
  350. ' ) As m ' +
  351. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid And c.sid = m.sid' +
  352. ' LEFT JOIN ' + this.ctx.service.ledger.tableName + ' As l ON c.lid = l.id' +
  353. ' LEFT JOIN ' + this.ctx.service.pos.tableName + ' As p ON c.pid = p.id';
  354. const sqlParam = [sid, cid];
  355. return await this.db.query(sql, sqlParam);
  356. }
  357. /**
  358. * 获取 本期 使用的变更令
  359. * @param sid
  360. * @return {Promise<void>}
  361. */
  362. async getStageUsedChangeId(sid) {
  363. const sql = 'SELECT c.`cid`, sum(qty) As qty FROM ' + this.tableName + ' As c' +
  364. ' INNER JOIN (' +
  365. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid` From ' + this.tableName +
  366. ' WHERE sid = ?' +
  367. ' GROUP By `lid`, `pid`, `cbid`' +
  368. ' ) As m' +
  369. ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid' +
  370. ' GROUP BY c.`cid`';
  371. const sqlParam = [sid];
  372. const result = await this.db.query(sql, sqlParam);
  373. return this._.map(this._.filter(result, 'qty'), 'cid');
  374. }
  375. async getFinalStageData(tid, sid) {
  376. const data = await this.getAllDataByCondition({ where: { tid, sid } });
  377. return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid']);
  378. }
  379. async _getTender(stage) {
  380. if (this.ctx.tender) return this.ctx.tender;
  381. const tender = { id: stage.tid };
  382. tender.data = await this.ctx.service.tender.getTender(stage.tid);
  383. tender.info = await this.service.tenderInfo.getTenderInfo(tender.id);
  384. return tender;
  385. }
  386. async getQualityTotalPrice(stage) {
  387. const helper = this.ctx.helper;
  388. const tender = await this._getTender(stage);
  389. const sql = 'SELECT sc.*, c.quality FROM ' + this.tableName + ' sc' +
  390. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON sc.cid = c.cid' +
  391. ' WHERE sid = ?';
  392. const data = await this.db.query(sql, [stage.id]);
  393. const bqData = [];
  394. for (const d of data) {
  395. if (!d.qty) continue;
  396. let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
  397. if (!bd) {
  398. const bills = await this.db.get(this.ctx.service.ledger.departTableName(tender.id), { id: d.lid });
  399. if (!bills) continue;
  400. bd = { lid: d.lid, quality: d.quality, unit_price: bills.unit_price };
  401. bqData.push(bd);
  402. }
  403. const tp = this.ctx.helper.mul(d.qty, bd.unit_price, tender.info.decimal.tp);
  404. bd.tp = this.ctx.helper.add(bd.tp, tp);
  405. }
  406. const result = {};
  407. result.common = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.common.value; }), 'tp'));
  408. result.more = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.more.value; }), 'tp'));
  409. result.great = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.great.value; }), 'tp'));
  410. return result;
  411. }
  412. }
  413. return StageChange;
  414. };