rpt_data_analysis.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  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. const valueCheck = {
  14. _typeFun: {
  15. bool: '_checkBoolean',
  16. str: '_checkString',
  17. num: '_checkNumber',
  18. },
  19. _checkBoolean(ctx, value, condition) {
  20. switch (condition.value) {
  21. case 'true':
  22. return !!value;
  23. case 'false':
  24. return !value;
  25. default:
  26. return true;
  27. }
  28. },
  29. _checkNumber(ctx, value, condition) {
  30. // if (ctx.helper._.isNil(value)) value = 0;
  31. switch (condition.operate) {
  32. case 'non-zero':
  33. return !ctx.helper.checkZero(value);
  34. case '=':
  35. return !ctx.helper._.isNil(value) ? value === condition.value : false;
  36. case '>':
  37. return !ctx.helper._.isNil(value) ? value > condition.value : false;
  38. case '<':
  39. return !ctx.helper._.isNil(value) ? value < condition.value : false;
  40. case '>=':
  41. return !ctx.helper._.isNil(value) ? value >= condition.value : false;
  42. case '<=':
  43. return !ctx.helper._.isNil(value) ? value <= condition.value : false;
  44. default:
  45. return true;
  46. }
  47. },
  48. _checkString(ctx, value, condition) {
  49. switch (condition.operate) {
  50. case '=':
  51. return value === condition.value;
  52. case 'part':
  53. return value ? value.indexOf(condition.value) >= 0 : false;
  54. case 'enum':
  55. return (value && condition.value instanceof Array) ? condition.value.indexOf(value) >= 0 : false;
  56. default:
  57. return true;
  58. }
  59. },
  60. loadTypeFun(condition) {
  61. for (const c of condition) {
  62. c.fun = this._typeFun[c.type];
  63. }
  64. },
  65. checkData(ctx, data, condition) {
  66. if (condition.length > 0) {
  67. let con = condition[0];
  68. let result = this[con.fun](ctx, data[con.field], con);
  69. for (let i = 1, iLen = condition.length; i < iLen; i++) {
  70. con = condition[i];
  71. result = (con.rela && con.rela === 'or')
  72. ? (result || this[con.fun](ctx, data[con.field], con))
  73. : (result && this[con.fun](ctx, data[con.field], con));
  74. }
  75. return result;
  76. }
  77. return true;
  78. },
  79. };
  80. class PosIndex {
  81. /**
  82. * 构造函数
  83. * @param {id|String, masterId|String, order|String} setting
  84. */
  85. constructor(setting) {
  86. // 无索引
  87. this.datas = [];
  88. // 以key为索引
  89. this.items = {};
  90. // 以分类id为索引的有序
  91. this.ledgerPos = {};
  92. // pos设置
  93. this.setting = setting;
  94. }
  95. /**
  96. * 加载部位明细数据
  97. * @param datas
  98. */
  99. loadDatas(datas) {
  100. this.datas = datas;
  101. this.items = {};
  102. this.ledgerPos = {};
  103. for (const data of this.datas) {
  104. const key = data[this.setting.id];
  105. this.items[key] = data;
  106. const masterKey = data[this.setting.masterId];
  107. if (!this.ledgerPos[masterKey]) {
  108. this.ledgerPos[masterKey] = [];
  109. }
  110. this.ledgerPos[masterKey].push(data);
  111. }
  112. for (const prop in this.ledgerPos) {
  113. this.resortLedgerPos(this.ledgerPos[prop]);
  114. }
  115. }
  116. getLedgerPos(mid) {
  117. return this.ledgerPos[mid];
  118. }
  119. resortLedgerPos(ledgerPos) {
  120. const self = this;
  121. if (ledgerPos instanceof Array) {
  122. ledgerPos.sort(function(a, b) {
  123. return a[self.setting.order] - b[self.setting.order];
  124. });
  125. }
  126. }
  127. }
  128. // 通用方法
  129. const rdaUtils = {
  130. orderCalc(ctx, data, fields) {
  131. const orderMatch = new RegExp('o[0-9]+', 'igm');
  132. for (const c of data) {
  133. if (c.order_calc && c.order_calc !== '') {
  134. const matchs = c.order_calc.match(orderMatch);
  135. const calcMatch = [];
  136. for (const m of matchs) {
  137. const order = m.substring(1, m.length);
  138. const orderData = data.find(function(x) { return (x.order + '') === order; });
  139. if (orderData) {
  140. calcMatch.push({ match: m, value: orderData });
  141. }
  142. }
  143. for (const f of fields) {
  144. let expr = c.order_calc;
  145. for (const m of calcMatch) {
  146. expr = expr.replace(m.match, m.value[f] ? m.value[f] : 0);
  147. }
  148. try {
  149. c[f] = ctx.helper.round(math.eval(expr), 6);
  150. } catch (err) {
  151. }
  152. }
  153. }
  154. }
  155. },
  156. };
  157. // 可提供的数据处理方法
  158. const changeSort = {
  159. name: '变更令排序',
  160. hint: '默认的变更令排序,同时对变更令,变更清单进行排序\n' +
  161. '变更令排序勿需勾选任何预定义处理指标,但是在指标映射中,需要添加如下指标:' +
  162. '1. 如果只有变更令数据,则必须添加,"变更令(change)"下的"变更令号"' +
  163. '2. 如果有变更清单需要排序,则必须在1的基础上添加,变更令(change)"下的"变更令uuid"和"变更清单(chang_audit_list)"下的"所属变更令uuid"&"清单编号"',
  164. intro: '报表对于主从表的排序有要求,解决变更令数据中的变更令、变更清单排序问题',
  165. /**
  166. *
  167. * @param ctx - context常量
  168. * @param data - 全部数据源{Array}
  169. * @param fieldsKey - 计算字段
  170. * @param options - 计算设置
  171. */
  172. fun(ctx, data, fieldsKey, options) {
  173. const change = options && options.change ? data[options.change] : data.change;
  174. if (!change) return;
  175. // 变更令排序
  176. change.sort(function(a, b) {
  177. return a.code.localeCompare(b.code);
  178. });
  179. const changeBills = options && options.changeBills ? data[options.changeBills] : data.change_audit_list;
  180. if (changeBills) {
  181. changeBills.sort(function(a, b) {
  182. const aCIndex = data.change.findIndex(function(c) {
  183. return c.cid === a.cid;
  184. });
  185. const bCIndex = data.change.findIndex(function(c) {
  186. return c.cid === b.cid;
  187. });
  188. return aCIndex === bCIndex
  189. ? ctx.helper.compareCode(a.code, b.code)
  190. : aCIndex - bCIndex;
  191. });
  192. }
  193. },
  194. };
  195. const gatherGcl = {
  196. name: '汇总工程量清单',
  197. hint: '请使用mem_stage_bills下指标,注意事项:\n' +
  198. '1. 以下字段,不管报表是否实际使用,均应添加至指标映射,且在此处应勾选(不要求顺序):\n' +
  199. ' 清单编号(b_code), 名称(name), 单位(unit), 单价(unit_price), 树结构-是否子项(is_leaf)\n' +
  200. '2. 汇总后,以下字段,均会失效, 请勿使用:\n' +
  201. ' 台账ID(id), 树结构-ID(ledger_id), 树结构父项-ID(ledger_pid),\n' +
  202. ' 树结构-层级(level), 树结构-同层排序(order), 树结构-完整路径(full_path),\n' +
  203. ' 图册号(drawing_code), 备注(memo), 节点类型(node_type), 总额计量(is_tp)\n' +
  204. '3. 如需汇总"未计入清单章节项",请勾选"章节编号(chapter)"字段\n',
  205. intro: '根据三级清单树结构,汇总平面工程量清单,目前仅支持mem_stage_bills表',
  206. _gatherCalcField(ctx, gcl, data) {
  207. for (const prop in data) {
  208. if (((prop === 'total_price' || prop.indexOf('tp') > 0) ||
  209. (prop === 'quantity' || prop.indexOf('qty') > 0)) && data[prop]) {
  210. gcl[prop] = ctx.helper.add(gcl[prop], data[prop]);
  211. }
  212. }
  213. },
  214. _gatherTpField(ctx, gcl, data) {
  215. for (const prop in data) {
  216. if ((prop === 'total_price' || prop.indexOf('tp') > 0) && data[prop]) {
  217. gcl[prop] = ctx.helper.add(gcl[prop], data[prop]);
  218. }
  219. }
  220. },
  221. _loadGatherInfo(gcl, data) {
  222. for (const prop in data) {
  223. if (/^t_[0-9]+_(id|name)$/.test(prop)) {
  224. gcl[prop] = data[prop];
  225. }
  226. }
  227. },
  228. _loadStageSumInfo(gcl, data) {
  229. for (const prop in data) {
  230. if (/^s_[0-9]+_order$/.test(prop)) {
  231. gcl[prop] = data[prop];
  232. }
  233. }
  234. },
  235. _gatherFields(gcl, data, fields) {
  236. for (const f of fields) {
  237. if (data[f]) {
  238. gcl[f] = ctx.helper.add(gcl[f], data[f]);
  239. }
  240. }
  241. },
  242. fun(ctx, data, fieldsKey, options) {
  243. const tableName = options ? options.table : 'mem_stage_bills';
  244. const gatherData = data[tableName];
  245. if (!gatherData || gatherData.length === 0) return;
  246. const fields = ctx.helper._.map(fieldsKey, 'field');
  247. const needFields = ['b_code', 'name', 'unit', 'unit_price', 'is_leaf'];
  248. for (const nf of needFields) {
  249. if (fields.indexOf(nf) === -1) return;
  250. }
  251. const gatherOther = fields.indexOf('chapter') >= 0;
  252. const gclBills = [],
  253. other = { name: '未计入清单章节项', chapter: '10000' };
  254. if (tableName.indexOf('mem_gather_') >= 0) this._loadGatherInfo(other, gatherData[0]);
  255. if (tableName.indexOf('mem_stage_sum_') >= 0) this._loadStageSumInfo(other, gatherData[0]);
  256. for (const b of gatherData) {
  257. const child = ctx.helper._.find(gatherData, { ledger_pid: b.ledger_id });
  258. if (child) continue;
  259. if (b.b_code && b.b_code !== '') {
  260. let gcl = gclBills.find(function(g) {
  261. return g.b_code === b.b_code && g.name === b.name && g.unit === b.unit
  262. && ctx.helper.checkZero(ctx.helper.sub(g.unit_price, b.unit_price));
  263. });
  264. if (!gcl) {
  265. gcl = {
  266. b_code: b.b_code, name: b.name, unit: b.unit,
  267. unit_price: b.unit_price,
  268. qc_bgl_code: [], chapter: b.chapter,
  269. deal_bills_qty: b.deal_bills_qty, deal_bills_tp: b.deal_bills_tp,
  270. };
  271. if (tableName.indexOf('mem_gather_') >= 0) this._loadGatherInfo(gcl, b);
  272. if (tableName.indexOf('mem_stage_sum_') >= 0) this._loadStageSumInfo(gcl, b);
  273. gclBills.push(gcl);
  274. }
  275. this._gatherCalcField(ctx, gcl, b);
  276. if (b.qc_bgl_code && b.qc_bgl_code !== '') {
  277. gcl.qc_bgl_code = gcl.qc_bgl_code.concat(b.qc_bgl_code.split(';'));
  278. }
  279. } else if (gatherOther) {
  280. this._gatherTpField(ctx, other, b);
  281. }
  282. }
  283. if (gatherOther) gclBills.push(other);
  284. for (const g of gclBills) {
  285. if (g.qc_bgl_code) g.qc_bgl_code = g.qc_bgl_code.join(';');
  286. g.final_ratio = ctx.helper.mul(ctx.helper.div(g.end_gather_tp, g.final_ratio), 100);
  287. }
  288. data[tableName] = gclBills;
  289. },
  290. };
  291. const sortGcl = {
  292. name: '工程量清单排序',
  293. hint: '只对一张表,进行工程量清单排序,排序哪张表,根据勾选的清单编号字段决定:\n' +
  294. 'e.g.1 要对mem_stage_bills排序,需要勾选mem_stage_bills下的"清单编号(b_code)"字段\n' +
  295. 'e.g.2 要对mem_stage_im_zl排序,需要勾选mem_stage_im_zl下的"中间计量总量信息_编号(code)"字段\n' +
  296. '特别的,如有"未计入清单章节项": \n' +
  297. ' 1. 默认"未计入清单章节项"排列在最后\n' +
  298. ' 2. 如须"未计入清单章节项"排在100章之后,请在清单编号字段后,依次勾选"章节编号(chapter)", "名称(name)"\n',
  299. intro: '根据选择列,对数据进行工程量清单排序,兼容1000章后清单,以及403-1-a类的非纯数字编号排序',
  300. fun(ctx, data, fieldsKey, options) {
  301. if (fieldsKey.length !== 1 && fieldsKey.length !== 3) return;
  302. const code = fieldsKey[0].field;
  303. const chapter = fieldsKey.length > 1 ? fieldsKey[1].field : '';
  304. const name = fieldsKey.length > 2 ? fieldsKey[2].field : '';
  305. const sortData = data[fieldsKey[0].table];
  306. if (!sortData) return;
  307. sortData.sort(function(a, b) {
  308. if (chapter !== '') {
  309. if (a[name] === '未计入清单章节项') {
  310. return b[chapter] === '100' ? 1 : -1;
  311. } else if (b[name] === '未计入清单章节项') {
  312. return a[chapter] === '100' ? -1 : 1;
  313. }
  314. return ctx.helper.compareCode(a[code], b[code]);
  315. }
  316. return ctx.helper.compareCode(a[code], b[code]);
  317. });
  318. },
  319. };
  320. const gatherChapter = {
  321. name: '汇总章级数据',
  322. hint: '请使用mem_stage_bills/mem_stage_bills_compare/ledger,仅对一张表进行汇总,并生成数据:\n' +
  323. '1. 因为是汇总章级数据,必须在离散数据中添加"章节代码"&"章节名称"\n' +
  324. '2. 需勾选"清单编号(b_code)", "树结构-是否子项(is_leaf)"字段,可以对任何含有这些字段的表汇总\n' +
  325. '注意事项:\n' +
  326. '1. 算法对数据表没有要求,保证有上述字段,且按顺序勾选即可, 仅汇总金额\n' +
  327. '2. 算法计算后,原数据表中非数字类型的字段全部失效(除清单编号、名称外),请勿在指标映射中添加\n' +
  328. '示例:\n' +
  329. 'e.g.1 要对mem_stage_bills汇总,须勾选mem_stage_bills下的"清单编号(b_code)", "树结构-是否子项((is_leaf)"字段\n' +
  330. 'e.g.2 要对mem_stage_bills_compare汇总,须勾选mem_stage_bills_compare下的"清单编号(b_code)", "树结构-是否子项((is_leaf)"字段\n' +
  331. '结果:\n' +
  332. '汇总结果可参照 清单汇总--章节合计,但是不过滤1000-1300章数据',
  333. intro: '用于得到类似“清单汇总--章级合计”的数据,可通过options自定义数据',
  334. defaultSetting: {
  335. count: 9,
  336. unChapter: {
  337. name: '未计入清单章节合计',
  338. order: 1,
  339. },
  340. gclSum: {
  341. name: '清单小计',
  342. order: 2,
  343. },
  344. unGcl: {
  345. name: '非清单项费用',
  346. order: 3,
  347. },
  348. sum: {
  349. name: '合计',
  350. order: 4,
  351. },
  352. filter: [{node_type: standard.nodeType.find(function (x) {return x.text === '计日工'}).value}, {field: 'name', part: '计日工'}],
  353. },
  354. customSetting1: {
  355. count: 7,
  356. gclSum: {
  357. name: '第100章至700章清单合计',
  358. order: 1,
  359. },
  360. custom: [
  361. {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2, visible: false},
  362. {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
  363. {name: '计日工合计', node_type: '计日工', order: 4},
  364. {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', order: 5, match: [{node_type: '暂列金额'}, {field: 'name', part: '暂列金额'}, {field: 'name', all: '暂定金额'}]},
  365. {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
  366. ],
  367. rela: [
  368. {
  369. table: 'deal_bills', key: 'code',
  370. fields: { source: 'total_price', target: 'ex_value1' },
  371. },
  372. {
  373. table: 'mem_change_bills', key: 'code',
  374. fields: { source: '', target: 'ex_value2' },
  375. },
  376. ],
  377. },
  378. _getCalcChapter(chapter, options) {
  379. const gclChapter = [],
  380. otherChapter = [],
  381. customChapter = [];
  382. let serialNo = 1;
  383. for (const c of chapter) {
  384. const cc = { code: c.code, name: c.name, cType: 1 };
  385. cc.serialNo = serialNo++;
  386. cc.filter = '^[\\D]*' + c.code.substr(0, c.code.length - 2) + '[0-9]{2}-';
  387. // cc.visible = true;
  388. gclChapter.push(cc);
  389. if (options.activeFields) {
  390. cc.active = cc.serialNo > options.count;
  391. } else {
  392. if (serialNo > options.count) break;
  393. }
  394. }
  395. if (options.unChapter) {
  396. gclChapter.push({
  397. name: options.unChapter.name, cType: 21,
  398. serialNo: serialNo + options.unChapter.order, order: options.unChapter.order,
  399. visible: options.unChapter.visible,
  400. });
  401. }
  402. if (options.gclSum) {
  403. otherChapter.push({
  404. name: options.gclSum.name, cType: 11,
  405. serialNo: serialNo + options.gclSum.order, order: options.gclSum.order,
  406. visible: options.gclSum.visible,
  407. });
  408. }
  409. if (options.unGcl) {
  410. otherChapter.push({
  411. name: options.unGcl.name, cType: 31,
  412. serialNo: serialNo + options.unGcl.order, order: options.unGcl.order,
  413. visible: options.unGcl.visible,
  414. });
  415. }
  416. if (options.sum) {
  417. otherChapter.push({
  418. name: options.sum.name , cType: 41,
  419. serialNo: serialNo + options.sum.order, order: options.sum.order,
  420. visible: options.sum.visible,
  421. });
  422. }
  423. if (options.custom && options.custom instanceof Array) {
  424. for (const c of options.custom) {
  425. const cc = {
  426. name: c.name, serialNo: serialNo + c.order,
  427. order_calc: c.order_calc,
  428. cType: 5, order: c.order,
  429. visible: c.visible,
  430. };
  431. if (c.match) {
  432. cc.match = JSON.parse(JSON.stringify(c.match));
  433. for (const m of cc.match) {
  434. if (m.node_type && m.node_type !== '') {
  435. const nodeType = standard.nodeType.find(function (x) {return x.text === m.node_type});
  436. m.node_type = nodeType.value;
  437. }
  438. }
  439. }
  440. customChapter.push(cc);
  441. }
  442. }
  443. return [gclChapter, otherChapter, customChapter];
  444. },
  445. _completeGatherInfo(chapters, source) {
  446. for (const f in source) {
  447. if (/^t_[0-9]*_(id|name)$/.test(f)) {
  448. for (const chapter of chapters) {
  449. chapter[f] = source[f];
  450. }
  451. }
  452. }
  453. },
  454. _completeStageSumInfo(chapters, source) {
  455. for (const f in source) {
  456. if (/^s_[0-9]*_order$/.test(f)) {
  457. for (const chapter of chapters) {
  458. chapter[f] = source[f];
  459. }
  460. }
  461. }
  462. },
  463. _getGclChapter(chapter, data, field) {
  464. for (const c of chapter) {
  465. if (c.filter) {
  466. const reg = new RegExp(c.filter);
  467. if (reg.test(data[field])) {
  468. return c;
  469. }
  470. } else {
  471. return c;
  472. }
  473. }
  474. },
  475. _checkFilter(fullPath, filter) {
  476. for (const f of filter) {
  477. if (fullPath.indexOf(f + '-') === 0 || fullPath === f) return true;
  478. }
  479. return false;
  480. },
  481. _gatherRela(ctx, data, rela, gclChapter, otherChapter) {
  482. if (!rela) return;
  483. const gatherRelaFields = function(chapter, source, field) {
  484. const fields = field instanceof Array ? field : [field];
  485. for (const f of fields) {
  486. chapter[f.target] = ctx.helper.add(chapter[f.target], source[f.source]);
  487. }
  488. };
  489. const relaBills = rela instanceof Array ? rela : [rela];
  490. for (const rb of relaBills) {
  491. if (!rb.table) continue;
  492. const relaData = data[rb.table];
  493. if (!relaData) continue;
  494. for (const rd of relaData) {
  495. for (const c of otherChapter) {
  496. if (c.cType === 41) {
  497. gatherRelaFields(c, rd, rb.fields);
  498. } else if (c.cType === 31 && (!rd[rb.key] || rd[rb.key] === '')) {
  499. gatherRelaFields(c, rd, rb.fields);
  500. } else if (c.cType === 11 && (rd[rb.key])) {
  501. gatherRelaFields(c, rd, rb.fields);
  502. }
  503. }
  504. if (rd[rb.key]) {
  505. const c = this._getGclChapter(gclChapter, rd, rb.key);
  506. if (c) gatherRelaFields(c, rd, rb.fields);
  507. }
  508. }
  509. }
  510. },
  511. _orderCalc(ctx, chapter, fields) {
  512. const orderMatch = new RegExp('o[0-9]+', 'igm');
  513. for (const c of chapter) {
  514. if (c.order_calc && c.order_calc !== '') {
  515. const matchs = c.order_calc.match(orderMatch);
  516. const calcMatch = [];
  517. for (const m of matchs) {
  518. const order = m.substring(1, m.length);
  519. const orderChapter = chapter.find(function(x) { return x.order == order; });
  520. if (orderChapter) {
  521. calcMatch.push({ match: m, value: orderChapter });
  522. }
  523. }
  524. for (const f of fields) {
  525. let expr = c.order_calc;
  526. for (const m of calcMatch) {
  527. expr = expr.replace(m.match, m.value[f] ? m.value[f] : 0);
  528. }
  529. try {
  530. c[f] = ctx.helper.round(math.eval(expr), 6);
  531. } catch (err) {
  532. }
  533. }
  534. }
  535. }
  536. },
  537. _checkMatch(match, d) {
  538. for (const m of match) {
  539. if (m.node_type) {
  540. if (m.node_type === d.node_type) return true;
  541. } else if (m.field) {
  542. const value = d[m.field];
  543. if (m.part && value) {
  544. if (value.indexOf(m.part) >= 0) return true;
  545. } else if (m.all && value) {
  546. if (m.all === value) return true;
  547. }
  548. }
  549. }
  550. return false;
  551. },
  552. fun(ctx, data, fieldsKey, options) {
  553. if (!data.tender_info || !data.tender_info.chapter) return;
  554. if (!fieldsKey && fieldsKey.length < 0) return;
  555. const calcFields = [];
  556. const gatherData = function(chapter, data) {
  557. if (!chapter) return;
  558. for (const f in data) {
  559. if (!data[f]) continue;
  560. if ((f.indexOf('tp') >= 0 || f === 'total_price')) {
  561. chapter[f] = ctx.helper.add(chapter[f], data[f]);
  562. if (calcFields.indexOf(f) === -1) calcFields.push(f);
  563. }
  564. }
  565. };
  566. const fields = ctx.helper._.map(fieldsKey, 'field');
  567. const needFields = ['b_code', 'is_leaf'];
  568. for (const nf of needFields) {
  569. if (fields.indexOf(nf) === -1) return;
  570. }
  571. const sourceData = data[fieldsKey[0].table];
  572. if (!sourceData) return;
  573. const [gclChapter, otherChapter, customChapter] = this._getCalcChapter(data.tender_info.chapter, options ? options : this.defaultSetting);
  574. if (fieldsKey[0].table.indexOf('mem_gather') >= 0) {
  575. this._completeGatherInfo(gclChapter, sourceData[0]);
  576. this._completeGatherInfo(otherChapter, sourceData[0]);
  577. this._completeGatherInfo(customChapter, sourceData[0]);
  578. }
  579. if (fieldsKey[0].table.indexOf('mem_stage_sum_') >= 0) {
  580. this._completeStageSumInfo(gclChapter, sourceData[0]);
  581. this._completeStageSumInfo(otherChapter, sourceData[0]);
  582. this._completeStageSumInfo(customChapter, sourceData[0]);
  583. }
  584. const filter = [],
  585. defaultFilter = [];
  586. for (const d of sourceData) {
  587. if (this._checkMatch(this.defaultSetting.filter, d)) defaultFilter.push(d.full_path);
  588. if (this._checkFilter(d.full_path, filter)) continue;
  589. for (const c of customChapter) {
  590. if (c.match && this._checkMatch(c.match, d)) {
  591. gatherData(c, d);
  592. filter.push(d.full_path);
  593. }
  594. }
  595. if (!d.is_leaf) continue;
  596. for (const c of otherChapter) {
  597. if (c.cType === 41) {
  598. gatherData(c, d);
  599. } else if (c.cType === 31 && (!d.b_code || d.b_code === '')) {
  600. gatherData(c, d);
  601. } else if (c.cType === 11 && (d.b_code)) {
  602. gatherData(c, d);
  603. }
  604. }
  605. if (d.b_code) {
  606. const c = this._checkFilter(d.full_path, defaultFilter)
  607. ? gclChapter.find(x => { return x.cType === 21; })
  608. : this._getGclChapter(gclChapter, d, 'b_code');
  609. if (c) {
  610. gatherData(c, d);
  611. }
  612. }
  613. }
  614. this._gatherRela(ctx, data, options.rela, gclChapter, otherChapter);
  615. const chapter = gclChapter.concat(otherChapter).concat(customChapter);
  616. this._orderCalc(ctx, chapter, calcFields);
  617. chapter.sort(function(a, b) { return a.serialNo - b.serialNo; });
  618. data[fieldsKey[0].table] = chapter.filter(function(x) {
  619. if (x.active) {
  620. for (const f of options.activeFields) {
  621. if (!ctx.helper.checkZero(x[f])) return true;
  622. }
  623. return false;
  624. }
  625. return (x.visible !== undefined && x.visible !== null) ? x.visible : true;
  626. });
  627. },
  628. };
  629. const join = {
  630. name: '连接两张数据表',
  631. hint: '用于处理类似于关联签约清单的情况,会改变主表的数据',
  632. intro: '用于处理类似于关联签约清单的情况,会根据关联表(sub)改变主表(main)的数据',
  633. defaultSetting: {
  634. main: 'mem_stage_bills',
  635. sub: 'deal_bills',
  636. keyFields: [
  637. { main: 'b_code', sub: 'code', type: 'string' },
  638. { main: 'name', sub: 'name', type: 'string' },
  639. { main: 'unit', sub: 'unit', type: 'string' },
  640. { main: 'unit_price', sub: 'unit_price', type: 'number' },
  641. ],
  642. importFields: [
  643. { main: 'ex_value1', sub: 'quantity', type: 'sum' },
  644. { main: 'ex_value2', sub: 'total_price', type: 'sum' },
  645. ],
  646. joinType: 'outer', // 'outer', 'main', 'sub', 'inner',
  647. },
  648. fun(ctx, data, fields, options) {
  649. if (!options || !options.main || !options.sub || !options.keyFields || options.keyFields.length === 0) return;
  650. const main = data[options.main];
  651. const sub = data[options.sub];
  652. if (!main || !sub) return;
  653. const _ = ctx.helper._,
  654. result = _.cloneDeep(main);
  655. for (const r of result) {
  656. r._join_tag = 'main';
  657. for (const i of options.importFields) {
  658. r[i.main] = null;
  659. }
  660. }
  661. for (const s of sub) {
  662. let r = result.find(function(x) {
  663. for (const k of options.keyFields) {
  664. switch (k.type) {
  665. case 'string':
  666. if ((x[k.main] || '') !== (s[k.sub] || '')) return false;
  667. break;
  668. case 'number':
  669. if (!ctx.helper.checkZero(ctx.helper.sub(x[k.main], s[k.sub]))) return false;
  670. break;
  671. }
  672. }
  673. return true;
  674. });
  675. if (r && r._join_tag === 'main') {
  676. r._join_tag = 'both';
  677. }
  678. if (!r) {
  679. r = { _join_tag: 'sub' };
  680. for (const k of options.keyFields) {
  681. r[k.main] = s[k.sub];
  682. }
  683. result.push(r);
  684. }
  685. for (const i of options.importFields) {
  686. // r[i.main] = s[i.sub];
  687. if (i.type === 'sum') {
  688. r[i.main] = ctx.helper.add(r[i.main], s[i.sub]);
  689. } else {
  690. r[i.main] = s[i.sub];
  691. }
  692. }
  693. }
  694. switch (options.joinType) {
  695. case 'main':
  696. data[options.main] = _.filter(result, function(r) { return ['main', 'both'].indexOf(r._join_tag) >= 0; });
  697. break;
  698. case 'sub':
  699. data[options.main] = _.filter(result, function(r) { return ['sub', 'both'].indexOf(r._join_tag) >= 0; });
  700. break;
  701. case 'inner':
  702. data[options.main] = _.filter(result, function(r) { return r._join_tag === 'both'; });
  703. break;
  704. case 'outer':
  705. data[options.main] = result;
  706. break;
  707. }
  708. },
  709. };
  710. const getChapterCode = {
  711. name: '获取章级编号',
  712. intro: '根据清单编号,计算章级编号,并写入指定字段,适用于未提供chapter字段的数据,例如签约清单',
  713. hint: '',
  714. defaultSetting: {
  715. table: 'mem_stage_bills',
  716. b_code: 'b_code',
  717. chapter: 'chapter',
  718. },
  719. fun(ctx, data, fields, options) {
  720. if (!options || !options.table || !options.b_code || !options.chapter) return;
  721. const cData = data[options.table];
  722. if (!cData) return;
  723. for (const d of cData) {
  724. d[options.chapter] = ctx.helper.getChapterCode(d[options.b_code]);
  725. }
  726. },
  727. };
  728. const filter = {
  729. name: '数据过滤',
  730. intro: '根据设置过滤数据,会直接修改数据表',
  731. defaultSetting: {
  732. table: 'pay',
  733. condition: [
  734. { field: 'minus', type: 'bool', value: 'false' },
  735. { field: 'ptype', type: 'num', operate: '=', value: 1, rela: 'and' },
  736. { field: 'name', type: 'str', operate: '=', value: '扣回', rela: 'or' },
  737. ],
  738. f_type: "or'",
  739. },
  740. _typeFun: {
  741. bool: '_checkBoolean',
  742. str: '_checkString',
  743. num: '_checkNumber',
  744. },
  745. fun(ctx, data, fields, options) {
  746. if (!options || !options.table || !options.condition) return;
  747. const fData = data[options.table];
  748. if (!fData) return;
  749. valueCheck.loadTypeFun(options.condition);
  750. data[options.table] = fData.filter(function(d) {
  751. if (options.condition.length > 0) {
  752. let con = options.condition[0];
  753. let result = valueCheck[con.fun](ctx, d[con.field], con);
  754. for (let i = 1, iLen = options.condition.length; i < iLen; i++) {
  755. con = options.condition[i];
  756. result = (con.rela && con.rela === 'or')
  757. ? (result || valueCheck[con.fun](ctx, d[con.field], con))
  758. : (result && valueCheck[con.fun](ctx, d[con.field], con));
  759. }
  760. return result;
  761. }
  762. return true;
  763. });
  764. },
  765. };
  766. const gatherStagePay = {
  767. name: '汇总合同支付数据',
  768. intro: '根据付扣款项等,分类汇总合同支付的数据',
  769. defaultSetting: {
  770. table: 'mem_stage_pay',
  771. custom: [
  772. { name: '本期完成计量', ptype: 4, order: 1, visible: false },
  773. { name: '业主违约罚金', match: '业主违约罚金', order: 2 },
  774. { name: '迟付款利息', match: '迟付款利息', order: 3 },
  775. { flow: true, minus: 0, rid: ['业主违约罚金', '迟付款利息'], order: 4 },
  776. { name: '其他付款', minus: 0, rid: ['业主违约罚金', '迟付款利息'], order: 4 },
  777. { name: '合计', order: 5, order_calc: 'o1+o2+o3+o4' },
  778. { name: '动员预付款', order: 6 },
  779. { name: '扣动员预付款', match: ['扣动员预付款', '扣回动员预付款', '扣开工预付款', '扣回开工预付款'], order: 7 },
  780. { name: '扣材料预付款', match: '扣材料预付款', order: 8 },
  781. { name: '承包人违约罚金', match: '承包人违约罚金', order: 9 },
  782. { name: '保留金', match: '保留金', order: 10 },
  783. { name: '税金', match: '税金', order: 11 },
  784. { name: '质量保证金', match: '质量保证金', order: 12 },
  785. { name: '其他扣款', minus: 1, rid: ['扣动员预付款', '扣回动员预付款', '扣开工预付款', '扣回开工预付款', '扣材料预付款', '承包人违约罚金', '保留金', '税金', '质量保证金'], order: 13 },
  786. { name: '扣款合计', minus: 1, rid: [], order: 14 },
  787. { name: '支付', ptype: 2, order: 15 },
  788. ],
  789. },
  790. _filterFields(ctx, d, source) {
  791. let filterData = source;
  792. if (d.ptype) {
  793. filterData = filterData.filter(function(x) {
  794. return x.ptype === d.ptype;
  795. });
  796. }
  797. if (d.match) {
  798. filterData = filterData.filter(function(x) {
  799. if (x.name) {
  800. if (d.match instanceof Array) {
  801. for (const m of d.match) {
  802. if (x.name.indexOf(m) >= 0) return true;
  803. }
  804. } else {
  805. return x.name.indexOf(d.match) >= 0;
  806. }
  807. } else {
  808. return false;
  809. }
  810. });
  811. }
  812. if (!ctx.helper._.isNil(d.minus)) {
  813. filterData = filterData.filter(function(x) {
  814. return d.minus === 1 ? x.minus : !x.minus;
  815. });
  816. }
  817. if (d.rid) {
  818. filterData = filterData.filter(function(x) {
  819. if (x.name) {
  820. for (const r of d.rid) {
  821. if (x.name.indexOf(r) >= 0) return false;
  822. }
  823. }
  824. return true;
  825. });
  826. }
  827. return filterData;
  828. },
  829. _gatherFields(ctx, d, source, calcFields) {
  830. const filterData = this._filterFields(ctx, d, source);
  831. for (const fd of filterData) {
  832. for (const prop in fd) {
  833. if (prop.indexOf('tp') >= 0) {
  834. d[prop] = ctx.helper.add(d[prop], fd[prop]);
  835. if (calcFields.indexOf(prop) === -1) calcFields.push(prop);
  836. }
  837. }
  838. }
  839. },
  840. _completeGatherInfo(d, source) {
  841. for (const f in source) {
  842. if (/^t_[0-9]*_(id|name)$/.test(f)) {
  843. d[f] = source[f];
  844. }
  845. }
  846. },
  847. _completeStageSumInfo(d, source) {
  848. for (const f in source) {
  849. if (/^t_[0-9]*_order$/.test(f)) {
  850. d[f] = source[f];
  851. }
  852. }
  853. },
  854. fun(ctx, data, fields, options) {
  855. if (!options || !options.table || !options.custom) return;
  856. const gatherData = data[options.table];
  857. const result = [],
  858. calcFields = [];
  859. for (const c of options.custom) {
  860. const cData = JSON.parse(JSON.stringify(c));
  861. cData.subOrder = 0;
  862. if (cData.flow) {
  863. const fData = this._filterFields(ctx, cData, gatherData);
  864. for (const [i, f] of fData.entries()) {
  865. f.order = cData.order;
  866. f.subOrder = i;
  867. result.push(f);
  868. }
  869. } else {
  870. if (!cData.order_calc && cData.empty !== 1) {
  871. this._gatherFields(ctx, cData, gatherData, calcFields);
  872. }
  873. if (options.table.indexOf('mem_gather') >= 0) this._completeGatherInfo(cData, gatherData[0]);
  874. if (options.table.indexOf('mem_stage_sum_') >= 0) this._completeStageSumInfo(cData, gatherData[0]);
  875. result.push(cData);
  876. }
  877. }
  878. rdaUtils.orderCalc(ctx, result, calcFields);
  879. data[options.table] = result.filter(function(x) {
  880. return x.visible === undefined || x.visible;
  881. });
  882. data[options.table].sort(function(a, b) {
  883. return a.order === b.order ? a.subOrder - b.subOrder : a.order - b.order;
  884. });
  885. },
  886. };
  887. const union = {
  888. name: '合并数据',
  889. intro: '类似sql的union,可合并任意数据,合并结果写到"预留扩展数据-合并(mem_union_data)"中',
  890. defaultSetting: {
  891. union: [
  892. {
  893. table: 'mem_stage_bills',
  894. fields: [
  895. { target: 'str1', source: 'chapter' },
  896. { target: 'str2', source: 'name' },
  897. { target: 'tp1', source: 'total_price' },
  898. { target: 'tp2', source: 'gather_tp' },
  899. { target: 'tp3', source: 'pre_gather_tp' },
  900. { target: 'tp4', source: 'end_gather_tp' },
  901. { target: 'str3', data: '章级合计哟' },
  902. ],
  903. }, {
  904. table: 'mem_stage_pay',
  905. fields: [
  906. { target: 'str2', source: 'name' },
  907. { target: 'tp2', source: 'tp' },
  908. { target: 'tp3', source: 'pre_tp' },
  909. { target: 'tp4', source: 'end_tp' },
  910. { target: 'str3', data: '合同支付哟' },
  911. ],
  912. },
  913. ],
  914. },
  915. fun(ctx, data, fields, options) {
  916. if (!options || !options.union) return;
  917. const result = [];
  918. for (const u of options.union) {
  919. const unionData = data[u.table];
  920. for (const d of unionData) {
  921. const nd = {};
  922. for (const f of u.fields) {
  923. if (f.data) {
  924. nd[f.target] = f.data;
  925. } else if (f.source) {
  926. nd[f.target] = d[f.source];
  927. }
  928. }
  929. result.push(nd);
  930. }
  931. }
  932. data.mem_union_data = result;
  933. },
  934. };
  935. const addSumChapter = {
  936. name: '添加章级合计',
  937. intro: '在排序好的工程量清单列表中,根据清单所属章级,添加章级标题行、合计行',
  938. defaultSetting: {
  939. table: 'mem_stage_bills',
  940. code: 'b_code',
  941. chapter: 'chapter',
  942. stdChapter: { title: '%s章', sum: '%s章合计' },
  943. otherChapter: { title: '其他章', sum: '其他章合计' },
  944. sum: { name: '总合计' },
  945. fields: ['ex_value1', 'ex_value2', 'end_gather_tp', 'pre_gather_tp', 'gather_tp'],
  946. },
  947. fun(ctx, data, fields, options) {
  948. if (!options || !options.table || !options.code || !options.chapter || !options.stdChapter) return;
  949. const gclData = data[options.table];
  950. if (!gclData || !data.tender_info) return;
  951. const chapters = ctx.helper._.uniq(ctx.helper._.map(gclData, options.chapter));
  952. const finalSum = options.sum ? { name: options.sum.name, chapterNum: 100000, chapterPart: 1 } : null;
  953. for (const chapter of chapters) {
  954. const chapterInfo = data.tender_info.chapter.find(function(x) { return x.code === chapter; });
  955. const chapterOptions = chapterInfo ? options.stdChapter : options.otherChapter;
  956. // sum
  957. const chapterGcl = gclData.filter(function(x) {
  958. return x.chapter === chapter;
  959. });
  960. const sum = { chapter, chapterPart: 3, chapterNum: parseInt(chapter) };
  961. for (const cg of chapterGcl) {
  962. cg.chapterPart = 2;
  963. cg.chapterNum = parseInt(cg[options.chapter]);
  964. for (const f of options.fields) {
  965. sum[f] = ctx.helper.add(sum[f], cg[f]);
  966. if (finalSum) {
  967. finalSum[f] = ctx.helper.add(finalSum[f], cg[f]);
  968. }
  969. }
  970. }
  971. if (chapterOptions.sum !== undefined) {
  972. sum.name = chapterOptions.sum.replace('%s', chapter);
  973. gclData.push(sum);
  974. }
  975. // title
  976. if (chapterOptions.title !== undefined) {
  977. const title = { chapter, chapterPart: 1, chapterNum: parseInt(chapter) };
  978. if (chapterInfo) {
  979. title[options.code] = options.stdChapter.title.replace('%s', chapter);
  980. title.name = chapterInfo.name;
  981. } else {
  982. title.name = chapterOptions.title;
  983. }
  984. gclData.push(title);
  985. }
  986. }
  987. if (finalSum) {
  988. gclData.push(finalSum);
  989. }
  990. gclData.sort(function(a, b) {
  991. if (a.chapter !== b.chapter) {
  992. return a.chapterNum - b.chapterNum;
  993. } else if (a.chapterPart !== b.chapterPart) {
  994. return a.chapterPart - b.chapterPart;
  995. }
  996. return ctx.helper.compareCode(a[options.code], b[options.code]);
  997. });
  998. },
  999. };
  1000. const auditSelect = {
  1001. name: '审批人选择',
  1002. hint: '需搭配用户交互--审批人选择一起使用',
  1003. defaultSetting: {
  1004. table: ['mem_stage_bills_compare', 'mem_stage_pos_compare', 'mem_stage_pay'],
  1005. },
  1006. _stageBillsCompare(data, order) {
  1007. const fields = [];
  1008. for (const [i, o] of order.entries()) {
  1009. const sPrefix = 'r' + o + '_';
  1010. const tPrefix = 'as' + i + '_';
  1011. fields.push({ source: sPrefix + 'contract_qty', target: tPrefix + 'contract_qty' });
  1012. fields.push({ source: sPrefix + 'contract_tp', target: tPrefix + 'contract_tp' });
  1013. fields.push({ source: sPrefix + 'qc_qty', target: tPrefix + 'qc_qty' });
  1014. fields.push({ source: sPrefix + 'qc_tp', target: tPrefix + 'qc_tp' });
  1015. fields.push({ source: sPrefix + 'gather_qty', target: tPrefix + 'gather_qty' });
  1016. fields.push({ source: sPrefix + 'gather_tp', target: tPrefix + 'gather_tp' });
  1017. }
  1018. for (const d of data) {
  1019. for (const f of fields) {
  1020. d[f.target] = d[f.source];
  1021. }
  1022. }
  1023. },
  1024. _stagePosCompare(data, order) {
  1025. const fields = [];
  1026. for (const [i, o] of order.entries()) {
  1027. const sPrefix = 'r' + o + '_';
  1028. const tPrefix = 'as' + i + '_';
  1029. fields.push({ source: sPrefix + 'contract_qty', target: tPrefix + 'contract_qty' });
  1030. fields.push({ source: sPrefix + 'qc_qty', target: tPrefix + 'qc_qty' });
  1031. fields.push({ source: sPrefix + 'gather_qty', target: tPrefix + 'gather_qty' });
  1032. }
  1033. for (const d of data) {
  1034. for (const f of fields) {
  1035. d[f.target] = d[f.source];
  1036. }
  1037. }
  1038. },
  1039. _stagePay(data, order) {
  1040. const fields = [];
  1041. for (const [i, o] of order.entries()) {
  1042. const sPrefix = 'r' + o + '_';
  1043. const tPrefix = 'as' + i + '_';
  1044. fields.push({ source: sPrefix + 'tp', target: tPrefix + 'tp' });
  1045. }
  1046. for (const d of data) {
  1047. for (const f of fields) {
  1048. d[f.target] = d[f.source];
  1049. }
  1050. }
  1051. },
  1052. fun(ctx, data, fieldsKey, options, csRela) {
  1053. if (!ctx.tender || !ctx.stage) return;
  1054. if (!csRela.tplDefine) return;
  1055. const asDefine = csRela.tplDefine.audit_select;
  1056. if (!asDefine || !asDefine.enable || !asDefine.setting || asDefine.setting === '') return;
  1057. const asCustom = csRela.cDefine ? csRela.cDefine.audit_select : null;
  1058. const order = [];
  1059. if (asCustom) {
  1060. for (const asc of asCustom) {
  1061. order.push(asc.sort || asc.order);
  1062. }
  1063. }
  1064. for (const t of options.table) {
  1065. switch (t) {
  1066. case 'mem_stage_bills_compare':
  1067. this._stageBillsCompare(data[t], order);
  1068. break;
  1069. case 'mem_stage_pos_compare':
  1070. this._stagePosCompare(data[t], order);
  1071. break;
  1072. case 'mem_stage_pay':
  1073. this._stagePay(data[t], order);
  1074. break;
  1075. }
  1076. }
  1077. },
  1078. };
  1079. const datetimeFormat = {
  1080. name: '日期格式化',
  1081. hint: '参见帮助',
  1082. defaultSetting: {
  1083. tables: [
  1084. { name: 'mem_stage_bonus', fields: [
  1085. { field: 'real_time', formatter: 'yyyy-MM-DD' },
  1086. { field: 'create_time', formatter: 'yyyy-MM-DD' },
  1087. ] },
  1088. ],
  1089. },
  1090. fun(ctx, data, fieldsKey, options, csRela) {
  1091. if (!options.tables) return;
  1092. const tables = options.tables instanceof Array ? options.tables : [options.tables];
  1093. if (tables.length === 0) return;
  1094. for (const table of tables) {
  1095. const formatData = data[table.name];
  1096. for (const fd of formatData) {
  1097. for (const f of table.fields) {
  1098. fd[f.field] = moment(fd[f.field]).format(f.formatter);
  1099. }
  1100. }
  1101. }
  1102. },
  1103. };
  1104. const gatherSelectConverse = {
  1105. name: '交叉汇总数据',
  1106. hint: '需搭配 用户交互--汇总标段选择 一起使用',
  1107. defaultSetting: {
  1108. table: ['mem_gather_stage_bills'],
  1109. },
  1110. _commonConverse(helper, data, count) {
  1111. const result = [];
  1112. const reg = new RegExp('^t_[0-9]+_');
  1113. for (let i = 0; i < count; i++) {
  1114. const curReg = new RegExp('^t_' + i + '_');
  1115. for (const [i, d] of data.entries()) {
  1116. const nd = { cross_index: i + 1 };
  1117. for (const prop in d) {
  1118. if (reg.test(prop)) {
  1119. if (curReg.test(prop)) {
  1120. nd[prop.replace(curReg, 't_')] = d[prop];
  1121. }
  1122. } else {
  1123. nd[prop] = d[prop];
  1124. }
  1125. }
  1126. result.push(nd);
  1127. }
  1128. }
  1129. // for (const d of data) {
  1130. // for (let i = 0; i < count; i++) {
  1131. // const curReg = new RegExp('^t_' + i + '_');
  1132. // const nd = {};
  1133. // for (const prop in d) {
  1134. // if (reg.test(prop)) {
  1135. // if (curReg.test(prop)) {
  1136. // nd[prop.replace(curReg, 't_')] = d[prop];
  1137. // }
  1138. // } else {
  1139. // nd[prop] = d[prop];
  1140. // }
  1141. // }
  1142. // result.push(nd);
  1143. // }
  1144. // }
  1145. return result;
  1146. },
  1147. fun(ctx, data, fieldsKey, options, csRela) {
  1148. if (!csRela.tplDefine) return;
  1149. const gsDefine = csRela.tplDefine.gather_select;
  1150. if (!gsDefine || !gsDefine.enable || !gsDefine.setting || gsDefine.setting === '') return;
  1151. const gsCustom = csRela.cDefine ? csRela.cDefine.gather_select : null;
  1152. const count = gsDefine.setting.special
  1153. ? gsCustom.tenders.length - gsDefine.setting.special.length
  1154. : gsCustom.tenders.length;
  1155. for (const t of options.table) {
  1156. switch (t) {
  1157. case 'mem_gather_stage_bills':
  1158. case 'mem_gather_stage_pay':
  1159. case 'mem_gather_deal_bills':
  1160. case 'mem_union_data':
  1161. data[t] = this._commonConverse(ctx.helper, data[t], count);
  1162. break;
  1163. }
  1164. }
  1165. },
  1166. };
  1167. const sortPos = {
  1168. name: '计量单元排序',
  1169. hint: '',
  1170. defaultSetting: {
  1171. bills: 'mem_stage_bills',
  1172. pos: 'mem_stage_pos',
  1173. },
  1174. fun(ctx, data, fieldsKey, options, csRela) {
  1175. if (!options || !options.bills || !options.pos) return;
  1176. const bills = data[options.bills];
  1177. const pos = data[options.pos];
  1178. if (!bills || bills.length === 0 || !pos || pos.length === 0) return;
  1179. const billsIndex = {};
  1180. const findBillsIndex = function(billsId) {
  1181. if (!billsIndex[billsId]) {
  1182. billsIndex[billsId] = ctx.helper._.findIndex(bills, function(x) {
  1183. return x.id === billsId;
  1184. });
  1185. }
  1186. return billsIndex[billsId];
  1187. };
  1188. pos.sort(function(x, y) {
  1189. const xIndex = findBillsIndex(x.lid) * 1000 + x.porder;
  1190. const yIndex = findBillsIndex(y.lid) * 1000 + y.porder;
  1191. return xIndex - yIndex;
  1192. });
  1193. },
  1194. };
  1195. const unionPos = {
  1196. name: '拼接计量单元',
  1197. hint: '',
  1198. defaultSetting: {
  1199. bills: 'mem_stage_bills',
  1200. pos: 'mem_stage_pos',
  1201. },
  1202. fun(ctx, data, fieldsKey, options, csRela) {
  1203. if (!options || !options.bills || !options.pos) return;
  1204. const bills = data[options.bills];
  1205. const pos = data[options.pos];
  1206. if (!bills || bills.length === 0 || !pos || pos.length === 0) return;
  1207. const posIndex = new PosIndex({
  1208. id: 'id',
  1209. masterId: 'lid',
  1210. order: 'porder',
  1211. });
  1212. posIndex.loadDatas(pos);
  1213. const unionData = [];
  1214. for (const b of bills) {
  1215. unionData.push(b);
  1216. const posRange = posIndex.getLedgerPos(b.id);
  1217. b.posCount = posRange ? posRange.length : 0;
  1218. if (!posRange || posRange.length === 0) continue;
  1219. for (const p of posRange) {
  1220. unionData.push(p);
  1221. }
  1222. }
  1223. data[options.bills] = unionData;
  1224. },
  1225. };
  1226. const splitXmjCode = {
  1227. name: '拆分项目节编号',
  1228. hint: '',
  1229. defaultSetting: {
  1230. table: 'mem_stage_bills',
  1231. type: '11', // '18', '18-0-1', '18-1', '18-1-1'
  1232. code: 'code',
  1233. targetField: ['xiang', 'mu', 'jie', 'ximu'],
  1234. },
  1235. // 11标准
  1236. _split11Std(data, options, helper) {
  1237. for (const d of data) {
  1238. if (!d[options.code]) continue;
  1239. const splitCodes = d[options.code].split('-');
  1240. if (d.level === 2) {
  1241. const field = options.targetField[0];
  1242. if (field && splitCodes.length > 1) {
  1243. d[field] = helper.transFormToChinese(splitCodes[1]);
  1244. }
  1245. } else if (d.level === 3) {
  1246. const field = options.targetField[1];
  1247. if (field && splitCodes.length > 2) {
  1248. d[field] = splitCodes[2];
  1249. }
  1250. } else if (d.level === 4) {
  1251. const field = options.targetField[2];
  1252. if (field && splitCodes.length > 3) {
  1253. d[field] = splitCodes[3];
  1254. }
  1255. } else if (d.level > 4) {
  1256. const field = options.targetField[3];
  1257. if (field && splitCodes.length > 4) {
  1258. d[field] = splitCodes.reduce(function(s, v, i) { return i >= 4 ? (s ? s + '-' + v : v + '') : ''; });
  1259. }
  1260. }
  1261. }
  1262. },
  1263. _getParentByLevel(data, node, level) {
  1264. if (node.full_path) {
  1265. const pid = node.full_path.split('-')[level - 1];
  1266. return data.find(function(x) {
  1267. return x.level === level && x.ledger_id == pid;
  1268. });
  1269. }
  1270. return null;
  1271. },
  1272. // 18标准
  1273. _split18Std(data, options, helper) {
  1274. const types = options.type.split('-');
  1275. const isSplitSub = !!(types[1] && types[1] === '1');
  1276. const isKeepGD = !!(types[2] && types[2] === '1');
  1277. for (const d of data) {
  1278. if (!d[options.code]) continue;
  1279. let target = '';
  1280. if (d.level === 2) {
  1281. target = options.targetField[0] ? options.targetField[0] : '';
  1282. } else if (d.level === 3) {
  1283. target = options.targetField[1] ? options.targetField[1] : '';
  1284. } else if (d.level === 4) {
  1285. target = options.targetField[2] ? options.targetField[2] : '';
  1286. } else if (d.level > 4) {
  1287. target = options.targetField[3] ? options.targetField[3] : '';
  1288. }
  1289. if (!target) continue;
  1290. if (helper.check18MainCode(d[options.code])) {
  1291. const parent = helper._.find(data, { ledger_id: d.ledger_pid });
  1292. const splitParent = !parent || parent.level < 5 ? parent : this._getParentByLevel(data, d, 4);
  1293. d[target] = !splitParent
  1294. ? d[options.code]
  1295. : d[options.code].replace(splitParent[options.code], '');
  1296. } else if (helper.check18SubCode(d[options.code]) && isSplitSub) {
  1297. const parent = helper._.find(data, { ledger_id: d.ledger_pid });
  1298. const splitParent = !parent || parent.level < 5 ? parent : this._getParentByLevel(data, d, 4);
  1299. d[target] = !splitParent || helper.check18MainCode(splitParent.code)
  1300. ? d[options.code]
  1301. : d[options.code].replace(splitParent[options.code], '');
  1302. } else {
  1303. d[target] = d[options.code];
  1304. }
  1305. if (!isKeepGD) d[target] = d[target].replace(/^G[D]?/, '');
  1306. }
  1307. },
  1308. // 根据层次填入
  1309. _splitDefault(data, options) {
  1310. for (const d of data) {
  1311. if (!d[options.code]) continue;
  1312. if (d.level === 2) {
  1313. if (options.targetField[0]) d[options.targetField[0]] = d[options.code];
  1314. } else if (d.level === 3) {
  1315. if (options.targetField[1]) d[options.targetField[1]] = d[options.code];
  1316. } else if (d.level === 4) {
  1317. if (options.targetField[2]) d[options.targetField[2]] = d[options.code];
  1318. } else if (d.level > 4) {
  1319. if (options.targetField[3]) d[options.targetField[3]] = d[options.code];
  1320. }
  1321. }
  1322. },
  1323. fun(ctx, data, fieldsKey, options, csRela) {
  1324. if (!options || !options.table || !options.code || !options.targetField) return;
  1325. if (!data[options.table]) return;
  1326. if (options.type === '11') {
  1327. this._split11Std(data[options.table], options, ctx.helper);
  1328. } else if (/^18(-[0,1]){0,2}$/.test(options.type)) {
  1329. this._split18Std(data[options.table], options, ctx.helper);
  1330. } else {
  1331. this._splitDefault(data[options.table], options);
  1332. }
  1333. },
  1334. };
  1335. const stageSelectConverse = {
  1336. name: '交叉多期汇总数据',
  1337. hint: '需搭配 用户交互--单标段多期汇总选择 一起使用',
  1338. defaultSetting: {
  1339. table: ['mem_stage_sum_bills'],
  1340. },
  1341. _commonConverse(helper, data, stages) {
  1342. const result = [];
  1343. const reg = new RegExp('^s_[0-9]+_');
  1344. for (const s of stages) {
  1345. const curReg = new RegExp('^s_' + s + '_');
  1346. for (const [i, d] of data.entries()) {
  1347. const nd = { cross_index: i + 1 };
  1348. for (const prop in d) {
  1349. if (reg.test(prop)) {
  1350. if (curReg.test(prop)) {
  1351. nd[prop.replace(curReg, 's_')] = d[prop];
  1352. }
  1353. } else {
  1354. nd[prop] = d[prop];
  1355. }
  1356. }
  1357. result.push(nd);
  1358. }
  1359. }
  1360. return result;
  1361. },
  1362. fun(ctx, data, fieldsKey, options, csRela) {
  1363. if (!csRela.tplDefine) return;
  1364. const gsDefine = csRela.tplDefine.stage_select;
  1365. if (!gsDefine || !gsDefine.enable || !gsDefine.setting || gsDefine.setting === '') return;
  1366. const gsCustom = csRela.cDefine ? csRela.cDefine.stage_select : null;
  1367. if (gsCustom) {
  1368. for (const t of options.table) {
  1369. switch (t) {
  1370. case 'mem_stage_sum_bills':
  1371. case 'mem_stage_sum_pay':
  1372. case 'mem_union_data':
  1373. data[t] = this._commonConverse(ctx.helper, data[t], gsCustom.stages);
  1374. break;
  1375. }
  1376. }
  1377. } else {
  1378. console.log('gsCustom is null!');
  1379. }
  1380. },
  1381. };
  1382. const loadCooperationData = {
  1383. name: '加载协作数据',
  1384. hint: '须使用台账、计量审批流程、协作数据作为基础',
  1385. defaultSetting: {
  1386. table: 'mem_stage_im_zl',
  1387. co_sign: [0, 1, 2, 3],
  1388. },
  1389. _findSign(relaId, stageCooperation, auditor) {
  1390. if (!stageCooperation) return '';
  1391. if (relaId.length > 0) {
  1392. for (const id of relaId) {
  1393. const c = stageCooperation.find(x => { return x.ledger_id == id; });
  1394. if (c) return c.sign_path;
  1395. }
  1396. return '';
  1397. }
  1398. return '';
  1399. },
  1400. _completeSign(auditor) {
  1401. if (!auditor || !auditor.end_time) return '';
  1402. return auditor.sign_path ? 'public/upload/sign/' + auditor.sign_path : '';
  1403. },
  1404. _loadImCooperationData(ctx, data, options, csRela) {
  1405. let coSignOrder = [];
  1406. if (csRela && csRela.tplDefine && csRela.tplDefine.audit_select && csRela.cDefine && csRela.cDefine.audit_select) {
  1407. if (csRela.cDefine.audit_select) {
  1408. for (const asc of csRela.cDefine.audit_select) {
  1409. coSignOrder.push(asc.order);
  1410. }
  1411. }
  1412. } else {
  1413. coSignOrder = options.co_sign || [];
  1414. }
  1415. const stageCooperation = [];
  1416. let finish = true;
  1417. for (const sa of data.stage_audit) {
  1418. if (sa.end_time) stageCooperation.push(data.ledger_cooperation.filter(x => { return x.user_id === sa.aid; }));
  1419. if (finish && !sa.end_time) finish = false;
  1420. }
  1421. for (const d of data[options.table]) {
  1422. const bills = data.mem_stage_bills.find(x => { return x.id === d.lid; });
  1423. const relaId = bills ? bills.full_path.split('-').reverse() : [];
  1424. d.cooperation = [];
  1425. for (const [i, sa] of data.stage_audit.entries()) {
  1426. d.cooperation.push(this._findSign(relaId, stageCooperation[i], sa));
  1427. }
  1428. if (finish) {
  1429. for (const [i, cs] of coSignOrder.entries()) {
  1430. if (data.stage_audit[cs] && data.stage_audit[cs].end_time) {
  1431. d['co_sign' + (i + 1)] = d.cooperation[cs] || this._completeSign(data.stage_audit[cs]);
  1432. d['co_opinion' + (i + 1)] = data.stage_audit[cs].opinion || '';
  1433. d['co_time' + (i + 1)] = data.stage_audit[cs].end_time;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. },
  1439. fun(ctx, data, fieldsKey, options, csRela) {
  1440. if (!options || !options.table) return;
  1441. if (!data[options.table]) return;
  1442. if (!data.mem_stage_bills) return;
  1443. if (!data.stage_audit) return;
  1444. if (!data.ledger_cooperation) return;
  1445. if (['mem_stage_im_zl', 'mem_stage_im_tz'].indexOf(options.table) >= 0) { this._loadImCooperationData(ctx, data, options, csRela); }
  1446. },
  1447. };
  1448. const signSelect = {
  1449. name: '电子签名',
  1450. hint: '协作模式下,才需使用,其他情况勿需使用',
  1451. defaultSetting: {
  1452. table: 'mem_stage_im_zl',
  1453. },
  1454. _findSign(relaId, stageCooperation, auditor) {
  1455. if (!stageCooperation) return '';
  1456. if (relaId.length > 0) {
  1457. for (const id of relaId) {
  1458. const c = stageCooperation.find(x => { return x.ledger_id == id; });
  1459. if (c) return c.sign_path;
  1460. }
  1461. return '';
  1462. }
  1463. return '';
  1464. },
  1465. _loadImCooperationData(ctx, data, options, csRela) {
  1466. const stageCooperation = {};
  1467. for (const sa of data.stage_audit) {
  1468. if (sa.end_time) stageCooperation[sa.aid] = data.ledger_cooperation.filter(x => { return x.user_id === sa.aid; });
  1469. }
  1470. for (const d of data[options.table]) {
  1471. const bills = data.mem_stage_bills.find(x => { return x.id === d.lid; });
  1472. const relaId = bills ? bills.full_path.split('-').reverse() : [];
  1473. for (const ss of data.sign_select) {
  1474. if (!ss.co_sign) ss.co_sign = [];
  1475. ss.co_sign.push(this._findSign(relaId, stageCooperation[ss.id], ss) || 'public/upload/sign/' + ss.sign_path);
  1476. }
  1477. }
  1478. },
  1479. fun(ctx, data, fieldsKey, options, csRela) {
  1480. if (!options || !options.table) return;
  1481. if (!data[options.table]) return;
  1482. if (!data.mem_stage_bills) return;
  1483. if (!data.stage_audit) return;
  1484. if (!data.ledger_cooperation) return;
  1485. if (['mem_stage_im_zl', 'mem_stage_im_tz'].indexOf(options.table) >= 0) { this._loadImCooperationData(ctx, data, options, csRela); }
  1486. },
  1487. };
  1488. const getChangeLedger = {
  1489. name: '获取 工程变更台账表 数据',
  1490. hint: '须提供mem_stage_bills, mem_stage_change_bills作为数据支撑, 结果写入mem_stage_change_ledger',
  1491. defaultSetting: {
  1492. mergeName: true,
  1493. calc: '', // split: 均分
  1494. level: '2-leaf', // 空表示表示保留所有的项目节,2-leaf表示保留第2层和最底层项目节,默认为空
  1495. },
  1496. _getSource(ctx, bills, changeList) {
  1497. const result = [];
  1498. for (const b of bills) {
  1499. if (b.b_code) continue;
  1500. const l = {
  1501. id: b.id,
  1502. code: b.code, name: b.name, unit: b.unit,
  1503. ledger_id: b.ledger_id, ledger_pid: b.ledger_pid, level: b.level, full_path: b.full_path,
  1504. total_price: b.total_price, deal_tp: b.deal_tp,
  1505. contract_tp: b.contract_tp, qc_tp: b.qc_tp, gather_tp: b.gather_tp,
  1506. end_contract_tp: b.end_contract_tp, end_qc_tp: b.end_qc_tp, end_gather_tp: b.end_gather_tp,
  1507. };
  1508. result.push(l);
  1509. const childGcl = bills.filter(x => { return x.ledger_pid === b.ledger_id && x.b_code});
  1510. if (!childGcl || childGcl.length === 0) continue;
  1511. const gcl = bills.filter(x => { return x.full_path.indexOf(l.full_path + '-') === 0 && x.b_code; });
  1512. if (gcl.length === 0) continue;
  1513. const gclIds = gcl.map(x => { return x.id; });
  1514. const changes = changeList.filter(x => { return gclIds.indexOf(x.lid) >= 0; });
  1515. if (!changes || changes.length === 0) continue;
  1516. l.changes = [];
  1517. for (const c of changes) {
  1518. let mc = l.changes.find(x => { return x.cid === c.cid; });
  1519. if (!mc) {
  1520. mc = {
  1521. cid: c.cid,
  1522. c_code: c.c_code, c_name: c.c_name,
  1523. c_new_code: c.c_new_code, c_new_name: c.c_new_name,
  1524. c_content: c.c_content, c_basis: c.c_basis, c_cin_time: c.c_cin_time * 1000,
  1525. c_bills: [],
  1526. };
  1527. l.changes.push(mc);
  1528. }
  1529. mc.c_bills.push(c);
  1530. }
  1531. }
  1532. return result;
  1533. },
  1534. _filterChangeLedger(ctx, changeLedger, options) {
  1535. const result = [];
  1536. for (const f of changeLedger) {
  1537. const calc = changeLedger.filter(x => { return x.full_path.indexOf(f.full_path) === 0 && x.changes && x.changes.length > 0; });
  1538. if (!calc || calc.length === 0) continue;
  1539. if (options.level === '2-leaf')
  1540. if (f.level !== 2 && (!f.changes || f.changes.length === 0)) continue;
  1541. result.push({
  1542. code: f.code, name: f.name, unit: f.unit,
  1543. ledger_id: f.ledger_id, ledger_pid: f.ledger_pid, level: f.level, full_path: f.full_path,
  1544. total_price: f.total_price, deal_tp: f.deal_tp,
  1545. contract_tp: f.contract_tp, qc_tp: f.qc_tp, gather_tp: f.gather_tp,
  1546. end_contract_tp: f.end_contract_tp, end_qc_tp: f.end_qc_tp, end_gather_tp: f.end_gather_tp,
  1547. });
  1548. if (f.changes && f.changes.length > 0) {
  1549. for (const c of f.changes) {
  1550. const fc = {
  1551. c_code: c.c_code, c_name: c.c_name,
  1552. c_new_code: c.c_new_code, c_new_name: c.c_new_name,
  1553. c_content: c.c_content, c_basis: c.c_basis, c_cin_time: c.c_cin_time,
  1554. };
  1555. if (options.mergeName) fc.name = fc.c_name;
  1556. result.push(fc);
  1557. }
  1558. }
  1559. }
  1560. return result;
  1561. },
  1562. fun(ctx, data, fieldsKey, options, csRela) {
  1563. if (!options) options = {};
  1564. if (!data.mem_stage_bills) return;
  1565. if (!data.mem_stage_change_bills) return;
  1566. const changeLedger = this._getSource(ctx, data.mem_stage_bills, data.mem_stage_change_bills);
  1567. data.mem_stage_change_ledger = this._filterChangeLedger(ctx, changeLedger, options);
  1568. },
  1569. };
  1570. const treeFilter = {
  1571. name: '树结构数据过滤',
  1572. hint: '过滤时,当父项符合条件时,会自动包含子项',
  1573. defaultSetting: {
  1574. table: 'mem_stage_bills',
  1575. type: 'match/filter',
  1576. subType: 'all/posterity',
  1577. condition: [
  1578. { field: 'name', type: 'str', value: '建筑项目管理费', isPart: true },
  1579. ],
  1580. },
  1581. _checkPath(matchPath, full_path) {
  1582. for (const mp of matchPath) {
  1583. if (full_path.indexOf(mp) === 0) return true;
  1584. }
  1585. return false;
  1586. },
  1587. fun(ctx, data, fieldsKey, options, csRela) {
  1588. if (!options || !options.table || !options.condition || !options.type) return;
  1589. const fData = data[options.table],
  1590. self = this;
  1591. if (!fData || fData.length === 0) return;
  1592. if (!fData[0].full_path) return;
  1593. valueCheck.loadTypeFun(options.condition);
  1594. const matchPath = [];
  1595. for (const d of fData) {
  1596. if (this._checkPath(matchPath, d.full_path)) continue;
  1597. if (valueCheck.checkData(ctx, d, options.condition)) {
  1598. matchPath.push(d.full_path + (options.subType === 'posterity' ? '-' : ''));
  1599. }
  1600. }
  1601. data[options.table] = fData.filter(x => {
  1602. const match = self._checkPath(matchPath, x.full_path) && (options.subType === 'leaf' ? x.is_leaf : true);
  1603. return options.type === 'match' ? match : !match;
  1604. });
  1605. },
  1606. };
  1607. const gatherGcl2 = {
  1608. name: '工程量清单汇总2',
  1609. hint: '会生成新的工程量清单指标&相关项目节指标',
  1610. defaultSetting: {
  1611. billsTable: 'mem_stage_bills',
  1612. posTable: 'mem_stage_pos',
  1613. dealTable: 'deal_bills',
  1614. },
  1615. fun(ctx, data, fieldsKey, options, csRela) {
  1616. if (!options || !options.billsTable || !options.posTable) return;
  1617. const bills = data[options.billsTable];
  1618. if (!bills) return;
  1619. const pos = data[options.posTable];
  1620. if (!pos) return;
  1621. const deal = data[options.dealTable];
  1622. const gclGatherModel = require('./gcl_gather').gclGather;
  1623. const gatherUtil = new gclGatherModel(ctx);
  1624. gatherUtil.gather(bills, pos, deal);
  1625. data.mem_gcl_gather_bills = gatherUtil.gclList;
  1626. data.mem_gcl_gather_xmj = gatherUtil.leafXmjs;
  1627. }
  1628. };
  1629. const analysisObj = {
  1630. changeSort,
  1631. gatherGcl,
  1632. sortGcl,
  1633. gatherChapter,
  1634. join,
  1635. getChapterCode,
  1636. filter,
  1637. union,
  1638. gatherStagePay,
  1639. addSumChapter,
  1640. auditSelect,
  1641. datetimeFormat,
  1642. gatherSelectConverse,
  1643. stageSelectConverse,
  1644. sortPos,
  1645. unionPos,
  1646. splitXmjCode,
  1647. loadCooperationData,
  1648. getChangeLedger,
  1649. treeFilter,
  1650. gatherGcl2,
  1651. };
  1652. const analysisDefine = (function(obj) {
  1653. const result = [];
  1654. for (const o in obj) {
  1655. const analysis = obj[o];
  1656. if (analysis.name && analysis.fun) {
  1657. result.push({
  1658. name: analysis.name,
  1659. key: o,
  1660. hint: analysis.hint,
  1661. intro: analysis.intro,
  1662. url: '/help?m=report&s=analysis&d=' + o,
  1663. });
  1664. }
  1665. }
  1666. return result;
  1667. })(analysisObj);
  1668. module.exports = {
  1669. analysisObj,
  1670. analysisDefine,
  1671. };