report_memory.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const _ = require('lodash');
  10. const StageIm = require('../lib/stage_im');
  11. const imType = require('../const/tender').imType;
  12. const audit = require('../const/audit');
  13. const changeConst = require('../const/change');
  14. const materialConst = require('../const/material');
  15. // const path = require('path');
  16. // const fs = require('fs');
  17. const stageImTz = 'mem_stage_im_tz';
  18. const stageImTzBills = 'mem_stage_im_tz_bills';
  19. const stageImZl = 'mem_stage_im_zl';
  20. const stageImVersion = '1.3';
  21. const Ledger = require('../lib/ledger');
  22. const billsFields = (function () {
  23. const cur = ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil'];
  24. const pre = ['pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp'];
  25. const end = ['end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp'];
  26. const final = ['final_tp', 'final_ratio'];
  27. const stageDgn = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  28. const stage = cur.concat(pre, end, final);
  29. const stageEnd = pre.concat(end, final);
  30. const bgl = ['qc_bgl_code'];
  31. const leafXmj = ['leaf_xmj_id'];
  32. return {cur, pre, end, final, stageDgn, stage, stageEnd, bgl, leafXmj};
  33. })();
  34. const posFields = (function () {
  35. const cur = ['contract_qty', 'qc_qty', 'gather_qty', 'postil'];
  36. const pre = ['pre_contract_qty', 'pre_qc_qty', 'pre_gather_qty'];
  37. const end = ['end_contract_qty', 'end_qc_qty', 'end_gather_qty'];
  38. const final = ['final_ratio'];
  39. const stage = cur.concat(pre, end, final);
  40. const stageEnd = pre.concat(end, final);
  41. const bgl = ['qc_bgl_code'];
  42. return {cur, pre, end, final, stage, stageEnd, bgl};
  43. })();
  44. module.exports = app => {
  45. class ReportMemory extends app.BaseService {
  46. /**
  47. * 构造函数
  48. *
  49. * @param {Object} ctx - egg全局context
  50. * @return {void}
  51. */
  52. constructor(ctx) {
  53. super(ctx);
  54. const self = this;
  55. this.tableName = 'report_memory';
  56. // 基础数据类
  57. // mainData
  58. this.pos = new Ledger.pos({
  59. id: 'id', ledgerId: 'lid',
  60. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  61. calc: function (p) {
  62. p.pre_gather_qty = ctx.helper.add(p.pre_contract_qty, p.pre_qc_qty);
  63. p.gather_qty = ctx.helper.add(p.contract_qty, p.qc_qty);
  64. p.end_contract_qty = self.ctx.helper.add(p.pre_contract_qty, p.contract_qty);
  65. p.end_qc_qty = self.ctx.helper.add(p.pre_qc_qty, p.qc_qty);
  66. p.end_gather_qty = self.ctx.helper.add(p.pre_gather_qty, p.gather_qty);
  67. }
  68. });
  69. // 需要缓存的数据
  70. this.stageImData = null;
  71. this.changeData = null;
  72. this.stageValidRole = [];
  73. }
  74. _getNewBillsTree(calcFields) {
  75. return new Ledger.billsTree(this.ctx, {
  76. id: 'ledger_id',
  77. pid: 'ledger_pid',
  78. order: 'order',
  79. level: 'level',
  80. rootId: -1,
  81. keys: ['id', 'tender_id', 'ledger_id'],
  82. stageId: 'id',
  83. calcFields: calcFields || ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
  84. calc: function (node, helper) {
  85. if (node.children && node.children.length === 0) {
  86. node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
  87. node.gather_qty = helper.add(node.contract_qty, node.qc_qty);
  88. node.end_contract_qty = helper.add(node.pre_contract_qty, node.contract_qty);
  89. node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty);
  90. node.end_gather_qty = helper.add(node.pre_gather_qty, node.gather_qty);
  91. }
  92. node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
  93. node.gather_tp = helper.add(node.contract_tp, node.qc_tp);
  94. node.end_contract_tp = helper.add(node.pre_contract_tp, node.contract_tp);
  95. node.end_qc_tp = helper.add(node.pre_qc_tp, node.qc_tp);
  96. node.end_gather_tp = helper.add(node.pre_gather_tp, node.gather_tp);
  97. node.final_tp = helper.add(node.total_price, node.end_qc_tp);
  98. node.final_ratio = helper.mul(helper.div(node.end_gather_tp, node.final_tp, 4), 100);
  99. }
  100. });
  101. }
  102. _checkFieldsExist(source, check) {
  103. for (const s of source) {
  104. if (check.indexOf(s) >= 0) {
  105. return true;
  106. }
  107. }
  108. return false;
  109. }
  110. _checkFieldsExistReg(source, regStr) {
  111. const reg = new RegExp(regStr, 'igm');
  112. for (const s of source) {
  113. if (reg.test(s)) {
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119. // build-time: 162-384ms, redis-cache: 0-41ms, mysql + IO: 116-146ms
  120. // 一定程度上算是大Value缓存,数据多了以后:
  121. // 1. 达到redis内存阈值时,数据会swap到磁盘,此时将消耗IO时间
  122. // 2. redis单独服务器
  123. // 3. redis集群
  124. async _getReportMemoryCache(name, tid, sid, time, version = '') {
  125. // redis
  126. const cacheKey = name + '-t' + tid + (sid ? '-s' + sid : '') + (time ? '-' + time : '') + version;
  127. const data = await this.cache.get(cacheKey);
  128. if (data) {
  129. return eval(data);
  130. } else {
  131. return null;
  132. }
  133. // mysql + IO
  134. // const rm = await this.getDataByCondition({
  135. // tid: tid, sid: sid, name: name, time: time
  136. // });
  137. // if (rm && rm.file) {
  138. // const file = path.join(this.ctx.app.config.filePath, 'report', 'cache', rm.file);
  139. // if (fs.existsSync(file)) {
  140. // const data = await fs.readFileSync(file, 'utf8');
  141. // return eval(data);
  142. // } else {
  143. // return null;
  144. // }
  145. // }
  146. }
  147. async _setReportMemoryCache(name, tid, sid, time, data, version = '') {
  148. // redis
  149. const cacheKey = name + '-t' + tid + (sid ? '-s' + sid : '') + (time ? '-' + time : '') + version;
  150. this.cache.set(cacheKey, JSON.stringify(data), 'EX', this.ctx.app.config.cacheTime);
  151. // mysql + IO
  152. // const file = path.join('report', 'cache', 'rm' + (new Date()).getTime() + '.json');
  153. // await this.ctx.helper.saveBufferFile(JSON.stringify(data), path.join(this.ctx.app.config.filePath, file));
  154. // const rm = await this.getDataByCondition({
  155. // tid: tid, sid: sid, name: name, time: time
  156. // });
  157. // if (rm) {
  158. // await this.db.update(this.tableName, {id: rm.id, file: file});
  159. // } else {
  160. // await this.db.insert(this.tableName, {tid: tid, sid: sid, name: name, time: time, file: file});
  161. // }
  162. }
  163. async _generateStageIm(tid, sid, isTz = true) {
  164. if (isTz && [imType.tz.value, imType.bb.value].indexOf(this.ctx.stage.im_type) === -1) {
  165. throw '您查看的报表跟设置不符,请查看“总量控制”的报表';
  166. } else if (!isTz && [imType.zl.value, imType.bw.value].indexOf(this.ctx.stage.im_type) === -1) {
  167. throw '您查看的报表跟设置不符,请查看“0号台账”的报表';
  168. }
  169. const stageIm = new StageIm(this.ctx);
  170. await stageIm.buildImData();
  171. this.stageImData.main = stageIm.ImData;
  172. if (isTz) {
  173. this.stageImData.bills = stageIm.ImBillsData;
  174. await this._setReportMemoryCache(stageImTz, tid, sid, this.ctx.stage.cacheTime, this.stageImData.main, stageImVersion);
  175. await this._setReportMemoryCache(stageImTzBills, tid, sid, this.ctx.stage.cacheTime, this.stageImData.bills, stageImVersion);
  176. } else {
  177. await this._setReportMemoryCache(stageImZl, tid, sid, this.ctx.stage.cacheTime, this.stageImData.main, stageImVersion);
  178. }
  179. }
  180. async getStageImTzData(tid, sid, fields, readCache = true) {
  181. try {
  182. await this.ctx.service.tender.checkTender(tid);
  183. await this.ctx.service.stage.checkStage(sid);
  184. if (readCache) {
  185. const cache = await this._getReportMemoryCache('mem_stage_im_tz', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
  186. if (cache) return cache;
  187. }
  188. if (!this.stageImData) {
  189. this.stageImData = {};
  190. try {
  191. await this._generateStageIm(tid, sid);
  192. } catch (err) {
  193. if (err.stack) {
  194. this.ctx.logger.error(err);
  195. }
  196. this.stageImData.main = err.stack ? '数据错误' : err;
  197. this.stageImData.bills = this.stageImData.main;
  198. }
  199. }
  200. return this.stageImData.main;
  201. } catch (err) {
  202. return [];
  203. }
  204. }
  205. async getStageImTzBillsData(tid, sid, fields, readCache = true) {
  206. try {
  207. await this.ctx.service.tender.checkTender(tid);
  208. await this.ctx.service.stage.checkStage(sid);
  209. if (readCache) {
  210. const cache = await this._getReportMemoryCache('mem_stage_im_tz_bills', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
  211. if (cache) return cache;
  212. }
  213. if (!this.stageImData) {
  214. this.stageImData = {};
  215. try {
  216. await this._generateStageIm(tid, sid);
  217. } catch (err) {
  218. if (err.stack) {
  219. this.ctx.logger.error(err);
  220. }
  221. this.stageImData.main = err.stack ? '数据错误' : err;
  222. this.stageImData.bills = this.stageImData.main;
  223. }
  224. }
  225. return this.stageImData.bills;
  226. } catch (err) {
  227. return [];
  228. }
  229. }
  230. async getStageImZlData(tid, sid, fields, readCache = true) {
  231. try {
  232. await this.ctx.service.tender.checkTender(tid);
  233. await this.ctx.service.stage.checkStage(sid);
  234. if (readCache) {
  235. const cache = await this._getReportMemoryCache('mem_stage_im_zl', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
  236. if (cache) return cache;
  237. }
  238. this.stageImData = {};
  239. try {
  240. await this._generateStageIm(tid, sid, false);
  241. } catch (err) {
  242. if (err.stack) {
  243. this.ctx.logger.error(err);
  244. }
  245. this.stageImData.main = err.statck ? '数据错误' : err;
  246. }
  247. return this.stageImData.main;
  248. } catch (err) {
  249. return [];
  250. }
  251. }
  252. async getMonthProgress(tid, fields) {
  253. const helper = this.ctx.helper;
  254. await this.ctx.service.tender.checkTender(tid);
  255. const tender = this.ctx.tender;
  256. const stages = await this.ctx.service.stage.getValidStages(tender.id);
  257. const lastStage = stages.length > 0 ? stages[0] : null;
  258. if (lastStage) {
  259. await this.ctx.service.stage.checkStageGatherData(lastStage);
  260. tender.gather_tp = helper.add(lastStage.contract_tp, lastStage.qc_tp);
  261. tender.end_contract_tp = helper.add(lastStage.contract_tp, lastStage.pre_contract_tp);
  262. tender.end_qc_tp = helper.add(lastStage.qc_tp, lastStage.pre_qc_tp);
  263. tender.end_gather_tp = helper.add(tender.end_contract_tp, tender.end_qc_tp);
  264. tender.pre_gather_tp = helper.add(lastStage.pre_contract_tp, lastStage.pre_qc_tp);
  265. tender.yf_tp = lastStage.yf_tp;
  266. tender.qc_ratio = helper.mul(helper.div(tender.end_qc_tp, tender.info.deal_param.contractPrice, 2), 100);
  267. tender.sum = helper.add(tender.total_price, tender.end_qc_tp);
  268. tender.pre_ratio = helper.mul(helper.div(tender.pre_gather_tp, tender.sum, 2), 100);
  269. tender.cur_ratio = helper.mul(helper.div(tender.gather_tp, tender.sum, 2), 100);
  270. tender.other_tp = helper.sub(helper.sub(tender.sum, tender.pre_gather_tp), tender.gather_tp);
  271. tender.other_ratio = Math.max(0, 100 - tender.pre_ratio - tender.cur_ratio);
  272. }
  273. const monthProgress = [];
  274. for (const s of stages) {
  275. if (s.s_time) {
  276. let progress = monthProgress.find(function (x) {
  277. return x.month === s.s_time;
  278. });
  279. if (!progress) {
  280. progress = {month: s.s_time};
  281. monthProgress.push(progress);
  282. }
  283. progress.tp = helper.add(helper.add(progress.tp, s.contract_tp), s.qc_tp);
  284. }
  285. }
  286. monthProgress.sort(function (x, y) {
  287. return Date.parse(x.month) - Date.parse(y.month);
  288. });
  289. let sum = 0;
  290. for (const p of monthProgress) {
  291. p.ratio = helper.mul(helper.div(p.tp, tender.sum, 4), 100);
  292. sum = helper.add(sum, p.tp);
  293. p.end_tp = sum;
  294. p.end_ratio = helper.mul(helper.div(p.end_tp, tender.sum, 4), 100);
  295. }
  296. return monthProgress;
  297. }
  298. async _calcBillsBgl(billsTree) {
  299. if (!this.ctx.stage) return;
  300. const helper = this.ctx.helper;
  301. const tender = this.ctx.tender;
  302. const stage = this.ctx.stage;
  303. const bglData = this.ctx.stage.readOnly
  304. ? await this.ctx.service.stageChange.getAuditorAllStageData(tender.id, stage.id, stage.curTimes, stage.curOrder)
  305. : await this.ctx.service.stageChange.getLastestAllStageData(tender.id, stage.id);
  306. for (const node of billsTree.nodes) {
  307. node.qc_bgl_code = '';
  308. if (node.children && node.children.length > 0) continue;
  309. const nodeBgl = helper._.filter(bglData, {lid: node.id});
  310. if (nodeBgl.length === 0) continue;
  311. helper._.pullAll(bglData, nodeBgl);
  312. const validBgl = helper._.filter(nodeBgl, function (x) {
  313. return !helper.checkZero(x.qty);
  314. });
  315. node.qc_bgl_code = helper._.uniq(helper._.map(validBgl, 'c_code')).join(';');
  316. }
  317. }
  318. _calcLeafXmjRela(billsTree) {
  319. for (const node of billsTree.nodes) {
  320. if (node.b_code) {
  321. const leafXmj = billsTree.getLeafXmjParent(node);
  322. node.leaf_xmj_id = leafXmj ? leafXmj.id : -1;
  323. }
  324. }
  325. }
  326. async getStageBillsData(tid, sid, fields) {
  327. try {
  328. await this.ctx.service.tender.checkTender(tid);
  329. if (sid) {
  330. await this.ctx.service.stage.checkStage(sid);
  331. }
  332. const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
  333. if (this._checkFieldsExist(fields, billsFields.stageDgn)) {
  334. const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(this.ctx.tender.id);
  335. for (const d of dgnData) {
  336. const l = this.ctx.helper._.find(billsData, {id: d.id});
  337. this.ctx.helper._.assignIn(l, d);
  338. }
  339. }
  340. if (this._checkFieldsExist(fields, billsFields.stage)) {
  341. if (this.ctx.stage.readOnly) {
  342. const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
  343. this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
  344. this.ctx.helper.assignRelaData(billsData, [
  345. {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'}
  346. ]);
  347. } else {
  348. const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
  349. this.ctx.helper.assignRelaData(billsData, [
  350. {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'}
  351. ]);
  352. }
  353. }
  354. if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
  355. const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
  356. this.ctx.helper.assignRelaData(billsData, [
  357. {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
  358. ]);
  359. }
  360. const billsTree = this._getNewBillsTree();
  361. billsTree.loadDatas(billsData);
  362. billsTree.calculateAll();
  363. if (this._checkFieldsExist(fields, billsFields.bgl)) {
  364. await this._calcBillsBgl(billsTree);
  365. }
  366. if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
  367. this._calcLeafXmjRela(billsTree);
  368. }
  369. return billsTree.getDatas([
  370. 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
  371. 'code', 'b_code', 'name', 'unit', 'unit_price',
  372. 'deal_qty', 'deal_tp',
  373. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  374. 'dgn_qty1', 'dgn_qty2',
  375. 'drawing_code', 'memo', 'node_type', 'is_tp',
  376. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
  377. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  378. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  379. 'final_tp', 'final_ratio',
  380. 'qc_bgl_code',
  381. 'chapter',
  382. 'leaf_xmj_id',
  383. 'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'contract_expr',
  384. 'deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2',
  385. ]);
  386. } catch(err) {
  387. return []
  388. }
  389. }
  390. async _calcPosBgl() {
  391. if (!this.ctx.stage) return;
  392. const helper = this.ctx.helper;
  393. const tender = this.ctx.tender;
  394. const stage = this.ctx.stage;
  395. const bglData = this.ctx.stage.readOnly
  396. ? await this.ctx.service.stageChange.getAuditorAllStageData(tender.id, stage.id, stage.curTimes, stage.curOrder)
  397. : await this.ctx.service.stageChange.getLastestAllStageData(tender.id, stage.id);
  398. for (const p of this.pos.datas) {
  399. p.qc_bgl_code = '';
  400. const pBgl = helper._.filter(bglData, {lid: p.lid, pid: p.id});
  401. if (pBgl.length === 0) continue;
  402. helper._.pullAll(bglData, pBgl);
  403. const validBgl = helper._.filter(pBgl, function (x) {
  404. return !helper.checkZero(x.qty);
  405. });
  406. p.qc_bgl_code = helper._.uniq(helper._.map(validBgl, 'c_code')).join(';');
  407. }
  408. }
  409. async getStagePosData(tid, sid, fields) {
  410. try {
  411. await this.ctx.service.tender.checkTender(tid);
  412. if (sid) {
  413. await this.ctx.service.stage.checkStage(sid);
  414. }
  415. const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
  416. if (this._checkFieldsExist(fields, posFields.stage)) {
  417. if (this.ctx.stage.readOnly) {
  418. const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
  419. this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
  420. this.ctx.helper.assignRelaData(posData, [
  421. {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
  422. ]);
  423. } else {
  424. const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
  425. this.ctx.helper.assignRelaData(posData, [
  426. {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
  427. ]);
  428. }
  429. }
  430. if (this._checkFieldsExist(fields, posFields.stageEnd)) {
  431. const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
  432. this.ctx.helper.assignRelaData(posData, [
  433. {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
  434. ]);
  435. }
  436. this.pos.loadDatas(posData);
  437. this.pos.calculateAll();
  438. if (this._checkFieldsExist(fields, posFields.bgl)) {
  439. await this._calcPosBgl();
  440. }
  441. return this.pos.getDatas();
  442. } catch (err) {
  443. return [];
  444. }
  445. }
  446. _getStageValidRole () {
  447. if (!this.ctx.stage) throw '期数据错误,请重试';
  448. if (this.stageValidRole && this.stageValidRole.length > 0) return;
  449. const result = [{dataOrder: 0, flowOrder: 0, uid: this.ctx.stage.user_id}];
  450. for (const auditor of this.ctx.stage.auditors) {
  451. if (auditor.status === audit.stage.status.checked ||
  452. (auditor.status === audit.stage.status.checking && !this.ctx.stage.readOnly)) {
  453. const role = result.find(function (r) {
  454. return r.uid === auditor.aid;
  455. });
  456. if (role) {
  457. role.dataOrder = auditor.order;
  458. } else {
  459. result.push({
  460. dataOrder: auditor.order,
  461. flowOrder: result.length,
  462. uid: auditor.aid
  463. })
  464. }
  465. }
  466. }
  467. this.stageValidRole = result;
  468. };
  469. async getStageBillsCompareData(tid, sid, fields) {
  470. try {
  471. await this.ctx.service.tender.checkTender(tid);
  472. await this.ctx.service.stage.checkStage(sid);
  473. await this._getStageValidRole();
  474. const stage = this.ctx.stage, helper = this.ctx.helper;
  475. const validRole = this.stageValidRole;
  476. const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
  477. const allStageBills = await this.ctx.service.stageBills.getAllDataByCondition({where: {sid: sid}});
  478. const stageBillsIndex = {}, timesLen = 100;
  479. for (const role of validRole) {
  480. const stageBills = this.ctx.helper._.filter(allStageBills, function (x) {
  481. return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
  482. });
  483. this.ctx.helper._.pullAll(allStageBills, stageBills);
  484. for (const sb of stageBills) {
  485. const key = 'sb-' + sb.lid;
  486. const sbi = stageBillsIndex[key];
  487. if (sbi) {
  488. if ((sbi.times * timesLen + sbi.order) < (sb.times * timesLen + sb.order)) stageBillsIndex[key] = sb;
  489. } else {
  490. stageBillsIndex[key] = sb;
  491. }
  492. }
  493. const filterStageBills = [];
  494. for (const prop in stageBillsIndex) {
  495. filterStageBills.push(stageBillsIndex[prop]);
  496. }
  497. this.ctx.helper.assignRelaData(billsData, [
  498. {data: filterStageBills, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'r' + role.flowOrder + '_', relaId: 'lid'}
  499. ]);
  500. }
  501. if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
  502. const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
  503. this.ctx.helper.assignRelaData(billsData, [
  504. {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
  505. ]);
  506. }
  507. const billsTree = this._getNewBillsTree();
  508. billsTree.loadDatas(billsData);
  509. for (const role of validRole) {
  510. const prefix = 'r' + role.flowOrder + '_';
  511. billsTree.setting.calcFields.push(prefix + 'contract_tp', prefix + 'qc_tp', prefix + 'gather_tp');
  512. }
  513. billsTree.calculateAll(function(node) {
  514. let prefix = '';
  515. if (node.children && node.children.length === 0) {
  516. node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
  517. for (const role of validRole) {
  518. prefix = 'r' + role.flowOrder + '_';
  519. node[prefix + 'gather_qty'] = helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
  520. }
  521. }
  522. node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
  523. for (const role of validRole) {
  524. prefix = 'r' + role.flowOrder + '_';
  525. node[prefix + 'gather_tp'] = helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
  526. }
  527. });
  528. if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
  529. this._calcLeafXmjRela(billsTree);
  530. }
  531. return billsTree.getDefaultDatas();
  532. // return billsTree.getDatas([
  533. // 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', //8
  534. // 'code', 'b_code', 'name', 'unit', 'unit_price', //5
  535. // 'deal_qty', 'deal_tp', 'quantity', 'total_price', 'dgn_qty1', 'dgn_qty2', //6
  536. // 'drawing_code', 'memo', 'node_type', 'is_tp', //4
  537. // 'r0_contract_qty', 'r0_contract_tp', 'r0_qc_qty', 'r0_qc_tp', 'r0_gather_qty', 'r0_gather_tp', //6
  538. // 'r1_contract_qty', 'r1_contract_tp', 'r1_qc_qty', 'r1_qc_tp', 'r1_gather_qty', 'r1_gather_tp',
  539. // 'r2_contract_qty', 'r2_contract_tp', 'r2_qc_qty', 'r2_qc_tp', 'r2_gather_qty', 'r2_gather_tp',
  540. // 'r3_contract_qty', 'r3_contract_tp', 'r3_qc_qty', 'r3_qc_tp', 'r3_gather_qty', 'r3_gather_tp',
  541. // 'r4_contract_qty', 'r4_contract_tp', 'r4_qc_qty', 'r4_qc_tp', 'r4_gather_qty', 'r4_gather_tp',
  542. // 'r5_contract_qty', 'r5_contract_tp', 'r5_qc_qty', 'r5_qc_tp', 'r5_gather_qty', 'r5_gather_tp',
  543. // 'r6_contract_qty', 'r6_contract_tp', 'r6_qc_qty', 'r6_qc_tp', 'r6_gather_qty', 'r6_gather_tp',
  544. // 'r7_contract_qty', 'r7_contract_tp', 'r7_qc_qty', 'r7_qc_tp', 'r7_gather_qty', 'r7_gather_tp',
  545. // 'r8_contract_qty', 'r8_contract_tp', 'r8_qc_qty', 'r8_qc_tp', 'r8_gather_qty', 'r8_gather_tp',
  546. // 'r9_contract_qty', 'r9_contract_tp', 'r9_qc_qty', 'r9_qc_tp', 'r9_gather_qty', 'r9_gather_tp',
  547. // 'r10_contract_qty', 'r10_contract_tp', 'r10_qc_qty', 'r10_qc_tp', 'r10_gather_qty', 'r10_gather_tp',
  548. // 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  549. // 'chapter', //1
  550. // ]);
  551. } catch (err) {
  552. return [];
  553. }
  554. }
  555. async getStagePosCompareData(tid, sid, fields) {
  556. try {
  557. await this.ctx.service.tender.checkTender(tid);
  558. await this.ctx.service.stage.checkStage(sid);
  559. await this._getStageValidRole();
  560. const stage = this.ctx.stage, helper = this.ctx.helper;
  561. const validRole = this.stageValidRole;
  562. const allStagePos = await this.ctx.service.stagePos.getAllDataByCondition({where: {sid: sid}});
  563. const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
  564. const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
  565. this.ctx.helper.assignRelaData(posData, [
  566. {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
  567. ]);
  568. const stagePosIndex = {}, timesLen = 100;
  569. for (const role of validRole) {
  570. const stagePos = this.ctx.helper._.filter(allStagePos, function (x) {
  571. return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
  572. });
  573. this.ctx.helper._.pullAll(allStagePos, stagePos);
  574. for (const sp of stagePos) {
  575. const key = 'sp-' + sp.pid;
  576. const spi = stagePosIndex[key];
  577. if (spi) {
  578. if ((spi.times * timesLen + spi.order) < (sp.times * timesLen + sp.order)) stagePosIndex[key] = sp;
  579. } else {
  580. stagePosIndex[key] = sp;
  581. }
  582. }
  583. const filterStagePos = [];
  584. for (const prop in stagePosIndex) {
  585. filterStagePos.push(stagePosIndex[prop]);
  586. }
  587. this.ctx.helper.assignRelaData(posData, [
  588. {data: filterStagePos, fields: ['contract_qty', 'qc_qty'], prefix: 'r' + role.flowOrder + '_', relaId: 'pid'}
  589. ]);
  590. }
  591. this.pos.loadDatas(posData);
  592. this.pos.calculateAll(function (p) {
  593. p.pre_gather_qty = helper.add(p.pre_contract_qty, p.pre_qc_qty);
  594. for (const role of validRole) {
  595. const prefix = 'r' + role.flowOrder + '_';
  596. p[prefix + 'gather_qty'] = helper.add(p[prefix + 'contract_qty'], p[prefix + 'qc_qty']);
  597. }
  598. });
  599. return this.pos.getDatas();
  600. } catch (err) {
  601. return [];
  602. }
  603. }
  604. async getStagePayData(tid, sid, fields) {
  605. try {
  606. await this.ctx.service.tender.checkTender(tid);
  607. await this.ctx.service.stage.checkStage(sid);
  608. const stage = this.ctx.stage;
  609. const dealPay = await this.ctx.service.stagePay.getStagePays(this.ctx.stage);
  610. if (!this.ctx.stage.readOnly) {
  611. // 计算 本期金额
  612. const PayCalculator = require('../lib/pay_calc');
  613. const payCalculator = new PayCalculator(this.ctx, this.ctx.stage, this.ctx.tender.info);
  614. await payCalculator.calculateAll(dealPay);
  615. }
  616. if (this._checkFieldsExist(fields, ['start_stage_order']) && this.ctx.stage.status !== audit.stage.status.checked) {
  617. for (const dp of dealPay) {
  618. if (!dp.start_stage_order || dp.start_stage_order === this.ctx.stage.order) {
  619. dp.start_stage_order = this.ctx.helper.checkZero(dp.tp) ? null : this.ctx.stage.order;
  620. }
  621. }
  622. }
  623. if (this._checkFieldsExistReg(fields, 'r[0-9]+_tp')) {
  624. this._getStageValidRole();
  625. const allStagePays = await this.ctx.service.stagePay.getAllDataByCondition({
  626. where: {sid: stage.id, stimes: stage.curTimes}
  627. });
  628. for (const [i, role] of this.stageValidRole.entries()) {
  629. if (i < this.stageValidRole.length - 1) {
  630. const stagePays = this.ctx.helper._.filter(allStagePays, function (x) {
  631. return x.stimes === stage.curTimes && x.sorder === role.dataOrder;
  632. });
  633. this.ctx.helper._.pullAll(allStagePays, stagePays);
  634. for (const sp of stagePays) {
  635. const dp = dealPay.find(function (x) {return x.pid === sp.pid});
  636. if (dp) {
  637. dp['r' + role.flowOrder + '_tp'] = sp.tp;
  638. }
  639. }
  640. } else {
  641. for (const dp of dealPay) {
  642. dp['r' + role.flowOrder + '_tp'] = dp.tp;
  643. }
  644. }
  645. }
  646. }
  647. return dealPay;
  648. } catch (err) {
  649. return [];
  650. }
  651. }
  652. _getChangeConstName(define, value) {
  653. for (const prop in define) {
  654. if (define[prop].value === value) {
  655. return define[prop].name;
  656. }
  657. }
  658. return '';
  659. }
  660. async _generateChange(tid) {
  661. if (this.changeData !== null) return;
  662. const self = this;
  663. try {
  664. const decimal = this.ctx.tender.info.decimal, ctx = this.ctx;
  665. const change = await this.ctx.service.change.getAllCheckedChanges(tid);
  666. for (const c of change) {
  667. const types = ctx.helper._.map(c.type.split(','), function (t) {
  668. return self._getChangeConstName(changeConst.type, ctx.helper._.toInteger(t));
  669. });
  670. c.type = types.join(';');
  671. c.class = this._getChangeConstName(changeConst.class, c.class);
  672. c.quality = this._getChangeConstName(changeConst.quality, c.quality);
  673. c.charge = this._getChangeConstName(changeConst.charge, c.charge);
  674. c.attachments = await ctx.service.changeAtt.getChangeAttachment(c.cid);
  675. const names = ctx.helper._.map(c.attachments, function (x) {
  676. return x.filename + x.fileext;
  677. });
  678. c.attNames = names.join('\n');
  679. }
  680. const changeBills = await this.ctx.service.changeAuditList.getChangeAuditBills(tid);
  681. for (const d of changeBills) {
  682. d.o_qty = d.oamount;
  683. d.o_tp = this.ctx.helper.mul(d.o_qty, d.unit_price, decimal.tp);
  684. d.c_qty = d.camount;
  685. d.c_tp = this.ctx.helper.mul(d.c_qty, d.unit_price, decimal.tp);
  686. d.s_qty = d.samount ? parseFloat(d.samount) : 0;
  687. d.s_tp = this.ctx.helper.mul(d.s_qty, d.unit_price, decimal.tp);
  688. const auditAmount = d.audit_amount.split(',');
  689. const relaChange = ctx.helper._.find(change, {cid: d.cid});
  690. for (const [i, aa] of auditAmount.entries()) {
  691. const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
  692. d[amountField] = aa ? parseFloat(aa) : 0;
  693. d[tpField] = ctx.helper.mul(d[amountField], d.unit_price, decimal.tp);
  694. if (relaChange) {
  695. relaChange[tpField] = ctx.helper.add(relaChange[tpField], d[tpField]);
  696. }
  697. }
  698. }
  699. change.sort(function (a, b) {
  700. return a.code.localeCompare(b.code);
  701. });
  702. changeBills.sort(function (a, b) {
  703. const aCIndex = change.findIndex(function (c) {
  704. return c.cid === a.cid;
  705. });
  706. const bCIndex = change.findIndex(function (c) {
  707. return c.cid === b.cid;
  708. });
  709. return aCIndex === bCIndex
  710. ? ctx.helper.compareCode(a.code, b.code)
  711. : aCIndex - bCIndex;
  712. });
  713. this.changeData = {change: change, bills: changeBills};
  714. } catch(err) {
  715. this.ctx.helper.log(err);
  716. throw err;
  717. this.changeData = {change: [], bills: []};
  718. }
  719. }
  720. async getChangeData(tid, sid, fields) {
  721. try {
  722. await this.ctx.service.tender.checkTender(tid);
  723. await this._generateChange(tid);
  724. return this.changeData.change;
  725. } catch (err) {
  726. return [];
  727. }
  728. }
  729. async getChangeBillsData(tid, sid, fields) {
  730. try {
  731. await this.ctx.service.tender.checkTender(tid);
  732. await this._generateChange(tid);
  733. return this.changeData.bills;
  734. } catch (err) {
  735. return [];
  736. }
  737. }
  738. async getStageJgcl(tid, sid, fields) {
  739. try {
  740. await this.ctx.service.tender.checkTender(tid);
  741. await this.ctx.service.stage.checkStage(sid);
  742. const data = await this.ctx.service.stageJgcl.getStageData(this.ctx.stage);
  743. const preData = await this.ctx.service.stageJgcl.getPreStageData(this.ctx.stage.order);
  744. for (const d of data) {
  745. const pd = this.ctx.helper._.find(preData, {uuid: d.uuid});
  746. if (pd) {
  747. d.pre_arrive_qty = pd.arrive_qty;
  748. d.pre_arrive_tp = pd.arrive_tp;
  749. d.pre_deduct_qty = pd.deduct_qty;
  750. d.pre_deduct_tp = pd.deduct_tp;
  751. }
  752. }
  753. return data;
  754. } catch (err) {
  755. return [];
  756. }
  757. }
  758. async getStageBonus(tid, sid, fields) {
  759. try {
  760. await this.ctx.service.tender.checkTender(tid);
  761. await this.ctx.service.stage.checkStage(sid);
  762. const data = await this.ctx.service.stageBonus.getEndStageData(this.ctx.stage.order);
  763. return data;
  764. } catch (err) {
  765. return [];
  766. }
  767. }
  768. async getStageOther(tid, sid, fields) {
  769. try {
  770. await this.ctx.service.tender.checkTender(tid);
  771. await this.ctx.service.stage.checkStage(sid);
  772. const data = await this.ctx.service.stageOther.getStageData(this.ctx.stage);
  773. const preData = await this.ctx.service.stageOther.getPreStageData(this.ctx.stage.order);
  774. for (const d of data) {
  775. const pd = this.ctx.helper._.find(preData, {uuid: d.uuid});
  776. if (pd) {
  777. d.pre_tp = pd.tp;
  778. }
  779. }
  780. return data;
  781. } catch (err) {
  782. return [];
  783. }
  784. }
  785. async getMaterial(tender_id, material_order, memFieldKeys) {
  786. return await this.ctx.service.material.getValidMaterials(tender_id);
  787. }
  788. _completeMaterialGl(materialGl) {
  789. const tTypeStr = [], mTypeStr = [];
  790. for (const t of materialConst.t_type) {
  791. tTypeStr[t.value] = t.text;
  792. }
  793. for (const m of materialConst.m_type) {
  794. mTypeStr[m.value] = m.text;
  795. }
  796. for (const gl of materialGl) {
  797. gl.tp = this.ctx.helper.mul(gl.quantity, gl.m_spread, 2);
  798. gl.t_type_str = tTypeStr[gl.t_type];
  799. gl.m_type_str = mTypeStr[gl.m_type];
  800. gl.end_tp = this.ctx.helper.add(gl.tp, gl.pre_tp);
  801. }
  802. }
  803. async getMaterialGl(tender_id, material_order, memFieldKeys) {
  804. const materials = await this.ctx.service.material.getAllDataByCondition({
  805. where: {tid: tender_id},
  806. orders: [['order', 'desc']],
  807. });
  808. if (materials.length > 0) {
  809. let result;
  810. if (materials[0].order === material_order) {
  811. result = await this.ctx.service.materialBills.getAllDataByCondition({
  812. where: {tid: tender_id}
  813. });
  814. } else {
  815. const material = this.ctx.helper._.find(materials, {order: material_order});
  816. if (!material) return [];
  817. const sql = 'SELECT m.id, m.tid, m.mid, m.t_type, m.code, m.name, m.unit, m.spec, m.m_type,' +
  818. ' m.basic_price, m.basic_times, m.remark, m.in_time,' +
  819. ' mh.quantity, mh.expr, mh.msg_tp, mh.msg_times, mh.msg_spread, mh.m_up_risk, mh.m_down_risk, mh.m_spread' +
  820. ' FROM ' + this.ctx.service.materialBills.tableName + ' m' +
  821. ' LEFT JOIN ' + this.ctx.service.materialBillsHistory.tableName + ' mh' +
  822. ' ON m.id = mh.mb_id' +
  823. ' WHERE mh.mid = ?';
  824. const sqlParam = [material.id];
  825. result = await this.ctx.app.mysql.query(sql, sqlParam);
  826. }
  827. this._completeMaterialGl(result);
  828. return result;
  829. } else {
  830. return [];
  831. }
  832. }
  833. async getSumStageBillsData(tid, sid, fields) {
  834. try {
  835. await this.ctx.service.tender.checkTender(tid);
  836. const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
  837. const checkStageField = function (stageOrder) {
  838. for (const f of fields) {
  839. if (f.indexOf('s' + stageOrder + '_') >= 0) {
  840. return true;
  841. }
  842. }
  843. return false;
  844. };
  845. const calcFields = ['deal_tp', 'total_price'], calcPrefix = [];
  846. const stages = this.ctx.service.stage.getValidStages(this.ctx.tender.id);
  847. for (const stage of stages) {
  848. if (!checkStageField(stage.order)) return;
  849. await this.ctx.service.stage.doCheckStage(stage);
  850. calcFields.push('s' + stage.order + '_contract_tp');
  851. calcFields.push('s' + stage.order + '_qc_tp');
  852. calcFields.push('s' + stage.order + '_gather_tp');
  853. calcFields.push('s' + stage.order + '_');
  854. const curStage = stage.readOnly
  855. ? await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id, stage.id, stage.curTimes, stage.curOrder)
  856. : await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, stage.id);
  857. this.ctx.helper.assignRelaData(billsData, [
  858. {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp'], prefix: 's' + stage.order + '_', relaId: 'lid'}
  859. ]);
  860. }
  861. const billsTree = new Ledger.billsTree(this.ctx, {
  862. id: 'ledger_id',
  863. pid: 'ledger_pid',
  864. order: 'order',
  865. level: 'level',
  866. rootId: -1,
  867. keys: ['id', 'tender_id', 'ledger_id'],
  868. stageId: 'id',
  869. calcFields: calcFields,
  870. calc: function (node) {
  871. for (const prefix of calcPrefix) {
  872. if (node.children && node.children.length === 0) {
  873. node[prefix + 'gather_qty'] = self.ctx.helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
  874. }
  875. node[prefix + 'gather_tp'] = self.ctx.helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
  876. }
  877. }
  878. });
  879. billsTree.loadDatas(billsData);
  880. billsTree.calculateAll();
  881. return billsTree.getDefaultDatas();
  882. } catch (err) {
  883. return [];
  884. }
  885. }
  886. async getStageAuditors(tid, sid) {
  887. await this.ctx.service.tender.checkTender(tid);
  888. await this.ctx.service.stage.checkStage(sid);
  889. const auditors = await this.ctx.service.stageAudit.getFinalAuditGroup(this.ctx.stage.id, this.ctx.stage.curTimes);
  890. const user = await this.ctx.service.projectAccount.getDataById(this.ctx.stage.user_id);
  891. const result = [{
  892. aid: user.id,
  893. name: user.name,
  894. company: user.company,
  895. role: user.role,
  896. mobile: user.mobile,
  897. telephone: user.telephone,
  898. sign_path: user.sign_path,
  899. opinion: user.opinion,
  900. end_time: auditors && auditors.length > 0 ? auditors[0].begin_time : null,
  901. sort: 0,
  902. }, ...auditors];
  903. return result;
  904. }
  905. async getSignSelect(tid, sid, customSelect) {
  906. await this.ctx.service.tender.checkTender(tid);
  907. await this.ctx.service.stage.checkStage(sid);
  908. const signSelect = customSelect.sign_select, result = {};
  909. for (const [i, ss] of signSelect.entries()) {
  910. const user = await this.ctx.service.projectAccount.getDataById(ss.id);
  911. const sign = {
  912. id: ss.id, name: user.name, company: user.company, role: user.role,
  913. mobile: user.mobile, telephone: user.telephone,
  914. };
  915. if (ss.id !== this.ctx.stage.user_id) {
  916. const audit = this.ctx.stage.auditors.find(x => {return x.aid === ss.id});
  917. user.end_time = audit ? audit.end_time : ss.audit_time;
  918. } else {
  919. user.end_time = this.ctx.stage.auditors[0].end_time;
  920. }
  921. if (user.end_time) sign.sign_path = user.sign_path;
  922. result['sign' + (i+1)] = sign;
  923. }
  924. return result;
  925. }
  926. }
  927. return ReportMemory;
  928. };