contract_tree.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. 'use strict';
  2. /**
  3. * Created by EllisRan on 2020/3/3.
  4. */
  5. const BaseService = require('../base/base_service');
  6. const contractConst = require('../const/contract');
  7. const rootId = -1;
  8. module.exports = app => {
  9. class ContractTree extends app.BaseBillsService {
  10. /**
  11. * 构造函数
  12. *
  13. * @param {Object} ctx - egg全局变量
  14. * @return {void}
  15. */
  16. constructor(ctx) {
  17. const setting = {
  18. spid: 'spid',
  19. mid: 'tid',
  20. type: 'contract_type',
  21. kid: 'contract_id',
  22. pid: 'contract_pid',
  23. order: 'order',
  24. level: 'level',
  25. isLeaf: 'is_leaf',
  26. fullPath: 'full_path',
  27. keyPre: 'contract_maxLid:', // 换个名称,防止缓存导致旧数据出问题
  28. uuid: true,
  29. };
  30. super(ctx, setting, 'pos');
  31. this.setting = setting;
  32. this.depart = 0;
  33. this.tableName = 'contract_tree';
  34. }
  35. _getStringOptions(options) {
  36. const optionStr = [];
  37. for (const key in options) {
  38. if (options.hasOwnProperty(key)) {
  39. optionStr.push(options[key]);
  40. }
  41. }
  42. return optionStr.join('&&');
  43. }
  44. /**
  45. * 获取最大节点id
  46. *
  47. * @param {Number} mid - master id
  48. * @return {Number}
  49. * @private
  50. */
  51. async _getMaxLid(options) {
  52. const cacheKey = this.setting.keyPre + this._getStringOptions(options);
  53. let maxId = parseInt(await this.cache.get(cacheKey)) || 0;
  54. if (!maxId) {
  55. const sql = 'SELECT Max(??) As max_id FROM ?? Where ' + this.ctx.helper._getOptionsSql(options);
  56. const sqlParam = [this.setting.kid, this.tableName];
  57. const queryResult = await this.db.queryOne(sql, sqlParam);
  58. if (maxId < queryResult.max_id || 0) {
  59. maxId = queryResult.max_id || 0;
  60. }
  61. const sql1 = 'SELECT Max(??) As max_id FROM ?? Where ' + this.ctx.helper._getOptionsSql(options);
  62. const sqlParam1 = [this.setting.kid, this.ctx.service.contract.tableName];
  63. const queryResult1 = await this.db.queryOne(sql1, sqlParam1);
  64. if (maxId < queryResult1.max_id || 0) {
  65. maxId = queryResult1.max_id || 0;
  66. }
  67. this.cache.set(cacheKey, maxId, 'EX', this.ctx.app.config.cacheTime);
  68. }
  69. return maxId;
  70. }
  71. _cacheMaxLid(options, maxId) {
  72. const cacheKey = this.setting.keyPre + this._getStringOptions(options);
  73. this.cache.set(cacheKey, maxId, 'EX', this.ctx.app.config.cacheTime);
  74. }
  75. /**
  76. * 更新order
  77. * @param {Number} mid - master id
  78. * @param {Number} pid - 父节点id
  79. * @param {Number} order - 开始更新的order
  80. * @param {Number} incre - 更新的增量
  81. * @returns {Promise<*>}
  82. * @private
  83. */
  84. async _updateChildrenOrder(options, pid, order, incre = 1, transaction = null) {
  85. const optionSql = this.ctx.helper._getOptionsSql(options);
  86. const sql = 'UPDATE ?? SET `' + this.setting.order + '` = `' + this.setting.order + '` ' + (incre > 0 ? '+' : '-') + Math.abs(incre) + ' WHERE ' + optionSql + ' AND `' + this.setting.order + '` >= ? AND ' + this.setting.pid + ' = ?';
  87. const sqlParam = [this.tableName, order, pid];
  88. const data = transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
  89. const sql1 = 'UPDATE ?? SET `' + this.setting.order + '` = `' + this.setting.order + '` ' + (incre > 0 ? '+' : '-') + Math.abs(incre) + ' WHERE ' + optionSql + ' AND `' + this.setting.order + '` >= ? AND ' + this.setting.pid + ' = ?';
  90. const sqlParam1 = [this.ctx.service.contract.tableName, order, pid];
  91. transaction ? await transaction.query(sql1, sqlParam1) : await this.db.query(sql1, sqlParam1);
  92. return data;
  93. }
  94. _getOptionsSql(options) {
  95. const optionSql = [];
  96. for (const key in options) {
  97. if (options.hasOwnProperty(key)) {
  98. optionSql.push(key + ' = ' + this.db.escape(options[key]));
  99. }
  100. }
  101. return optionSql.join(' AND ');
  102. }
  103. async insertTree(options, subInfo) {
  104. const hadTree = await this.getDataByCondition(options);
  105. if (!hadTree) {
  106. if (options.tid && !subInfo.spid) {
  107. throw '该标段未绑定项目';
  108. }
  109. const subProj = options.spid ? subInfo : await this.ctx.service.subProject.getDataById(subInfo.spid);
  110. if (subProj.std_id === 0) {
  111. throw '该项目未绑定概预算标准';
  112. }
  113. const stdInfo = await this.ctx.service.budgetStd.getDataById(subProj.std_id);
  114. if (!stdInfo) {
  115. throw '概预算标准不存在';
  116. } else if (options.spid && !stdInfo.ht_project_template_id) {
  117. throw '概预算标准未绑定项目合同模板';
  118. } else if (options.tid && !stdInfo.ht_tender_template_id) {
  119. throw '概预算标准未绑定标段合同模板';
  120. }
  121. const ht_template_id = options.spid ? stdInfo.ht_project_template_id.split(',')[0] : stdInfo.ht_tender_template_id.split(',')[0];
  122. const ht_template_datas = await this.ctx.service.tenderNodeTemplate.getData(ht_template_id);
  123. if (!ht_template_datas.length) throw '模板数据有误';
  124. const expensesDatas = [];
  125. const incomeDatas = [];
  126. for (const t of ht_template_datas) {
  127. const insertData = {
  128. spid: options.spid || null,
  129. tid: options.tid || null,
  130. contract_id: t.template_id,
  131. contract_pid: t.pid,
  132. level: t.level,
  133. order: t.order,
  134. full_path: t.full_path,
  135. is_leaf: t.is_leaf,
  136. code: t.code,
  137. name: t.name,
  138. unit: t.unit,
  139. };
  140. const expensesData = this.ctx.helper._.cloneDeep(insertData);
  141. expensesData.id = this.uuid.v4();
  142. expensesData.contract_type = contractConst.type.expenses;
  143. expensesDatas.push(expensesData);
  144. const incomeData = this.ctx.helper._.cloneDeep(insertData);
  145. incomeData.id = this.uuid.v4();
  146. incomeData.contract_type = contractConst.type.income;
  147. incomeDatas.push(incomeData);
  148. }
  149. await this.db.insert(this.tableName, [...expensesDatas, ...incomeDatas]);
  150. }
  151. }
  152. /**
  153. * 提交数据 - 响应计算(增量方式计算)
  154. * @param {Number} tenderId
  155. * @param {Object} data
  156. * @return {Promise<*>}
  157. */
  158. async updateCalc(options, data) {
  159. const helper = this.ctx.helper;
  160. if (!data) {
  161. throw '提交数据错误';
  162. }
  163. const datas = data instanceof Array ? data : [data];
  164. const ids = [];
  165. for (const row of datas) {
  166. ids.push(row.id);
  167. }
  168. const transaction = await this.db.beginTransaction();
  169. try {
  170. const updateDatas = [];
  171. for (const row of datas) {
  172. const updateNode = await this.getDataById(row.id);
  173. if (!updateNode) {
  174. throw '提交数据错误';
  175. }
  176. const updateData = this._filterUpdateInvalidField(updateNode.id, row);
  177. // 如非子节点,需要更新底下所有已选清单的分部分项等数据
  178. updateDatas.push(updateData);
  179. }
  180. if (updateDatas.length > 0) await transaction.updateRows(this.tableName, updateDatas);
  181. await transaction.commit();
  182. } catch (err) {
  183. await transaction.rollback();
  184. throw err;
  185. }
  186. return { update: await this.getDataById(ids) };
  187. }
  188. async getDataByKid(options, kid) {
  189. const condition = { ...options };
  190. condition[this.setting.kid] = kid;
  191. return await this.getDataByCondition(condition) || await this.ctx.service.contract.getDataByCondition(condition);
  192. }
  193. async getDataByKidAndCount(options, kid, count) {
  194. if (kid <= 0) return [];
  195. const select = await this.getDataByKid(options, kid);
  196. if (!select) throw '数据错误';
  197. if (count > 1) {
  198. const selects = await this.getNextsData(options, select[this.setting.pid], select[this.setting.order] - 1);
  199. if (selects.length < count) throw '数据错误';
  200. return selects.slice(0, count);
  201. } else {
  202. return [select];
  203. }
  204. }
  205. /**
  206. * 根据 父节点id 和 节点排序order 获取数据
  207. *
  208. * @param {Number} mid - master id
  209. * @param {Number} pid - 父节点id
  210. * @param {Number|Array} order - 排序
  211. * @return {Object|Array} - 查询结果
  212. */
  213. async getDataByParentAndOrder(options, pid, order) {
  214. const condition = { ...options };
  215. condition[this.setting.pid] = pid;
  216. condition[this.setting.order] = order;
  217. const result = await this.db.select(this.tableName, {
  218. where: condition,
  219. });
  220. const result1 = await this.db.select(this.ctx.service.contract.tableName, {
  221. where: condition,
  222. });
  223. // data和data1合并且按order排序
  224. const resultData = result.concat(result1).sort((a, b) => a.order - b.order);
  225. return order instanceof Array ? resultData : (resultData.length > 0 ? resultData[0] : null);
  226. }
  227. async addNodeBatch(options, kid, count = 1) {
  228. if (!options[this.setting.type]) throw '参数有误';
  229. const select = kid ? await this.getDataByKid(options, kid) : null;
  230. if (kid && !select) throw '新增节点数据错误';
  231. const transaction = await this.db.beginTransaction();
  232. try {
  233. // 判断select的父节点是否是变更新增的,如果是则修改自己的表就行了,否则修改2个ledger,changeLedger表
  234. if (select) await this._updateChildrenOrder(options, select[this.setting.pid], select[this.setting.order] + 1, count, transaction);
  235. const newDatas = [];
  236. const maxId = await this._getMaxLid(options);
  237. for (let i = 1; i < count + 1; i++) {
  238. const newData = [];
  239. if (this.setting.uuid) newData.id = this.uuid.v4();
  240. newData[this.setting.kid] = maxId + i;
  241. newData[this.setting.pid] = select ? select[this.setting.pid] : rootId;
  242. newData[this.setting.spid] = options.spid || null;
  243. newData[this.setting.type] = options[this.setting.type];
  244. newData[this.setting.mid] = options.tid || null;
  245. newData[this.setting.level] = select ? select[this.setting.level] : 1;
  246. newData[this.setting.order] = select ? select[this.setting.order] + i : i;
  247. newData[this.setting.fullPath] = newData[this.setting.level] > 1
  248. ? select[this.setting.fullPath].replace('-' + select[this.setting.kid], '-' + newData[this.setting.kid])
  249. : newData[this.setting.kid] + '';
  250. newData[this.setting.isLeaf] = true;
  251. newDatas.push(newData);
  252. }
  253. const insertResult = await transaction.insert(this.tableName, newDatas);
  254. this._cacheMaxLid(options, maxId + count);
  255. if (insertResult.affectedRows !== count) throw '新增节点数据错误';
  256. await transaction.commit();
  257. } catch (err) {
  258. await transaction.rollback();
  259. throw err;
  260. }
  261. if (select) {
  262. let createData = await this.getChildBetween(options, select[this.setting.pid], select[this.setting.order], select[this.setting.order] + count + 1);
  263. let updateData = await this.getNextsData(options, select[this.setting.pid], select[this.setting.order] + count);
  264. return { create: createData, update: updateData };
  265. } else {
  266. const createData = await this.getChildBetween(options, -1, 0, count + 1);
  267. return { create: createData };
  268. }
  269. }
  270. async addChildNode(options, kid, count = 1) {
  271. if (!options[this.setting.type]) throw '参数有误';
  272. const select = kid ? await this.getDataByKid(options, kid) : null;
  273. if (!select) throw '新增子节点数据错误';
  274. if (select && select.c_code) throw '合同无法新增子节点';
  275. const transaction = await this.db.beginTransaction();
  276. try {
  277. // 判断select的父节点是否是变更新增的,如果是则修改自己的表就行了,否则修改2个ledger,changeLedger表
  278. // if (select) await this._updateChildrenOrder(options, select[this.setting.pid], select[this.setting.order] + 1, count, transaction);
  279. const maxOrder = await this.ctx.service.contract.getMaxOrder(options, select[this.setting.kid], transaction);
  280. const newDatas = [];
  281. const maxId = await this._getMaxLid(options);
  282. for (let i = 0; i < count; i++) {
  283. const newData = [];
  284. if (this.setting.uuid) newData.id = this.uuid.v4();
  285. newData[this.setting.kid] = maxId + i;
  286. newData[this.setting.pid] = select[this.setting.kid];
  287. newData[this.setting.spid] = options.spid || null;
  288. newData[this.setting.type] = options[this.setting.type];
  289. newData[this.setting.mid] = options.tid || null;
  290. newData[this.setting.level] = select[this.setting.level] + 1;
  291. newData[this.setting.order] = maxOrder + i;
  292. newData[this.setting.fullPath] = select[this.setting.fullPath] + '-' + newData[this.setting.kid];
  293. newData[this.setting.isLeaf] = true;
  294. newDatas.push(newData);
  295. }
  296. const insertResult = await transaction.insert(this.tableName, newDatas);
  297. this._cacheMaxLid(options, maxId + count);
  298. if (insertResult.affectedRows !== count) throw '新增子节点数据错误';
  299. if (select[this.setting.isLeaf]) {
  300. select.is_leaf = 0;
  301. await transaction.update(this.tableName, { id: select.id, is_leaf: 0 });
  302. }
  303. await transaction.commit();
  304. } catch (err) {
  305. await transaction.rollback();
  306. throw err;
  307. }
  308. let createData = await this.getLastChildData(options, select[this.setting.kid]);
  309. let updateData = select;
  310. return { create: createData, update: updateData };
  311. }
  312. /**
  313. * tenderId标段中, 删除选中节点及其子节点
  314. *
  315. * @param {Number} tenderId - 标段id
  316. * @param {Number} selectId - 选中节点id
  317. * @return {Array} - 被删除的数据
  318. */
  319. async deleteNode(options, kid) {
  320. if (kid <= 0) return [];
  321. const select = await this.getDataByKid(options, kid);
  322. if (!select) throw '删除节点数据错误';
  323. const parent = await this.getDataByKid(options, select[this.setting.pid]);
  324. // 获取将要被删除的数据
  325. const deleteData = await this.getDataByFullPath(options, select[this.setting.fullPath] + '-%');
  326. deleteData.unshift(select);
  327. if (deleteData.length === 0) throw '删除节点数据错误';
  328. const transaction = await this.db.beginTransaction();
  329. try {
  330. // 删除
  331. if (select.c_code) {
  332. if (select.uid !== this.ctx.session.sessionUser.accountId && !this.ctx.session.sessionUser.is_admin) throw '当前合同无权删除';
  333. const contractPays = await this.ctx.service.contractPay.getDataByCondition({ cid: select.id });
  334. if (contractPays) throw '还存在合同支付项,无法删除';
  335. await transaction.delete(this.ctx.service.contract.tableName, { id: select.id });
  336. const attList = await this.ctx.service.contractAtt.getAllDataByCondition({ where: { cid: select.id } });
  337. await this.ctx.helper.delFiles(attList);
  338. await transaction.delete(this.ctx.service.contractAtt.tableName, { cid: select.id });
  339. } else {
  340. await transaction.delete(this.tableName, { id: select.id });
  341. const delOptions = this._.cloneDeep(options);
  342. delOptions.contract_id = this._.map(deleteData, 'contract_id');
  343. await transaction.delete(this.ctx.service.contractTreeAudit.tableName, delOptions);
  344. const contracts = this.ctx.helper._.filter(deleteData, function (item) {
  345. return item.c_code;
  346. });
  347. if (contracts.length > 0) {
  348. const contractUids = this.ctx.helper._.uniq(this.ctx.helper._.map(contracts, 'uid'));
  349. if (contractUids.length > 1 || !(contractUids[0] === this.ctx.session.sessionUser.accountId || this.ctx.session.sessionUser.is_admin)) throw '存在合同你无权删除';
  350. const contractPays = await transaction.select(this.ctx.service.contractPay.tableName, { where: { cid: this.ctx.helper._.map(contracts, 'id') } });
  351. if (contractPays.length > 0) throw '还存在合同支付项,无法删除';
  352. const attList = await this.ctx.service.contractAtt.getAllDataByCondition({ where: { cid: this.ctx.helper._.map(contracts, 'id') } });
  353. await this.ctx.helper.delFiles(attList);
  354. await transaction.delete(this.ctx.service.contractAtt.tableName, { cid: this.ctx.helper._.map(contracts, 'id') });
  355. }
  356. const operate = await this._deletePosterity(options, select, transaction);
  357. }
  358. // 选中节点--父节点 只有一个子节点时,应升级isLeaf
  359. if (parent) {
  360. const condition = { ...options };
  361. condition[this.setting.pid] = select[this.setting.pid];
  362. const count = await this.db.count(this.tableName, condition);
  363. const count1 = await this.db.count(this.ctx.service.contract.tableName, condition);
  364. const sum = count + count1;
  365. if (sum === 1) {
  366. const updateParent = {id: parent.id };
  367. updateParent[this.setting.isLeaf] = true;
  368. await transaction.update(this.tableName, updateParent);
  369. }
  370. }
  371. // 选中节点--全部后节点 order--
  372. await this._updateChildrenOrder(options, select[this.setting.pid], select[this.setting.order] + 1, -1, transaction);
  373. await transaction.commit();
  374. } catch (err) {
  375. await transaction.rollback();
  376. throw err;
  377. }
  378. // 查询结果
  379. const updateData = await this.getNextsData(options, select[this.setting.pid], select[this.setting.order] - 1);
  380. if (parent) {
  381. const updateData1 = await this.getDataByKid(options, select[this.setting.pid]);
  382. if (updateData1[this.setting.isLeaf]) {
  383. updateData.push(updateData1);
  384. }
  385. }
  386. return { delete: deleteData, update: updateData };
  387. }
  388. async deleteNodes(options, kid, count) {
  389. const _ = this.ctx.helper._;
  390. if ((kid <= 0) || (count <= 0)) return [];
  391. const selects = await this.getDataByKidAndCount(options, kid, count);
  392. const first = selects[0];
  393. const parent = await this.getDataByKid(options, first[this.setting.pid]);
  394. const condition = { ...options };
  395. condition[this.setting.pid] = parent[this.setting.kid];
  396. const childCount1 = parent ? await this.count(condition) : -1;
  397. const childCount2 = parent ? await this.db.count(this.ctx.service.contract.tableName, condition) : -1;
  398. const childCount = childCount1 + childCount2;
  399. let deleteData = [];
  400. for (const s of selects) {
  401. deleteData = deleteData.concat(await this.getDataByFullPath(options, s[this.setting.fullPath] + '-%'));
  402. deleteData.push(s);
  403. }
  404. const transaction = await this.db.beginTransaction();
  405. try {
  406. // 删除
  407. for (const s of selects) {
  408. if (s.c_code) {
  409. if (s.uid !== this.ctx.session.sessionUser.accountId && !this.ctx.session.sessionUser.is_admin) throw '存在合同你无权删除';
  410. const contractPays = await this.ctx.service.contractPay.getDataByCondition({ cid: s.id });
  411. if (contractPays) throw '部分合同还存在合同支付项,无法删除';
  412. await transaction.delete(this.ctx.service.contract.tableName, { id: s.id });
  413. const attList = await this.ctx.service.contractAtt.getAllDataByCondition({ where: { cid: s.id } });
  414. await this.ctx.helper.delFiles(attList);
  415. await transaction.delete(this.ctx.service.contractAtt.tableName, { cid: s.id });
  416. } else {
  417. await transaction.delete(this.tableName, { id: s.id });
  418. const contracts = _.filter(deleteData, function (item) {
  419. return item.c_code && _.includes(s.full_path, item.full_path);
  420. });
  421. if (contracts.length > 0) {
  422. const contractUids = _.uniq(_.map(contracts, 'uid'));
  423. if (contractUids.length > 1 || !(contractUids[0] === this.ctx.session.sessionUser.accountId || this.ctx.session.sessionUser.is_admin)) throw '存在合同你无权删除';
  424. const contractPays = await transaction.select(this.ctx.service.contractPay.tableName, { where: { cid: _.map(contracts, 'id') } });
  425. if (contractPays.length > 0) throw '还存在合同支付项,无法删除';
  426. const attList = await this.ctx.service.contractAtt.getAllDataByCondition({ where: { cid: _.map(contracts, 'id') } });
  427. await this.ctx.helper.delFiles(attList);
  428. await transaction.delete(this.ctx.service.contractAtt.tableName, { cid: _.map(contracts, 'id') });
  429. }
  430. }
  431. const operate = await this._deletePosterity(options, s, transaction);
  432. }
  433. // 选中节点--父节点 只有一个子节点时,应升级isLeaf
  434. if (parent && childCount === count) {
  435. const updateParent = {id: parent.id };
  436. updateParent[this.setting.isLeaf] = true;
  437. await transaction.update(this.tableName, updateParent);
  438. }
  439. // 选中节点--全部后节点 order--
  440. await this._updateChildrenOrder(options, first[this.setting.pid], first[this.setting.order] + count, -count, transaction);
  441. const delOptions = this._.cloneDeep(options);
  442. delOptions.contract_id = this._.map(deleteData, 'contract_id');
  443. await transaction.delete(this.ctx.service.contractTreeAudit.tableName, delOptions);
  444. await transaction.commit();
  445. } catch (err) {
  446. await transaction.rollback();
  447. throw err;
  448. }
  449. const updateData = await this.getNextsData(options, first[this.setting.pid], first[this.setting.order] - 1);
  450. if (parent && childCount === count) {
  451. const updateData1 = await this.getDataByKid(options, parent[this.setting.kid]);
  452. updateData.push(updateData1);
  453. }
  454. return { delete: deleteData, update: updateData };
  455. }
  456. async delete(options, kid, count = null) {
  457. if (count && count > 1) {
  458. return await this.deleteNodes(options, kid, count);
  459. } else {
  460. return await this.deleteNode(options, kid);
  461. }
  462. }
  463. /**
  464. * 上移节点
  465. *
  466. * @param {Number} mid - master id
  467. * @param {Number} kid - 选中节点id
  468. * @return {Array} - 发生改变的数据
  469. */
  470. async upMoveNode(options, kid, count) {
  471. if (!count) count = 1;
  472. if (!kid || (kid <= 0)) return null;
  473. const selects = await this.getDataByKidAndCount(options, kid, count);
  474. if (selects.length !== count) throw '上移节点数据错误';
  475. const first = selects[0];
  476. const pre = await this.getDataByParentAndOrder(options, first[this.setting.pid], first[this.setting.order] - 1);
  477. if (!pre) throw '节点不可上移';
  478. const order = [];
  479. const transaction = await this.db.beginTransaction();
  480. try {
  481. for (const s of selects) {
  482. const sData = { id: s.id };
  483. sData[this.setting.order] = s[this.setting.order] - 1;
  484. !s.c_code ? await transaction.update(this.tableName, sData) : await transaction.update(this.ctx.service.contract.tableName, sData);
  485. order.push(s[this.setting.order] - 1);
  486. }
  487. const pData = { id: pre.id };
  488. pData[this.setting.order] = pre[this.setting.order] + count;
  489. !pre.c_code ? await transaction.update(this.tableName, pData) : await transaction.update(this.ctx.service.contract.tableName, pData);
  490. order.push(pre[this.setting.order] + count);
  491. await transaction.commit();
  492. } catch (err) {
  493. await transaction.rollback();
  494. throw err;
  495. }
  496. const resultData = await this.getDataByParentAndOrder(options, first[this.setting.pid], order);
  497. return { update: resultData };
  498. }
  499. /**
  500. * 下移节点
  501. *
  502. * @param {Number} mid - master id
  503. * @param {Number} kid - 选中节点id
  504. * @return {Array} - 发生改变的数据
  505. */
  506. async downMoveNode(options, kid, count) {
  507. if (!count) count = 1;
  508. if (!kid || (kid <= 0)) return null;
  509. const selects = await this.getDataByKidAndCount(options, kid, count);
  510. if (selects.length !== count) {
  511. throw '下移节点数据错误';
  512. }
  513. const last = selects[count - 1];
  514. const next = await this.getDataByParentAndOrder(options, last[this.setting.pid], last[this.setting.order] + 1);
  515. if (!next) {
  516. throw '节点不可下移';
  517. }
  518. const order = [];
  519. const transaction = await this.db.beginTransaction();
  520. try {
  521. for (const s of selects) {
  522. const sData = { id: s.id };
  523. sData[this.setting.order] = s[this.setting.order] + 1;
  524. !s.c_code ? await transaction.update(this.tableName, sData) : await transaction.update(this.ctx.service.contract.tableName, sData);
  525. order.push(s[this.setting.order] + 1);
  526. }
  527. const nData = { id: next.id };
  528. nData[this.setting.order] = next[this.setting.order] - count;
  529. !next.c_code ? await transaction.update(this.tableName, nData) : await transaction.update(this.ctx.service.contract.tableName, nData);
  530. order.push(next[this.setting.order] - count);
  531. await transaction.commit();
  532. } catch (err) {
  533. await transaction.rollback();
  534. throw err;
  535. }
  536. const resultData = await this.getDataByParentAndOrder(options, last[this.setting.pid], order);
  537. return { update: resultData };
  538. }
  539. /**
  540. * 升级节点
  541. *
  542. * @param {Number} tenderId - 标段id
  543. * @param {Number} selectId - 选中节点id
  544. * @return {Array} - 发生改变的数据
  545. */
  546. async upLevelNode(options, kid, count) {
  547. if (!count) count = 1;
  548. const selects = await this.getDataByKidAndCount(options, kid, count);
  549. if (selects.length !== count) throw '升级节点数据错误';
  550. const first = selects[0], last = selects[count - 1];
  551. const parent = await this.getDataByKid(options, first[this.setting.pid]);
  552. if (!parent) throw '升级节点数据错误';
  553. const newPath = [];
  554. const transaction = await this.db.beginTransaction();
  555. try {
  556. // 选中节点--父节点 选中节点为firstChild时,修改isLeaf
  557. if (first[this.setting.order] === 1) {
  558. const updateParentData = { id: parent.id };
  559. updateParentData[this.setting.isLeaf] = true;
  560. await transaction.update(this.tableName, updateParentData);
  561. }
  562. // 选中节点--父节点--全部后兄弟节点 order+1
  563. await this._updateChildrenOrder(options, parent[this.setting.pid], parent[this.setting.order] + 1, count, transaction);
  564. for (const [i, s] of selects.entries()) {
  565. // 选中节点 修改pid, order, fullPath, level, isLeaf, 清空计算项
  566. const updateData = { id: s.id };
  567. updateData[this.setting.pid] = parent[this.setting.pid];
  568. updateData[this.setting.order] = parent[this.setting.order] + i + 1;
  569. updateData[this.setting.level] = s[this.setting.level] - 1;
  570. updateData[this.setting.fullPath] = s[this.setting.fullPath].replace(`-${s[this.setting.pid]}-`, '-');
  571. newPath.push(updateData[this.setting.fullPath]);
  572. if (s[this.setting.isLeaf] && s.id === last.id) {
  573. const nexts = await this.getNextsData(options, parent[this.setting.kid], last[this.setting.order]);
  574. if (nexts.length > 0) {
  575. updateData[this.setting.isLeaf] = false;
  576. }
  577. }
  578. await transaction.update(this.tableName, updateData);
  579. // 选中节点--全部子节点(含孙) level-1, fullPath变更
  580. await this._syncUplevelChildren(options, s, transaction);
  581. }
  582. // 选中节点--全部后兄弟节点 收编为子节点 修改pid, order, fullPath
  583. await this._syncUpLevelNexts(options, last, transaction);
  584. await transaction.commit();
  585. } catch (err) {
  586. await transaction.rollback();
  587. throw err;
  588. }
  589. // 查询修改的数据
  590. let updateData = await this.getNextsData(options, parent[this.setting.pid], parent[this.setting.order] - 1);
  591. for (const path of newPath) {
  592. const children = await this.getDataByFullPath(options, path + '-%');
  593. updateData = updateData.concat(children);
  594. }
  595. return { update: updateData };
  596. }
  597. /**
  598. * 降级节点
  599. *
  600. * @param {Number} tenderId - 标段id
  601. * @param {Number} selectId - 选中节点id
  602. * @return {Array} - 发生改变的数据
  603. */
  604. async downLevelNode(options, kid, count) {
  605. if (!count) count = 1;
  606. const selects = await this.getDataByKidAndCount(options, kid, count);
  607. if (!selects) throw '降级节点数据错误';
  608. const first = selects[0], last = selects[count - 1];
  609. const pre = await this.getDataByParentAndOrder(options, first[this.setting.pid], first[this.setting.order] - 1);
  610. if (!pre) throw '节点不可降级';
  611. const preLastChild = await this.getLastChildData(options, pre[this.setting.kid]);
  612. const newPath = [];
  613. const transaction = await this.db.beginTransaction();
  614. try {
  615. // 选中节点--全部后节点 order--
  616. await this._updateChildrenOrder(options, first[this.setting.pid], last[this.setting.order] + 1, -count, transaction);
  617. for (const [i, s] of selects.entries()) {
  618. // 选中节点 修改pid, level, order, fullPath
  619. const updateData = { id: s.id };
  620. updateData[this.setting.pid] = pre[this.setting.kid];
  621. updateData[this.setting.order] = preLastChild ? preLastChild[this.setting.order] + i + 1 : i + 1;
  622. updateData[this.setting.level] = s[this.setting.level] + 1;
  623. if (s[this.setting.level] === 1) {
  624. updateData[this.setting.fullPath] = pre[this.setting.kid] + '-' + s[this.setting.kid];
  625. } else {
  626. const index = s[this.setting.fullPath].lastIndexOf(s[this.setting.kid]);
  627. updateData[this.setting.fullPath] = s[this.setting.fullPath].substring(0, index-1) + '-' + pre[this.setting.kid] + '-' + s[this.setting.kid];
  628. }
  629. newPath.push(updateData[this.setting.fullPath]);
  630. await transaction.update(this.tableName, updateData);
  631. // 选中节点--全部子节点(含孙) level++, fullPath
  632. await this._syncDownlevelChildren(options, s, updateData[this.setting.fullPath], transaction);
  633. }
  634. // 选中节点--前兄弟节点 isLeaf应为false, 清空计算相关字段
  635. const updateData2 = { id: pre.id };
  636. updateData2[this.setting.isLeaf] = false;
  637. await transaction.update(this.tableName, updateData2);
  638. await transaction.commit();
  639. } catch (err) {
  640. await transaction.rollback();
  641. throw err;
  642. }
  643. // 查询修改的数据
  644. let updateData = await this.getNextsData(options, pre[this.setting.pid], pre[this.setting.order] - 1);
  645. // 选中节点及子节点
  646. for (const p of newPath) {
  647. updateData = updateData.concat(await this.getDataByFullPath(options, p + '-%'));
  648. }
  649. updateData = updateData.concat(await this.getDataById(selects.map(x => { return x.id; })));
  650. // 选中节点--原前兄弟节点&全部后兄弟节点
  651. return { update: updateData };
  652. }
  653. async pasteBlockData(options, kid, pasteData, defaultData) {
  654. if (!options[this.setting.type]) throw '参数有误';
  655. if (!pasteData || pasteData.length <= 0) throw '复制数据错误';
  656. for (const pd of pasteData) {
  657. if (!pd || pd.length <= 0) throw '复制数据错误';
  658. pd.sort(function (x, y) {
  659. return x.level - y.level
  660. });
  661. if (pd[0].contract_pid !== pasteData[0][0].contract_pid) throw '复制数据错误:仅可操作同层节点';
  662. }
  663. const selectData = await this.getDataByKid(options, kid);
  664. if (!selectData) throw '粘贴数据错误';
  665. const newParentPath = selectData.full_path.replace(selectData.contract_id, '');
  666. const pasteBillsData = [];
  667. let maxId = await this._getMaxLid(options);
  668. for (const [i, pd] of pasteData.entries()) {
  669. for (const d of pd) {
  670. d.children = pd.filter(function (x) {
  671. return x.contract_pid === d.contract_id;
  672. });
  673. }
  674. const pbd = [];
  675. for (const [j, d] of pd.entries()) {
  676. const newBills = {
  677. id: this.uuid.v4(),
  678. spid: options.spid || null,
  679. tid: options.tid || null,
  680. contract_type: options.contract_type,
  681. contract_id: maxId + j + 1,
  682. contract_pid: j === 0 ? selectData.contract_pid : d.contract_pid,
  683. level: d.level + selectData.level - pd[0].level,
  684. order: j === 0 ? selectData.order + i + 1 : d.order,
  685. is_leaf: d.is_leaf,
  686. code: d.code,
  687. name: d.name,
  688. remark: d.remark,
  689. };
  690. for (const c of d.children) {
  691. c.contract_pid = newBills.contract_id;
  692. }
  693. pbd.push(newBills);
  694. }
  695. for (const d of pbd) {
  696. const parent = pbd.find(function (x) {
  697. return x.contract_id === d.contract_pid;
  698. });
  699. d.full_path = parent
  700. ? parent.full_path + '-' + d.contract_id
  701. : newParentPath + d.contract_id;
  702. if (defaultData) this.ctx.helper._.assignIn(pbd, defaultData);
  703. pasteBillsData.push(d);
  704. }
  705. maxId = maxId + pbd.length;
  706. }
  707. const transaction = await this.db.beginTransaction();
  708. try {
  709. // 选中节点的所有后兄弟节点,order+粘贴节点个数
  710. await this._updateChildrenOrder(options, selectData.ledger_pid, selectData.order + 1, pasteData.length, transaction);
  711. // 数据库创建新增节点数据
  712. if (pasteBillsData.length > 0) {
  713. const newData = await transaction.insert(this.tableName, pasteBillsData);
  714. }
  715. this._cacheMaxLid(options, maxId);
  716. await transaction.commit();
  717. } catch (err) {
  718. await transaction.rollback();
  719. throw err;
  720. }
  721. // 查询应返回的结果
  722. const updateData = await this.getNextsData(options, selectData.contract_pid, selectData.order + pasteData.length);
  723. return {
  724. ledger: { create: pasteBillsData, update: updateData },
  725. };
  726. }
  727. /**
  728. * 删除节点
  729. * @param {Number} tenderId - 标段id
  730. * @param {Object} deleteData - 删除节点数据
  731. * @return {Promise<*>}
  732. * @private
  733. */
  734. async _deletePosterity(options, node, transaction = null) {
  735. const sql = 'DELETE FROM ?? WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.fullPath + ' LIKE ?';
  736. const sqlParam = [this.tableName, node[this.setting.fullPath] + '-%'];
  737. const result = transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam)
  738. const sql1 = 'DELETE FROM ?? WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.fullPath + ' LIKE ?';
  739. const sqlParam1 = [this.ctx.service.contract.tableName, node[this.setting.fullPath] + '-%'];
  740. const result1 = transaction ? await transaction.query(sql1, sqlParam1) : await this.db.query(sql1, sqlParam1)
  741. return result;
  742. }
  743. /**
  744. * 根据fullPath获取数据 fullPath Like ‘1.2.3%’(传参fullPath = '1.2.3%')
  745. * @param {Number} tenderId - 标段id
  746. * @param {String} fullPath - 路径
  747. * @return {Promise<void>}
  748. */
  749. async getDataByFullPath(options, fullPath) {
  750. const sql = 'SELECT * FROM ?? WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.fullPath + ' LIKE ?';
  751. const sqlParam = [this.tableName, fullPath];
  752. const resultData = await this.db.query(sql, sqlParam);
  753. const sql1 = 'SELECT * FROM ?? WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.fullPath + ' LIKE ?';
  754. const sqlParam1 = [this.ctx.service.contract.tableName, fullPath];
  755. const resultData1 = await this.db.query(sql1, sqlParam1);
  756. return resultData.concat(resultData1).sort((a, b) => a.order - b.order);
  757. }
  758. async getChildBetween(options, pid, order1, order2) {
  759. const sql = 'SELECT * FROM ?? WHERE '+ this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? AND `order` > ? AND `order` < ? ORDER BY `order` ASC';
  760. const sqlParam = [this.tableName, pid, order1, order2];
  761. const data = await this.db.query(sql, sqlParam);
  762. const sql1 = 'SELECT * FROM ?? WHERE '+ this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? AND `order` > ? AND `order` < ? ORDER BY `order` ASC';
  763. const sqlParam1 = [this.ctx.service.contract.tableName, pid, order1, order2];
  764. const data1 = await this.db.query(sql1, sqlParam1);
  765. const resultData = data.concat(data1).sort((a, b) => a.order - b.order);
  766. return resultData;
  767. }
  768. /**
  769. * 根据 父节点ID 和 节点排序order 获取全部后节点数据
  770. * @param {Number} mid - master id
  771. * @param {Number} pid - 父节点id
  772. * @param {Number} order - 排序
  773. * @return {Array}
  774. */
  775. async getNextsData(options, pid, order) {
  776. const sql = 'SELECT * FROM ?? WHERE '+ this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? AND `order` > ? ORDER BY `order` ASC';
  777. const sqlParam = [this.tableName, pid, order];
  778. const data = await this.db.query(sql, sqlParam);
  779. const sql1 = 'SELECT * FROM ?? WHERE '+ this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? AND `order` > ? ORDER BY `order` ASC';
  780. const sqlParam1 = [this.ctx.service.contract.tableName, pid, order];
  781. const data1 = await this.db.query(sql1, sqlParam1);
  782. // data和data1合并且按order排序
  783. const resultData = data.concat(data1).sort((a, b) => a.order - b.order);
  784. return resultData;
  785. }
  786. /**
  787. * 获取最末的子节点
  788. * @param {Number} mid - masterId
  789. * @param {Number} pid - 父节点id
  790. * @return {Object}
  791. */
  792. async getLastChildData(options, pid, transaction = null) {
  793. const sql = 'SELECT * FROM ?? WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? ORDER BY `order` DESC';
  794. const sqlParam = [this.tableName, pid];
  795. const resultData = await this.db.queryOne(sql, sqlParam);
  796. const sql1 = 'SELECT * FROM ?? WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? ORDER BY `order` DESC';
  797. const sqlParam1 = [this.ctx.service.contract.tableName, pid];
  798. const resultData1 = await this.db.queryOne(sql1, sqlParam1);
  799. // 比较两个结果,返回order大的
  800. if (resultData && resultData1) {
  801. return resultData.order > resultData1.order ? resultData : resultData1;
  802. } else {
  803. return resultData || resultData1;
  804. }
  805. }
  806. /**
  807. * 选中节点的后兄弟节点,全部变为当前节点的子节点
  808. * @param {Object} selectData - 选中节点
  809. * @return {Object}
  810. * @private
  811. */
  812. async _syncUpLevelNexts(options, select, transaction = null) {
  813. // 查询selectData的lastChild
  814. const lastChild = await this.getLastChildData(options, select[this.setting.kid]);
  815. const nexts = await this.getNextsData(options, select[this.setting.pid], select[this.setting.order]);
  816. if (nexts && nexts.length > 0) {
  817. // 修改nextsData pid, 排序
  818. // this.initSqlBuilder();
  819. // this.sqlBuilder.setUpdateData(this.setting.pid, {
  820. // value: select[this.setting.kid],
  821. // });
  822. // const orderInc = lastChild ? lastChild[this.setting.order] - select[this.setting.order] : - select[this.setting.order];
  823. // this.sqlBuilder.setUpdateData(this.setting.order, {
  824. // value: Math.abs(orderInc),
  825. // selfOperate: orderInc > 0 ? '+' : '-',
  826. // });
  827. // this.sqlBuilder.setAndWhere(this.setting.mid, {
  828. // value: select[this.setting.mid],
  829. // operate: '=',
  830. // });
  831. // this.sqlBuilder.setAndWhere(this.setting.pid, {
  832. // value: select[this.setting.pid],
  833. // operate: '=',
  834. // });
  835. // this.sqlBuilder.setAndWhere(this.setting.order, {
  836. // value: select[this.setting.order],
  837. // operate: '>',
  838. // });
  839. // const [sql1, sqlParam1] = this.sqlBuilder.build(this.tableName, 'update');
  840. const orderInc = lastChild ? lastChild[this.setting.order] - select[this.setting.order] : - select[this.setting.order];
  841. const sql1 = 'UPDATE ?? SET `' + this.setting.order + '` = ' + (orderInc > 0 ? '+' : '-') + Math.abs(orderInc) + ' WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.pid + ' = ? AND `' + this.setting.order + '` > ?';
  842. const sqlParam1 = [this.tableName, select[this.setting.kid], select[this.setting.pid], select[this.setting.order]];
  843. transaction ? await transaction.query(sql1, sqlParam1) : await this.db.query(sql1, sqlParam1);
  844. // 选中节点 isLeaf应为false
  845. if (select[this.setting.isLeaf]) {
  846. const updateData = { id: select.id };
  847. updateData[this.setting.isLeaf] = false;
  848. transaction ? await transaction.update(this.tableName, updateData) : await this.db.update(this.tableName, updateData);
  849. }
  850. // 修改nextsData及其子节点的fullPath
  851. const oldSubStr = this.db.escape(select[this.setting.pid] + '-');
  852. const newSubStr = this.db.escape(select[this.setting.kid] + '-');
  853. const sqlArr = [];
  854. sqlArr.push('Update ?? SET `' + this.setting.fullPath + '` = Replace(`' + this.setting.fullPath + '`,' + oldSubStr + ',' + newSubStr + ') Where');
  855. sqlArr.push('(`' + this.ctx.helper._getOptionsSql(options) + ')');
  856. sqlArr.push(' And (');
  857. for (const data of nexts) {
  858. sqlArr.push('`' + this.setting.fullPath + '` Like ' + this.db.escape(data[this.setting.fullPath] + '%'));
  859. if (nexts.indexOf(data) < nexts.length - 1) {
  860. sqlArr.push(' Or ');
  861. }
  862. }
  863. sqlArr.push(')');
  864. const sql = sqlArr.join('');
  865. const resultData = transaction ? await transaction.query(sql, [this.tableName]) : await this.db.query(sql, [this.tableName]);
  866. return resultData;
  867. }
  868. }
  869. /**
  870. * 升级selectData, 同步修改所有子节点
  871. * @param {Object} selectData - 升级操作,选中节点
  872. * @return {Object}
  873. * @private
  874. */
  875. async _syncUplevelChildren(options, select, transaction = null) {
  876. // this.initSqlBuilder();
  877. // this.sqlBuilder.setAndWhere(this.setting.mid, {
  878. // value: select[this.setting.mid],
  879. // operate: '=',
  880. // });
  881. // this.sqlBuilder.setAndWhere(this.setting.fullPath, {
  882. // value: this.db.escape(select[this.setting.fullPath] + '-%'),
  883. // operate: 'like',
  884. // });
  885. // this.sqlBuilder.setUpdateData(this.setting.level, {
  886. // value: 1,
  887. // selfOperate: '-',
  888. // });
  889. // this.sqlBuilder.setUpdateData(this.setting.fullPath, {
  890. // value: [this.setting.fullPath, this.db.escape(`-${select[this.setting.pid]}-`), this.db.escape('-')],
  891. // literal: 'Replace',
  892. // });
  893. // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  894. const sql = 'UPDATE ?? SET ' + this.setting.level + ' = ' + this.setting.level + ' -1, ' + this.setting.fullPath + ' = ' +
  895. 'Replace('+ [this.setting.fullPath, this.db.escape(`-${select[this.setting.pid]}-`), this.db.escape('-')].join(',') +') ' +
  896. 'WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.fullPath + ' LIKE ?';
  897. const sqlParam = [this.tableName, select[this.setting.fullPath] + '-%'];
  898. const data = transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
  899. return data;
  900. }
  901. /**
  902. * 降级selectData, 同步修改所有子节点
  903. * @param {Object} selectData - 选中节点
  904. * @param {Object} preData - 选中节点的前一节点(降级后为父节点)
  905. * @return {Promise<*>}
  906. * @private
  907. */
  908. async _syncDownlevelChildren(options, select, newFullPath, transaction = null) {
  909. // this.initSqlBuilder();
  910. // this.sqlBuilder.setAndWhere(this.setting.mid, {
  911. // value: select[this.setting.mid],
  912. // operate: '=',
  913. // });
  914. // this.sqlBuilder.setAndWhere(this.setting.fullPath, {
  915. // value: this.db.escape(select[this.setting.fullPath] + '-%'),
  916. // operate: 'like',
  917. // });
  918. // this.sqlBuilder.setUpdateData(this.setting.level, {
  919. // value: 1,
  920. // selfOperate: '+',
  921. // });
  922. // this.sqlBuilder.setUpdateData(this.setting.fullPath, {
  923. // value: [this.setting.fullPath, this.db.escape(select[this.setting.fullPath] + '-'), this.db.escape(newFullPath + '-')],
  924. // literal: 'Replace',
  925. // });
  926. // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  927. const sql = 'UPDATE ?? SET ' + this.setting.level + ' = ' + this.setting.level + ' + 1, ' + this.setting.fullPath + ' = ' +
  928. 'Replace(' + [[this.setting.fullPath, this.db.escape(select[this.setting.fullPath] + '-'), this.db.escape(newFullPath + '-')]].join(',') + ') ' +
  929. 'WHERE ' + this.ctx.helper._getOptionsSql(options) + ' AND ' + this.setting.fullPath + ' LIKE ?';
  930. const sqlParam = [this.tableName, select[this.setting.fullPath] + '-%'];
  931. const data = transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
  932. return data;
  933. }
  934. }
  935. return ContractTree;
  936. };