rpt_data_analysis.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const math = require('mathjs');
  10. const standard = require('../const/standard');
  11. const moment = require('moment');
  12. moment.locale('zh-cn');
  13. class PosIndex {
  14. /**
  15. * 构造函数
  16. * @param {id|String, masterId|String, order|String} setting
  17. */
  18. constructor (setting) {
  19. // 无索引
  20. this.datas = [];
  21. // 以key为索引
  22. this.items = {};
  23. // 以分类id为索引的有序
  24. this.ledgerPos = {};
  25. // pos设置
  26. this.setting = setting;
  27. }
  28. /**
  29. * 加载部位明细数据
  30. * @param datas
  31. */
  32. loadDatas(datas) {
  33. this.datas = datas;
  34. this.items = {};
  35. this.ledgerPos = {};
  36. for (const data of this.datas) {
  37. const key = data[this.setting.id];
  38. this.items[key] = data;
  39. const masterKey = data[this.setting.masterId];
  40. if (!this.ledgerPos[masterKey]) {
  41. this.ledgerPos[masterKey] = [];
  42. }
  43. this.ledgerPos[masterKey].push(data);
  44. }
  45. for (const prop in this.ledgerPos) {
  46. this.resortLedgerPos(this.ledgerPos[prop]);
  47. }
  48. }
  49. getLedgerPos(mid) {
  50. return this.ledgerPos[mid];
  51. }
  52. resortLedgerPos(ledgerPos) {
  53. const self = this;
  54. if (ledgerPos instanceof Array) {
  55. ledgerPos.sort(function (a, b) {
  56. return a[self.setting.order] - b[self.setting.order];
  57. })
  58. }
  59. }
  60. }
  61. // 通用方法
  62. const rdaUtils = {
  63. orderCalc: function (ctx, data, fields) {
  64. const orderMatch = new RegExp('o[0-9]+', 'igm');
  65. for (const c of data) {
  66. if (c.order_calc && c.order_calc !== '') {
  67. const matchs = c.order_calc.match(orderMatch);
  68. const calcMatch = [];
  69. for (const m of matchs) {
  70. const order = m.substring(1, m.length);
  71. const orderData = data.find(function (x) {return (x.order + '') === order});
  72. if (orderData) {
  73. calcMatch.push({match: m, value: orderData})
  74. }
  75. }
  76. for (const f of fields) {
  77. let expr = c.order_calc;
  78. for (const m of calcMatch) {
  79. expr = expr.replace(m.match, m.value[f] ? m.value[f] : 0);
  80. }
  81. try {
  82. c[f] = ctx.helper.round(math.eval(expr), 6);
  83. } catch(err) {
  84. }
  85. }
  86. }
  87. }
  88. }
  89. };
  90. // 可提供的数据处理方法
  91. const changeSort = {
  92. name: '变更令排序',
  93. hint: '默认的变更令排序,同时对变更令,变更清单进行排序\n' +
  94. '变更令排序勿需勾选任何预定义处理指标,但是在指标映射中,需要添加如下指标:' +
  95. '1. 如果只有变更令数据,则必须添加,"变更令(change)"下的"变更令号"' +
  96. '2. 如果有变更清单需要排序,则必须在1的基础上添加,变更令(change)"下的"变更令uuid"和"变更清单(chang_audit_list)"下的"所属变更令uuid"&"清单编号"',
  97. intro: '报表对于主从表的排序有要求,解决变更令数据中的变更令、变更清单排序问题',
  98. /**
  99. *
  100. * @param ctx - context常量
  101. * @param data - 全部数据源{Array}
  102. * @param fieldsKey - 计算字段
  103. * @param options - 计算设置
  104. */
  105. fun: function(ctx, data, fieldsKey, options) {
  106. const change = options && options.change ? data[options.change] : data.change;
  107. if (!change) return;
  108. // 变更令排序
  109. change.sort(function (a, b) {
  110. return a.code.localeCompare(b.code);
  111. });
  112. const changeBills = options && options.changeBills ? data[options.changeBills] : data.change_audit_list;
  113. if (changeBills) {
  114. changeBills.sort(function (a, b) {
  115. const aCIndex = data.change.findIndex(function (c) {
  116. return c.cid === a.cid;
  117. });
  118. const bCIndex = data.change.findIndex(function (c) {
  119. return c.cid === b.cid;
  120. });
  121. return aCIndex === bCIndex
  122. ? ctx.helper.compareCode(a.code, b.code)
  123. : aCIndex - bCIndex;
  124. });
  125. }
  126. },
  127. };
  128. const gatherGcl = {
  129. name: '汇总工程量清单',
  130. hint: '请使用mem_stage_bills下指标,注意事项:\n' +
  131. '1. 以下字段,不管报表是否实际使用,均应添加至指标映射,且在此处应勾选(不要求顺序):\n' +
  132. ' 清单编号(b_code), 名称(name), 单位(unit), 单价(unit_price), 树结构-是否子项(is_leaf)\n' +
  133. '2. 汇总后,以下字段,均会失效, 请勿使用:\n' +
  134. ' 台账ID(id), 树结构-ID(ledger_id), 树结构父项-ID(ledger_pid),\n' +
  135. ' 树结构-层级(level), 树结构-同层排序(order), 树结构-完整路径(full_path),\n' +
  136. ' 图册号(drawing_code), 备注(memo), 节点类型(node_type), 总额计量(is_tp)\n' +
  137. '3. 如需汇总"未计入清单章节项",请勾选"章节编号(chapter)"字段\n',
  138. intro: '根据三级清单树结构,汇总平面工程量清单,目前仅支持mem_stage_bills表',
  139. fun: function (ctx, data, fieldsKey, options) {
  140. const gatherFields = function(gcl, data, fields) {
  141. for (const f of fields) {
  142. if (data[f]) {
  143. gcl[f] = ctx.helper.add(gcl[f], data[f]);
  144. }
  145. }
  146. };
  147. if (!data.mem_stage_bills) return;
  148. const fields = ctx.helper._.map(fieldsKey, 'field');
  149. const needFields = ['b_code', 'name', 'unit', 'unit_price', 'is_leaf'];
  150. for (const nf of needFields) {
  151. if (fields.indexOf(nf) === -1) return;
  152. }
  153. const gatherOther = fields.indexOf('chapter') >= 0;
  154. const gclBills = [], other = {name: '未计入清单章节项', chapter: '10000'};
  155. for (const b of data.mem_stage_bills) {
  156. const child = ctx.helper._.find(data.mem_stage_bills, {ledger_pid: b.ledger_id});
  157. if (child) continue;
  158. if (b.b_code && b.b_code !== '') {
  159. let gcl = gclBills.find(function (g) {
  160. return g.b_code === b.b_code && g.name === b.name && g.unit === b.unit
  161. && ctx.helper.checkZero(ctx.helper.sub(g.unit_price, b.unit_price));
  162. });
  163. if (!gcl) {
  164. gcl = {
  165. b_code: b.b_code, name: b.name, unit: b.unit,
  166. unit_price: b.unit_price,
  167. qc_bgl_code: [], chapter: b.chapter,
  168. deal_bills_qty: b.deal_bills_qty, deal_bills_tp: b.deal_bills_tp,
  169. };
  170. gclBills.push(gcl);
  171. }
  172. gatherFields(gcl, b, [
  173. 'deal_qty', 'deal_tp',
  174. 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
  175. 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp',
  176. 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
  177. 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
  178. 'final_tp'
  179. ]);
  180. if (b.qc_bgl_code && b.qc_bgl_code !== '') {
  181. gcl.qc_bgl_code = gcl.qc_bgl_code.concat(b.qc_bgl_code.split(';'));
  182. }
  183. } else if (gatherOther) {
  184. gatherFields(other, b, [
  185. 'deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price',
  186. 'contract_tp', 'qc_tp', 'gather_tp',
  187. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp',
  188. 'end_contract_tp', 'end_qc_tp', 'end_gather_tp',
  189. 'final_tp'
  190. ]);
  191. }
  192. }
  193. if (gatherOther) gclBills.push(other);
  194. for (const g of gclBills) {
  195. if (g.qc_bgl_code) g.qc_bgl_code = g.qc_bgl_code.join(';');
  196. g.final_ratio = ctx.helper.mul(ctx.helper.div(g.end_gather_tp, g.final_ratio), 100);
  197. }
  198. data.mem_stage_bills = gclBills;
  199. }
  200. };
  201. const sortGcl = {
  202. name: '工程量清单排序',
  203. hint: '只对一张表,进行工程量清单排序,排序哪张表,根据勾选的清单编号字段决定:\n' +
  204. 'e.g.1 要对mem_stage_bills排序,需要勾选mem_stage_bills下的"清单编号(b_code)"字段\n' +
  205. 'e.g.2 要对mem_stage_im_zl排序,需要勾选mem_stage_im_zl下的"中间计量总量信息_编号(code)"字段\n' +
  206. '特别的,如有"未计入清单章节项": \n' +
  207. ' 1. 默认"未计入清单章节项"排列在最后\n' +
  208. ' 2. 如须"未计入清单章节项"排在100章之后,请在清单编号字段后,依次勾选"章节编号(chapter)", "名称(name)"\n',
  209. intro: '根据选择列,对数据进行工程量清单排序,兼容1000章后清单,以及403-1-a类的非纯数字编号排序',
  210. fun: function (ctx, data, fieldsKey, options) {
  211. if (fieldsKey.length !== 1 && fieldsKey.length !== 3) return;
  212. const code = fieldsKey[0].field;
  213. const chapter = fieldsKey.length > 1 ? fieldsKey[1].field : '';
  214. const name = fieldsKey.length > 2 ? fieldsKey[2].field : '';
  215. const sortData = data[fieldsKey[0].table];
  216. if (!sortData) return;
  217. sortData.sort(function (a, b) {
  218. if (chapter !== '') {
  219. if (a[name] === '未计入清单章节项') {
  220. return b[chapter] === '100' ? 1 : -1;
  221. } else if (b[name] === '未计入清单章节项') {
  222. return a[chapter] === '100' ? -1 : 1
  223. } else {
  224. return ctx.helper.compareCode(a[code], b[code]);
  225. }
  226. } else {
  227. return ctx.helper.compareCode(a[code], b[code]);
  228. }
  229. });
  230. }
  231. };
  232. const gatherChapter = {
  233. name: '汇总章级数据',
  234. hint: '请使用mem_stage_bills/mem_stage_bills_compare/ledger,仅对一张表进行汇总,并生成数据:\n'+
  235. '1. 因为是汇总章级数据,必须在离散数据中添加"章节代码"&"章节名称"\n' +
  236. '2. 需勾选"清单编号(b_code)", "树结构-是否子项(is_leaf)"字段,可以对任何含有这些字段的表汇总\n' +
  237. '注意事项:\n' +
  238. '1. 算法对数据表没有要求,保证有上述字段,且按顺序勾选即可, 仅汇总金额\n' +
  239. '2. 算法计算后,原数据表中非数字类型的字段全部失效(除清单编号、名称外),请勿在指标映射中添加\n' +
  240. '示例:\n' +
  241. 'e.g.1 要对mem_stage_bills汇总,须勾选mem_stage_bills下的"清单编号(b_code)", "树结构-是否子项((is_leaf)"字段\n' +
  242. 'e.g.2 要对mem_stage_bills_compare汇总,须勾选mem_stage_bills_compare下的"清单编号(b_code)", "树结构-是否子项((is_leaf)"字段\n' +
  243. '结果:\n' +
  244. '汇总结果可参照 清单汇总--章节合计,但是不过滤1000-1300章数据',
  245. intro: '用于得到类似“清单汇总--章级合计”的数据,可通过options自定义数据',
  246. defaultSetting: {
  247. count: 9,
  248. unChapter: {
  249. name: '未计入清单章节合计',
  250. order: 1,
  251. },
  252. gclSum: {
  253. name: '清单小计',
  254. order: 2,
  255. },
  256. unGcl: {
  257. name: '非清单项费用',
  258. order: 3,
  259. },
  260. sum: {
  261. name: '合计',
  262. order: 4,
  263. }
  264. },
  265. customSetting1: {
  266. count: 7,
  267. gclSum: {
  268. name: '第100章至700章清单合计',
  269. order: 1,
  270. },
  271. custom: [
  272. {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2, visible: false},
  273. {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  274. {name: '计日工合计', node_type: '计日工', order: 4},
  275. {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', order: 5, match: [{node_type: '暂列金额'}, {field: 'name', part: '暂列金额'}, {field: 'name', all: '暂定金额'}]},
  276. {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  277. ],
  278. rela: [
  279. {
  280. table: 'deal_bills', key: 'code',
  281. fields: {source: 'total_price', target: 'ex_value1'},
  282. },
  283. {
  284. table: 'mem_change_bills', key: 'code',
  285. fields: {source: '', target: 'ex_value2'},
  286. }
  287. ]
  288. },
  289. _getCalcChapter: function (chapter, options) {
  290. const gclChapter = [], otherChapter = [], customChapter = [];
  291. let serialNo = 1;
  292. for (const c of chapter) {
  293. const cc = { code: c.code, name: c.name, cType: 1 };
  294. cc.serialNo = serialNo++;
  295. cc.filter = '^' + c.code.substr(0, c.code.length - 2) + '[0-9]{2}-';
  296. //cc.visible = true;
  297. gclChapter.push(cc);
  298. if (options.activeFields) {
  299. cc.active = cc.serialNo > options.count;
  300. } else {
  301. if (serialNo > options.count) break;
  302. }
  303. }
  304. if (options.unChapter) {
  305. gclChapter.push({
  306. name: options.unChapter.name, cType: 21,
  307. serialNo: serialNo + options.unChapter.order, order: options.unChapter.order,
  308. visible: options.unChapter.visible,
  309. });
  310. }
  311. if (options.gclSum) {
  312. otherChapter.push({
  313. name: options.gclSum.name, cType: 11,
  314. serialNo: serialNo + options.gclSum.order, order: options.gclSum.order,
  315. visible: options.gclSum.visible,
  316. });
  317. }
  318. if (options.unGcl) {
  319. otherChapter.push({
  320. name: options.unGcl.name, cType: 31,
  321. serialNo: serialNo + options.unGcl.order, order: options.unGcl.order,
  322. visible: options.unGcl.visible,
  323. });
  324. }
  325. if (options.sum) {
  326. otherChapter.push({
  327. name: options.sum.name , cType: 41,
  328. serialNo: serialNo + options.sum.order, order: options.sum.order,
  329. visible: options.sum.visible,
  330. });
  331. }
  332. if (options.custom && options.custom instanceof Array) {
  333. for (const c of options.custom) {
  334. const cc = {
  335. name: c.name, serialNo: serialNo + c.order,
  336. order_calc: c.order_calc,
  337. cType: 5, order: c.order,
  338. visible: c.visible,
  339. };
  340. if (c.match) {
  341. cc.match = JSON.parse(JSON.stringify(c.match));
  342. for (const m of cc.match) {
  343. if (m.node_type && m.node_type !== '') {
  344. const nodeType = standard.nodeType.find(function (x) {return x.text === m.node_type});
  345. m.node_type = nodeType.value;
  346. }
  347. }
  348. }
  349. customChapter.push(cc);
  350. }
  351. }
  352. return [gclChapter, otherChapter, customChapter];
  353. },
  354. _getGclChapter: function (chapter, data, field) {
  355. for (const c of chapter) {
  356. if (c.filter) {
  357. const reg = new RegExp(c.filter);
  358. if (reg.test(data[field])) {
  359. return c;
  360. }
  361. } else {
  362. return c;
  363. }
  364. }
  365. },
  366. _checkFilter: function (fullPath, filter) {
  367. for (const f of filter) {
  368. if (fullPath.indexOf(f + '-') === 0 || fullPath === f) return true;
  369. }
  370. return false;
  371. },
  372. _gatherRela: function (ctx, data, rela, gclChapter, otherChapter) {
  373. if (!rela) return;
  374. const gatherRelaFields = function (chapter, source, field) {
  375. const fields = field instanceof Array ? field : [field];
  376. for (const f of fields) {
  377. chapter[f.target] = ctx.helper.add(chapter[f.target], source[f.source]);
  378. }
  379. };
  380. const relaBills = rela instanceof Array ? rela : [rela];
  381. for (const rb of relaBills) {
  382. if (!rb.table) continue;
  383. const relaData = data[rb.table];
  384. if (!relaData) continue;
  385. for (const rd of relaData) {
  386. for (const c of otherChapter) {
  387. if (c.cType === 41) {
  388. gatherRelaFields(c, rd, rb.fields);
  389. } else if (c.cType === 31 && (!rd[rb.key] || rd[rb.key] === '')) {
  390. gatherRelaFields(c, rd, rb.fields);
  391. } else if (c.cType === 11 && (rd[rb.key])) {
  392. gatherRelaFields(c, rd, rb.fields);
  393. }
  394. }
  395. if (rd[rb.key]) {
  396. const c = this._getGclChapter(gclChapter, rd, rb.key);
  397. gatherRelaFields(c, rd, rb.fields);
  398. }
  399. }
  400. }
  401. },
  402. _orderCalc: function (ctx, chapter, fields) {
  403. const orderMatch = new RegExp('o[0-9]+', 'igm');
  404. for (const c of chapter) {
  405. if (c.order_calc && c.order_calc !== '') {
  406. const matchs = c.order_calc.match(orderMatch);
  407. const calcMatch = [];
  408. for (const m of matchs) {
  409. const order = m.substring(1, m.length);
  410. const orderChapter = chapter.find(function (x) {return x.order == order});
  411. if (orderChapter) {
  412. calcMatch.push({match: m, value: orderChapter})
  413. }
  414. }
  415. for (const f of fields) {
  416. let expr = c.order_calc;
  417. for (const m of calcMatch) {
  418. expr = expr.replace(m.match, m.value[f] ? m.value[f] : 0);
  419. }
  420. try {
  421. c[f] = ctx.helper.round(math.eval(expr), 6);
  422. } catch(err) {
  423. }
  424. }
  425. }
  426. }
  427. },
  428. _checkMatch: function (match, d) {
  429. for (const m of match) {
  430. if (m.node_type) {
  431. if (m.node_type === d.node_type) return true;
  432. } else if (m.field) {
  433. const value = d[m.field];
  434. if (m.part && value) {
  435. if (value.indexOf(m.part) >= 0) return true;
  436. } else if (m.all && value) {
  437. if (m.all === value) return true;
  438. }
  439. }
  440. }
  441. return false;
  442. },
  443. fun: function (ctx, data, fieldsKey, options) {
  444. if (!data.tender_info || !data.tender_info.chapter) return;
  445. if (!fieldsKey && fieldsKey.length < 0) return;
  446. const calcFields = [];
  447. const gatherData = function (chapter, data) {
  448. if (!chapter) return;
  449. for (const f in data) {
  450. if (data[f] && (f.indexOf('tp') >= 0 || f === 'total_price')) {
  451. chapter[f] = ctx.helper.add(chapter[f], data[f]);
  452. if (calcFields.indexOf(f) === -1) calcFields.push(f);
  453. }
  454. }
  455. };
  456. const [gclChapter, otherChapter, customChapter] = this._getCalcChapter(data.tender_info.chapter, options ? options : this.defaultSetting);
  457. const fields = ctx.helper._.map(fieldsKey, 'field');
  458. const needFields = ['b_code', 'is_leaf'];
  459. for (const nf of needFields) {
  460. if (fields.indexOf(nf) === -1) return;
  461. }
  462. const sourceData = data[fieldsKey[0].table];
  463. if (!sourceData) return;
  464. const filter = [];
  465. for (const d of sourceData) {
  466. for (const c of customChapter) {
  467. if (c.match && this._checkMatch(c.match, d)) {
  468. gatherData(c, d);
  469. filter.push(d.full_path);
  470. }
  471. }
  472. if (!d.is_leaf || this._checkFilter(d.full_path, filter)) continue;
  473. for (const c of otherChapter) {
  474. if (c.cType === 41) {
  475. gatherData(c, d);
  476. } else if (c.cType === 31 && (!d.b_code || d.b_code === '')) {
  477. gatherData(c, d);
  478. } else if (c.cType === 11 && (d.b_code)) {
  479. gatherData(c, d);
  480. }
  481. }
  482. if (d.b_code) {
  483. const c = this._getGclChapter(gclChapter, d, 'b_code');
  484. if (c) {
  485. gatherData(c, d);
  486. }
  487. }
  488. }
  489. this._gatherRela(ctx, data, options.rela, gclChapter, otherChapter);
  490. const chapter = gclChapter.concat(otherChapter).concat(customChapter);
  491. this._orderCalc(ctx, chapter, calcFields);
  492. chapter.sort(function (a, b) {return a.serialNo - b.serialNo});
  493. data[fieldsKey[0].table] = chapter.filter(function (x) {
  494. if (x.active) {
  495. for (const f of options.activeFields) {
  496. if (!ctx.helper.checkZero(x[f])) return true;
  497. }
  498. return false;
  499. } else {
  500. return (x.visible !== undefined && x.visible !== null) ? x.visible : true;
  501. }
  502. });
  503. },
  504. };
  505. const join = {
  506. name: "连接两张数据表",
  507. hint: "用于处理类似于关联签约清单的情况,会改变主表的数据",
  508. intro: '用于处理类似于关联签约清单的情况,会根据关联表(sub)改变主表(main)的数据',
  509. defaultSetting: {
  510. main: 'mem_stage_bills',
  511. sub: 'deal_bills',
  512. keyFields: [
  513. {main: 'b_code', sub: 'code', type: 'string'},
  514. {main: 'name', sub: 'name',type: 'string'},
  515. {main: 'unit', sub: 'unit',type: 'string'},
  516. {main: 'unit_price', sub: 'unit_price',type: 'number'},
  517. ],
  518. importFields: [
  519. {main: 'ex_value1', sub: 'quantity', type: 'sum'},
  520. {main: 'ex_value2', sub: 'total_price', type: 'sum'}
  521. ],
  522. joinType: 'outer', //'outer', 'main', 'sub', 'inner',
  523. },
  524. fun: function (ctx, data, fields, options) {
  525. if (!options || !options.main || !options.sub || !options.keyFields || options.keyFields.length === 0) return;
  526. const main = data[options.main];
  527. const sub = data[options.sub];
  528. if (!main || !sub) return;
  529. const _ = ctx.helper._, result = _.cloneDeep(main);
  530. for (const r of result) {
  531. r._join_tag = 'main';
  532. for (const i of options.importFields) {
  533. r[i.main] = null;
  534. }
  535. }
  536. for (const s of sub) {
  537. let r = result.find(function (x) {
  538. for (const k of options.keyFields) {
  539. switch (k.type) {
  540. case 'string':
  541. if (x[k.main] !== s[k.sub] && (!_.isNil(x[k.main]) || !_.isNil(s[k.sub]))) return false;
  542. break;
  543. case 'number':
  544. if (!ctx.helper.checkZero(ctx.helper.sub(x[k.main] - s[k.sub]))) return false;
  545. break;
  546. }
  547. }
  548. return true;
  549. });
  550. if (r && r._join_tag === 'main') {
  551. r._join_tag = 'both';
  552. }
  553. if (!r) {
  554. r = {_join_tag: 'sub'};
  555. for (const k of options.keyFields) {
  556. r[k.main] = s[k.sub];
  557. }
  558. result.push(r);
  559. }
  560. for (const i of options.importFields) {
  561. //r[i.main] = s[i.sub];
  562. if (i.type === 'sum') {
  563. r[i.main] = ctx.helper.add(r[i.main], s[i.sub]);
  564. } else {
  565. r[i.main] = s[i.sub];
  566. }
  567. }
  568. }
  569. switch (options.joinType) {
  570. case 'main':
  571. data[options.main] = _.filter(result, function (r) {return ['main', 'both'].indexOf(r._join_tag) >= 0});
  572. break;
  573. case 'sub':
  574. data[options.main] = _.filter(result, function (r) {return ['sub', 'both'].indexOf(r._join_tag) >= 0});
  575. break;
  576. case 'inner':
  577. data[options.main] = _.filter(result, function (r) {return r._join_tag === 'both'});
  578. break;
  579. case 'outer':
  580. data[options.main] = result;
  581. break;
  582. }
  583. }
  584. };
  585. const getChapterCode = {
  586. name: '获取章级编号',
  587. intro: '根据清单编号,计算章级编号,并写入指定字段,适用于未提供chapter字段的数据,例如签约清单',
  588. hint: '',
  589. defaultSetting: {
  590. table: 'mem_stage_bills',
  591. b_code: 'b_code',
  592. chapter: 'chapter',
  593. },
  594. fun: function (ctx, data, fields, options) {
  595. if (!options || !options.table || !options.b_code || !options.chapter) return;
  596. const cData = data[options.table];
  597. if (!cData) return;
  598. for (const d of cData) {
  599. d[options.chapter] = ctx.helper.getChapterCode(d[options.b_code]);
  600. }
  601. }
  602. };
  603. const filter = {
  604. name: '数据过滤',
  605. intro: '根据设置过滤数据,会直接修改数据表',
  606. defaultSetting: {
  607. "table": "pay",
  608. "condition": [
  609. {"field": "minus", "type": "bool", "value": "false", },
  610. {"field": "ptype", "type": "num", "operate": "=", "value": 1, "rela": "and"},
  611. {"field": "name", "type": "str", "operate": "=", "value": "扣回", "rela": "or"}
  612. ],
  613. "f_type": "or'",
  614. },
  615. _typeFun: {
  616. bool: '_checkBoolean',
  617. str: '_checkString',
  618. num: '_checkNumber',
  619. },
  620. _checkBoolean: function (ctx, value, condition) {
  621. switch (condition.value) {
  622. case 'true':
  623. return value ? true : false;
  624. case 'false':
  625. return value ? false : true;
  626. default:
  627. return true;
  628. }
  629. },
  630. _checkNumber: function (ctx, value, condition) {
  631. //if (ctx.helper._.isNil(value)) value = 0;
  632. switch (condition.operate) {
  633. case 'non-zero':
  634. return !ctx.helper.checkZero(value);
  635. case '=':
  636. return !ctx.helper._.isNil(value) ? value === condition.value : false;
  637. case '>':
  638. return !ctx.helper._.isNil(value) ? value > condition.value : false;
  639. case '<':
  640. return !ctx.helper._.isNil(value) ? value < condition.value : false;
  641. case '>=':
  642. return !ctx.helper._.isNil(value) ? value >= condition.value : false;
  643. case '<=':
  644. return !ctx.helper._.isNil(value) ? value <= condition.value : false;
  645. default:
  646. return true;
  647. }
  648. },
  649. _checkString: function (ctx, value, condition) {
  650. switch (condition.operate) {
  651. case '=':
  652. return value === condition.value;
  653. case 'part':
  654. return !ctx.helper._.isNil(value) ? value.indexOf(condition.value) >= 0 : false;
  655. case 'enum':
  656. return (!ctx.helper._.isNil(value) && condition.value instanceof Array) ? condition.value.indexOf(value) >= 0 : false;
  657. default:
  658. return true;
  659. }
  660. },
  661. fun: function (ctx, data, fields, options) {
  662. if (!options || !options.table || !options.condition) return;
  663. const fData = data[options.table], self = this;
  664. if (!fData) return;
  665. for (const c of options.condition) {
  666. c.fun = this._typeFun[c.type];
  667. }
  668. data[options.table] = fData.filter(function (d) {
  669. if (options.condition.length > 0) {
  670. let con = options.condition[0];
  671. let result = self[con.fun](ctx, d[con.field], con);
  672. for (let i = 1, iLen = options.condition.length; i < iLen; i++) {
  673. con = options.condition[i];
  674. result = (con.rela && con.rela === 'or')
  675. ? (result || self[con.fun](ctx, d[con.field], con))
  676. : (result && self[con.fun](ctx, d[con.field], con));
  677. }
  678. return result;
  679. } else {
  680. return true;
  681. }
  682. // const result;
  683. // for (const c of options.condition) {
  684. // if (!self[c.fun](ctx, d[c.field], c)) return false;
  685. // }
  686. // return true;
  687. });
  688. }
  689. };
  690. const gatherStagePay = {
  691. name: '汇总合同支付数据',
  692. intro: '根据付扣款项等,分类汇总合同支付的数据',
  693. defaultSetting: {
  694. table: 'mem_stage_pay',
  695. custom: [
  696. {name: '本期完成计量', ptype: 4, order: 1, visible: false},
  697. {name: '业主违约罚金', match: '业主违约罚金', order: 2},
  698. {name: '迟付款利息', match: '迟付款利息', order: 3},
  699. {flow: true, minus: 0, rid: ['业主违约罚金', '迟付款利息'], order: 4},
  700. {name: '其他付款', minus: 0, rid: ['业主违约罚金', '迟付款利息'], order: 4},
  701. {name: '合计', order: 5, order_calc: 'o1+o2+o3+o4', },
  702. {name: '动员预付款', order: 6},
  703. {name: '扣动员预付款', match: ['扣动员预付款', '扣回动员预付款', '扣开工预付款', '扣回开工预付款'], order: 7},
  704. {name: '扣材料预付款', match: '扣材料预付款', order: 8},
  705. {name: '承包人违约罚金', match: '承包人违约罚金', order: 9},
  706. {name: '保留金', match: '保留金', order: 10},
  707. {name: '税金', match: '税金', order: 11},
  708. {name: '质量保证金', match: '质量保证金', order: 12},
  709. {name: '其他扣款', minus: 1, rid: ['扣动员预付款', '扣回动员预付款', '扣开工预付款', '扣回开工预付款', '扣材料预付款', '承包人违约罚金', '保留金', '税金', '质量保证金'], order: 13},
  710. {name: '扣款合计', minus: 1, rid: [], order: 14},
  711. {name: '支付', ptype: 2, order: 15},
  712. ]
  713. },
  714. _filterFields: function (ctx, d, source) {
  715. let filterData = source;
  716. if (d.ptype) {
  717. filterData = filterData.filter(function (x) {
  718. return x.ptype === d.ptype;
  719. });
  720. }
  721. if (d.match) {
  722. filterData = filterData.filter(function (x) {
  723. if (x.name) {
  724. if (d.match instanceof Array) {
  725. for (const m of d.match) {
  726. if (x.name.indexOf(m) >= 0) return true;
  727. }
  728. } else {
  729. return x.name.indexOf(d.match) >= 0;
  730. }
  731. } else {
  732. return false;
  733. }
  734. });
  735. }
  736. if (!ctx.helper._.isNil(d.minus)) {
  737. filterData = filterData.filter(function (x) {
  738. return d.minus === 1 ? x.minus : !x.minus;
  739. });
  740. }
  741. if (d.rid) {
  742. filterData = filterData.filter(function (x) {
  743. if (x.name) {
  744. for (const r of d.rid) {
  745. if (x.name.indexOf(r) >= 0) return false;
  746. }
  747. }
  748. return true;
  749. });
  750. }
  751. return filterData;
  752. },
  753. _gatherFields: function (ctx, d, source, calcFields) {
  754. const filterData = this._filterFields(ctx, d, source);
  755. for (const fd of filterData) {
  756. for (const prop in fd) {
  757. if (prop.indexOf('tp') >= 0) {
  758. d[prop] = ctx.helper.add(d[prop], fd[prop]);
  759. if (calcFields.indexOf(prop) === -1) calcFields.push(prop);
  760. }
  761. }
  762. }
  763. },
  764. fun: function (ctx, data, fields, options) {
  765. if (!options || !options.table || !options.custom) return;
  766. const gatherData = data[options.table];
  767. const result = [], calcFields = [];
  768. for (const c of options.custom) {
  769. const cData = JSON.parse(JSON.stringify(c));
  770. cData.subOrder = 0;
  771. if (cData.flow) {
  772. const fData = this._filterFields(ctx, cData, gatherData);
  773. for (const [i, f] of fData.entries()) {
  774. f.order = cData.order;
  775. f.subOrder = i;
  776. result.push(f);
  777. }
  778. } else {
  779. if (!cData.order_calc && cData.empty !== 1) {
  780. this._gatherFields(ctx, cData, gatherData, calcFields);
  781. }
  782. result.push(cData);
  783. }
  784. }
  785. rdaUtils.orderCalc(ctx, result, calcFields);
  786. data[options.table] = result.filter(function (x) {
  787. return x.visible === undefined || x.visible;
  788. });
  789. data[options.table].sort(function (a, b) {
  790. return a.order === b.order ? a.subOrder - b.subOrder : a.order - b.order;
  791. });
  792. },
  793. };
  794. const union = {
  795. name: '合并数据',
  796. intro: '类似sql的union,可合并任意数据,合并结果写到"预留扩展数据-合并(mem_union_data)"中',
  797. defaultSetting: {
  798. union: [
  799. {
  800. table: 'mem_stage_bills',
  801. fields: [
  802. {target: 'str1', source: 'chapter'},
  803. {target: 'str2', source: 'name'},
  804. {target: 'tp1', source: 'total_price'},
  805. {target: 'tp2', source: 'gather_tp'},
  806. {target: 'tp3', source: 'pre_gather_tp'},
  807. {target: 'tp4', source: 'end_gather_tp'},
  808. {target: 'str3', data: '章级合计哟'},
  809. ]
  810. }, {
  811. table: 'mem_stage_pay',
  812. fields: [
  813. {target: 'str2', source: 'name'},
  814. {target: 'tp2', source: 'tp'},
  815. {target: 'tp3', source: 'pre_tp'},
  816. {target: 'tp4', source: 'end_tp'},
  817. {target: 'str3', data: '合同支付哟'},
  818. ]
  819. }
  820. ]
  821. },
  822. fun: function(ctx, data, fields, options) {
  823. if (!options || !options.union) return;
  824. const result = [];
  825. for (const u of options.union) {
  826. const unionData = data[u.table];
  827. for (const d of unionData) {
  828. const nd = {};
  829. for (const f of u.fields) {
  830. if (f.data) {
  831. nd[f.target] = f.data;
  832. } else if (f.source) {
  833. nd[f.target] = d[f.source];
  834. }
  835. }
  836. result.push(nd);
  837. }
  838. }
  839. data.mem_union_data = result;
  840. }
  841. };
  842. const addSumChapter = {
  843. name: '添加章级合计',
  844. intro: '在排序好的工程量清单列表中,根据清单所属章级,添加章级标题行、合计行',
  845. defaultSetting: {
  846. table: 'mem_stage_bills',
  847. code: 'b_code',
  848. chapter: 'chapter',
  849. stdChapter: { title: '%s章', sum: '%s章合计'},
  850. otherChapter: { title: '其他章', sum: '其他章合计'},
  851. sum: { name: '总合计' },
  852. fields: ['ex_value1', 'ex_value2', 'end_gather_tp', 'pre_gather_tp', 'gather_tp'],
  853. },
  854. fun: function (ctx, data, fields, options) {
  855. if (!options || !options.table || !options.code || !options.chapter || !options.stdChapter) return;
  856. const gclData = data[options.table];
  857. if (!gclData || !data.tender_info) return;
  858. const chapters = ctx.helper._.uniq(ctx.helper._.map(gclData, options.chapter));
  859. const finalSum = options.sum ? {name: options.sum.name, chapterNum: 100000, chapterPart: 1} : null;
  860. for (const chapter of chapters) {
  861. const chapterInfo = data.tender_info.chapter.find(function (x) { return x.code === chapter});
  862. const chapterOptions = chapterInfo ? options.stdChapter : options.otherChapter;
  863. // sum
  864. const chapterGcl = gclData.filter(function (x) {
  865. return x.chapter === chapter;
  866. });
  867. const sum = { chapter: chapter, chapterPart: 3, chapterNum: parseInt(chapter) };
  868. for (const cg of chapterGcl) {
  869. cg.chapterPart = 2;
  870. cg.chapterNum = parseInt(cg[options.chapter]);
  871. for (const f of options.fields) {
  872. sum[f] = ctx.helper.add(sum[f], cg[f]);
  873. if (finalSum) {
  874. finalSum[f] = ctx.helper.add(finalSum[f], cg[f]);
  875. }
  876. }
  877. }
  878. if (chapterOptions.sum !== undefined) {
  879. sum.name = chapterOptions.sum.replace('%s', chapter);
  880. gclData.push(sum);
  881. }
  882. // title
  883. if (chapterOptions.title !== undefined) {
  884. const title = { chapter: chapter, chapterPart: 1, chapterNum: parseInt(chapter) };
  885. if (chapterInfo) {
  886. title[options.code] = options.stdChapter.title.replace('%s', chapter);
  887. title.name = chapterInfo.name;
  888. } else {
  889. title.name = chapterOptions.title;
  890. }
  891. gclData.push(title);
  892. }
  893. }
  894. if (finalSum) {
  895. gclData.push(finalSum);
  896. }
  897. gclData.sort(function (a, b) {
  898. if (a.chapter !== b.chapter) {
  899. return a.chapterNum - b.chapterNum;
  900. } else if (a.chapterPart !== b.chapterPart) {
  901. return a.chapterPart - b.chapterPart;
  902. } else {
  903. return ctx.helper.compareCode(a[options.code], b[options.code]);
  904. }
  905. });
  906. }
  907. };
  908. const auditSelect = {
  909. name: '审批人选择',
  910. hint: '需搭配用户交互--审批人选择一起使用',
  911. defaultSetting: {
  912. table: ['mem_stage_bills_compare', 'mem_stage_pos_compare', 'mem_stage_pay'],
  913. },
  914. _stageBillsCompare(data, order) {
  915. const fields = [];
  916. for (const [i, o] of order.entries()) {
  917. const sPrefix = 'r' + o + '_';
  918. const tPrefix = 'as' + i + '_';
  919. fields.push({source: sPrefix + 'contract_qty', target: tPrefix + 'contract_qty'});
  920. fields.push({source: sPrefix + 'contract_tp', target: tPrefix + 'contract_tp'});
  921. fields.push({source: sPrefix + 'qc_qty', target: tPrefix + 'qc_qty'});
  922. fields.push({source: sPrefix + 'qc_tp', target: tPrefix + 'qc_tp'});
  923. fields.push({source: sPrefix + 'gather_qty', target: tPrefix + 'gather_qty'});
  924. fields.push({source: sPrefix + 'gather_tp', target: tPrefix + 'gather_tp'});
  925. }
  926. for (const d of data) {
  927. for (const f of fields) {
  928. d[f.target] = d[f.source];
  929. }
  930. }
  931. },
  932. _stagePosCompare(data, order) {
  933. const fields = [];
  934. for (const [i, o] of order.entries()) {
  935. const sPrefix = 'r' + o + '_';
  936. const tPrefix = 'as' + i + '_';
  937. fields.push({source: sPrefix + 'contract_qty', target: tPrefix + 'contract_qty'});
  938. fields.push({source: sPrefix + 'qc_qty', target: tPrefix + 'qc_qty'});
  939. fields.push({source: sPrefix + 'gather_qty', target: tPrefix + 'gather_qty'});
  940. }
  941. for (const d of data) {
  942. for (const f of fields) {
  943. d[f.target] = d[f.source];
  944. }
  945. }
  946. },
  947. _stagePay(data, order) {
  948. const fields = [];
  949. for (const [i, o] of order.entries()) {
  950. const sPrefix = 'r' + o + '_';
  951. const tPrefix = 'as' + i + '_';
  952. fields.push({source: sPrefix + 'tp', target: tPrefix + 'tp'});
  953. }
  954. for (const d of data) {
  955. for (const f of fields) {
  956. d[f.target] = d[f.source];
  957. }
  958. }
  959. },
  960. fun: function (ctx, data, fieldsKey, options, csRela) {
  961. if (!ctx.tender || !ctx.stage) return;
  962. if (!csRela.tplDefine) return;
  963. const asDefine = csRela.tplDefine.audit_select;
  964. if (!asDefine || !asDefine.enable || !asDefine.setting || asDefine.setting === '') return;
  965. const asCustom = csRela.cDefine ? csRela.cDefine.audit_select : null;
  966. const order = [];
  967. if (asCustom) {
  968. for (const asc of asCustom) {
  969. order.push(asc.order);
  970. }
  971. } else {
  972. const setting = JSON.stringify(asDefine.setting);
  973. for (const [i, s] of setting.select.entries()) {
  974. order.push(i);
  975. }
  976. }
  977. for (const t of options.table) {
  978. switch (t) {
  979. case 'mem_stage_bills_compare':
  980. this._stageBillsCompare(data[t], order);
  981. break;
  982. case 'mem_stage_pos_compare':
  983. this._stagePosCompare(data[t], order);
  984. break;
  985. case 'mem_stage_pay':
  986. this._stagePay(data[t], order);
  987. break;
  988. }
  989. }
  990. }
  991. };
  992. const datetimeFormat = {
  993. name: '日期格式化',
  994. hint: '参见帮助',
  995. defaultSetting: {
  996. tables: [
  997. {name: 'mem_stage_bonus', fields: [
  998. {field: 'real_time', formatter: 'yyyy-MM-DD'},
  999. {field: 'create_time', formatter: 'yyyy-MM-DD'}
  1000. ]},
  1001. ]
  1002. },
  1003. fun: function (ctx, data, fieldsKey, options, csRela) {
  1004. if (!options.tables) return;
  1005. const tables = options.tables instanceof Array ? tables : [options.tables];
  1006. if (tables.length === 0) return;
  1007. for (const table of tables) {
  1008. const formatData = data[table.name];
  1009. for (const fd of formatData) {
  1010. for (const f of table.fields) {
  1011. fd[f.field] = moment(fd[f.field]).format(f.formatter);
  1012. }
  1013. }
  1014. }
  1015. }
  1016. };
  1017. const gatherSelectConverse = {
  1018. name: '交叉汇总数据',
  1019. hint: '需搭配 用户交互--汇总标段选择 一起使用',
  1020. defaultSetting: {
  1021. table: ['mem_gather_stage_bills'],
  1022. },
  1023. _commonConverse: function (helper, data, count) {
  1024. const result = [];
  1025. const reg = new RegExp('^t_[0-9]+_');
  1026. for (let i = 0; i < count; i++) {
  1027. const curReg = new RegExp('^t_' + i + '_');
  1028. for (const [i, d] of data.entries()) {
  1029. const nd = { cross_index: i + 1};
  1030. for (const prop in d) {
  1031. if (reg.test(prop)) {
  1032. if (curReg.test(prop)) {
  1033. nd[prop.replace(curReg, 't_')] = d[prop];
  1034. }
  1035. } else {
  1036. nd[prop] = d[prop];
  1037. }
  1038. }
  1039. result.push(nd);
  1040. }
  1041. }
  1042. // for (const d of data) {
  1043. // for (let i = 0; i < count; i++) {
  1044. // const curReg = new RegExp('^t_' + i + '_');
  1045. // const nd = {};
  1046. // for (const prop in d) {
  1047. // if (reg.test(prop)) {
  1048. // if (curReg.test(prop)) {
  1049. // nd[prop.replace(curReg, 't_')] = d[prop];
  1050. // }
  1051. // } else {
  1052. // nd[prop] = d[prop];
  1053. // }
  1054. // }
  1055. // result.push(nd);
  1056. // }
  1057. // }
  1058. return result;
  1059. },
  1060. fun: function (ctx, data, fieldsKey, options, csRela) {
  1061. if (!csRela.tplDefine) return;
  1062. const gsDefine = csRela.tplDefine.gather_select;
  1063. if (!gsDefine || !gsDefine.enable || !gsDefine.setting || gsDefine.setting === '') return;
  1064. const gsCustom = csRela.cDefine ? csRela.cDefine.gather_select : null;
  1065. const count = gsDefine.setting.special
  1066. ? gsCustom.tenders.length - gsDefine.setting.special.length
  1067. : gsCustom.tenders.length;
  1068. for (const t of options.table) {
  1069. switch (t) {
  1070. case 'mem_gather_stage_bills':
  1071. case 'mem_gather_stage_pay':
  1072. case 'mem_gather_deal_bills':
  1073. data[t] = this._commonConverse(ctx.helper, data[t], count);
  1074. break;
  1075. }
  1076. }
  1077. }
  1078. };
  1079. const sortPos = {
  1080. name: '计量单元排序',
  1081. hint: '',
  1082. defaultSetting: {
  1083. bills: 'mem_stage_bills',
  1084. pos: 'mem_stage_pos',
  1085. },
  1086. fun: function (ctx, data, fieldsKey, options, csRela) {
  1087. if (!options || !options.bills || !options.pos) return;
  1088. const bills = data[options.bills];
  1089. const pos = data[options.pos];
  1090. if (!bills || bills.length === 0 || !pos || pos.length === 0) return;
  1091. const billsIndex = {};
  1092. const findBillsIndex = function (billsId) {
  1093. if (!billsIndex[billsId]) {
  1094. billsIndex[billsId] = ctx.helper._.findIndex(bills, function (x) {
  1095. return x.id === billsId;
  1096. });
  1097. }
  1098. return billsIndex[billsId];
  1099. };
  1100. pos.sort(function (x, y) {
  1101. const xIndex = findBillsIndex(x) * 1000 + x.porder;
  1102. const yIndex = findBillsIndex(y) * 1000 + y.porder;
  1103. return xIndex - yIndex;
  1104. });
  1105. }
  1106. };
  1107. const unionPos = {
  1108. name: '拼接计量单元',
  1109. hint: '',
  1110. defaultSetting: {
  1111. bills: 'mem_stage_bills',
  1112. pos: 'mem_stage_pos',
  1113. },
  1114. fun: function (ctx, data, fieldsKey, options, csRela) {
  1115. if (!options || !options.bills || !options.pos) return;
  1116. const bills = data[options.bills];
  1117. const pos = data[options.pos];
  1118. console.log(bills.length);
  1119. console.log(pos.length);
  1120. if (!bills || bills.length === 0 || !pos || pos.length === 0) return;
  1121. const posIndex = new PosIndex({
  1122. id: 'id',
  1123. masterId: 'lid',
  1124. order: 'porder',
  1125. });
  1126. posIndex.loadDatas(pos);
  1127. const unionData = [];
  1128. for (const b of bills) {
  1129. unionData.push(b);
  1130. const posRange = posIndex.getLedgerPos(b.id);
  1131. b.posCount = posRange ? posRange.length : 0;
  1132. console.log(b.id + '-posCount: ' + b.posCount);
  1133. if (!posRange || posRange.length === 0) continue;
  1134. for (const p of posRange) {
  1135. unionData.push(p);
  1136. }
  1137. }
  1138. data[options.bills] = unionData;
  1139. }
  1140. }
  1141. const analysisObj = {
  1142. changeSort,
  1143. gatherGcl,
  1144. sortGcl,
  1145. gatherChapter,
  1146. join,
  1147. getChapterCode,
  1148. filter,
  1149. union,
  1150. gatherStagePay,
  1151. addSumChapter,
  1152. auditSelect,
  1153. datetimeFormat,
  1154. gatherSelectConverse,
  1155. sortPos,
  1156. unionPos,
  1157. };
  1158. const analysisDefine = (function (obj) {
  1159. const result = [];
  1160. for (const o in obj) {
  1161. const analysis = obj[o];
  1162. if (analysis.name && analysis.fun) {
  1163. result.push({
  1164. name: analysis.name,
  1165. key: o,
  1166. hint: analysis.hint,
  1167. intro: analysis.intro,
  1168. url: '/help?m=report&s=analysis&d=' + o,
  1169. })
  1170. }
  1171. }
  1172. return result;
  1173. })(analysisObj);
  1174. module.exports = {
  1175. analysisObj,
  1176. analysisDefine
  1177. };