change_audit_list.js 53 KB

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