change_audit_list.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/14
  7. * @version
  8. */
  9. const audit = require('../const/audit');
  10. module.exports = app => {
  11. class ChangeAuditList extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'change_audit_list';
  21. }
  22. /**
  23. * 取出变更令清单列表,并按台账清单在前,空白清单在后排序
  24. * @return {void}
  25. */
  26. async getList(cid, order_by = this.ctx.change.order_by) {
  27. if (order_by) {
  28. return await this.getAllDataByCondition({ where: { cid }, orders: [['order', 'asc']] });
  29. }
  30. const sql = 'SELECT * FROM ?? WHERE `cid` = ? ORDER BY `lid` = "0", `id` asc';
  31. const sqlParam = [this.tableName, cid];
  32. return await this.db.query(sql, sqlParam);
  33. }
  34. /**
  35. * 移除清单时,同步其后清单order
  36. * @param transaction - 事务
  37. * @param {Number} cid - 变更cid
  38. * @param {Number} order - order之后的
  39. * @return {Promise<*>}
  40. * @private
  41. */
  42. async _syncOrder(transaction, cid, order, selfOperate = '-', num = 1) {
  43. this.initSqlBuilder();
  44. this.sqlBuilder.setAndWhere('cid', {
  45. value: this.db.escape(cid),
  46. operate: '=',
  47. });
  48. this.sqlBuilder.setAndWhere('order', {
  49. value: order,
  50. operate: '>=',
  51. });
  52. this.sqlBuilder.setUpdateData('order', {
  53. value: num,
  54. selfOperate,
  55. });
  56. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  57. const data = await transaction.query(sql, sqlParam);
  58. return data;
  59. }
  60. /**
  61. * 添加空白变更清单
  62. * @return {void}
  63. */
  64. async add(data) {
  65. if (!this.ctx.tender || !this.ctx.change) {
  66. throw '数据错误';
  67. }
  68. const transaction = await this.db.beginTransaction();
  69. try {
  70. let order = null;
  71. if (this.ctx.change.order_by) {
  72. if (data) {
  73. order = parseInt(data) + 1;
  74. // order以下的清单+1
  75. await this._syncOrder(transaction, this.ctx.change.cid, order, '+');
  76. } else {
  77. order = await this.count({ cid: this.ctx.change.cid });
  78. order = order ? order + 1 : 1;
  79. }
  80. }
  81. const insertData = {
  82. tid: this.ctx.tender.id,
  83. cid: this.ctx.change.cid,
  84. lid: '0',
  85. code: '',
  86. name: '',
  87. bwmx: '',
  88. unit: '',
  89. unit_price: null,
  90. oamount: 0,
  91. camount: 0,
  92. samount: '',
  93. detail: '',
  94. spamount: 0,
  95. xmj_code: null,
  96. xmj_jldy: null,
  97. xmj_dwgc: null,
  98. xmj_fbgc: null,
  99. xmj_fxgc: null,
  100. gcl_id: '',
  101. order,
  102. };
  103. // 新增工料
  104. const result = await transaction.insert(this.tableName, insertData);
  105. if (result.affectedRows === 0) {
  106. throw '新增空白清单数据失败';
  107. }
  108. await transaction.commit();
  109. return await this.getDataById(result.insertId);
  110. } catch (err) {
  111. await transaction.rollback();
  112. throw err;
  113. }
  114. }
  115. /**
  116. * 批量添加空白变更清单
  117. * @return {void}
  118. */
  119. async batchAdd(data) {
  120. if (!this.ctx.tender || !this.ctx.change) {
  121. throw '数据错误';
  122. }
  123. const transaction = await this.db.beginTransaction();
  124. try {
  125. const num = data.num ? parseInt(data.num) : 0;
  126. if (num < 1 || num > 100) {
  127. throw '批量添加的空白清单数目不能小于1或大于100';
  128. }
  129. let order = null;
  130. if (this.ctx.change.order_by) {
  131. if (data) {
  132. order = parseInt(data.postData) + 1;
  133. // order以下的清单+1
  134. await this._syncOrder(transaction, this.ctx.change.cid, order, '+', num);
  135. } else {
  136. order = await this.count({ cid: this.ctx.change.cid });
  137. order = order ? order + 1 : 1;
  138. }
  139. }
  140. const insertArray = [];
  141. for (let i = 0; i < num; i++) {
  142. const insertData = {
  143. tid: this.ctx.tender.id,
  144. cid: this.ctx.change.cid,
  145. lid: '0',
  146. code: '',
  147. name: '',
  148. bwmx: '',
  149. unit: '',
  150. unit_price: null,
  151. oamount: 0,
  152. camount: 0,
  153. samount: '',
  154. detail: '',
  155. spamount: 0,
  156. xmj_code: null,
  157. xmj_jldy: null,
  158. xmj_dwgc: null,
  159. xmj_fbgc: null,
  160. xmj_fxgc: null,
  161. gcl_id: '',
  162. order: order ? order + i : null,
  163. };
  164. insertArray.push(insertData);
  165. }
  166. // 新增工料
  167. const result = await transaction.insert(this.tableName, insertArray);
  168. if (result.affectedRows !== num) {
  169. throw '批量添加空白清单数据失败';
  170. }
  171. await transaction.commit();
  172. // // 获取刚批量添加的所有list
  173. // for (let j = 0; j < num; j++) {
  174. // insertArray[j].id = result.insertId + j;
  175. // }
  176. // return insertArray;
  177. return await this.getList(this.ctx.change.cid);
  178. } catch (err) {
  179. await transaction.rollback();
  180. throw err;
  181. }
  182. }
  183. /**
  184. * 删除变更清单
  185. * @param {int} id 清单id
  186. * @return {void}
  187. */
  188. async del(data) {
  189. if (!this.ctx.tender || !this.ctx.change) {
  190. throw '数据错误';
  191. }
  192. const transaction = await this.db.beginTransaction();
  193. try {
  194. // 判断是否可删
  195. await transaction.delete(this.tableName, { id: data.ids });
  196. // // order以下的清单-1
  197. if (this.ctx.change.order_by) {
  198. await this._syncOrder(transaction, this.ctx.change.cid, data.postData, '-', data.ids.length);
  199. }
  200. // 重新算变更令总额
  201. await this.calcCamountSum(transaction);
  202. await transaction.commit();
  203. return true;
  204. } catch (err) {
  205. await transaction.rollback();
  206. throw err;
  207. }
  208. }
  209. /**
  210. * 修改变更清单
  211. * @param {Object} data 工料内容
  212. * @param {int} order 期数
  213. * @return {void}
  214. */
  215. async save(data, order) {
  216. if (!this.ctx.tender || !this.ctx.change) {
  217. throw '数据错误';
  218. }
  219. const transaction = await this.db.beginTransaction();
  220. try {
  221. // const mb_id = data.mb_id;
  222. // delete data.mb_id;
  223. await transaction.update(this.tableName, data);
  224. // await this.calcQuantityByML(transaction, mb_id);
  225. await this.calcCamountSum(transaction);
  226. await transaction.commit();
  227. return true;
  228. } catch (err) {
  229. await transaction.rollback();
  230. throw err;
  231. }
  232. }
  233. /**
  234. * 修改变更清单 复制粘贴
  235. * @param {Object} datas 修改内容
  236. * @return {void}
  237. */
  238. async saveDatas(datas) {
  239. if (!this.ctx.tender || !this.ctx.change) {
  240. throw '数据错误';
  241. }
  242. // 判断是否可修改
  243. // 判断t_type是否为费用
  244. const transaction = await this.db.beginTransaction();
  245. try {
  246. // for (const data of datas) {
  247. // const mb_id = data.mb_id;
  248. // delete data.mb_id;
  249. // await transaction.update(this.tableName, data);
  250. // await this.calcQuantityByML(transaction, mb_id);
  251. // }
  252. await transaction.updateRows(this.tableName, datas);
  253. await this.calcCamountSum(transaction);
  254. await transaction.commit();
  255. return true;
  256. } catch (err) {
  257. await transaction.rollback();
  258. throw err;
  259. }
  260. }
  261. /**
  262. * 台账数据清单 重新选择
  263. * @param {Object} datas 内容
  264. * @return {void}
  265. */
  266. async saveLedgerListDatas(datas, data = null, order_by = this.ctx.change.order_by) {
  267. if (!this.ctx.tender || !this.ctx.change) {
  268. throw '数据错误';
  269. }
  270. // 判断是否可修改
  271. // 判断t_type是否为费用
  272. const transaction = await this.db.beginTransaction();
  273. try {
  274. let usedList = [];
  275. let order = null;
  276. if (order_by) {
  277. if (data) {
  278. order = parseInt(data) + 1;
  279. // order以下的清单+1
  280. await this._syncOrder(transaction, this.ctx.change.cid, order, '+', datas.length);
  281. } else {
  282. order = await this.count({ cid: this.ctx.change.cid });
  283. order = order ? order + 1 : 1;
  284. }
  285. } else {
  286. const sql1 = 'SELECT a.* FROM ?? as b LEFT JOIN ?? as a ON b.cbid = a.id WHERE b.cid = ? GROUP BY b.cbid';
  287. const sqlParam1 = [this.ctx.service.stageChange.tableName, this.tableName, this.ctx.change.cid];
  288. usedList = await transaction.query(sql1, sqlParam1);
  289. // 先删除原本的台账清单数据
  290. const sql = 'DELETE FROM ?? WHERE cid = ? and lid != "0"';
  291. const sqlParam = [this.tableName, this.ctx.change.cid];
  292. await transaction.query(sql, sqlParam);
  293. }
  294. const insertDatas = [];
  295. for (const data of datas) {
  296. data.tid = this.ctx.tender.id;
  297. data.cid = this.ctx.change.cid;
  298. data.spamount = data.camount;
  299. data.samount = '';
  300. data.order = order ? order : null;
  301. order = order ? order + 1 : null;
  302. insertDatas.push(data);
  303. }
  304. if (insertDatas.length > 0) await transaction.insert(this.tableName, insertDatas);
  305. await this.calcCamountSum(transaction);
  306. if (!order_by) {
  307. // 更新stage_change和stage_change_final的cbid
  308. if (usedList.length > 0) {
  309. const updateList = [];
  310. const sql2 = 'SELECT * FROM ?? WHERE `cid` = ? AND `lid` != "0"';
  311. const sqlParam2 = [this.tableName, this.ctx.change.cid];
  312. const newList = await transaction.query(sql2, sqlParam2);
  313. // const newList = await transaction.select(this.tableName, { where: { cid: this.ctx.change.cid } });
  314. for (const used of usedList) {
  315. const newone = this._.find(newList, { lid: used.lid, gcl_id: used.gcl_id, bwmx: used.bwmx, mx_id: used.mx_id });
  316. if (newone) {
  317. updateList.push({
  318. row: {
  319. cbid: newone.id,
  320. },
  321. where: {
  322. cid: this.ctx.change.cid,
  323. cbid: used.id,
  324. },
  325. });
  326. }
  327. }
  328. if (updateList.length > 0) {
  329. await transaction.updateRows(this.ctx.service.stageChange.tableName, updateList);
  330. await transaction.updateRows(this.ctx.service.stageChangeFinal.tableName, updateList);
  331. }
  332. }
  333. }
  334. await transaction.commit();
  335. return true;
  336. } catch (err) {
  337. await transaction.rollback();
  338. throw err;
  339. }
  340. }
  341. /**
  342. * 台账数据清单 清除部分并重新算原设计总金额
  343. * @param {Object} datas 内容
  344. * @return {void}
  345. */
  346. async removeLedgerListDatas(datas) {
  347. if (!this.ctx.tender || !this.ctx.change) {
  348. throw '数据错误';
  349. }
  350. // 判断是否可修改
  351. // 判断t_type是否为费用
  352. const transaction = await this.db.beginTransaction();
  353. try {
  354. // 先删除原本的台账清单数据
  355. // const sql = 'DELETE FROM ?? WHERE cid = ? and lid != "0"';
  356. // const sqlParam = [this.tableName, this.ctx.change.cid];
  357. // await transaction.query(sql, sqlParam);
  358. // const insertDatas = [];
  359. for (const data of datas) {
  360. // data.tid = this.ctx.tender.id;
  361. // data.cid = this.ctx.change.cid;
  362. // data.spamount = data.camount;
  363. // data.samount = '';
  364. // insertDatas.push(data);
  365. await transaction.delete(this.tableName, { id: data.id });
  366. }
  367. // if (insertDatas.length > 0) await transaction.insert(this.tableName, insertDatas);
  368. await this.calcCamountSum(transaction);
  369. await transaction.commit();
  370. return true;
  371. } catch (err) {
  372. await transaction.rollback();
  373. throw err;
  374. }
  375. }
  376. async calcCamountSum(transaction, updateTpDecimal = false) {
  377. // const sql = 'SELECT SUM(ROUND(`camount`*`unit_price`, )) as total_price FROM ?? WHERE cid = ?';
  378. // const sqlParam = [this.tableName, this.change.cid];
  379. // const tp = await transaction.queryOne(sql, sqlParam);
  380. // 防止小数位不精确,采用取值计算
  381. const sql = 'SELECT unit_price, spamount FROM ?? WHERE cid = ?';
  382. const sqlParam = [this.tableName, this.ctx.change.cid];
  383. const changeList = await transaction.query(sql, sqlParam);
  384. let total_price = 0;
  385. let positive_tp = 0;
  386. let negative_tp = 0;
  387. const tp_decimal = this.ctx.change.tp_decimal ? this.ctx.change.tp_decimal : this.ctx.tender.info.decimal.tp;
  388. for (const cl of changeList) {
  389. const price = this.ctx.helper.mul(cl.unit_price, cl.spamount, tp_decimal);
  390. total_price = this.ctx.helper.accAdd(total_price, price);
  391. if (price >= 0) {
  392. positive_tp = this.ctx.helper.accAdd(positive_tp, price);
  393. } else {
  394. negative_tp = this.ctx.helper.accAdd(negative_tp, price);
  395. }
  396. }
  397. const updateData = {
  398. total_price,
  399. positive_tp,
  400. negative_tp,
  401. };
  402. if (updateTpDecimal) {
  403. updateData.tp_decimal = tp_decimal;
  404. }
  405. const options = {
  406. where: {
  407. cid: this.ctx.change.cid,
  408. },
  409. };
  410. await transaction.update(this.ctx.service.change.tableName, updateData, options);
  411. }
  412. /**
  413. * 用户数据数量提交
  414. * @param {Object} data 内容
  415. * @return {void}
  416. */
  417. async saveAmountData(data) {
  418. if (!this.ctx.tender || !this.ctx.change) {
  419. throw '数据错误';
  420. }
  421. // 判断是否可修改
  422. // 判断t_type是否为费用
  423. const transaction = await this.db.beginTransaction();
  424. try {
  425. await transaction.update(this.tableName, data);
  426. await this.calcCamountSum(transaction);
  427. await transaction.commit();
  428. return true;
  429. } catch (err) {
  430. await transaction.rollback();
  431. throw err;
  432. }
  433. }
  434. async gatherBgBills(tid) {
  435. const sql = 'SELECT cb.code, cb.name, cb.unit, cb.unit_price, Round(Sum(cb.samount + 0), 6) as quantity' +
  436. ' FROM ' + this.tableName + ' cb' +
  437. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON cb.cid = c.cid' +
  438. ' WHERE cb.tid = ? and c.status = ?' +
  439. ' GROUP BY code, name, unit, unit_price';
  440. const param = [tid, audit.flow.status.checked];
  441. const result = await this.db.query(sql, param);
  442. for (const b of result) {
  443. b.total_price = this.ctx.helper.mul(b.unit_price, b.quantity, this.ctx.tender.info.decimal.tp);
  444. }
  445. return result;
  446. }
  447. /**
  448. * 报表用
  449. * Tony Kang
  450. * @param {tid} tid - 标段id
  451. * @return {void}
  452. */
  453. async getChangeAuditBills(tid, onlyChecked) {
  454. const sql = 'SELECT cb.*' +
  455. ' FROM ' + this.tableName + ' cb' +
  456. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON cb.cid = c.cid' +
  457. ' WHERE c.tid = ? ' + (onlyChecked ? 'and c.status = 3' : '') +
  458. ' ORDER BY cb.cid, cb.code';
  459. const param = [tid];
  460. const result = await this.db.query(sql, param);
  461. return result;
  462. }
  463. /**
  464. * 删除变更清单(form 变更新增部位页)
  465. * Tony Kang
  466. * @param {String} transaction - 队列
  467. * @param {String} tid - 标段id
  468. * @param {Array} ids - id列表
  469. * @param {String} column - id所属字段
  470. * @param {String} mx_id - mx_id为空列删除
  471. * @return {void}
  472. */
  473. async deleteDataByRevise(transaction, tid, ids, column = 'gcl_id', mx_id = 'hello') {
  474. if (ids.length > 0) {
  475. const addSql = mx_id === '' ? ' AND (`mx_id` is NULL OR `mx_id` = "")' : '';
  476. const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')' + addSql + ' GROUP BY `cid`';
  477. const params = [this.tableName, tid];
  478. const changes = await transaction.query(sql, params);
  479. if (changes.length > 0) {
  480. const delData = {
  481. tid,
  482. };
  483. delData[column] = ids;
  484. await transaction.delete(this.tableName, delData);
  485. for (const c of changes) {
  486. // 重算选了此清单的变更令已变更金额
  487. await this.reCalcTp(transaction, c.cid);
  488. }
  489. }
  490. }
  491. }
  492. /**
  493. * 修改变更清单(form 变更新增部位页台账子节点清单编号编辑)
  494. * Tony Kang
  495. * @param {String} transaction - 队列
  496. * @param {String} tid - 标段id
  497. * @param {Array} datas - 更新列表
  498. * @param {String} column - id所属字段
  499. * @return {void}
  500. */
  501. async updateDataByReviseLedger(transaction, tid, datas, column = 'gcl_id') {
  502. if (datas.length > 0) {
  503. const ids = this._.map(datas, 'id');
  504. const sql = 'SELECT ' + column + ' FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ') GROUP BY ' + column;
  505. const params = [this.tableName, tid];
  506. const changeAuditLists = await transaction.query(sql, params);
  507. if (changeAuditLists.length > 0) {
  508. const updateArr = [];
  509. const cidList = [];
  510. for (const ca of changeAuditLists) {
  511. const d = this._.find(datas, { id: ca[column] });
  512. if (d.id) {
  513. const changePosNum = await transaction.count(this.ctx.service.changePos.tableName, { lid: d.id });
  514. const updateCol = {};
  515. if (column === 'gcl_id' && d.b_code) updateCol.code = d.b_code;
  516. if (column === 'gcl_id' && d.quantity !== undefined && changePosNum === 0) updateCol.oamount = d.quantity ? d.quantity : 0;
  517. if (column === 'gcl_id' && d.unit_price !== undefined) updateCol.unit_price = d.unit_price ? d.unit_price : 0;
  518. if (column === 'gcl_id' && d.unit !== undefined) updateCol.unit = d.unit;
  519. if (column === 'gcl_id' && d.name !== undefined) updateCol.name = d.name;
  520. if (d.b_code !== undefined && d.b_code === null) {
  521. // 清单升级成了项目节,故删除变更已有的此清单,并找出需要重新计算的变更令
  522. const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
  523. const params = [this.tableName, tid, d.id];
  524. const changes = await transaction.query(sql, params);
  525. for (const c of changes) {
  526. if (this._.indexOf(cidList, c.cid) === -1) {
  527. cidList.push(c.cid);
  528. }
  529. }
  530. const delData = {
  531. tid,
  532. };
  533. delData[column] = d.id;
  534. await transaction.delete(this.tableName, delData);
  535. } else {
  536. const options = {
  537. row: {},
  538. where: {},
  539. };
  540. options.row = updateCol;
  541. options.where[column] = d.id;
  542. if (!this._.isEmpty(options.row)) updateArr.push(options);
  543. if (updateCol.unit !== undefined || updateCol.unit_price !== undefined) {
  544. const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
  545. const params = [this.tableName, tid, d.id];
  546. const changes = await transaction.query(sql, params);
  547. for (const c of changes) {
  548. if (this._.indexOf(cidList, c.cid) === -1) {
  549. cidList.push(c.cid);
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. if (updateArr.length > 0) await transaction.updateRows(this.tableName, updateArr);
  557. if (cidList.length > 0) {
  558. for (const c of cidList) {
  559. await this.reCalcTp(transaction, c);
  560. }
  561. }
  562. }
  563. // 针对项目节更新可能对清单影响判断,修正变更清单项目节编号,细目,单位工程,分部分项工程数据
  564. for (const data of datas) {
  565. const select = await transaction.get(this.ctx.service.changeLedger.tableName, { id: data.id });
  566. if (select && select.is_leaf === 0) {
  567. const lists = await this.ctx.service.changeLedger.getDataByFullPath(this.ctx.service.changeLedger.tableName, tid, select.full_path + '%', transaction);
  568. const childLists = this._.filter(lists, { level: select.level + 1 }); // 细目or项目节编号更新
  569. if (childLists.length > 0) {
  570. const d = { xmj_code: '', xmj_jldy: '' };
  571. if (select.code !== null) {
  572. d.xmj_code = select.code;
  573. d.xmj_jldy = select.name;
  574. } else {
  575. // 再找出上一个项目节节点并更新
  576. this.newBills = false;
  577. const parents = await this.ctx.service.changeLedger.getDataByKid(tid, select.ledger_pid);
  578. d.xmj_code = parents.code;
  579. d.xmj_jldy = parents.name;
  580. }
  581. for (const cl of childLists) {
  582. await transaction.update(this.tableName, { xmj_code: d.xmj_code, xmj_jldy: d.xmj_jldy }, { where: { tid, gcl_id: cl.id } });
  583. }
  584. }
  585. if (select.code !== null && data.name !== undefined) { // 名称修改则可能影响几个数据
  586. const secondChildLists = this._.filter(lists, { level: select.level + 2 }); // 分项工程更新
  587. const thirdChildLists = this._.filter(lists, { level: select.level + 3 }); // 分部工程更新
  588. const fourthChildLists = this._.filter(lists, { level: select.level + 4 }); // 单位工程更新
  589. if (secondChildLists.length > 0) {
  590. for (const sl of secondChildLists) {
  591. await transaction.update(this.tableName, { xmj_fxgc: select.name }, { where: { tid, gcl_id: sl.id } });
  592. }
  593. }
  594. if (thirdChildLists.length > 0) {
  595. for (const tl of thirdChildLists) {
  596. await transaction.update(this.tableName, { xmj_fbgc: select.name }, { where: { tid, gcl_id: tl.id } });
  597. }
  598. }
  599. if (fourthChildLists.length > 0 && select.level === 2) {
  600. for (const fl of fourthChildLists) {
  601. await transaction.update(this.tableName, { xmj_dwgc: select.name }, { where: { tid, gcl_id: fl.id } });
  602. }
  603. }
  604. }
  605. }
  606. }
  607. }
  608. }
  609. /**
  610. * 修改变更清单(form 变更新增部位页台账节点清单编号升降级)
  611. * Tony Kang
  612. * @param {String} transaction - 队列
  613. * @param {String} tid - 标段id
  614. * @param {Array} datas - 更新列表
  615. * @param {String} column - id所属字段
  616. * @return {void}
  617. */
  618. async updateDataByReviseLedgerUpDownLevel(transaction, tid, datas, column = 'gcl_id') {
  619. if (datas.length > 0) {
  620. console.log(datas);
  621. // const ids = this._.map(datas, 'id');
  622. // const sql = 'SELECT ' + column + ' FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ') GROUP BY ' + column;
  623. // const params = [this.tableName, tid];
  624. // const changeAuditLists = await transaction.query(sql, params);
  625. // if (changeAuditLists.length > 0) {
  626. // const updateArr = [];
  627. // const cidList = [];
  628. // for (const ca of changeAuditLists) {
  629. // const d = this._.find(datas, { id: ca[column] });
  630. // console.log(d);
  631. // if (d.id) {
  632. // const changePosNum = await transaction.count(this.ctx.service.changePos.tableName, { lid: d.id });
  633. // const updateCol = {};
  634. // if (column === 'gcl_id' && d.b_code !== undefined) updateCol.code = d.b_code;
  635. // if (column === 'gcl_id' && d.sgfh_qty !== undefined && changePosNum === 0) updateCol.oamount = d.sgfh_qty ? d.sgfh_qty : 0;
  636. // if (column === 'gcl_id' && d.unit_price !== undefined) updateCol.unit_price = d.unit_price ? d.unit_price : 0;
  637. // if (column === 'gcl_id' && d.unit !== undefined) updateCol.unit = d.unit;
  638. // if (column === 'gcl_id' && d.name !== undefined) updateCol.name = d.name;
  639. // if (d.code !== undefined && d.b_code === null) {
  640. // // 清单升级成了项目节,故删除变更已有的此清单,并找出需要重新计算的变更令
  641. // const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
  642. // const params = [this.tableName, tid, d.id];
  643. // const changes = await transaction.query(sql, params);
  644. // for (const c of changes) {
  645. // if (this._.indexOf(cidList, c.cid) === -1) {
  646. // cidList.push(c.cid);
  647. // }
  648. // }
  649. // const delData = {
  650. // tid,
  651. // };
  652. // delData[column] = d.id;
  653. // console.log(delData);
  654. // await transaction.delete(this.tableName, delData);
  655. // } else {
  656. // const options = {
  657. // row: {},
  658. // where: {},
  659. // };
  660. // options.row = updateCol;
  661. // options.where[column] = d.id;
  662. // if (!this._.isEmpty(options.row)) updateArr.push(options);
  663. // if (updateCol.unit !== undefined || updateCol.unit_price !== undefined) {
  664. // const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
  665. // const params = [this.tableName, tid, d.id];
  666. // const changes = await transaction.query(sql, params);
  667. // for (const c of changes) {
  668. // if (this._.indexOf(cidList, c.cid) === -1) {
  669. // cidList.push(c.cid);
  670. // }
  671. // }
  672. // }
  673. // }
  674. // }
  675. // }
  676. // console.log(updateArr, cidList);
  677. // if (updateArr.length > 0) await transaction.updateRows(this.tableName, updateArr);
  678. // if (cidList.length > 0) {
  679. // for (const c of cidList) {
  680. // await this.reCalcTp(transaction, c);
  681. // }
  682. // }
  683. // }
  684. // 针对项目节更新可能对清单影响判断,修正变更清单项目节编号,细目,单位工程,分部分项工程数据
  685. // for (const data of datas) {
  686. // const select = await transaction.get(this.ctx.service.changeLedger.tableName, { id: data.id });
  687. // console.log(select);
  688. // if (select && select.is_leaf === 0) {
  689. // const lists = await this.ctx.service.changeLedger.getDataByFullPath(this.ctx.service.changeLedger.tableName, tid, select.full_path + '%', transaction);
  690. // const childLists = this._.filter(lists, { level: select.level + 1 }); // 细目or项目节编号更新
  691. // if (childLists.length > 0) {
  692. // const d = { xmj_code: '', xmj_jldy: '' };
  693. // if (select.code !== null) {
  694. // d.xmj_code = select.code;
  695. // d.xmj_jldy = select.name;
  696. // } else {
  697. // // 再找出上一个项目节节点并更新
  698. // this.newBills = false;
  699. // const parents = await this.ctx.service.changeLedger.getDataByKid(tid, select.ledger_pid);
  700. // console.log('hello :', parents);
  701. // d.xmj_code = parents.code;
  702. // d.xmj_jldy = parents.name;
  703. // }
  704. // for (const cl of childLists) {
  705. // await transaction.update(this.tableName, { xmj_code: d.xmj_code, xmj_jldy: d.xmj_jldy }, { where: { tid, gcl_id: cl.id } });
  706. // }
  707. // }
  708. // if (select.code !== null && data.name !== undefined) { // 名称修改则可能影响几个数据
  709. // const secondChildLists = this._.filter(lists, { level: select.level + 2 }); // 分项工程更新
  710. // const thirdChildLists = this._.filter(lists, { level: select.level + 3 }); // 分部工程更新
  711. // const fourthChildLists = this._.filter(lists, { level: select.level + 4 }); // 单位工程更新
  712. // if (secondChildLists.length > 0) {
  713. // for (const sl of secondChildLists) {
  714. // await transaction.update(this.tableName, { xmj_fxgc: select.name }, { where: { tid, gcl_id: sl.id } });
  715. // }
  716. // }
  717. // if (thirdChildLists.length > 0) {
  718. // for (const tl of thirdChildLists) {
  719. // await transaction.update(this.tableName, { xmj_fbgc: select.name }, { where: { tid, gcl_id: tl.id } });
  720. // }
  721. // }
  722. // if (fourthChildLists.length > 0) {
  723. // for (const fl of fourthChildLists) {
  724. // await transaction.update(this.tableName, { xmj_dwgc: select.name }, { where: { tid, gcl_id: fl.id } });
  725. // }
  726. // }
  727. // }
  728. // }
  729. // }
  730. }
  731. }
  732. /**
  733. * 修改变更清单(form 变更新增部位页计量单元编辑)
  734. * Tony Kang
  735. * @param {String} transaction - 队列
  736. * @param {String} tid - 标段id
  737. * @param {Array} datas - 更新列表
  738. * @param {String} column - id所属字段
  739. * @return {void}
  740. */
  741. async updateDataByRevisePos(transaction, tid, datas, column = 'mx_id') {
  742. if (datas.length > 0) {
  743. const ids = this._.map(datas, 'id');
  744. const sql = 'SELECT ' + column + ' FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ') GROUP BY ' + column;
  745. const params = [this.tableName, tid];
  746. const changeAuditLists = await transaction.query(sql, params);
  747. if (changeAuditLists.length > 0) {
  748. const updateArr = [];
  749. for (const ca of changeAuditLists) {
  750. const d = this._.find(datas, { id: ca[column] });
  751. if (d.id) {
  752. const updateCol = {};
  753. if (column === 'mx_id' && d.name !== undefined) updateCol.bwmx = d.name;
  754. if (column === 'mx_id' && d.quantity !== undefined) updateCol.oamount = d.quantity ? d.quantity : 0;
  755. if (column === 'mx_id' && d.quantity === undefined &&
  756. ((d.sgfh_expr && d.sgfh_expr === '') || (d.sjcl_expr && d.sjcl_expr === '') || (d.qtcl_expr && d.qtcl_expr === ''))) updateCol.oamount = 0;
  757. const options = {
  758. row: {},
  759. where: {},
  760. };
  761. options.row = updateCol;
  762. options.where[column] = d.id;
  763. // if (!this._.isEmpty(updateCol)) await transaction.update(this.tableName, updateCol, options);
  764. if (!this._.isEmpty(options.row)) updateArr.push(options);
  765. }
  766. }
  767. if (updateArr.length > 0) await transaction.updateRows(this.tableName, updateArr);
  768. }
  769. }
  770. }
  771. /**
  772. * 重算变更令总金额(变更新增部位设置时使用)
  773. * @param {String} transaction - 队列
  774. * @param {String} cid - 变更令id
  775. */
  776. async reCalcTp(transaction, cid) {
  777. const change = await transaction.get(this.ctx.service.change.tableName, { cid });
  778. let count = '';
  779. if (change.status === audit.flow.status.uncheck || change.status === audit.flow.status.back || change.status === audit.flow.status.revise) {
  780. count = '`camount`';
  781. } else if (change.status === audit.flow.status.checking || change.status === audit.flow.status.backnew) {
  782. count = '`spamount`';
  783. }
  784. if (count) {
  785. const sql = 'SELECT `unit_price`, ' + count + ' as `count` FROM ?? WHERE `cid` = ?';
  786. const params = [this.tableName, change.cid];
  787. const caLists = await transaction.query(sql, params);
  788. let tp = 0;
  789. const tpUnit = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
  790. for (const ca of caLists) {
  791. const catp = this.ctx.helper.round(this.ctx.helper.mul(ca.unit_price, ca.count), tpUnit);
  792. tp = this.ctx.helper.add(tp, catp);
  793. }
  794. console.log(tp);
  795. if (tp !== change.total_price) {
  796. const options = {
  797. where: {
  798. cid: change.cid,
  799. },
  800. };
  801. const change_update = {
  802. total_price: tp,
  803. };
  804. await transaction.update(this.ctx.service.change.tableName, change_update, options);
  805. }
  806. }
  807. }
  808. async updateToLedger(transaction, tid, cid) {
  809. // 找出本条变更属于新增部位的数据
  810. const allList = await transaction.select(this.tableName, { where: { tid, cid } });
  811. const result = [];
  812. const result2 = [];
  813. for (const l of allList) {
  814. const changeLedgerInfo = await transaction.get(this.ctx.service.changeLedger.tableName, { id: l.gcl_id });
  815. if (changeLedgerInfo && this._.findIndex(result, { id: l.gcl_id }) === -1) {
  816. result.push(changeLedgerInfo);
  817. }
  818. const changePosInfo = await transaction.get(this.ctx.service.changePos.tableName, { id: l.mx_id });
  819. if (changePosInfo) {
  820. result2.push(changePosInfo);
  821. }
  822. }
  823. // const sql = 'SELECT a.* FROM ?? a LEFT JOIN ?? b ON a.id = b.gcl_id WHERE b.tid = ? AND b.cid = ? GROUP BY a.id';
  824. // const sqlParam = [this.ctx.service.changeLedger.tableName, this.tableName, tid, cid];
  825. // const result = await transaction.query(sql, sqlParam);
  826. // const sql2 = 'SELECT a.* FROM ?? a LEFT JOIN ?? b ON a.id = b.mx_id WHERE b.tid = ? AND b.cid = ?';
  827. // const sqlParam2 = [this.ctx.service.changePos.tableName, this.tableName, tid, cid];
  828. // const result2 = await transaction.query(sql2, sqlParam2);
  829. if (result.length > 0 || result2.length > 0) {
  830. const changeLedgerGclIdList = this._.map(result, 'id');
  831. const changeLedgerIdList = this._.uniq(this._.map(result, 'ledger_pid'));// 父节点集合
  832. const needUpdateLedgerList = [];// 找出需要更新的原台账清单的id
  833. const needUpdateChangeLedgerList = [];// 找出需要更新的新台账清单的id
  834. const tpDecimal = this.ctx.tender.info.decimal.tp;
  835. // 要更新的ledger节点,数量及总数
  836. for (const data of result2) {
  837. if (this._.indexOf(changeLedgerGclIdList, data.lid) === -1) {
  838. const info = this._.find(needUpdateLedgerList, { id: data.lid });
  839. if (info) {
  840. info.sgfh_qty = this.ctx.helper.add(info.sgfh_qty, data.sgfh_qty);
  841. info.sjcl_qty = this.ctx.helper.add(info.sjcl_qty, data.sjcl_qty);
  842. info.qtcl_qty = this.ctx.helper.add(info.qtcl_qty, data.qtcl_qty);
  843. info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
  844. } else {
  845. needUpdateLedgerList.push({ id: data.lid, sgfh_qty: data.sgfh_qty, sjcl_qty: data.sjcl_qty, qtcl_qty: data.qtcl_qty, quantity: data.quantity });
  846. }
  847. } else {
  848. const info = this._.find(needUpdateChangeLedgerList, { id: data.lid });
  849. if (info) {
  850. info.sgfh_qty = this.ctx.helper.add(info.sgfh_qty, data.sgfh_qty);
  851. info.sjcl_qty = this.ctx.helper.add(info.sjcl_qty, data.sjcl_qty);
  852. info.qtcl_qty = this.ctx.helper.add(info.qtcl_qty, data.qtcl_qty);
  853. info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
  854. } else {
  855. needUpdateChangeLedgerList.push({ id: data.lid, sgfh_qty: data.sgfh_qty, sjcl_qty: data.sjcl_qty, qtcl_qty: data.qtcl_qty, quantity: data.quantity });
  856. }
  857. }
  858. }
  859. // 更新到result上
  860. if (needUpdateChangeLedgerList.length > 0) {
  861. for (const nucl of needUpdateChangeLedgerList) {
  862. const now = this._.find(result, { id: nucl.id });
  863. now.sgfh_qty = nucl.sgfh_qty;
  864. now.sjcl_qty = nucl.sjcl_qty;
  865. now.qtcl_qty = nucl.qtcl_qty;
  866. now.quantity = nucl.quantity;
  867. now.sgfh_tp = this.ctx.helper.mul(now.sgfh_qty, now.unit_price, tpDecimal);
  868. now.sjcl_tp = this.ctx.helper.mul(now.sjcl_qty, now.unit_price, tpDecimal);
  869. now.qtcl_tp = this.ctx.helper.mul(now.qtcl_qty, now.unit_price, tpDecimal);
  870. now.total_price = this.ctx.helper.mul(now.quantity, now.unit_price, tpDecimal);
  871. }
  872. }
  873. // 更新到ledger上
  874. if (needUpdateLedgerList.length > 0) {
  875. for (const nul of needUpdateLedgerList) {
  876. const ledgerInfo = await this.ctx.service.ledger.getDataById(nul.id);
  877. ledgerInfo.sgfh_qty = this.ctx.helper.add(ledgerInfo.sgfh_qty, nul.sgfh_qty);
  878. ledgerInfo.sjcl_qty = this.ctx.helper.add(ledgerInfo.sjcl_qty, nul.sjcl_qty);
  879. ledgerInfo.qtcl_qty = this.ctx.helper.add(ledgerInfo.qtcl_qty, nul.qtcl_qty);
  880. ledgerInfo.quantity = this.ctx.helper.add(ledgerInfo.quantity, nul.quantity);
  881. ledgerInfo.sgfh_tp = this.ctx.helper.mul(ledgerInfo.sgfh_qty, ledgerInfo.unit_price, tpDecimal);
  882. ledgerInfo.sjcl_tp = this.ctx.helper.mul(ledgerInfo.sjcl_qty, ledgerInfo.unit_price, tpDecimal);
  883. ledgerInfo.qtcl_tp = this.ctx.helper.mul(ledgerInfo.qtcl_qty, ledgerInfo.unit_price, tpDecimal);
  884. ledgerInfo.total_price = this.ctx.helper.mul(ledgerInfo.quantity, ledgerInfo.unit_price, tpDecimal);
  885. await transaction.update(this.ctx.service.ledger.tableName, ledgerInfo);
  886. }
  887. }
  888. // 找出所有新增的父节点并插入到result中
  889. for (const r of changeLedgerIdList) {
  890. await this._findParents(transaction, tid, r, result);
  891. }
  892. // 插入到计量单元表,并删除变更的计量单元数据, 插入清单表,并删除变更的清单表
  893. await this._insertByChangeRevise(transaction, tid, cid, result, result2);
  894. // 更新标段总金额
  895. const sumSql = 'SELECT Sum(total_price) As total_price, Sum(deal_tp) As deal_tp' +
  896. ' FROM ' + this.ctx.service.ledger.tableName + this.ctx.helper.whereSql({ tender_id: tid });
  897. const sum = await transaction.queryOne(sumSql);
  898. await transaction.update(this.ctx.service.tender.tableName, {
  899. id: tid,
  900. total_price: sum.total_price,
  901. deal_tp: sum.deal_tp,
  902. });
  903. // 清除修订及台账的maxLid缓存,防止树结构混乱
  904. await this.ctx.service.reviseBills._removeCacheMaxLid(tid);
  905. await this.ctx.service.ledger._removeCacheMaxLid(tid);
  906. }
  907. }
  908. async _findParents(transaction, tid, id, result) {
  909. const info = await transaction.get(this.ctx.service.changeLedger.tableName, { tender_id: tid, ledger_id: id });
  910. if (info && this._.findIndex(result, { ledger_id: info.ledger_id }) === -1) {
  911. result.push(info);
  912. await this._findParents(transaction, tid, info.ledger_pid, result);
  913. } else {
  914. return;
  915. }
  916. }
  917. async _insertByChangeRevise(transaction, tid, cid, ledgerList, posList) {
  918. if (ledgerList.length > 0) {
  919. const insertLedgerArr = [];
  920. for (const l of ledgerList) {
  921. const insertL = [
  922. l.id, l.code, l.b_code, l.name, l.unit, l.source, l.remark, l.ledger_id,
  923. l.ledger_pid, l.level, l.order, l.full_path, l.is_leaf, l.quantity, l.total_price,
  924. l.unit_price, l.drawing_code, l.memo, l.dgn_qty1, l.dgn_qty2, l.deal_qty, l.deal_tp,
  925. l.sgfh_qty, l.sgfh_tp, l.sjcl_qty, l.sjcl_tp, l.qtcl_qty, l.qtcl_tp, l.node_type, l.crid, l.ccid,
  926. l.tender_id, l.sgfh_expr, l.sjcl_expr, l.qtcl_expr, l.check_calc,
  927. l.ex_memo1, l.ex_memo2, l.ex_memo3,
  928. ];
  929. insertLedgerArr.push('(' + this.ctx.helper.getInArrStrSqlFilter(insertL) + ')');
  930. await transaction.delete(this.ctx.service.changeLedger.tableName, { id: l.id });
  931. // 日志添加
  932. await transaction.insert(this.ctx.service.changeReviseLog.tableName, { tid, cid, lid: l.id, name: l.name ? l.name : (l.code ? l.code : ''), create_time: new Date() });
  933. }
  934. const bSql = 'Insert Into ' +
  935. this.ctx.service.ledger.tableName +
  936. ' (id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
  937. ' quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
  938. ' sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, ccid, tender_id,' +
  939. ' sgfh_expr, sjcl_expr, qtcl_expr, check_calc,' +
  940. ' ex_memo1, ex_memo2, ex_memo3) VALUES ' + insertLedgerArr.join(',') + ';';
  941. await transaction.query(bSql, []);
  942. }
  943. if (posList.length > 0) {
  944. const insertPosArr = [];
  945. for (const p of posList) {
  946. const insertp = [
  947. p.id, p.tid, p.lid, p.name, p.drawing_code, p.quantity, p.add_stage, p.add_stage_order, p.add_times,
  948. p.add_user, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.crid, p.ccid, p.porder, p.position,
  949. p.sgfh_expr, p.sjcl_expr, p.qtcl_expr, p.real_qty,
  950. p.ex_memo1, p.ex_memo2, p.ex_memo3,
  951. ];
  952. insertPosArr.push('(' + this.ctx.helper.getInArrStrSqlFilter(insertp) + ')');
  953. await transaction.delete(this.ctx.service.changePos.tableName, { id: p.id });
  954. // 日志添加
  955. await transaction.insert(this.ctx.service.changeReviseLog.tableName, { tid, cid, pid: p.id, name: p.name, create_time: new Date() });
  956. }
  957. const pSql =
  958. 'Insert Into ' +
  959. this.ctx.service.pos.tableName +
  960. ' (id, tid, lid, name, drawing_code, quantity, add_stage, add_stage_order, add_times, add_user,' +
  961. ' sgfh_qty, sjcl_qty, qtcl_qty, crid, ccid, porder, position, ' +
  962. ' sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
  963. ' ex_memo1, ex_memo2, ex_memo3) VALUES ' + insertPosArr.join(',') + ';';
  964. await transaction.query(pSql, []);
  965. }
  966. }
  967. async checkedChangeBills(tid) {
  968. const DefaultDecimal = this.ctx.tender.info.decimal.tp;
  969. const sql = 'SELECT cal.*, c.tp_decimal FROM ' + this.ctx.service.changeAuditList.tableName + ' cal LEFT JOIN ' + this.ctx.service.change.tableName + ' c on cal.cid = c.cid where c.tid = ? and c.valid and c.status = ?';
  970. const changeBills = await this.db.query(sql, [tid, audit.flow.status.checked]);
  971. changeBills.forEach(x => {
  972. x.tp_decimal = x.tp_decimal !== 0 ? x.tp_decimal : DefaultDecimal
  973. });
  974. return changeBills;
  975. }
  976. /**
  977. * 交换两个清单的顺序
  978. * @param {Number} id1 - 工料1的id
  979. * @param {Number} id2 - 工料2的id
  980. * @returns {Promise<void>}
  981. */
  982. async changeOrder(datas) {
  983. if (!this.ctx.tender || !this.ctx.change) {
  984. throw '数据错误';
  985. }
  986. // const bill1 = await this.getDataByCondition({ tid: this.ctx.tender.id, id: id1 });
  987. // const bill2 = await this.getDataByCondition({ tid: this.ctx.tender.id, id: id2 });
  988. // if (!bill1 || !bill2) {
  989. // throw '数据错误';
  990. // }
  991. const transaction = await this.db.beginTransaction();
  992. try {
  993. // const order = bill1.order;
  994. // bill1.order = bill2.order;
  995. // bill2.order = order;
  996. // await transaction.update(this.tableName, { id: bill1.id, order: bill1.order });
  997. // await transaction.update(this.tableName, { id: bill2.id, order: bill2.order });
  998. await transaction.updateRows(this.tableName, datas);
  999. await transaction.commit();
  1000. return true;
  1001. } catch (err) {
  1002. await transaction.rollback();
  1003. throw err;
  1004. }
  1005. }
  1006. }
  1007. return ChangeAuditList;
  1008. };