rpt_data_analysis.js 69 KB

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