change_audit_list.js 53 KB

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