material_list.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. 'use strict';
  2. /**
  3. * 调差清单关联工料表 数据模型
  4. *
  5. * @author Mai
  6. * @date 2018/8/13
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').material;
  10. module.exports = app => {
  11. class MaterialList extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'material_list';
  21. }
  22. /**
  23. * 添加工料清单关联
  24. * @return {void}
  25. */
  26. async add(data) {
  27. if (!this.ctx.tender || !this.ctx.material) {
  28. throw '数据错误';
  29. }
  30. const list = [];
  31. for (const mb of data.mb_id) {
  32. const newLists = {
  33. tid: this.ctx.tender.id,
  34. order: this.ctx.material.order,
  35. mid: this.ctx.material.id,
  36. mb_id: mb,
  37. gcl_id: data.gcl_id,
  38. xmj_id: data.xmj_id,
  39. mx_id: data.mx_id,
  40. gather_qty: data.gather_qty,
  41. is_join: data.is_join,
  42. is_self: 1,
  43. in_time: new Date(),
  44. };
  45. list.push(newLists);
  46. }
  47. // 新增工料
  48. const result = await this.db.insert(this.tableName, list);
  49. if (result.affectedRows === 0) {
  50. throw '新增工料数据失败';
  51. }
  52. return await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id);
  53. }
  54. /**
  55. * 删除工料清单关联
  56. * @param {int} id 工料id
  57. * @return {void}
  58. */
  59. async del(id, mb_id) {
  60. if (!this.ctx.tender || !this.ctx.material) {
  61. throw '数据错误';
  62. }
  63. const transaction = await this.db.beginTransaction();
  64. try {
  65. // 判断是否可删
  66. await transaction.delete(this.tableName, { id });
  67. await this.calcQuantityByML(transaction, mb_id);
  68. await transaction.commit();
  69. return true;
  70. } catch (err) {
  71. await transaction.rollback();
  72. throw err;
  73. }
  74. }
  75. /**
  76. * 修改工料清单关联信息
  77. * @param {Object} data 工料内容
  78. * @param {int} order 期数
  79. * @return {void}
  80. */
  81. async save(data, order) {
  82. if (!this.ctx.tender || !this.ctx.material) {
  83. throw '数据错误';
  84. }
  85. const transaction = await this.db.beginTransaction();
  86. try {
  87. const mb_id = data.mb_id;
  88. delete data.mb_id;
  89. await transaction.update(this.tableName, data);
  90. await this.calcQuantityByML(transaction, mb_id);
  91. await transaction.commit();
  92. return true;
  93. } catch (err) {
  94. await transaction.rollback();
  95. throw err;
  96. }
  97. }
  98. /**
  99. * 修改工料信息
  100. * @param {Object} data 工料内容
  101. * @return {void}
  102. */
  103. async saveDatas(datas) {
  104. if (!this.ctx.tender || !this.ctx.material) {
  105. throw '数据错误';
  106. }
  107. // 判断是否可修改
  108. // 判断t_type是否为费用
  109. const transaction = await this.db.beginTransaction();
  110. try {
  111. for (const data of datas) {
  112. const mb_id = data.mb_id;
  113. delete data.mb_id;
  114. await transaction.update(this.tableName, data);
  115. await this.calcQuantityByML(transaction, mb_id);
  116. }
  117. await transaction.commit();
  118. return true;
  119. } catch (err) {
  120. await transaction.rollback();
  121. throw err;
  122. }
  123. }
  124. /**
  125. * 应用工料清单到其它清单中
  126. * @return {void}
  127. */
  128. async addOther(data) {
  129. if (!this.ctx.tender || !this.ctx.material) {
  130. throw '数据错误';
  131. }
  132. const transaction = await this.db.beginTransaction();
  133. try {
  134. // 先删除addxmj里所有的清单工料再添加新工料,并重新计算每个工料的单价数量
  135. // 还要找出删除的工料,更新单价数量
  136. const list = [];
  137. const delList = [];
  138. const materialBills = data.materialBills;
  139. const mb_idList = [];
  140. for (const xmj of data.addXmj) {
  141. const mlList = await this.getAllDataByCondition({
  142. where: {
  143. mid: this.ctx.material.id,
  144. gcl_id: xmj.gcl_id,
  145. xmj_id: xmj.id,
  146. mx_id: xmj.mx_id ? xmj.mx_id : [null, ''],
  147. },
  148. });
  149. const mbIdList = this._.map(mlList, 'mb_id');
  150. mb_idList.push(...mbIdList);
  151. delList.push(...this._.map(mlList, 'id'));
  152. for (const mb of materialBills) {
  153. const newLists = {
  154. tid: this.ctx.tender.id,
  155. order: mb.order,
  156. mid: this.ctx.material.id,
  157. mb_id: mb.mb_id,
  158. gcl_id: xmj.gcl_id,
  159. xmj_id: xmj.id,
  160. mx_id: xmj.mx_id ? xmj.mx_id : '',
  161. gather_qty: xmj.gather_qty ? xmj.gather_qty : null,
  162. quantity: mb.quantity,
  163. expr: mb.expr,
  164. in_time: new Date(),
  165. };
  166. list.push(newLists);
  167. mb_idList.push(mb.mb_id);
  168. }
  169. }
  170. // 删除工料清单关联
  171. if (delList.length > 0) await transaction.delete(this.tableName, { id: delList });
  172. // 新增工料清单关联
  173. if (list.length > 0) {
  174. const result = await transaction.insert(this.tableName, list);
  175. if (result.affectedRows === 0) {
  176. throw '新增工料数据失败';
  177. }
  178. }
  179. // 重算工料和总金额
  180. const calcMBIdList = this._.uniq(mb_idList);
  181. if (calcMBIdList.length > 0) {
  182. for (const select of calcMBIdList) {
  183. await this.calcQuantityByML(transaction, select);
  184. }
  185. }
  186. // throw 'fail';
  187. // await this.calcQuantityByML(transaction, select.mb_id);
  188. await transaction.commit();
  189. return await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id);
  190. } catch (err) {
  191. await transaction.rollback();
  192. throw err;
  193. }
  194. }
  195. /**
  196. * 修改material_bills的quantity值和计算本期金额
  197. * @param transaction
  198. * @param mb_id
  199. * @return {Promise<*>}
  200. */
  201. async calcQuantityByML(transaction, mb_id) {
  202. // 修改material_bills值
  203. const mbInfo = await this.ctx.service.materialBills.getDataById(mb_id);
  204. if (!mbInfo) {
  205. throw '不存在该工料';
  206. }
  207. const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
  208. const sqlParam = [this.ctx.material.id, mb_id];
  209. const mb_quantity = await transaction.queryOne(sql, sqlParam);
  210. console.log(mb_quantity);
  211. const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
  212. const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, mbInfo.m_spread), this.ctx.material.decimal.tp);
  213. const updateData = {
  214. id: mb_id,
  215. quantity: newQuantity,
  216. m_tp: newTp,
  217. m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), this.ctx.material.decimal.tp),
  218. };
  219. await transaction.update(this.ctx.service.materialBills.tableName, updateData);
  220. // 计算本期总金额
  221. const sql2 = 'SELECT SUM(`m_tp`) as total_price, SUM(IF(`m_tax_tp` is null, `m_tp`, `m_tax_tp`)) as tax_total_price FROM ' + this.ctx.service.materialBills.tableName + ' WHERE `tid` = ? AND `is_summary` = 1';
  222. const sqlParam2 = [this.ctx.tender.id];
  223. const tp = await transaction.queryOne(sql2, sqlParam2);
  224. console.log(tp);
  225. const updateData2 = {
  226. id: this.ctx.material.id,
  227. m_tp: tp.total_price,
  228. m_tax_tp: tp.tax_total_price,
  229. };
  230. return await transaction.update(this.ctx.service.material.tableName, updateData2);
  231. }
  232. /**
  233. * 获取工料清单关联表
  234. * @param {int} tid 标段id
  235. * @param {Object} mid 期id
  236. * @return {void}
  237. */
  238. async getMaterialData(tid, mid) {
  239. const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`order`, ml.`quantity`, ml.`expr`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`tid`, ml.`mid`' +
  240. ' FROM ' + this.tableName + ' as ml' +
  241. ' LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' as mb' +
  242. ' ON ml.`mb_id` = mb.`id`' +
  243. ' WHERE ml.`tid` = ? AND ml.`mid` = ?';
  244. const sqlParam = [tid, mid];
  245. return await this.db.query(sql, sqlParam);
  246. }
  247. /**
  248. * 复制上一期并生成新一期清单工料关联,计算新一期小计值
  249. * @param transaction
  250. * @param preMaterial
  251. * @param newMid
  252. * @return {Promise<void>}
  253. */
  254. async copyPreMaterialList(transaction, preMaterial, newMaterial) {
  255. const materialListData = await this.getAllDataByCondition({ where: { tid: this.ctx.tender.id, mid: preMaterial.id } });
  256. const copyMLArray = [];
  257. for (const ml of materialListData) {
  258. // 获取小计值
  259. let gather_qty = null;
  260. if (ml.mx_id !== null && ml.mx_id !== '') {
  261. gather_qty = await this.ctx.service.stagePos.getGatherQtyByMaterial(ml.tid, newMaterial.stage_id, ml.gcl_id, ml.mx_id);
  262. } else {
  263. gather_qty = await this.ctx.service.stageBills.getGatherQtyByMaterial(ml.tid, newMaterial.stage_id, ml.gcl_id);
  264. }
  265. const newMaterialList = {
  266. tid: ml.tid,
  267. order: ml.order,
  268. mid: newMaterial.id,
  269. mb_id: ml.mb_id,
  270. gcl_id: ml.gcl_id,
  271. xmj_id: ml.xmj_id,
  272. mx_id: ml.mx_id,
  273. gather_qty,
  274. quantity: ml.quantity,
  275. expr: ml.expr,
  276. is_join: ml.is_join,
  277. in_time: new Date(),
  278. };
  279. copyMLArray.push(newMaterialList);
  280. }
  281. return copyMLArray.length !== 0 ? await transaction.insert(this.tableName, copyMLArray) : true;
  282. }
  283. /**
  284. * 复制上一期并生成新一期清单工料关联,计算新一期小计值
  285. * @param transaction
  286. * @param preMaterial
  287. * @param newMid
  288. * @return {Promise<void>}
  289. */
  290. async copyPreMaterialList2(transaction, materialListData, materialSelfListData, notJoinList, newMaterial) {
  291. if (materialListData && materialListData.length > 0) {
  292. const copyMLArray = [];
  293. for (const ml of materialListData) {
  294. const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
  295. const newMaterialList = {
  296. tid: newMaterial.tid,
  297. order: ml.order,
  298. mid: newMaterial.id,
  299. mb_id: ml.mb_id,
  300. gcl_id: ml.gcl_id,
  301. xmj_id: ml.xmj_id,
  302. mx_id: ml.mx_id,
  303. gather_qty: ml.gather_qty,
  304. quantity: ml.quantity ? ml.quantity : 0,
  305. expr: ml.expr ? ml.expr : '',
  306. is_join: is_join ? 0 : 1,
  307. in_time: new Date(),
  308. };
  309. copyMLArray.push(newMaterialList);
  310. }
  311. if (copyMLArray.length !== 0) await transaction.insert(this.tableName, copyMLArray);
  312. }
  313. if (materialSelfListData && materialSelfListData.length > 0) {
  314. const copyMLArray2 = [];
  315. for (const ml of materialSelfListData) {
  316. const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
  317. const newMaterialList = {
  318. tid: newMaterial.tid,
  319. order: ml.order,
  320. mid: newMaterial.id,
  321. mb_id: ml.mb_id,
  322. gcl_id: ml.gcl_id,
  323. xmj_id: ml.xmj_id,
  324. mx_id: ml.mx_id,
  325. gather_qty: ml.gather_qty,
  326. quantity: ml.quantity ? ml.quantity : 0,
  327. expr: ml.expr ? ml.expr : '',
  328. is_join: is_join ? 0 : 1,
  329. is_self: 1,
  330. in_time: new Date(),
  331. };
  332. copyMLArray2.push(newMaterialList);
  333. }
  334. if (copyMLArray2.length !== 0) await transaction.insert(this.tableName, copyMLArray2);
  335. }
  336. }
  337. /**
  338. * 添加工料清单关联(多清单对应)
  339. * @return {void}
  340. */
  341. async adds(datas, checklist = false) {
  342. if (!this.ctx.tender || !this.ctx.material) {
  343. throw '数据错误';
  344. }
  345. const transaction = await this.db.beginTransaction();
  346. try {
  347. const list = [];
  348. const listGcl = [];
  349. // const delList = [];
  350. // const mb_idList = [];
  351. for (const xmj of datas.xmjs) {
  352. const selfList = await transaction.select(this.ctx.service.materialListSelf.tableName, { where: { tid: this.ctx.tender.id, mid: this.ctx.material.id } });
  353. for (const mb of datas.mbIds) {
  354. // // 旧数据兼容问题,要去删除相同已存在的工料
  355. // const mlInfo = await this.getDataByCondition({
  356. // mid: this.ctx.material.id,
  357. // gcl_id: xmj.gcl_id,
  358. // xmj_id: xmj.xmj_id,
  359. // mx_id: xmj.mx_id ? xmj.mx_id : [null, ''],
  360. // mb_id: mb,
  361. // });
  362. // if (mlInfo) {
  363. // delList.push(mlInfo.id);
  364. // mb_idList.push(mb);
  365. // }
  366. if (xmj.gather_qty && this._.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.xmj_id, mx_id: xmj.mx_id }) === -1) {
  367. const newLists = {
  368. tid: this.ctx.tender.id,
  369. order: this.ctx.material.order,
  370. mid: this.ctx.material.id,
  371. mb_id: mb,
  372. gcl_id: xmj.gcl_id,
  373. xmj_id: xmj.xmj_id,
  374. mx_id: xmj.mx_id,
  375. gather_qty: xmj.gather_qty,
  376. in_time: new Date(),
  377. is_join: xmj.is_join,
  378. };
  379. list.push(newLists);
  380. }
  381. if (this._.findIndex(listGcl, { gcl_id: xmj.gcl_id, mb_id: mb }) === -1) {
  382. const newListGcl = {
  383. tid: this.ctx.tender.id,
  384. order: this.ctx.material.order,
  385. mid: this.ctx.material.id,
  386. mb_id: mb,
  387. gcl_id: xmj.gcl_id,
  388. quantity: 0,
  389. expr: '',
  390. };
  391. listGcl.push(newListGcl);
  392. }
  393. }
  394. }
  395. // 维护list_gcl表
  396. // 删除工料清单关联
  397. // if (delList.length > 0) await transaction.delete(this.tableName, { id: delList });
  398. // 新增工料清单关联
  399. if (list.length > 0) {
  400. const result = await transaction.insert(this.tableName, list);
  401. if (result.affectedRows === 0) {
  402. throw '新增工料数据失败';
  403. }
  404. }
  405. if (listGcl.length > 0) {
  406. const result2 = await transaction.insert(this.ctx.service.materialListGcl.tableName, listGcl);
  407. if (result2.affectedRows === 0) {
  408. throw '新增工料关联数据失败';
  409. }
  410. }
  411. if (checklist) {
  412. await this.ctx.service.materialChecklist.updateHadBills(transaction, checklist.id, checklist.had_bills);
  413. }
  414. // 重算工料和总金额
  415. // const calcMBIdList = this._.uniq(mb_idList);
  416. // if (calcMBIdList.length > 0) {
  417. // for (const select of calcMBIdList) {
  418. // await this.calcQuantityByML(transaction, select);
  419. // }
  420. // }
  421. await transaction.commit();
  422. const gclList = await this.ctx.service.materialListGcl.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
  423. return checklist ? gclList : {
  424. gclList,
  425. materialListData: await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id),
  426. };
  427. } catch (err) {
  428. await transaction.rollback();
  429. throw err;
  430. }
  431. }
  432. /**
  433. * 删除工料清单关联(多清单对应)
  434. * @param {int} id 工料id
  435. * @return {void}
  436. */
  437. async dels(datas, checklist = false) {
  438. if (!this.ctx.tender || !this.ctx.material) {
  439. throw '数据错误';
  440. }
  441. const transaction = await this.db.beginTransaction();
  442. try {
  443. // 判断是否可删
  444. const listGcl = [];
  445. for (const xmj of datas.xmjs) {
  446. await transaction.delete(this.tableName, { tid: this.ctx.tender.id, mid: this.ctx.material.id, mb_id: datas.mb_id, gcl_id: xmj.gcl_id, xmj_id: xmj.xmj_id, mx_id: xmj.mx_id, is_self: 0 });
  447. if (this._.indexOf(listGcl, xmj.gcl_id) === -1) {
  448. await transaction.delete(this.service.materialListGcl.tableName, { tid: this.ctx.tender.id, mid: this.ctx.material.id, mb_id: datas.mb_id, gcl_id: xmj.gcl_id });
  449. listGcl.push(xmj.gcl_id);
  450. }
  451. }
  452. // await transaction.delete(this.tableName, { id });
  453. await this.calcQuantityByML(transaction, datas.mb_id);
  454. if (checklist) {
  455. await this.ctx.service.materialChecklist.updateHadBills(transaction, checklist.id, checklist.had_bills);
  456. }
  457. await transaction.commit();
  458. // console.log(datas);
  459. const gclList = await this.ctx.service.materialListGcl.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
  460. return checklist ? gclList : {
  461. gclList,
  462. materialListData: await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id),
  463. };
  464. } catch (err) {
  465. await transaction.rollback();
  466. throw err;
  467. }
  468. }
  469. /**
  470. * 修改工料清单关联信息(多清单对应)
  471. * @param {Object} data 工料内容
  472. * @param {int} order 期数
  473. * @return {void}
  474. */
  475. async saves(datas, checklist = false) {
  476. if (!this.ctx.tender || !this.ctx.material) {
  477. throw '数据错误';
  478. }
  479. const transaction = await this.db.beginTransaction();
  480. try {
  481. const mb_id = datas.mb_id;
  482. const updateDatas = [];
  483. const updateListGcl = [];
  484. const listGcl = [];
  485. const selfList = await transaction.select(this.ctx.service.materialListSelf.tableName, { where: { tid: this.ctx.tender.id, mid: this.ctx.material.id } });
  486. for (const xmj of datas.xmjs) {
  487. if (this._.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.xmj_id, mx_id: xmj.mx_id }) === -1) {
  488. const udata = {
  489. row: {
  490. expr: datas.expr,
  491. quantity: datas.quantity,
  492. },
  493. where: {
  494. tid: this.ctx.tender.id,
  495. mid: this.ctx.material.id,
  496. mb_id,
  497. gcl_id: xmj.gcl_id,
  498. xmj_id: xmj.xmj_id,
  499. mx_id: xmj.mx_id,
  500. },
  501. };
  502. updateDatas.push(udata);
  503. }
  504. if (this._.indexOf(listGcl, xmj.gcl_id) === -1) {
  505. listGcl.push(xmj.gcl_id);
  506. updateListGcl.push({
  507. row: {
  508. expr: datas.expr,
  509. quantity: datas.quantity,
  510. },
  511. where: {
  512. tid: this.ctx.tender.id,
  513. // mid: this.ctx.material.id,
  514. mb_id,
  515. gcl_id: xmj.gcl_id,
  516. },
  517. });
  518. }
  519. }
  520. if (updateDatas.length > 0) await transaction.updateRows(this.tableName, updateDatas);
  521. if (updateListGcl.length > 0) await transaction.updateRows(this.service.materialListGcl.tableName, updateListGcl);
  522. await this.calcQuantityByML(transaction, mb_id);
  523. await transaction.commit();
  524. const gclList = await this.ctx.service.materialListGcl.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
  525. return checklist ? gclList : {
  526. gclList,
  527. materialListData: await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id),
  528. };
  529. } catch (err) {
  530. await transaction.rollback();
  531. throw err;
  532. }
  533. }
  534. /**
  535. * 复制粘贴多工料信息(多清单对应)
  536. * @param {Object} data 工料内容
  537. * @return {void}
  538. */
  539. async savePastes(datas, checklist = false) {
  540. if (!this.ctx.tender || !this.ctx.material) {
  541. throw '数据错误';
  542. }
  543. // 判断是否可修改
  544. // 判断t_type是否为费用
  545. const transaction = await this.db.beginTransaction();
  546. try {
  547. const selfList = await transaction.select(this.ctx.service.materialListSelf.tableName, { where: { tid: this.ctx.tender.id, mid: this.ctx.material.id } });
  548. for (const data of datas.pasteData) {
  549. const updateDatas = [];
  550. const updateListGcl = [];
  551. const listGcl = [];
  552. for (const xmj of datas.xmjs) {
  553. if (this._.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.xmj_id, mx_id: xmj.mx_id }) === -1) {
  554. const udata = {
  555. row: {
  556. expr: data.expr,
  557. quantity: data.quantity,
  558. },
  559. where: {
  560. tid: this.ctx.tender.id,
  561. mid: this.ctx.material.id,
  562. mb_id: data.mb_id,
  563. gcl_id: xmj.gcl_id,
  564. xmj_id: xmj.xmj_id,
  565. mx_id: xmj.mx_id,
  566. },
  567. };
  568. updateDatas.push(udata);
  569. }
  570. if (this._.indexOf(listGcl, xmj.gcl_id) === -1) {
  571. listGcl.push(xmj.gcl_id);
  572. updateListGcl.push({
  573. row: {
  574. expr: data.expr,
  575. quantity: data.quantity,
  576. },
  577. where: {
  578. tid: this.ctx.tender.id,
  579. // mid: this.ctx.material.id,
  580. mb_id: data.mb_id,
  581. gcl_id: xmj.gcl_id,
  582. },
  583. });
  584. }
  585. }
  586. if (updateDatas.length > 0) await transaction.updateRows(this.tableName, updateDatas);
  587. if (updateListGcl.length > 0) await transaction.updateRows(this.service.materialListGcl.tableName, updateListGcl);
  588. await this.calcQuantityByML(transaction, data.mb_id);
  589. }
  590. await transaction.commit();
  591. const gclList = await this.ctx.service.materialListGcl.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
  592. return checklist ? gclList : {
  593. gclList,
  594. materialListData: await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id),
  595. };
  596. } catch (err) {
  597. await transaction.rollback();
  598. throw err;
  599. }
  600. }
  601. }
  602. return MaterialList;
  603. };