pos.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. 'use strict';
  2. /**
  3. * 部位明细
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class Pos extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.depart = 20;
  20. this.tableName = 'pos';
  21. }
  22. async getPosData(condition, column) {
  23. if (!condition.tid) throw '查询计量单元缺少必要信息';
  24. return await this.db.select(this.departTableName(condition.tid), {
  25. where: condition,
  26. columns: column || ['id', 'tid', 'lid', 'name', 'quantity', 'position', 'drawing_code', 'sgfh_qty', 'sjcl_qty',
  27. 'qtcl_qty', 'in_time', 'porder', 'add_stage', 'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'real_qty',
  28. 'dagl_status', 'dagl_url', 'gxby_status', 'gxby_url', 'gxby_limit', 'dagl_limit',
  29. 'ex_memo1', 'ex_memo2', 'ex_memo3'],
  30. order: [['porder', 'ASC']],
  31. });
  32. }
  33. async getPosDataWithAddStageOrder(condition) {
  34. if (!condition.tid) throw '查询计量单元缺少必要信息';
  35. const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
  36. ' sgfh_qty, sjcl_qty, qtcl_qty, porder, add_stage, add_times, add_user, add_stage_order,' +
  37. ' sgfh_expr, sjcl_expr, qtcl_expr, real_qty, gxby_status, gxby_url, dagl_status, dagl_url,' +
  38. ' gxby_limit, dagl_limit, ex_memo1, ex_memo2, ex_memo3' +
  39. ' FROM ' + this.departTableName(condition.tid) + this.ctx.helper.whereSql(condition);
  40. return await this.db.query(sql);
  41. }
  42. async getPosDataByIds(tid, ids) {
  43. if (ids instanceof Array && ids.length > 0) {
  44. const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
  45. ' sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user, sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
  46. ' dagl_status, dagl_url, gxby_status, gxby_url, gxby_limit, dagl_limit, ex_memo1, ex_memo2, ex_memo3' +
  47. ' FROM ' + this.departTableName(tid) +
  48. ' WHERE id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')';
  49. return await this.db.query(sql, []);
  50. } else {
  51. return [];
  52. }
  53. // this.initSqlBuilder();
  54. // this.sqlBuilder.setAndWhere('id', {
  55. // operate: 'in',
  56. // value: ids
  57. // });
  58. // this.sqlBuilder.columns = ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty'];
  59. // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName)
  60. // return await this.db.query(sql, sqlParam);
  61. }
  62. async getPosDataByUnits(tenderId, units) {
  63. const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
  64. ' FROM ' + this.departTableName(tenderId) + ' p' +
  65. ' LEFT JOIN ' + this.ctx.service.ledger.tableName + ' b' +
  66. ' ON p.lid = b.id ' +
  67. ' WHERE p.tid = ? and b.unit IN (?)';
  68. const sqlParam = [tenderId, units];
  69. return await this.db.query(sql, sqlParam);
  70. }
  71. async _insertPosData(transaction, data, tid) {
  72. data.id = this.uuid.v4();
  73. data.tid = tid;
  74. // todo 新增期
  75. data.add_stage = 0;
  76. data.add_stage_order = 0;
  77. data.add_times = 0;
  78. data.in_time = new Date();
  79. data.add_user = this.ctx.session.sessionUser.accountId;
  80. if (data.quantity) {
  81. const bills = await this.ctx.service.ledger.getDataById(data.lid);
  82. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  83. data.quantity = this.round(data.quantity, precision.value);
  84. }
  85. if (transaction) {
  86. const addRst = await transaction.insert(this.tableName, data);
  87. } else {
  88. const addRst = await this.db.insert(this.tableName, data);
  89. }
  90. }
  91. async _completeInsertPosData(tid, data) {
  92. data.id = this.uuid.v4();
  93. data.tid = tid;
  94. // todo 新增期
  95. data.add_stage = 0;
  96. data.add_stage_order = 0;
  97. data.add_times = 0;
  98. data.in_time = new Date();
  99. data.add_user = this.ctx.session.sessionUser.accountId;
  100. }
  101. async _getUpdateBills(data) {
  102. const datas = data instanceof Array ? data : [data];
  103. const bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
  104. const billsPos = await this.getAllDataByCondition({where: {tid: bills.tender_id, lid: bills.id} });
  105. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  106. const updateBills = {id: bills.id};
  107. for (const bp of billsPos) {
  108. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  109. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  110. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  111. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  112. }
  113. for (const d of datas) {
  114. if (d.sgfh_qty) {
  115. d.sgfh_qty = this.ctx.helper.round(d.sgfh_qty, precision.value);
  116. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
  117. }
  118. if (d.sjcl_qty) {
  119. d.sjcl_qty = this.ctx.helper.round(d.sjcl_qty, precision.value);
  120. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
  121. }
  122. if (d.qtcl_qty) {
  123. d.qtcl_qty = this.ctx.helper.round(d.qtcl_qty, precision.value);
  124. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
  125. }
  126. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  127. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
  128. }
  129. const info = this.ctx.tender.info;
  130. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  131. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  132. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  133. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  134. return updateBills;
  135. }
  136. async _addPosData(tid, data) {
  137. let updateBills = null;
  138. if (data instanceof Array) {
  139. for (const d of data) {
  140. this._completeInsertPosData(tid, d);
  141. }
  142. if (data[0].sgfh_qty !== undefined || data[0].sjcl_qty !== undefined || data[0].qtcl_qty !== undefined) {
  143. updateBills = await this._getUpdateBills(data);
  144. }
  145. } else {
  146. this._completeInsertPosData(tid, data);
  147. if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
  148. updateBills = await this._getUpdateBills(data);
  149. }
  150. }
  151. if (updateBills) {
  152. const transaction = await this.db.beginTransaction();
  153. try {
  154. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  155. updateBills.ledger_id = bills.ledger_id;
  156. await transaction.commit();
  157. } catch (err) {
  158. await transaction.rollback();
  159. throw err;
  160. }
  161. return {
  162. ledger: { update: [updateBills] },
  163. pos: data,
  164. }
  165. } else {
  166. await this.db.insert(this.tableName, data);
  167. return { pos: data }
  168. }
  169. }
  170. async _updatePosData(tid, data) {
  171. if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
  172. const op = await this.getDataById(data.id);
  173. const bills = await this.ctx.service.ledger.getDataById(op.lid);
  174. if (!bills) throw '数据错误';
  175. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
  176. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  177. if (data.sgfh_qty !== undefined) {
  178. data.sgfh_qty = this.round(data.sgfh_qty, precision.value);
  179. } else if (op) {
  180. data.sgfh_qty = op.sgfh_qty;
  181. }
  182. if (data.sjcl_qty !== undefined) {
  183. data.sjcl_qty = this.round(data.sjcl_qty, precision.value);
  184. } else if (op) {
  185. data.sjcl_qty = op.sjcl_qty;
  186. }
  187. if (data.qtcl_qty !== undefined) {
  188. data.qtcl_qty = this.round(data.qtcl_qty, precision.value);
  189. } else if (op) {
  190. data.qtcl_qty = op.qtcl_qty;
  191. }
  192. data.quantity = this.ctx.helper.sum([data.sgfh_qty, data.qtcl_qty, data.sjcl_qty]);
  193. const updateBills = {id: bills.id};
  194. for (const bp of billsPos) {
  195. const calcData = bp.id === data.id ? data : bp;
  196. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, calcData.sgfh_qty);
  197. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
  198. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
  199. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
  200. }
  201. const info = this.ctx.tender.info;
  202. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  203. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  204. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  205. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  206. const transaction = await this.db.beginTransaction();
  207. try {
  208. await transaction.update(this.tableName, data);
  209. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  210. await transaction.commit();
  211. updateBills.ledger_id = bills.ledger_id;
  212. return {
  213. ledger: { update: [updateBills] },
  214. pos: data,
  215. }
  216. } catch(err) {
  217. await transaction.rollback();
  218. throw err;
  219. }
  220. } else {
  221. await this.db.update(this.tableName, data);
  222. return {pos: data};
  223. }
  224. }
  225. async _updatePosDatas(tid, data) {
  226. if (data.length === 0) return;
  227. const op = await this.getDataById(data[0].id);
  228. const bills = await this.ctx.service.ledger.getDataById(op.lid);
  229. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
  230. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  231. let needUpdateBills;
  232. for (const d of data) {
  233. if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
  234. if (d.sgfh_qty !== undefined) {
  235. d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
  236. } else if (op) {
  237. d.sgfh_qty = op.sgfh_qty;
  238. }
  239. if (d.sjcl_qty !== undefined) {
  240. d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
  241. } else if (op) {
  242. d.sjcl_qty = op.sjcl_qty;
  243. }
  244. if (d.qtcl_qty !== undefined) {
  245. d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
  246. } else if (op) {
  247. d.qtcl_qty = op.qtcl_qty;
  248. }
  249. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  250. needUpdateBills = true;
  251. }
  252. }
  253. const updateBills = {id: bills.id};
  254. if (needUpdateBills) {
  255. for (const bp of billsPos) {
  256. const newPos = data.find(function (x) { return x.id === bp.id });
  257. updateBills.sgfh_qty = newPos && newPos.sgfh_qty !== undefined
  258. ? this.ctx.helper.add(updateBills.sgfh_qty, newPos.sgfh_qty)
  259. : this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  260. updateBills.sjcl_qty = newPos && newPos.sjcl_qty !== undefined
  261. ? this.ctx.helper.add(updateBills.sjcl_qty, newPos.sjcl_qty)
  262. : this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  263. updateBills.qtcl_qty = newPos && newPos.qtcl_qty !== undefined
  264. ? this.ctx.helper.add(updateBills.qtcl_qty, newPos.qtcl_qty)
  265. : this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  266. updateBills.quantity = newPos && newPos.quantity !== undefined
  267. ? this.ctx.helper.add(updateBills.quantity, newPos.quantity)
  268. : this.ctx.helper.add(updateBills.quantity, bp.quantity);
  269. }
  270. const info = this.ctx.tender.info;
  271. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  272. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  273. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  274. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  275. }
  276. const transaction = await this.db.beginTransaction();
  277. try {
  278. for (const d of data) {
  279. await transaction.update(this.tableName, d);
  280. }
  281. if (needUpdateBills) await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  282. await transaction.commit();
  283. updateBills.ledger_id = bills.ledger_id;
  284. return {
  285. ledger: { update: [updateBills] },
  286. pos: data,
  287. }
  288. } catch(err) {
  289. await transaction.rollback();
  290. throw err;
  291. }
  292. }
  293. async _deletePosData(tid, data) {
  294. if (!data || data.length === 0) throw '提交数据错误';
  295. const pos = await this.getPosData({tid: tid, id: data});
  296. if (!pos || pos.length === 0) throw '删除的计量单元不存在';
  297. const bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
  298. const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
  299. const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
  300. for (const bp of billsPos) {
  301. if (data.indexOf(bp.id) >= 0) continue;
  302. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  303. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  304. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  305. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  306. }
  307. const info = this.ctx.tender.info;
  308. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  309. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  310. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  311. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  312. const transaction = await this.db.beginTransaction();
  313. try {
  314. await transaction.delete(this.tableName, {tid: tid, id: data});
  315. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  316. await transaction.commit();
  317. updateBills.ledger_id = bills.ledger_id;
  318. return { ledger: { update: [updateBills] }, pos: data };
  319. } catch(err) {
  320. await transaction.rollback();
  321. throw err;
  322. }
  323. }
  324. async _insertPosData(tid, data) {
  325. if (!data.length) return;
  326. let porder = data[0].porder, lid = data[0].lid;
  327. for (const d of data) {
  328. this._completeInsertPosData(tid, d);
  329. porder = Math.min(porder, d.porder);
  330. }
  331. const transaction = await this.db.beginTransaction();
  332. try {
  333. this.initSqlBuilder();
  334. this.sqlBuilder.setAndWhere('lid', {
  335. value: this.db.escape(lid),
  336. operate: '=',
  337. });
  338. this.sqlBuilder.setAndWhere('porder', {
  339. value: porder,
  340. operate: '>=',
  341. });
  342. this.sqlBuilder.setUpdateData('porder', {
  343. value: data.length,
  344. selfOperate: '+',
  345. });
  346. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  347. const result = await transaction.query(sql, sqlParam);
  348. await transaction.insert(this.tableName, data);
  349. await transaction.commit();
  350. } catch (err) {
  351. await transaction.rollback();
  352. throw err;
  353. }
  354. this.initSqlBuilder();
  355. this.sqlBuilder.setAndWhere('lid', {
  356. value: this.db.escape(lid),
  357. operate: '=',
  358. });
  359. this.sqlBuilder.setAndWhere('porder', {
  360. value: porder,
  361. operate: '>=',
  362. });
  363. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  364. const update = await this.db.query(sql, sqlParam);
  365. return { pos: update }
  366. }
  367. /**
  368. * 保存部位明细数据
  369. * @param data
  370. * @param {Number} tid - 标段id
  371. * @returns {Promise<{ledger: {}, pos: null}>}
  372. */
  373. async savePosData(data, tid) {
  374. switch (data.updateType) {
  375. case 'add':
  376. return await this._addPosData(tid, data.updateData);
  377. case 'update':
  378. if (data.updateData instanceof Array) {
  379. return await this._updatePosDatas(tid, data.updateData);
  380. } else {
  381. return await this._updatePosData(tid, data.updateData);
  382. }
  383. case 'delete':
  384. return await this._deletePosData(tid, data.updateData);
  385. case 'insert':
  386. return await this._insertPosData(tid, data.updateData);
  387. }
  388. }
  389. /**
  390. * 复制粘贴 部位明细数据
  391. * @param {Array} data - 复制粘贴的数据
  392. * @param {Number} tid - 标段id
  393. * @returns {Promise<{ledger: {}, pos: null}>}
  394. */
  395. async pastePosData(data, tid) {
  396. if (!(data instanceof Array)) {
  397. throw '提交数据错误';
  398. }
  399. const transaction = await this.db.beginTransaction();
  400. const result = { ledger: {}, pos: null };
  401. const bills = await this.ctx.service.ledger.getDataById(data[0].lid);
  402. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  403. const updateBills = {id: bills.id};
  404. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: bills.id} });
  405. for (const bp of billsPos) {
  406. const d = data.find(function (x) {
  407. return bp.id ? x.id === bp.id : false;
  408. });
  409. if (d) continue;
  410. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  411. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  412. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  413. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  414. }
  415. try {
  416. for (const d of data) {
  417. const op = d.id ? this._.find(billsPos, {id: d.id}) : null;
  418. if (d.sgfh_qty !== undefined) {
  419. d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
  420. } else if (op) {
  421. d.sgfh_qty = op.sgfh_qty;
  422. }
  423. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
  424. if (d.sjcl_qty !== undefined) {
  425. d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
  426. } else if (op) {
  427. d.sjcl_qty = op.sjcl_qty;
  428. }
  429. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
  430. if (d.qtcl_qty) {
  431. d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
  432. } else if (op) {
  433. d.qtcl_qty = op.qtcl_qty;
  434. }
  435. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
  436. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  437. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
  438. if (d.id) {
  439. await transaction.update(this.tableName, d);
  440. } else {
  441. this._completeInsertPosData(tid, d);
  442. await transaction.insert(this.tableName, d);
  443. }
  444. }
  445. const info = this.ctx.tender.info;
  446. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  447. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  448. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  449. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  450. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  451. updateBills.ledger_id = bills.ledger_id;
  452. await transaction.commit();
  453. } catch (err) {
  454. await transaction.rollback();
  455. throw err;
  456. }
  457. result.pos = data;
  458. result.ledger.update = [updateBills];
  459. return result;
  460. }
  461. /**
  462. * 删除清单下部位明细数据(删除清单时调用)
  463. *
  464. * @param transaction - 事务
  465. * @param tid - 标段id
  466. * @param lid - 清单id
  467. * @returns {Promise<void>}
  468. */
  469. async deletePosData(transaction, tid, lid) {
  470. await transaction.delete(this.tableName, {tid: tid, lid: lid});
  471. }
  472. async loadDataFromOss(tid, url) {
  473. const data = await this.ctx.helper.loadLedgerDataFromOss(url);
  474. const curData = await this.getAllDataByCondition({
  475. columns: ['id', 'gxby_status', 'gxby_limit', 'gxby_url', 'dagl_status', 'dagl_limit', 'dagl_url'],
  476. where: { tid: tid }
  477. });
  478. this.ctx.helper.assignRelaData(data, [
  479. { data: curData, fields: ['gxby_status', 'gxby_limit', 'gxby_url', 'dagl_status', 'dagl_limit', 'dagl_url'], prefix: '', relaId: 'id' },
  480. ]);
  481. return data;
  482. }
  483. }
  484. return Pos;
  485. };