change_audit_list.js 53 KB

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